Default language.

Multithreaded API clients


The BMC Remedy AR System API supports multithreaded clients through the use of sessions. Each session maintains its own state information, enabling simultaneous operations against BMC Remedy AR System servers. This feature enables more sophisticated client programs to perform multiple operations simultaneously against the same or different servers. You establish a session with a call to ARInitialization and terminate it with a call to ARTermination. The session identifier returned in the control record from an ARInitialization call must be in the control record for all subsequent API function calls intended to operate in that session. Operations for a session are not restricted to a single thread; however, each session can be active on only one thread at a time.

Following is an example of a generic API program source file.

 {anchor:_Ref375052960}
#include <stdlib.h>
#include <string.h>
#include <ar.h>
#include <arextern.h>
#include <arfree.h>

int main( int argc, char* argv[] )
{
ARStatusList status;

/* read command line arguments */
if (argc < 6) exit(-1);
char* server = argv[1];
char* user   = argv[2];
char* pass   = argv[3];
char* schema = argv[4];
char* eid    = argv[5];

/* set control parameters (server, user, etc) */
ARControlStruct control;
control.cacheId          = 0;
control.sessionId        = 0;
strcpy(control.user,     user);
strcpy(control.password, pass);
strcpy(control.language, "");
strcpy(control.server,   server);

/* Remedy Startup */
if (ARInitialization(&control, &status) >= AR_RETURN_ERROR) {
printf("\n **** initialization error ****\n");
exit(-1);
}
FreeARStatusList(&status, FALSE);

/* Verify user/password/server */
if (ARVerifyUser(&control, NULL,NULL,NULL,&status) >= AR_RETURN_ERROR) {
printf("\n **** verification failed ****\n");
exit(-1);
}

/* Set the entryid of the record we want */
AREntryIdList entryId;
entryId.numItems    = 1;
entryId.entryIdList = (AREntryIdType *) calloc(1, sizeof(AREntryIdType));
strncpy( entryId.entryIdList[0], eid, AR_MAX_ENTRYID_SIZE );
entryId.entryIdList[0][AR_MAX_ENTRYID_SIZE] = '\0';

/* Get the entry */
ARFieldValueList fieldValues;
if( ARGetEntry(&control,
schema, &entryId, NULL, &fieldValues,
&status) >= AR_RETURN_ERROR) {
printf("\n **** get entry error ****\n");
exit(-1);
}

/* Clean up */
FreeARStatusList(&status, FALSE);
FreeARFieldValueList(&fieldValues, FALSE);
FreeAREntryIdList(&entryId, FALSE);

/* Terminate */
(void) ARTermination(&control, &status);
FreeARStatusList(&status, FALSE);

return 0;
}

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*