#include "os.h"
#include "common.h"
typedef struct messageCorrelationStruct
{
struct messageCorrelationStruct *next_p;
int msgId;
BOOL isAcked;
BOOL isAccepted;
} messageCorrelationStruct_t, *messageCorrelationStruct_pt;
void
{
messageCorrelationStruct_pt correlationInfo = ( messageCorrelationStruct_pt ) eventInfo_p->
correlation_p;
"adPubAck_eventCallback() called - %s\n",
printf ( "adPubAck_eventCallback() correlation info - ID: %i\n", correlationInfo->msgId );
correlationInfo->isAcked = TRUE;
correlationInfo->isAccepted = TRUE;
break;
printf ( "adPubAck_eventCallback() called - %s; subCode %s, responseCode %d, reason %s\n",
printf ( "adPubAck_eventCallback() correlation info - ID: %i\n", correlationInfo->msgId );
correlationInfo->isAcked = TRUE;
correlationInfo->isAccepted = FALSE;
break;
"adPubAck_eventCallback() called - %s\n",
break;
printf ( "adPubAck_eventCallback() called - %s; subCode %s, responseCode %d, reason %s\n",
break;
default:
printf ( "adPubAck_eventCallback() called - %s. Unrecognized or deprecated event.\n",
break;
}
}
int
main ( int argc, char *argv[] )
{
struct commonOptions commandOpts;
int loop;
char binMsg[1024];
messageCorrelationStruct_pt msgMemoryItem_p = NULL;
messageCorrelationStruct_pt msgMemoryListHead_p = NULL;
messageCorrelationStruct_pt msgMemoryListTail_p = NULL;
printf ( "\nadPubAck.c (Copyright 2010-2024 Solace Corporation. All rights reserved.)\n" );
common_initCommandOptions(&commandOpts,
( USER_PARAM_MASK ),
( HOST_PARAM_MASK |
PASS_PARAM_MASK |
NUM_MSGS_MASK |
LOG_LEVEL_MASK |
USE_GSS_MASK |
ZIP_LEVEL_MASK));
if ( common_parseCommandOptions ( argc, argv, &commandOpts, NULL ) == 0 ) {
exit(1);
}
common_handleError ( rc, "solClient_initialize()" );
goto notInitialized;
}
common_printCCSMPversion ( );
initSigHandler ( );
&context_p, &contextFuncInfo,
sizeof ( contextFuncInfo ) ) ) !=
SOLCLIENT_OK ) {
common_handleError ( rc, "solClient_context_create()" );
goto cleanup;
}
if ( ( rc = common_createAndConnectSession ( context_p,
&session_p,
common_messageReceivePrintMsgCallback,
adPubAck_eventCallback, NULL, &commandOpts ) ) !=
SOLCLIENT_OK ) {
common_handleError ( rc, "common_createAndConnectSession()" );
goto cleanup;
}
for ( loop = 0; ( loop < commandOpts.numMsgsToSend ) && !gotCtlC; loop++ ) {
common_handleError ( rc, "solClient_msg_alloc()" );
goto sessionConnected;
}
common_handleError ( rc, "solClient_msg_setDeliveryMode()" );
goto sessionConnected;
}
memset ( ( void * ) binMsg, 0xab, sizeof ( binMsg ) );
common_handleError ( rc, "solClient_msg_setBinaryAttachmentPtr()" );
goto sessionConnected;
}
destination.
dest = COMMON_MY_SAMPLE_TOPIC;
common_handleError ( rc, "solClient_msg_setDestination()" );
goto sessionConnected;
}
msgMemoryItem_p = ( messageCorrelationStruct_pt ) malloc ( sizeof ( messageCorrelationStruct_t ) );
msgMemoryItem_p->next_p = NULL;
msgMemoryItem_p->msgId = loop;
msgMemoryItem_p->msg_p = msg_p;
msgMemoryItem_p->isAcked = FALSE;
msgMemoryItem_p->isAccepted = FALSE;
if ( msgMemoryListTail_p != NULL ) {
msgMemoryListTail_p->next_p = msgMemoryItem_p;
}
if ( msgMemoryListHead_p == NULL ) {
msgMemoryListHead_p = msgMemoryItem_p;
}
msgMemoryListTail_p = msgMemoryItem_p;
common_handleError ( rc, "solClient_msg_setCorrelationTag()" );
goto sessionConnected;
}
common_handleError ( rc, "solClient_session_send" );
break;
}
sleepInSec ( 1 );
while ( ( msgMemoryListHead_p != NULL ) && msgMemoryListHead_p->isAcked ) {
printf ( "Freeing memory for message %i, Result: Acked (%i), Accepted (%i)\n",
msgMemoryListHead_p->msgId, msgMemoryListHead_p->isAcked, msgMemoryListHead_p->isAccepted );
msgMemoryItem_p = msgMemoryListHead_p;
if ( ( msgMemoryListHead_p = msgMemoryListHead_p->next_p ) == NULL ) {
msgMemoryListTail_p = NULL;
}
free ( msgMemoryItem_p );
}
}
if ( gotCtlC ) {
printf ( "Got Ctrl-C, cleaning up\n" );
} else {
sleepInSec ( 1 );
}
sessionConnected:
common_handleError ( rc, "solClient_session_disconnect()" );
}
cleanup:
while ( msgMemoryListHead_p != NULL ) {
printf ( "Freeing memory for message %i, Result: Acked (%i), Accepted (%i)\n",
msgMemoryListHead_p->msgId, msgMemoryListHead_p->isAcked, msgMemoryListHead_p->isAccepted );
msgMemoryItem_p = msgMemoryListHead_p;
if ( ( msgMemoryListHead_p = msgMemoryListHead_p->next_p ) == NULL ) {
msgMemoryListTail_p = NULL;
}
free ( msgMemoryItem_p );
}
common_handleError ( rc, "solClient_cleanup()" );
}
goto notInitialized;
notInitialized:
return 0;
}