/* account-client.c hacked by Frank Rehberger * . */ #include #include #include #include #include #include #include "byteseq.h" /** * test for exception */ static gboolean raised_exception(CORBA_Environment *ev) { return ((ev)->_major != CORBA_NO_EXCEPTION); } /** * in case of any exception this macro will abort the process */ static void abort_if_exception(CORBA_Environment *ev, const char* mesg) { if (raised_exception (ev)) { g_error ("%s %s", mesg, CORBA_exception_id (ev)); CORBA_exception_free (ev); abort(); } } static CORBA_ORB global_orb = CORBA_OBJECT_NIL; /* global orb */ /* Is called in case of process signals. it invokes CORBA_ORB_shutdown() * function, which will terminate the processes main loop. */ static void client_shutdown (int sig) { CORBA_Environment local_ev[1]; CORBA_exception_init(local_ev); if (global_orb != CORBA_OBJECT_NIL) { CORBA_ORB_shutdown (global_orb, FALSE, local_ev); abort_if_exception (local_ev, "caught exception"); } } /* Inits ORB @orb using @argv arguments for configuration. For each * ORBit options consumed from vector @argv the counter of @argc_ptr * will be decremented. Signal handler is set to call * echo_client_shutdown function in case of SIGINT and SIGTERM * signals. If error occures @ev points to exception object on * return. */ static void client_init (int *argc_ptr, char *argv[], CORBA_ORB *orb, CORBA_Environment *ev) { /* init signal handling */ signal(SIGINT, client_shutdown); signal(SIGTERM, client_shutdown); /* create Object Request Broker (ORB) */ (*orb) = CORBA_ORB_init(argc_ptr, argv, "orbit-local-orb", ev); if (raised_exception(ev)) return; } /* Releases @servant object and finally destroys @orb. If error * occures @ev points to exception object on return. */ static void client_cleanup (CORBA_ORB orb, Examples_ByteSeq_Storage servant, CORBA_Environment *ev) { /* releasing managed object */ CORBA_Object_release(servant, ev); if (raised_exception(ev)) return; /* tear down the ORB */ if (orb != CORBA_OBJECT_NIL) { /* going to destroy orb.. */ CORBA_ORB_destroy(orb, ev); if (raised_exception(ev)) return; } } /** * */ static Examples_ByteSeq_Storage client_import_object_from_stream (CORBA_ORB orb, FILE *stream, CORBA_Environment *ev) { CORBA_Object obj = CORBA_OBJECT_NIL; gchar *objref=NULL; fscanf (stream, "%as", &objref); /* FIXME, handle input error */ obj = (CORBA_Object) CORBA_ORB_string_to_object (global_orb, objref, ev); free (objref); return (Examples_ByteSeq_Storage) obj; } /** * */ static Examples_ByteSeq_Chunk* chunk_create (CORBA_long maximum) { Examples_ByteSeq_Chunk* chunk = Examples_ByteSeq_Chunk__alloc(); /* FIXME, handle out of memory */ chunk->_buffer = Examples_ByteSeq_Chunk_allocbuf (maximum); /* FIXME, handle out of memory */ chunk->_maximum = maximum; chunk->_length = 0; return chunk; } /** * */ static void client_run_set (Examples_ByteSeq_Storage servant, CORBA_Environment *ev) { CORBA_long maximum=2048; CORBA_long length =0; Examples_ByteSeq_Chunk* chunk = chunk_create (maximum+1); /* increment sequence length, beginning with 0 up to 2048 */ for (length=0; length_buffer [length+1] = (CORBA_octet) 0xFF; chunk->_length = length+1; } CORBA_free (chunk); } /** * */ static void client_run_get (Examples_ByteSeq_Storage servant, CORBA_Environment *ev) { CORBA_long n=100; CORBA_long i=0; Examples_ByteSeq_Chunk* chunk = NULL; /* increment sequence length, beginning with 0 up to 2048 */ for (i=0; i