#import "SempGetOverMbExample.h"
@implementation SempGetOverMbExample
- (id)initWithExampleInterface:(ExampleInterface *)exampleInterface {
self = [super initWithExampleInterface:exampleInterface];
self.name = @"SempGetOverMb";
self.description =
@"Demonstrates how to perform a SEMP request over the message backbone";
[self.parameters addParameter:PARAMETER_SEMP_VERSION];
return self;
}
- (void)sempRequestRequestAndReplyWithSession:
sempVersion:(const char *)sempVersion {
char sempTopic[SOLCLIENT_BUFINFO_MAX_TOPIC_SIZE + 1];
char sempRequest[512];
void *sempReplyBuf_p;
solClient_uint32_t sempReplyBufSize;
solClient_uint32_t ix;
snprintf(sempRequest, sizeof(sempRequest),
"<rpc "
"semp-version=\"%s\"><show><"
"client><name>*</name></client></"
"show></rpc>",
sempVersion);
[self handleErrorWithReturnCode:rc errorString:"solClient_msg_alloc()"];
return;
}
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_getCapability()"];
goto freeMsg;
}
snprintf(sempTopic, sizeof(sempTopic), COMMON_SEMP_TOPIC_FORMAT,
destination.
dest = sempTopic;
msg_p, &destination,
sizeof(destination))) !=
SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_msg_setDestination()"];
goto freeMsg;
}
msg_p, (void *)sempRequest,
(solClient_uint32_t)strlen(sempRequest))) !=
SOLCLIENT_OK) {
[self
handleErrorWithReturnCode:rc
errorString:"solClient_msg_setBinaryAttachmentPtr()"];
goto freeMsg;
}
replyMsg_p, &sempReplyBuf_p, &sempReplyBufSize)) !=
[self handleErrorWithReturnCode:
rc errorString:"solClient_msg_getBinaryAttachmentPtr()"];
goto freeReplyMsg;
}
if (sempReplyBufSize >= 5000) {
"SEMP reply exceeds buffer length and will be truncated.");
}
char buffer[5000];
for (ix = 0; ix < 4999; ix++) {
buffer[ix] = ((char *)sempReplyBuf_p)[ix];
}
buffer[ix] = (char)0;
freeReplyMsg:
[self handleErrorWithReturnCode:rc
errorString:"solClient_msg_free()"];
goto freeMsg;
}
} else {
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_sendRequest()"];
goto freeMsg;
}
freeMsg:
[self handleErrorWithReturnCode:rc errorString:"solClient_msg_free()"];
}
}
- (void)run {
[super run];
char sempVersion[256];
int sempVersionLength = (int)strlen(
[[self.parameters parameterWithId:PARAMETER_SEMP_VERSION].value
cStringUsingEncoding:NSASCIIStringEncoding]);
for (int i = 0; i < sempVersionLength && i < 255; i++) {
sempVersion[i] =
[[self.parameters parameterWithId:PARAMETER_SEMP_VERSION].value
cStringUsingEncoding:NSASCIIStringEncoding][i];
}
sempVersion[sempVersionLength] = (char)0;
[self handleErrorWithReturnCode:rc
errorString:"solClient_initialize()"];
goto notInitialized;
}
[self setLoggingLevel];
[self logCCSMPVersion];
&contextFuncInfo,
sizeof(contextFuncInfo))) !=
SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_context_create()"];
goto cleanup;
}
if ((rc = [self createAndConnectSessionWithContext:context_p
session:&session_p
messageCallback:messageReceiveCallback
eventCallback:eventCallback]) !=
[self handleErrorWithReturnCode:
rc errorString:"createAndConnectSessionWithContext:session:"
"messageCallback:eventCallback:userData:"];
goto cleanup;
}
[self sempRequestRequestAndReplyWithSession:session_p
sempVersion:sempVersion];
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_disconnect()"];
}
cleanup:
[self handleErrorWithReturnCode:rc errorString:"solClient_cleanup()"];
}
notInitialized:
[self cleanup];
}
@end