PubSub+ Messaging API For C  7.29.0.6
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ex/ios/examples/RedirectLogsExample.m
/*
* Copyright 2007-2024 Solace Corporation. All rights reserved.
*/
#import "RedirectLogsExample.h"
@implementation RedirectLogsExample
- (id)initWithExampleInterface:(ExampleInterface *)exampleInterface {
self = [super initWithExampleInterface:exampleInterface];
// Set example name and description
self.name = @"RedirectLogs";
self.description = @"Demonstrates how to redirect logs to stdout";
// Setup example parameters
[self.parameters addParameter:PARAMETER_DESTINATION_TOPIC];
return self;
}
- (void)logCallbackWithLogInfo:(solClient_log_callbackInfo_pt)logInfo_p
userData:(void *)userData {
printf("Log: Category=%s, Level=%s, Msg=%s\n",
solClient_log_levelToString(logInfo_p->level), logInfo_p->msg_p);
}
- (void)run {
[super run];
solClient_opaqueMsg_pt msg_p; //*< The message pointer
char binMsg[1024];
// Setup logging callback
if (solClient_log_setCallback(logCallback, self.nullBridge_p) !=
[self handleErrorWithReturnCode:rc
errorString:"solClient_log_setCallback()"];
goto notInitialized;
}
[self printToTextView:
@"All logging output is now being redirected to stdout.\n"];
// 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];
"RedirectLogsExample.m (Copyright 2007-2024 Solace Corporation. All rights reserved.)\n");
[self logCCSMPVersion];
solClient_log(SOLCLIENT_LOG_INFO, "Creating solClient context");
// Create a context, and specify that the context thread should be created
// automatically instead of having the application create its own
// context thread.
&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;
}
[[self.parameters parameterWithId:PARAMETER_DESTINATION_TOPIC]
.value cStringUsingEncoding:NSASCIIStringEncoding])) !=
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_topicSubscribe()"];
goto sessionConnected;
}
solClient_log(SOLCLIENT_LOG_INFO, "Publishing message");
// Allocate a message.
if ((rc = solClient_msg_alloc(&msg_p)) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc errorString:"solClient_msg_alloc()"];
goto sessionConnected;
}
// Set the delivery mode for the message.
[self handleErrorWithReturnCode:rc
errorString:"solClient_msg_setDeliveryMode()"];
goto sessionConnected;
}
// Initialize a binary attachment and use it as part of the message.
memset((void *)binMsg, 0xab, sizeof(binMsg));
msg_p, binMsg, sizeof(binMsg))) != SOLCLIENT_OK) {
[self
handleErrorWithReturnCode:rc
errorString:"solClient_msg_setBinaryAttachmentPtr()"];
goto sessionConnected;
}
destination.dest = COMMON_MY_SAMPLE_TOPIC;
msg_p, &destination, sizeof(destination))) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_msg_setDestination()"];
goto sessionConnected;
}
if ((rc = solClient_session_sendMsg(session_p, msg_p)) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_send"];
goto sessionConnected;
}
if ((rc = solClient_msg_free(&msg_p)) != SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc errorString:"solClient_msg_free()"];
goto sessionConnected;
}
[NSThread sleepForTimeInterval:2];
[[self.parameters parameterWithId:PARAMETER_DESTINATION_TOPIC]
.value cStringUsingEncoding:NSASCIIStringEncoding])) !=
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_topicSubscribe()"];
goto sessionConnected;
}
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