Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
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;     
 }  
Exemplo n.º 4
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;
}