void frame_received (VortexChannel * channel, VortexConnection * connection, VortexFrame * frame, axlPointer user_data) { int iterator = 10; printf ("A frame received on channl: %d\n", vortex_channel_get_number (channel)); printf ("Data received: '%s'\n", (char*) vortex_frame_get_payload (frame)); /* reply the peer client with the same content 10 times */ while (iterator >= 0) { printf ("Sending the reply..\n"); if (! vortex_channel_send_ans_rpyv (channel, vortex_frame_get_msgno (frame), "Received Ok(%d): %s", iterator, vortex_frame_get_payload (frame))) { fprintf (stderr, "There was an error while sending the reply message"); } printf ("Reply: %d sent..\n", iterator); iterator--; } /* send the last reply. */ if (!vortex_channel_finalize_ans_rpy (channel, vortex_frame_get_msgno (frame))) { fprintf (stderr, "There was an error while sending the NUL reply message"); } printf ("VORTEX_LISTENER: end task (pid: %d)\n", getpid ()); return; }
void test_22_frame_received (VortexChannel * channel, VortexConnection * conn, VortexFrame * frame, axlPointer user_data) { const char * payload = (const char *) vortex_frame_get_payload (frame); char * value; if (axl_cmp (payload, "getServerName")) { /* get servername or empty string */ payload = vortex_connection_get_server_name (conn); if (payload == NULL) payload = ""; vortex_channel_send_rpy (channel, payload, strlen (payload), vortex_frame_get_msgno (frame)); return; } /* end if */ /* support for getRemoveAddress */ if (axl_cmp (payload, "getRemoteAddress")) { value = axl_strdup_printf ("%s:%s", vortex_connection_get_host (conn), vortex_connection_get_port (conn)); printf ("Test 28: (SERVER), sending %s (%d)\n", value, (int) strlen (value)); vortex_channel_send_rpy (channel, value, strlen (value), vortex_frame_get_msgno (frame)); axl_free (value); return; } /* end if */ /* send rpy */ vortex_channel_send_rpy (channel, vortex_frame_get_payload (frame), vortex_frame_get_payload_size (frame), vortex_frame_get_msgno (frame)); return; }
void mod_test_11_frame_received (VortexChannel * channel, VortexConnection * connection, VortexFrame * frame, axlPointer user_data) { /* get the command */ const char * command = (const char *) vortex_frame_get_payload (frame); char * result; axlList * connList; msg ("Received command: '%s'", command); if (axl_cmp (command, "content")) { if (axl_cmp (vortex_connection_get_server_name (connection), "test-12.third-server")) { /* send reply */ vortex_channel_send_rpy (channel, "profile path notified for test-12.third-server", 46, vortex_frame_get_msgno (frame)); } else { /* send reply */ vortex_channel_send_rpy (channel, "profile path notified", 21, vortex_frame_get_msgno (frame)); } } else if (axl_cmp (command, "connections count")) { /* get the list of connections */ connList = turbulence_conn_mgr_conn_list (ctx, VortexRoleListener, NULL); result = axl_strdup_printf ("%d", axl_list_length (connList)); vortex_channel_send_rpy (channel, result, strlen (result), vortex_frame_get_msgno (frame)); axl_free (result); axl_list_free (connList); } return; }
void test_16_received (VortexChannel * channel, VortexConnection * connection, VortexFrame * frame, axlPointer user_data) { char * result; if (vortex_frame_get_type (frame) == VORTEX_FRAME_TYPE_MSG) { if (axl_cmp (vortex_frame_get_payload (frame), "process-id")) { result = axl_strdup_printf ("%d", getpid ()); vortex_channel_send_rpy (channel, result, strlen (result), vortex_frame_get_msgno (frame)); axl_free (result); return; } /* do echo */ vortex_channel_send_rpy (channel, vortex_frame_get_payload (frame), vortex_frame_get_payload_size (frame), vortex_frame_get_msgno (frame)); return; } /* end if */ return; }
void test_10_received (VortexChannel * channel, VortexConnection * connection, VortexFrame * frame, axlPointer user_data) { #if ! defined(SHOW_FORMAT_BUGS) TurbulenceCtx * ctx = user_data; #endif TurbulencePPathDef * ppath_selected; msg ("Received frame request at child (pid: %d): %s", getpid (), (char*) vortex_frame_get_payload (frame)); /* send pid reply */ if (axl_cmp ("GET pid", (char*) vortex_frame_get_payload (frame))) vortex_channel_send_rpyv (channel, vortex_frame_get_msgno (frame), "%d", getpid ()); if (axl_cmp ("GET profile path", (char*) vortex_frame_get_payload (frame))) { ppath_selected = turbulence_ppath_selected (connection); vortex_channel_send_rpyv (channel, vortex_frame_get_msgno (frame), "%s", turbulence_ppath_get_name (ppath_selected)); } return; }
void frame_received (VortexChannel * channel, VortexConnection * connection, VortexFrame * frame, axlPointer user_data) { printf ("VORTEX_LISTENER: STARTED (pid: %d)\n", getpid ()); printf ("A frame received on channl: %d\n", vortex_channel_get_number (channel)); printf ("Data received: '%s'\n", (char*) vortex_frame_get_payload (frame)); /* reply */ vortex_channel_send_rpy (channel, "I have received you message, thanks..", 37, vortex_frame_get_msgno (frame)); printf ("VORTEX_LISTENER: CLOSE CHANNEL (pid: %d)\n", getpid ()); /* close the channel */ vortex_channel_close (channel, NULL); printf ("VORTEX_LISTENER: FINSHED (pid: %d)\n", getpid ()); return; }
void test_20_frame_received (VortexChannel * channel, VortexConnection * conn, VortexFrame * frame, axlPointer user_data) { const char * profile_path; TurbulencePPathDef * ppath; char * conn_id; if (axl_cmp ((const char *) vortex_frame_get_payload (frame), "get-profile-path-name")) { /* get profile path */ ppath = turbulence_ppath_selected (conn); if (ppath == NULL) { vortex_channel_send_rpy (channel, "no profile path selected!!!", 27, vortex_frame_get_msgno (frame)); return; } /* end if */ /* get profile path name */ profile_path = turbulence_ppath_get_name (ppath); if (profile_path == NULL) { vortex_channel_send_rpy (channel, "no profile path name defined", 28, vortex_frame_get_msgno (frame)); return; } printf ("Test 20: CHILD: returning profile path name: %s\n", profile_path); /* set profile path name */ vortex_channel_send_rpy (channel, profile_path, strlen (profile_path), vortex_frame_get_msgno (frame)); return; } /* send conn-id in case no other command was received */ conn_id = axl_strdup_printf ("%d", vortex_connection_get_id (conn)); vortex_channel_send_rpy (channel, conn_id, strlen (conn_id), vortex_frame_get_msgno (frame)); axl_free (conn_id); return; }
void frame_received (VortexChannel * channel, VortexConnection * connection, VortexFrame * frame, axlPointer user_data) { VortexAsyncQueue * queue; int iterator = 0; printf ("A frame received on channl: %d\n", vortex_channel_get_number (channel)); printf ("Data received: '%s'\n", (char*) vortex_frame_get_payload (frame)); if (vortex_frame_get_type (frame) == VORTEX_FRAME_TYPE_MSG) { /* send back a series of replies */ queue = vortex_async_queue_new (); while (iterator < 100) { /* wait during 50ms */ vortex_async_queue_timedpop (queue, 50000); /* send a reply */ vortex_channel_send_ans_rpy (channel, "This is a reply to the message", 30, vortex_frame_get_msgno (frame)); /* next message */ iterator++; } /* send NUL */ vortex_channel_finalize_ans_rpy (channel, vortex_frame_get_msgno (frame)); } printf ("VORTEX_LISTENER: end task (pid: %d)\n", getpid ()); return; }
int main (int argc, char ** argv) { /* the all frames received queue */ VortexAsyncQueue * queue; VortexFrame * frame; VortexChannel * channel; /* count */ int iterator = 0; /* create the context */ ctx = vortex_ctx_new (); /* init vortex library */ if (! vortex_init_ctx (ctx)) { /* unable to init context */ vortex_ctx_free (ctx); return -1; } /* end if */ /* create the queue */ queue = vortex_async_queue_new (); /* register a profile */ vortex_profiles_register (ctx, PROFILE_URI, /* no start handler, accept all channels */ NULL, NULL, /* no close channel, accept all * channels to be closed */ NULL, NULL, vortex_channel_queue_reply, queue); /* now create a vortex server listening on several ports */ vortex_listener_new (ctx, "0.0.0.0", "4400", NULL, NULL); /* and handle all frames received */ while (axl_true) { /* get the next message, blocking at this call. * * NOTE: This call must be evolved to something with * error handling, timeout and channel piggyback * support, but, for the example will do. */ frame = vortex_async_queue_pop (queue); if (frame == NULL) { /* for our example, the default action is: * keep on reading!. */ continue; } printf ("Frame received, content: %s\n", (char*) vortex_frame_get_payload (frame)); /* get the channel */ channel = vortex_frame_get_channel_ref (frame); /* reply */ vortex_channel_send_rpy (channel, vortex_frame_get_payload (frame), vortex_frame_get_payload_size (frame), vortex_frame_get_msgno (frame)); /* deallocate the frame received */ vortex_frame_free (frame); iterator++; /* close the channel */ if (iterator == 10) { /* close the channel */ if (! vortex_channel_close (channel, NULL)) { printf ("Unable to close the channel!\n"); } printf ("Ok, channel closed\n"); /* reset */ iterator = 0; } /* end if */ } /* end while */ /* end vortex internal subsystem (if no one have done it yet!) */ vortex_exit_ctx (ctx, axl_true); /* that's all to start BEEPing! */ return 0; }
/** * @brief a frame received Callback */ void listenerFrameReceivedCallback (VortexChannel* channel, VortexConnection* connection, VortexFrame* frame, axlPointer user_data) { VORTEXListenerFrameReceivedCallbackData* callbackData = (VORTEXListenerFrameReceivedCallbackData*) user_data; TML_INT32 iRet = TML_SUCCESS; ///////////////////////////////////////////////////////////////////////////// // Fetching all necessary attributes from Vortex: /////////////////////////// // Die Connection ID: callbackData->pLog->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "listenerFrameReceivedCallback", "Vortex CMD", "vortex_connection_get_id"); int iConnectionID = vortex_connection_get_id(connection); /////////////////////////// // Die Host IP: callbackData->pLog->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "listenerFrameReceivedCallback", "Vortex CMD", "vortex_connection_get_host_ip"); const char* sHostIP = vortex_connection_get_host_ip(connection); /////////////////////////// // Der Port: callbackData->pLog->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "listenerFrameReceivedCallback", "Vortex CMD", "vortex_connection_get_local_port"); const char* sPort = vortex_connection_get_port(connection); /////////////////////////// // Die Channel ID: callbackData->pLog->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "listenerFrameReceivedCallback", "Vortex CMD", "vortex_channel_get_number"); int iChannelID = vortex_channel_get_number (channel); if (-1 == iChannelID) iRet = TML_ERR_LISTENER_COMMUNICATION; /////////////////////////// // Die Message ID: callbackData->pLog->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "listenerFrameReceivedCallback", "Vortex CMD", "vortex_frame_get_msgno"); int iMsgID = vortex_frame_get_msgno (frame); if (-1 == iMsgID) iRet = TML_ERR_LISTENER_COMMUNICATION; /////////////////////////// // Das Profil, mit dem der Sender conneted ist: callbackData->pLog->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "listenerFrameReceivedCallback", "Vortex CMD", "vortex_channel_get_profile"); const char* sProfile = vortex_channel_get_profile (channel); if (NULL == sProfile) iRet = TML_ERR_LISTENER_COMMUNICATION; /////////////////////////// // Das Payload: callbackData->pLog->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "listenerFrameReceivedCallback", "Vortex CMD", "vortex_frame_get_payload"); char* cPayload = (char*)vortex_frame_get_payload (frame); if (NULL == cPayload) iRet = TML_ERR_LISTENER_COMMUNICATION; /////////////////////////// // Die Payloadsize: callbackData->pLog->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "listenerFrameReceivedCallback", "Vortex CMD", "vortex_frame_get_payload_size"); int iPayloadSize = vortex_frame_get_payload_size (frame); if (-1 == iPayloadSize) iRet = TML_ERR_LISTENER_COMMUNICATION; ///////////////////////////////////////////////////////////////////////////// // Set all necessary Vortex attributes into the TML_COMMAND_HANDLE Obj: if (TML_SUCCESS == iRet){ // A new TML_COMMAND_HANDLE object out of the payload: TML_COMMAND_HANDLE cmdHandle; iRet = tml_Cmd_Create(&cmdHandle); if (TML_SUCCESS == iRet){ SIDEX_HANDLE sHandle; /////////////////////////////////////////////// // Acquire critical section use: tml_Cmd_Acquire_Sidex_Handle(cmdHandle, &sHandle); iRet = sidex_Set_Content(sHandle, cPayload); /////////////////////////////////////////////// // Now I can release the critical section use: tml_Cmd_Release_Sidex_Handle(cmdHandle); } if (TML_SUCCESS == iRet){ // Vortex- session ID into the TML_COMMAND_HANDLE object: tml_Cmd_Attr_Set_Session_ID(cmdHandle, iConnectionID); // Don't mind of return value // Vortex- channel ID into the TML_COMMAND_HANDLE object: tml_Cmd_Attr_Set_Channel_ID(cmdHandle, iChannelID); // Don't mind of return value callbackData->pLog->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "listenerFrameReceivedCallback", "Vortex CMD", "vortex_channel_ref"); vortex_channel_ref(channel); // I will be shure to have a valid channel until the reply is send // Vortex- channel into the TML_COMMAND_HANDLE object: tml_Cmd_Attr_Set_Channel(cmdHandle, channel); // Don't mind of return value // Vortex- message ID into the TML_COMMAND_HANDLE object: tml_Cmd_Attr_Set_Message_ID(cmdHandle, iMsgID); // Don't mind of return value // Vortex- profile into the TML_COMMAND_HANDLE object: tml_Cmd_Attr_Set_Profile(cmdHandle, sProfile); // The core handle: tml_Cmd_Attr_Set_Core_Reference(cmdHandle, callbackData->tmlcorehandle); // Don't mind of return value TML_CONNECTION_HANDLE connectionHandle = TML_HANDLE_TYPE_NULL; ////////////////////////////////////////////////////////////////// // Add the connection to the list: if (NULL != sHostIP && NULL != sPort && NULL != connection){ ((tmlCoreWrapper*)callbackData->tmlcorehandle)->tmlCoreWrapper_Connect(sHostIP, sPort, false, &connectionHandle, connection); ((tmlObjWrapper*)cmdHandle)->tmlObjWrapper_Set_Connection(connectionHandle); } // Now call the callback method: globalCallback(callbackData->callback, (void*) cmdHandle); } } else{ callbackData->pLog->log ("TMLCoreListener", "listenerFrameReceivedCallback", "ERROR", "Problem on getting some attributes."); } return; }