/** * 发送请求负载,读取返回内容。如果发送或接受过程出错,返回-1,否则返回0 **/ static si_t send_request_and_recv_respond(si_t request_type, si_t respond_type, const_addr_t body, ui_t body_size, addr_t result) { if(0 != comm_send_request(lib_uds, request_type, body, body_size)) { EGUI_PRINT_ERROR("failed to send request[%s]", request_type_to_str(request_type)); return -1; } if(0 != comm_recv_respond(lib_uds, respond_type, result, message_queue)) { EGUI_PRINT_ERROR("failed to receive respond[%s]", respond_type_to_str(respond_type)); return -1; } return 0; }
/** * 发送window_manager_exit请求 **/ int fake_window_manager_exit(struct egui_uds* uds_ptr) { si_t ret = 0; if(0 != comm_send_request(uds_ptr, REQUEST_TYPE_WINDOW_MANAGER_QUIT, NULL, 0)) { EGUI_PRINT_ERROR("failed to send window manager exit request"); return -1; } if(0 != comm_recv_respond(uds_ptr, RESPOND_TYPE_WINDOW_MANAGER_QUIT, &ret, NULL)) { EGUI_PRINT_ERROR("failed to recv window manager exit respond"); return -1; } EGUI_PRINT_INFO("send window manager exit request, recv ret %d", (int)ret); return ret; }
/** * 发送带有附加内容的负载,读取返回的retval。如果发送或接受过程出错或malloc失败返回-1,否则返回回应包的retval * * @param request_type 请求类型 * @param respond_type 回应类型 * @param body 标准负载指针 * @param body_len 标准负载的长度 * @param extra_context 附加内容指针 * @param extra_context_len 附加内容长度 **/ static si_t send_body_with_extra_context_and_return_respond(si_t request_type, si_t respond_type, const_addr_t body , ui_t body_len, const_addr_t extra_context, ui_t extra_context_len) { si_t result = 0; if(0 != comm_send_request_with_extra(lib_uds, request_type, body, body_len, extra_context, extra_context_len)) { EGUI_PRINT_ERROR("failed to send request[%s] with extra content", request_type_to_str(request_type)); return -1; } if(0 != comm_recv_respond(lib_uds, respond_type, &result, message_queue)) { EGUI_PRINT_ERROR("failed to receive respond[%s]", respond_type_to_str(respond_type)); return -1; } return result; }
/** * 发送draw line请求 **/ int fake_draw_line(struct egui_uds* uds_ptr, si_t x1, si_t y1, si_t x2, si_t y2) { struct packet_body_draw_line body; si_t ret = 0; request_set_draw_line(&body, 0, x1, y1, x2, y2); if(0 != comm_send_request(uds_ptr, REQUEST_TYPE_DRAW_LINE, &body, sizeof(body))) { EGUI_PRINT_ERROR("failed to send draw line request"); return -1; } if(0 != comm_recv_respond(uds_ptr, RESPOND_TYPE_DRAW_LINE, &ret, NULL)) { EGUI_PRINT_ERROR("failed to recv draw line respond"); return -1; } EGUI_PRINT_INFO("send draw line request, recv ret %d", (int)ret); return ret; }
/** * 发送注册窗口请求 **/ int fake_register_window(struct egui_uds* uds_ptr, si_t parent_fd, char* title) { struct packet_body_register_window body; si_t ret = 0; request_set_register_window(&body, parent_fd, title, strlen(title) + 1, 0, 0, 0, 0, 0, 0, 0); if(0 != comm_send_request_with_extra(uds_ptr, REQUEST_TYPE_REGISTER_WINDOW, &body, sizeof(body), title, strlen(title) + 1)) { EGUI_PRINT_ERROR("failed to send register window request"); return -1; } if(0 != comm_recv_respond(uds_ptr, RESPOND_TYPE_REGISTER_WINDOW, &ret, NULL)) { EGUI_PRINT_ERROR("failed to recv register window respond"); return -1; } EGUI_PRINT_INFO("send register window request, recv ret %d", (int)ret); return 0; }