PubSub+ Messaging API For C  7.31.0.7
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ex/ios/examples/SyncCacheRequestExample.m
/*
* Copyright 2009-2024 Solace Corporation. All rights reserved.
*/
#import "SyncCacheRequestExample.h"
@implementation SyncCacheRequestExample
- (id)initWithExampleInterface:(ExampleInterface *)exampleInterface {
self = [super initWithExampleInterface:exampleInterface];
// Set example name and description
self.name = @"SyncCacheRequest";
self.description = @"Demonstrates how to send a synchronous cache request";
// Set example parameters
[self.parameters addParameter:PARAMETER_CACHE_NAME];
[self.parameters addParameter:PARAMETER_DESTINATION_TOPIC];
return self;
}
- (void)run {
[super run];
// Context.
// Session.
// Cache Session.
const char *cacheProps[20];
int propIndex = 0;
solClient_uint64_t cacheRequestId = 1;
// 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];
"SyncCacheRequestExample.m (Copyright 2009-2024 Solace Corporation. 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:&session_p
messageCallback:messageReceivePrintMsgCallback
eventCallback:eventCallback]) !=
[self handleErrorWithReturnCode:
rc errorString:"createAndConnectSessionWithContext:session:"
"messageCallback:eventCallback:userData:"];
goto cleanup;
}
// Message is published to ensure one is cached
if ((rc = [self
publishMessageWithSession:
session_p topic:(char *)
[[self.parameters
parameterWithId:PARAMETER_DESTINATION_TOPIC]
.value
cStringUsingEncoding:NSASCIIStringEncoding]
[self handleErrorWithReturnCode:rc
errorString:"common_publishMessage()"];
goto sessionConnected;
}
propIndex = 0;
cacheProps[propIndex++] = SOLCLIENT_CACHESESSION_PROP_CACHE_NAME;
cacheProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_CACHE_NAME].value
cStringUsingEncoding:NSASCIIStringEncoding];
cacheProps[propIndex] = NULL;
(const char *const *)cacheProps, session_p, &cacheSession_p)) !=
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_createCacheSession"];
goto sessionConnected;
}
solClient_log(SOLCLIENT_LOG_NOTICE, "Sending cache request.\n\n");
cacheSession_p,
[[self.parameters parameterWithId:PARAMETER_DESTINATION_TOPIC]
.value cStringUsingEncoding:NSASCIIStringEncoding],
cacheRequestId, NULL, NULL, cacheFlags, 0)) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:
rc errorString:"solClient_cacheSession_sendCacheRequest()"];
goto cleanupCache;
}
solClient_log(SOLCLIENT_LOG_NOTICE, "Cache request sent.\n\n");
cleanupCache:
if ((rc = solClient_cacheSession_destroy(&cacheSession_p)) !=
[self handleErrorWithReturnCode:rc
errorString:"solClient_cacheSession_destroy()"];
}
sessionConnected:
// Disconnect the session
if ((rc = solClient_session_disconnect(session_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