OpenXR Monado创建跨进程通信通道 ipc_connect
OpenXR Monado创建跨进程通信通道 ipc_connect
@monado/src/xrt/targets/openxr/target.c
xrt_instance_create
@monado/src/xrt/ipc/client/ipc_client_instance.c
ipc_instance_create(ii, out_xinst);
ipc_connect
ipc_c->ica = ipc_client_android_create(android_globals_get_vm(), android_globals_get_activity());
@monado/src/xrt/ipc/android/ipc_client_android.cpp
int socket = ipc_client_android_blocking_connect(ipc_c->ica);
@monado/src/xrt/ipc/android/org.freedesktop.monado.ipc.impl.hpp
int fd = ica->client.blockingConnect(ica->activity, XRT_ANDROID_PACKAGE); // blockingConnect(classRef().getMethod("blockingConnect", "(Landroid/content/Context;Ljava/lang/String;)I"))
@monado/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/Client.java
blockingConnect(Context context_, String packageName) //packageName=org.freedesktop.monado.openxr_runtime.out_of_process
bind(context_, packageName)
Intent intent = new Intent(BuildConfig.SERVICE_ACTION).setPackage(packageName); // String SERVICE_ACTION = "org.freedesktop.monado.ipc.CONNECT";
bindService(context, intent)
result = context.bindService(intent, this, flags);
@monado/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/MonadoService.kt
MonadoService::onCreate
val intent = Intent(this, javaClass)
intent.action = BuildConfig.SERVICE_ACTION
startService(intent) //启动org.freedesktop.monado.ipc.MonadoService服务
onServiceConnected
monado = IMonado.Stub.asInterface(service);
ParcelFileDescriptor[] fds = ParcelFileDescriptor.createSocketPair();
ours = fds[0]; //75
theirs = fds[1]; //76
fd = ours;
@monado/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/MonadoImpl.java
monado.connect(theirs); //跨进程,进入server进程
int fd = parcelFileDescriptor.getFd(); //78(从76复制过来)
@monado/src/xrt/targets/service-lib/service_target.cpp
nativeAddClient(fd) //Java_org_freedesktop_monado_ipc_MonadoImpl_nativeAddClient
return IpcServerHelper::instance().addClient(fd);
@monado/src/xrt/ipc/server/ipc_server_mainloop_android.c
return ipc_server_mainloop_add_fd(server, &server->ml, fd);
int ret = write(ml->pipe_write, &newfd, sizeof(newfd)); //pipe_write=82, newfd=78
int ret = epoll_wait(epoll_fd, events, NUM_POLL_EVENTS, NO_SLEEP);
if (events[i].data.fd == ml->pipe_read) { handle_listen(vs, ml); }
read(ml->pipe_read, &newfd, sizeof(newfd)) //pipe_read=81,newfd=78
ml->last_accepted_fd = newfd;
@monado/src/xrt/ipc/server/ipc_server_process.c
ipc_server_start_client_listener_thread(vs, newfd);
ics->imc.ipc_handle = ipc_handle; //ipc_handle=78,openxr_runtime.out_of_process-25265
os_thread_start(&it->thread, ipc_server_client_thread, (void *)ics);
@monado/src/xrt/ipc/server/ipc_server_per_client_thread.c
ipc_server_client_thread //新线程,openxr_runtime.out_of_process-26722
volatile struct ipc_client_state *ics = (volatile struct ipc_client_state *)_ics;
client_loop(ics);
while (ics->server->running) { //开启线程循环
int ret = epoll_wait(epoll_fd, &event, 1, half_a_second_ms);
ssize_t len = recv(ics->imc.ipc_handle, &buf, IPC_BUF_SIZE, 0); //ipc_handle=78
@monado/src/xrt/targets/openxr_android/.cxx/Debug/4h1i2215/arm64-v8a/src/xrt/ipc/ipc_server_generated.c
xrt_result_t result = ipc_dispatch(ics, ipc_command);
@monado/src/xrt/ipc/server/ipc_server_handler.c
case IPC_SWAPCHAIN_ACQUIRE_IMAGE: reply.result = ipc_handle_swapchain_acquire_image(ics, msg->id,&reply.index);
xrt_result_t ret = ipc_send((struct ipc_message_channel *)&ics->imc, &reply, sizeof(reply));
return fd.getFd();
socket = dup(socket); //复制一份fd=77,openxr.hello_xr.opengles
ipc_c->imc.ipc_handle = socket; //77
@monado/src/xrt/targets/openxr/target.c xrt_instance_create @monado/src/xrt/ipc/client/ipc_client_instance.c ipc_instance_create(ii, out_xinst); ipc_connect ipc_c->ica = ipc_client_android_create(android_globals_get_vm(), android_globals_get_activity()); @monado/src/xrt/ipc/android/ipc_client_android.cpp int socket = ipc_client_android_blocking_connect(ipc_c->ica); @monado/src/xrt/ipc/android/org.freedesktop.monado.ipc.impl.hpp int fd = ica->client.blockingConnect(ica->activity, XRT_ANDROID_PACKAGE); // blockingConnect(classRef().getMethod("blockingConnect", "(Landroid/content/Context;Ljava/lang/String;)I")) @monado/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/Client.java blockingConnect(Context context_, String packageName) //packageName=org.freedesktop.monado.openxr_runtime.out_of_process bind(context_, packageName) Intent intent = new Intent(BuildConfig.SERVICE_ACTION).setPackage(packageName); // String SERVICE_ACTION = "org.freedesktop.monado.ipc.CONNECT"; bindService(context, intent) result = context.bindService(intent, this, flags); @monado/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/MonadoService.kt MonadoService::onCreate val intent = Intent(this, javaClass) intent.action = BuildConfig.SERVICE_ACTION startService(intent) //启动org.freedesktop.monado.ipc.MonadoService服务 onServiceConnected monado = IMonado.Stub.asInterface(service); ParcelFileDescriptor[] fds = ParcelFileDescriptor.createSocketPair(); ours = fds[0]; //75 theirs = fds[1]; //76 fd = ours; @monado/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/MonadoImpl.java monado.connect(theirs); //跨进程,进入server进程 int fd = parcelFileDescriptor.getFd(); //78(从76复制过来) @monado/src/xrt/targets/service-lib/service_target.cpp nativeAddClient(fd) //Java_org_freedesktop_monado_ipc_MonadoImpl_nativeAddClient return IpcServerHelper::instance().addClient(fd); @monado/src/xrt/ipc/server/ipc_server_mainloop_android.c return ipc_server_mainloop_add_fd(server, &server->ml, fd); int ret = write(ml->pipe_write, &newfd, sizeof(newfd)); //pipe_write=82, newfd=78 int ret = epoll_wait(epoll_fd, events, NUM_POLL_EVENTS, NO_SLEEP); if (events[i].data.fd == ml->pipe_read) { handle_listen(vs, ml); } read(ml->pipe_read, &newfd, sizeof(newfd)) //pipe_read=81,newfd=78 ml->last_accepted_fd = newfd; @monado/src/xrt/ipc/server/ipc_server_process.c ipc_server_start_client_listener_thread(vs, newfd); ics->imc.ipc_handle = ipc_handle; //ipc_handle=78,openxr_runtime.out_of_process-25265 os_thread_start(&it->thread, ipc_server_client_thread, (void *)ics); @monado/src/xrt/ipc/server/ipc_server_per_client_thread.c ipc_server_client_thread //新线程,openxr_runtime.out_of_process-26722 volatile struct ipc_client_state *ics = (volatile struct ipc_client_state *)_ics; client_loop(ics); while (ics->server->running) { //开启线程循环 int ret = epoll_wait(epoll_fd, &event, 1, half_a_second_ms); ssize_t len = recv(ics->imc.ipc_handle, &buf, IPC_BUF_SIZE, 0); //ipc_handle=78 @monado/src/xrt/targets/openxr_android/.cxx/Debug/4h1i2215/arm64-v8a/src/xrt/ipc/ipc_server_generated.c xrt_result_t result = ipc_dispatch(ics, ipc_command); @monado/src/xrt/ipc/server/ipc_server_handler.c case IPC_SWAPCHAIN_ACQUIRE_IMAGE: reply.result = ipc_handle_swapchain_acquire_image(ics, msg->id,&reply.index); xrt_result_t ret = ipc_send((struct ipc_message_channel *)&ics->imc, &reply, sizeof(reply)); return fd.getFd(); socket = dup(socket); //复制一份fd=77,openxr.hello_xr.opengles ipc_c->imc.ipc_handle = socket; //77