PubSub+ Messaging API For C  7.29.0.6
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ex/ios/examples/SubscribeOnBehalfOfClientExample.m
/*
* Copyright 2010-2024 Solace Corporation. All rights reserved.
*/
#import "SubscribeOnBehalfOfClientExample.h"
@implementation SubscribeOnBehalfOfClientExample
- (id)initWithExampleInterface:(ExampleInterface *)exampleInterface {
self = [super initWithExampleInterface:exampleInterface];
// Set example name and description
self.name = @"SubscribeOnBehalfOfClient";
self.description =
@"Demonstrates how to subscribe on behalf of another client";
return self;
}
- (void)run {
[super run];
solClient_opaqueSession_pt sessionClient_p;
const char *topic_str = "sample/topic/pasta";
static const char subscriptionManager[] = "Subscription Manager";
static const char subscriptionClient[] = "Subscription Client";
char clientName_a[SOLCLIENT_SESSION_PROP_MAX_CLIENT_NAME_LEN + 1];
const char *props[40];
int propIndex;
// Initialize the API; this must be done prior to first usage
[self handleErrorWithReturnCode:rc
errorString:"solClient_initialize()"];
goto notInitialized;
}
// Set up logging level and log example and API information
[self setLoggingLevel];
"SubscribeOnBehalfOfClientExample.m (Copyright 2010-2024 Solace Corporation. All rights reserved. "
"Systems, Inc. All rights reserved.)\n");
[self logCCSMPVersion];
// Create a context, and specify that the context thread be created
// automatically instead of having the application create its own
// context thread.
solClient_log(SOLCLIENT_LOG_INFO, "Creating solClient context");
&contextFuncInfo, sizeof(contextFuncInfo))) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_context_create()"];
goto cleanup;
}
solClient_log(SOLCLIENT_LOG_INFO, "Creating solClient sessions.");
if ((rc = [self
createAndConnectSessionWithContext:context_p
session:&sessionMgr_p
messageCallback:messageReceivePrintMsgCallback
eventCallback:eventCallback]) !=
[self handleErrorWithReturnCode:
rc errorString:"createAndConnectSessionWithContext:session:"
"messageCallback:eventCallback:userData:"];
goto cleanup;
}
if ((rc = [self
createAndConnectSessionWithContext:context_p
session:&sessionClient_p
messageCallback:messageReceivePrintMsgCallback
eventCallback:eventCallback]) !=
[self handleErrorWithReturnCode:
rc errorString:"createAndConnectSessionWithContext:session:"
"messageCallback:eventCallback:userData:"];
goto cleanup;
}
solClient_log(SOLCLIENT_LOG_INFO, "Checking for capability: ...");
"Subscription Manager Not Supported. Exiting");
goto sessionConnected;
} else {
}
sessionClient_p, SOLCLIENT_SESSION_PROP_CLIENT_NAME, clientName_a,
sizeof(clientName_a)) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_getProperty()"];
goto sessionConnected;
}
"Adding subscription %s in %s on behalf of client %s",
topic_str, subscriptionManager, subscriptionClient);
propIndex = 0;
props[propIndex++] = SOLCLIENT_ENDPOINT_PROP_ID;
props[propIndex++] = SOLCLIENT_ENDPOINT_PROP_NAME;
props[propIndex++] = clientName_a;
props[propIndex++] = NULL;
(char **)props, sessionMgr_p,
[self handleErrorWithReturnCode:
rc errorString:"solClient_session_endpointTopicSubscribe()"];
goto sessionConnected;
}
// Send a message on the manager session and see it received on the client
// only
if ([self publishMessageWithSession:sessionMgr_p
topic:(char *)topic_str
[self handleErrorWithReturnCode:rc
errorString:"common_publishDirectMessage()"];
goto sessionConnected;
}
// Wait for half a second
[NSThread sleepForTimeInterval:0.5];
sessionConnected:
// Disconnect the session
if ((rc = solClient_session_disconnect(sessionMgr_p)) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_disconnect()"];
}
if ((rc = solClient_session_disconnect(sessionClient_p)) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_disconnect()"];
}
cleanup:
// Cleanup solclient
if ((rc = solClient_cleanup()) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc errorString:"solClient_cleanup()"];
}
notInitialized:
[self cleanup];
}
@end