#include "os.h"
#include "common.h"
#include "RRcommon.h"
typedef struct requestMessageInfo
{
    BOOL                           replyReceived;
} requestMessageInfo_t, *requestMessageInfo_pt; 
{
    requestMessageInfo_pt  requestInfo_p = (requestMessageInfo_pt)user_p;
    double      result;
    requestInfo_p->replyReceived = TRUE;
    
        common_handleError ( rc, "solClient_msg_getBinaryAttachmentStream()" );
        goto done;
    }
    
        common_handleError ( rc, "solClient_container_getBoolean() for operation" );
        goto done;
    }
    
    if (resultOk == FALSE) {
        goto done;
    }
    
        common_handleError ( rc, "solClient_container_getDouble() for operation" );
        goto done;
    }
    printf("Received reply message, result = %f\n", result );
 done:
}
int
main ( int argc, char *argv[] )
{
    struct commonOptions commandOpts;
    const char     *sessionProps[50];
    const char     *flowProps[20];
    int             propIndex = 0;
    solClient_int32_t operand1 = 9;
    solClient_int32_t operand2 = 5;
    RR_operation_t     operation = firstOperation;
    int             waitInSec = 10; 
    requestMessageInfo_t  requestInfo;
    char                  requestQueue_a[256];
    char                  *positionalParms = "\tQUEUE               Guaranteed Message Queue.\n";
    printf ( "RRGuaranteedRequester.c (Copyright 2013-2025 Solace Corporation. All rights reserved.)\n" );
    
    initSigHandler (  );
    
    common_initCommandOptions(&commandOpts, 
                               ( USER_PARAM_MASK |
                                 DEST_PARAM_MASK ),    
                               ( HOST_PARAM_MASK |
                                PASS_PARAM_MASK |
                                LOG_LEVEL_MASK |
                                USE_GSS_MASK |
                                ZIP_LEVEL_MASK));                       
    if ( common_parseCommandOptions ( argc, argv, &commandOpts, positionalParms ) == 0 ) {
        exit (1);
    }
    
    if (optind < argc) {
        if (commandOpts.destinationName[0] != '\0') {
            printf("%s does not support topic ('-t, --topic) and queue name (%s) at the same time\n",
                argv[0], argv[optind]);
            exit(1);
        }
        strncpy(requestQueue_a, argv[optind], sizeof(requestQueue_a));
    }
    else {
        if (commandOpts.destinationName[0] == '\0') {
            printf("%s must specify either a topic ('-t, --topic) or a queue name argument\n",
                argv[0]);
            exit(1);
        }
    }
    
    
        common_handleError ( rc, "solClient_initialize()" );
        goto notInitialized;
    }
    common_printCCSMPversion (  );
    
    
    
                                           &context_p, &contextFuncInfo, 
sizeof ( contextFuncInfo ) ) ) != 
SOLCLIENT_OK ) {
        common_handleError ( rc, "solClient_context_create()" );
        goto cleanup;
    }
    
    propIndex = 0;
    if ( commandOpts.targetHost[0] != (char) 0 ) {
        sessionProps[propIndex++] = commandOpts.targetHost;
    }
    sessionProps[propIndex++] = ( commandOpts.enableCompression ) ? "9" : "0";
    sessionProps[propIndex++] = "3";
    sessionProps[propIndex++] = "3";
    
    
    if ( commandOpts.vpn[0] ) {
        sessionProps[propIndex++] = commandOpts.vpn;
    }
    
    
    sessionProps[propIndex++] = commandOpts.username;
    
    sessionProps[propIndex++] = commandOpts.password;
    if ( commandOpts.useGSS ) {
    }
    sessionProps[propIndex] = NULL;
    
                                           context_p,
                                           &session_p, &sessionFuncInfo, 
sizeof ( sessionFuncInfo ) ) ) != 
SOLCLIENT_OK ) {
        common_handleError ( rc, "solClient_session_create()" );
         goto cleanup;
    }
    
        common_handleError ( rc, "solClient_session_connect()" );
         goto cleanup;
    }
    
    propIndex = 0;
    flowProps[propIndex] = NULL;
                                               session_p, &flow_p, &flowFuncInfo, 
sizeof ( flowFuncInfo ) ) ) != 
SOLCLIENT_OK ) {
                        "solClient_session_createFlow() did not return SOLCLIENT_OK " "after session create. rc = %d ", rc );
        goto sessionConnected;
    }
    
    if (commandOpts.destinationName[0] == '\0') {
        printf ( "Send request messages to queue '%s', Ctrl-C to stop.....\n", requestQueue_a );
    }
    else {
        printf ( "Send request messages to topic '%s', Ctrl-C to stop.....\n", commandOpts.destinationName );
    }
    
      common_handleError ( rc, "solClient_msg_alloc()" );
      goto cleanupFlow;
    }
    
    operation = firstOperation;
    while ( !gotCtlC && operation <= lastOperation + 1 ){
         
        requestInfo.replyReceived = FALSE;
         
        waitInSec = 10; 
            common_handleError ( rc, "solClient_msg_reset()" );
            goto freeMsg;
        }
        
            common_handleError ( rc, "solClient_msg_setDeliveryMode()" );
            goto freeMsg;
        }
        
            common_handleError ( rc, "solClient_msg_createBinaryAttachmentStream()" );
            goto freeMsg;
        }
        
            common_handleError ( rc, "solClient_container_addInt8()" );
            goto freeMsg;
        }
            common_handleError ( rc, "solClient_container_addInt32()" );
            goto freeMsg;
        }
            common_handleError ( rc, "solClient_container_addInt32()" );
            goto freeMsg;
        }
        
        if (commandOpts.destinationName[0] == '\0') {
            
            destination.
dest = requestQueue_a;
                common_handleError ( rc, "solClient_msg_setDestination()" );
                goto cleanupFlow;
            }
        }
        else {
            
            destination.
dest = commandOpts.destinationName;
                common_handleError ( rc, "solClient_msg_setDestination()" );
                goto cleanupFlow;
            }
        }
        
            common_handleError ( rc, "solClient_flow_getDestination()" );
            goto freeMsg;
        }
        
            common_handleError ( rc, "solClient_msg_setDestination()" );
            goto freeMsg;
        }
        
        if ( operation <= lastOperation ) {
            printf ( "Sending request for '%d %s %d'\n", operand1, RR_operationToString ( operation ), operand2 );
        }
        else {
           printf ( "Sending request for a bad operation '%d %s %d', expect an APP error\n",
                    operand1, RR_operationToString ( operation ), operand2 );
        }
            common_handleError ( rc, "solClient_session_send" );
            goto freeMsg;
        }
         
        while ((!requestInfo.replyReceived)&&(!gotCtlC) &&(waitInSec>0)) {
            sleepInSec ( 1 );
            waitInSec--;
        }
        if (waitInSec == 0) {
            goto freeMsg;
        }
        operation++;
    }
    
    if ( gotCtlC ) {
        printf ( "Got Ctrl-C, cleaning up\n" );
    }
    
 freeMsg:
      common_handleError ( rc, "solClient_msg_free()" );
     }
 
  cleanupFlow:
        common_handleError ( rc, "solClient_flow_destroy()" );
    }
  sessionConnected:
    
        common_handleError ( rc, "solClient_session_disconnect()" );
    }
  cleanup:
    
        common_handleError ( rc, "solClient_cleanup()" );
    }
    goto notInitialized;
  notInitialized:
    return 0;
}