/* Sends UI command to the core. * Param: * cmd_type, cmd_param, cmd_param_size - Define the command. * Return: * 0 On success, or < 0 on failure. */ static int _coreCmdProxy_send_command(uint8_t cmd_type, void* cmd_param, uint32_t cmd_param_size) { int status; UICmdHeader header; // Prepare the command header. header.cmd_type = cmd_type; header.cmd_param_size = cmd_param_size; status = syncsocket_start_write(_coreCmdProxy.sync_writer); if (!status) { // Send the header. status = syncsocket_write(_coreCmdProxy.sync_writer, &header, sizeof(header), core_connection_get_timeout(sizeof(header))); // If there is request data, send it too. if (status > 0 && cmd_param != NULL && cmd_param_size > 0) { status = syncsocket_write(_coreCmdProxy.sync_writer, cmd_param, cmd_param_size, core_connection_get_timeout(cmd_param_size)); } status = syncsocket_result(status); syncsocket_stop_write(_coreCmdProxy.sync_writer); } if (status < 0) { derror("Unable to send UI control command %d (size %u): %s\n", cmd_type, cmd_param_size, errno_str); } return status; }
/* Reads UI control command response from the core. * Param: * resp - Upon success contains command response header. * resp_data - Upon success contains allocated reponse data (if any). The caller * is responsible for deallocating the memory returned here. * Return: * 0 on success, or < 0 on failure. */ static int _coreCmdProxy_get_response(UICmdRespHeader* resp, void** resp_data) { int status = syncsocket_start_read(_coreCmdProxy.sync_reader); if (!status) { // Read the header. status = syncsocket_read(_coreCmdProxy.sync_reader, resp, sizeof(UICmdRespHeader), core_connection_get_timeout(sizeof(UICmdRespHeader))); // Read response data (if any). if (status > 0 && resp->resp_data_size) { *resp_data = malloc(resp->resp_data_size); if (*resp_data == NULL) { APANIC("_coreCmdProxy_get_response is unable to allocate response data buffer.\n"); } status = syncsocket_read(_coreCmdProxy.sync_reader, *resp_data, resp->resp_data_size, core_connection_get_timeout(resp->resp_data_size)); } status = syncsocket_result(status); syncsocket_stop_read(_coreCmdProxy.sync_reader); } if (status < 0) { derror("Unable to get UI command response from the Core: %s\n", errno_str); } return status; }
static int _userEventsProxy_send(uint8_t event, const void* event_param, size_t size) { int res; UserEventHeader header; header.event_type = event; res = syncsocket_start_write(_userEventsProxy.sync_writer); if (!res) { res = syncsocket_write(_userEventsProxy.sync_writer, &header, sizeof(header), core_connection_get_timeout(sizeof(header))); if (res > 0) { res = syncsocket_write(_userEventsProxy.sync_writer, event_param, size, core_connection_get_timeout(sizeof(size))); } res = syncsocket_result(res); syncsocket_stop_write(_userEventsProxy.sync_writer); } if (res < 0) { derror("Unable to send user event: %s\n", errno_str); } return res; }