void message_test_receiver() { message_receiver_tid = g_get_tid(); size_t buflen = 128; g_message msg; while (true) { int c = 1000; for (int i = 0; i < c; i++) { auto stat = g_recv_msg(message_receiver_tid, &msg); if (stat != G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) { klog("failed receiving with status %i", stat); break; } } klog("content: %i times * %i = %i", c, sizeof(g_message), c * sizeof(g_message)); } }
void RequestHandler::run() { if (!g_task_register_id(G_WINDOW_MANAGER_IDENTIFIER)) { g_logger::log("window manager: could not register with task identifier '%s'", (char*) G_WINDOW_MANAGER_IDENTIFIER); return; } uint32_t tid = g_get_tid(); g_logger::log("window manager: ready for requests"); while (true) { g_message* request = new g_message; g_recv_msg(tid, request); if (request->type == G_UI_COMMAND_OPEN_REQUEST) { g_create_thread_d((void*) handling_thread, (void*) request); } else { g_logger::log("window manager: received unknown command %i from task %i", request->type, request->sender); } } }
/** * 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; }
g_spawn_status g_spawn_poi(const char* path, const char* args, const char* workdir, g_security_level securityLevel, g_pid* pid, g_fd out_stdio[3], g_fd in_stdio[3]) { g_spawn_status res = G_SPAWN_STATUS_UNKNOWN; uint32_t tid = g_get_tid(); // get spawner task identifier g_tid spawner_tid = g_task_get_id(G_SPAWNER_IDENTIFIER); if (spawner_tid == -1) { return res; } // create transaction g_message_transaction tx = g_get_message_tx_id(); // create request size_t path_bytes = __g_strlen(path) + 1; size_t args_bytes = __g_strlen(args) + 1; size_t workdir_bytes = __g_strlen(workdir) + 1; size_t requestlen = sizeof(g_spawn_command_spawn_request) + path_bytes + args_bytes + workdir_bytes; g_local<uint8_t> _request(new uint8_t[requestlen]); uint8_t* request = _request(); // copy request contents g_spawn_command_spawn_request* req = (g_spawn_command_spawn_request*) request; req->header.command = G_SPAWN_COMMAND_SPAWN_REQUEST; req->security_level = securityLevel; req->path_bytes = path_bytes; req->args_bytes = args_bytes; req->workdir_bytes = workdir_bytes; if (in_stdio != nullptr) { req->stdin = in_stdio[0]; req->stdout = in_stdio[1]; req->stderr = in_stdio[2]; } else { req->stdin = G_FD_NONE; req->stdout = G_FD_NONE; req->stderr = G_FD_NONE; } uint8_t* insert = request; insert += sizeof(g_spawn_command_spawn_request); __g_memcpy(insert, path, path_bytes); insert += path_bytes; __g_memcpy(insert, args, args_bytes); insert += args_bytes; __g_memcpy(insert, workdir, workdir_bytes); // send request to spawner g_send_message_t(spawner_tid, request, requestlen, tx); // receive response size_t resp_len = sizeof(g_message_header) + sizeof(g_spawn_command_spawn_response); g_local<uint8_t> resp_buf(new uint8_t[resp_len]); g_receive_message_t(resp_buf(), resp_len, tx); g_spawn_command_spawn_response* response = (g_spawn_command_spawn_response*) G_MESSAGE_CONTENT(resp_buf()); // if successful, take response parameters if (response->status == G_SPAWN_STATUS_SUCCESSFUL) { if (pid != nullptr) { *pid = response->spawned_process_id; } if (out_stdio != nullptr) { out_stdio[0] = response->stdin_write; out_stdio[1] = response->stdout_read; out_stdio[2] = response->stderr_read; } } return response->status; }