A simple client program written to use a local "Stack" object is displayed below. This C program is shown so that the differences between a local and remote client program can be highlighted.
#include <stack.h>
boolean OperationOK(Environment *ev);
int main(int argc, char *argv[])
{
Environment ev;
Stack stk;
long num = 100;
SOM_InitEnvironment(&ev);
/* The StackNewClass invocation is optional and unnecessary
* in the client program when the class object is created in
* the SOMInitModule function that is invoked during DLL
* initialization.
*/
StackNewClass(Stack_MajorVersion, Stack_MinorVersion);
stk = StackNew();
/* Verify successful object creation */
if ( stk != NULL )
{
while ( !_full(stk, &ev) )
{
_push(stk, &ev, num);
somPrintf("Top: %d\n", _top(stk, &ev));
num += 100;
}
/* Test stack overflow exception */
_push(stk, &ev, num);
OperationOK(&ev);
while ( !_empty(stk, &ev) )
{
somPrintf("Pop: %d\n", _pop(stk, &ev));
}
/* Test stack underflow exception */
somPrintf("Top Underflow: %d\n", _top(stk, &ev));
OperationOK(&ev);
somPrintf("Pop Underflow: %d\n", _pop(stk, &ev));
OperationOK(&ev);
_push(stk, &ev, -10000);
somPrintf("Top: %d\n", _top(stk, &ev));
somPrintf("Pop: %d\n", _top(stk, &ev));
_somFree(stk);
}
SOM_UninitEnvironment(&ev);
return(0);
}
boolean OperationOK(Environment *ev)
{
char *exID;
switch (ev->_major)
{
case SYSTEM_EXCEPTION:
exID = somExceptionId(ev);
somPrintf("System exception: %s\n", exID);
somdExceptionFree(ev);
return (FALSE);
case USER_EXCEPTION:
exID = somExceptionId(ev);
somPrintf("User exception: %s\n", exID);
somdExceptionFree(ev);
return (FALSE);
case NO_EXCEPTION:
return (TRUE);
default:
somPrintf("Invalid exception type in Environment.\n");
somdExceptionFree(ev);
return (FALSE);
}
}