/** * This method will be invoked whene the rw.cli executes a command and * requires a transport to send the message. */ static rw_status_t messaging_hook(NetconfReq *req, NetconfRsp **rsp) { // Send message to the CLI-AGENT and wait for a message back unsigned msg_len = netconf_req__get_packed_size(NULL, req); uint8_t msg_buf[msg_len]; rw_status_t status; netconf_req__pack(NULL, req, msg_buf); if (rwcli_agent_ch.in.fd.write == -1) { RWTRACE_CRIT(rwcli_trace, RWTRACE_CATEGORY_RWCLI, "Messaging not initialized, failed to execute the command"); return RW_STATUS_FAILURE; } // Consume any prvious unread messages on the stream consume_unread_agent_messages(); // TODO handle EPIPE write(rwcli_agent_ch.in.fd.write, (const void*)(&msg_len), sizeof(unsigned)); write(rwcli_agent_ch.in.fd.write, msg_buf, msg_len); RWTRACE_DEBUG(rwcli_trace, RWTRACE_CATEGORY_RWCLI, "\nSHELL: sent %d bytes to CLI-AGENT", msg_len); status = recv_msg_from_agent(&msg_len); if (status != RW_STATUS_SUCCESS) { *rsp = NULL; return status; } RWTRACE_DEBUG(rwcli_trace, RWTRACE_CATEGORY_RWCLI, "\nSHELL: received %u bytes from CLI-AGENT msglen\n", msg_len); rw_resp = netconf_rsp__unpack(NULL, msg_len, recv_buf); if (rw_resp == NULL) { RWTRACE_ERROR(rwcli_trace, RWTRACE_CATEGORY_RWCLI, "\nReceived message unpack failed\n"); *rsp = NULL; return RW_STATUS_FAILURE; } *rsp = rw_resp; return RW_STATUS_SUCCESS; }
/** * Executes a request towards the specified agent and receives the response. * The response is stored in rwcli_controller.recv_buf. * * @param[in] inst - Controller instance * @param[in] agent_type - Agent on which the command is to be executed * @param[in] msg_type - Message type * @param[in] msg_buf - Reqest payload (encoded) * @param[in] msg_len - Size of the Request payload * @param[out] recv_msg_len - Size of the received message (encoded) * * @returns RW_STATUS_SUCCESS on success, RW_STATUS_FAILURE otherwise. */ static rw_status_t controller_execute( rwcli_controller_t* inst, rwcli_transport_mode_t agent_type, rwcli_msg_type_t msg_type, uint8_t* msg_buf, unsigned msg_len, unsigned* recv_msg_len) { rw_status_t status = RW_STATUS_SUCCESS; if (!controller_is_channel_initialized(inst, agent_type)) { RWTRACE_CRIT(inst->trace_ctxt, RWTRACE_CATEGORY_RWCLI, "Messaging not initialized, failed to execute the command"); return RW_STATUS_FAILURE; } // Consume any previous unread messages on the stream controller_consume_unread_agent_messages(inst, agent_type); status = controller_send_to_agent(inst, agent_type, msg_type, msg_buf, msg_len); if (status != RW_STATUS_SUCCESS) { return status; } RWTRACE_DEBUG(inst->trace_ctxt, RWTRACE_CATEGORY_RWCLI, "\nSHELL: sent %d bytes to CLI-AGENT", msg_len); status = controller_recv_from_agent(inst, agent_type, recv_msg_len); if (status != RW_STATUS_SUCCESS) { return status; } RWTRACE_DEBUG(inst->trace_ctxt, RWTRACE_CATEGORY_RWCLI, "\nSHELL: received %u bytes from CLI-AGENT msglen\n", *recv_msg_len); return status; }
static void init_rwtrace(rwvx_instance_ptr_t rwvx, char ** argv) { rw_status_t status; char * cmdline; status = rwtrace_ctx_category_severity_set( rwvx->rwtrace, RWTRACE_CATEGORY_RWMAIN, RWTRACE_SEVERITY_DEBUG); RW_ASSERT(status == RW_STATUS_SUCCESS); status = rwtrace_ctx_category_destination_set( rwvx->rwtrace, RWTRACE_CATEGORY_RWMAIN, RWTRACE_DESTINATION_CONSOLE); RW_ASSERT(status == RW_STATUS_SUCCESS); cmdline = g_strjoinv(" | ", argv); RWTRACE_DEBUG( rwvx->rwtrace, RWTRACE_CATEGORY_RWMAIN, "main() entered, cmdline = \"%s\"", cmdline); g_free(cmdline); }