// redirect void g_pipe(g_fd* out_write, g_fd* out_read) { return g_pipe_s(out_write, out_read, 0); }
/** * Opens a connection to the window server. */ g_ui_open_status g_ui::open() { // check if already open if (g_ui_ready) { return G_UI_OPEN_STATUS_EXISTING; } // get window managers id g_tid window_mgr = g_task_get_id(G_WINDOW_MANAGER_IDENTIFIER); if (window_mgr == -1) { g_logger::log("failed to retrieve task id of window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // open in/out pipes g_fs_pipe_status status; g_fd g_ui_channel_out_read; g_pipe_s(&g_ui_channel_out, &g_ui_channel_out_read, &status); g_fd g_ui_channel_in_write; g_pipe_s(&g_ui_channel_in_write, &g_ui_channel_in, &status); if (status == G_FS_PIPE_ERROR) { g_logger::log("failed to open UI communication pipe"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // tell window manager to open uint32_t topic = g_ipc_next_topic(); g_message_empty(open_request); open_request.type = G_UI_COMMAND_OPEN_REQUEST; open_request.topic = topic; open_request.parameterA = g_ui_channel_out_read; open_request.parameterB = g_ui_channel_in_write; auto request_status = g_send_msg(window_mgr, &open_request); if (request_status != G_MESSAGE_SEND_STATUS_SUCCESSFUL) { g_logger::log("failed to send UI-open request to window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // wait for response g_message_empty(open_response); auto response_status = g_recv_topic_msg(g_get_tid(), topic, &open_response); if (response_status != G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) { g_logger::log("failed to receive UI-open response from window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // check response message if (open_response.type != G_UI_COMMAND_OPEN_RESPONSE) { g_logger::log("window servers UI-open response was not a proper 'opened'-response"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // start asynchronous receiver g_create_thread((void*) &asynchronous_receiver_thread); g_create_thread((void*) &event_dispatch_thread); // mark UI as ready g_logger::log("successfully opened UI in window server"); g_ui_ready = true; return G_UI_OPEN_STATUS_SUCCESSFUL; }