static void client_run (Account service, CORBA_long amount, CORBA_Environment *ev) { CORBA_long balance=0; /* * use calculator server */ balance = Account__get_balance (service, ev); if (etk_raised_exception (ev)) return; g_print ("balance %5d, ", balance); if (amount > 0) { Account_deposit (service, amount, ev); if (etk_raised_exception (ev)) return; } else { Account_withdraw (service, abs(amount), ev); if (etk_raised_exception (ev)) return; } balance = Account__get_balance (service, ev); if (etk_raised_exception (ev)) return; g_print ("new balance %5d\n", balance); }
*/static void server_init (int *argc_ptr, char *argv[], CORBA_ORB *orb, PortableServer_POA *poa, CORBA_Environment *ev) { PortableServer_POA rootpoa = CORBA_OBJECT_NIL; PortableServer_POAManager rootpoa_mgr = CORBA_OBJECT_NIL; CORBA_Environment local_ev[1]; CORBA_exception_init(local_ev); /* init signal handling */ signal(SIGTERM, server_shutdown); /* create Object Request Broker (ORB) */ (*orb) = CORBA_ORB_init(argc_ptr, argv, "orbit-local-mt-orb", ev); if (etk_raised_exception(ev)) goto failed_orb; rootpoa = (PortableServer_POA) CORBA_ORB_resolve_initial_references(*orb, "RootPOA", ev); if (etk_raised_exception(ev)) goto failed_poa; rootpoa_mgr = PortableServer_POA__get_the_POAManager(rootpoa, ev); if (etk_raised_exception(ev)) goto failed_poamanager; /* create default POA with specific policies */ (*poa) = server_create_multi_threaded_poa (*orb, rootpoa, rootpoa_mgr, ev); if (etk_raised_exception(ev)) goto failed_child_poa; PortableServer_POAManager_activate(rootpoa_mgr, ev); if (etk_raised_exception(ev)) goto failed_activation; CORBA_Object_release ((CORBA_Object) rootpoa_mgr, ev); return; failed_activation: failed_child_poa: failed_poamanager: CORBA_Object_release ((CORBA_Object) rootpoa_mgr, local_ev); failed_poa: CORBA_ORB_destroy(*orb, local_ev); failed_orb: return; }
PortableServer_POA server_create_multi_threaded_poa (CORBA_ORB orb, PortableServer_POA poa, PortableServer_POAManager poa_mgr, CORBA_Environment *ev) { const static MAX_POLICIES = 1; PortableServer_POA child_poa = CORBA_OBJECT_NIL; CORBA_PolicyList *poa_policies; poa_policies = CORBA_PolicyList__alloc (); poa_policies->_maximum = MAX_POLICIES; poa_policies->_length = MAX_POLICIES; poa_policies->_buffer = CORBA_PolicyList_allocbuf (MAX_POLICIES); CORBA_sequence_set_release (poa_policies, CORBA_TRUE); poa_policies->_buffer[0] = (CORBA_Policy) PortableServer_POA_create_thread_policy ( poa, PortableServer_ORB_CTRL_MODEL, ev); child_poa = PortableServer_POA_create_POA (poa, "Thread Per Request POA", poa_mgr, poa_policies, ev); if (etk_raised_exception(ev)) goto failed_create_poa; ORBit_ObjectAdaptor_set_thread_hint ((ORBit_ObjectAdaptor) child_poa, ORBIT_THREAD_HINT_PER_REQUEST); CORBA_Policy_destroy (poa_policies->_buffer[0], ev); if (etk_raised_exception(ev)) goto failed; CORBA_free (poa_policies); return child_poa; failed_create_poa: /* FIXME, in case of error, ev is set, but destructor should not * return except anyway */ CORBA_Policy_destroy (poa_policies->_buffer[0], ev); CORBA_free (poa_policies); failed: return CORBA_OBJECT_NIL; }
static void client_cleanup (CORBA_ORB orb, CORBA_Object service, CORBA_Environment *ev) { CORBA_Object_release(service, ev); if (etk_raised_exception(ev)) return; if (orb != CORBA_OBJECT_NIL) { CORBA_ORB_destroy(orb, ev); if (etk_raised_exception(ev)) return; } }
static void server_run (CORBA_ORB orb, CORBA_Environment *ev) { CORBA_ORB_run(orb, ev); if (etk_raised_exception(ev)) return; }
*/static void server_init (int *argc_ptr, char *argv[], CORBA_ORB *orb, PortableServer_POA *poa, CORBA_Environment *ev) { PortableServer_POAManager poa_manager = CORBA_OBJECT_NIL; CORBA_Environment local_ev[1]; CORBA_exception_init(local_ev); /* init signal handling */ signal(SIGINT, server_shutdown); signal(SIGTERM, server_shutdown); /* create Object Request Broker (ORB) */ (*orb) = CORBA_ORB_init(argc_ptr, argv, "orbit-local-mt-orb", ev); if (etk_raised_exception(ev)) goto failed_orb; (*poa) = (PortableServer_POA) CORBA_ORB_resolve_initial_references(*orb, "RootPOA", ev); if (etk_raised_exception(ev)) goto failed_poa; poa_manager = PortableServer_POA__get_the_POAManager(*poa, ev); if (etk_raised_exception(ev)) goto failed_poamanager; PortableServer_POAManager_activate(poa_manager, ev); if (etk_raised_exception(ev)) goto failed_activation; CORBA_Object_release ((CORBA_Object) poa_manager, ev); return; failed_activation: failed_poamanager: CORBA_Object_release ((CORBA_Object) poa_manager, local_ev); failed_poa: CORBA_ORB_destroy(*orb, local_ev); failed_orb: return; }
void etk_ignore_if_exception (CORBA_Environment *ev, const char* mesg) { if (etk_raised_exception (ev)) { g_warning ("%s %s", mesg, CORBA_exception_id (ev)); CORBA_exception_free (ev); } }
void etk_abort_if_exception (CORBA_Environment *ev, const char* mesg) { if (etk_raised_exception (ev)) { g_error ("%s %s", mesg, CORBA_exception_id (ev)); CORBA_exception_free (ev); abort(); } }
/* Releases @servant object and finally destroys @orb. If error * occures @ev points to exception object on return. */ static void client_cleanup (CORBA_ORB orb, CORBA_Object service, CORBA_Environment *ev) { /* releasing managed object */ CORBA_Object_release(service, ev); if (etk_raised_exception(ev)) return; /* tear down the ORB */ if (orb != CORBA_OBJECT_NIL) { /* going to destroy orb.. */ CORBA_ORB_destroy(orb, ev); if (etk_raised_exception(ev)) return; } }
/* Entering main loop @orb handles incoming request and delegates to * servants. If error occures @ev points to exception object on * return. */ static void server_run (CORBA_ORB orb, CORBA_Environment *ev) { /* enter main loop until SIGINT or SIGTERM */ CORBA_ORB_run(orb, ev); if (etk_raised_exception(ev)) return; /* user pressed SIGINT or SIGTERM and in signal handler * CORBA_ORB_shutdown(.) has been called */ }
/* Releases @servant object and finally destroys @orb. If error * occures @ev points to exception object on return. */ static void server_cleanup (CORBA_ORB orb, PortableServer_POA poa, CORBA_Object ref, CORBA_Environment *ev) { PortableServer_ObjectId *objid = NULL; objid = PortableServer_POA_reference_to_id (poa, ref, ev); if (etk_raised_exception(ev)) return; /* Servant: deactivatoin - will invoke __fini destructor */ PortableServer_POA_deactivate_object (poa, objid, ev); if (etk_raised_exception(ev)) return; PortableServer_POA_destroy (poa, TRUE, FALSE, ev); if (etk_raised_exception(ev)) return; CORBA_free (objid); CORBA_Object_release ((CORBA_Object) poa, ev); if (etk_raised_exception(ev)) return; CORBA_Object_release (ref, ev); if (etk_raised_exception(ev)) return; /* ORB: tear down the ORB */ if (orb != CORBA_OBJECT_NIL) { /* going to destroy orb.. */ CORBA_ORB_destroy(orb, ev); if (etk_raised_exception(ev)) return; } }
static void server_cleanup (CORBA_ORB orb, PortableServer_POA poa, CORBA_Object ref, CORBA_Environment *ev) { PortableServer_ObjectId *objid = NULL; objid = PortableServer_POA_reference_to_id (poa, ref, ev); if (etk_raised_exception(ev)) return; PortableServer_POA_deactivate_object (poa, objid, ev); if (etk_raised_exception(ev)) return; PortableServer_POA_destroy (poa, TRUE, FALSE, ev); if (etk_raised_exception(ev)) return; CORBA_free (objid); CORBA_Object_release ((CORBA_Object) poa, ev); if (etk_raised_exception(ev)) return; CORBA_Object_release (ref, ev); if (etk_raised_exception(ev)) return; if (orb != CORBA_OBJECT_NIL) { CORBA_ORB_destroy(orb, ev); if (etk_raised_exception(ev)) return; } }
static CORBA_Object server_activate_service (CORBA_ORB orb, PortableServer_POA poa, CORBA_Environment *ev) { Test_LargeSeq ref = CORBA_OBJECT_NIL; ref = impl_Test_LargeSeq__create (poa, ev); if (etk_raised_exception(ev)) return CORBA_OBJECT_NIL; return ref; }
/* Creates servant and registers in context of ORB @orb. The ORB will * delegate incoming requests to specific servant object. @return * object reference. If error occures @ev points to exception object * on return. */ static CORBA_Object server_activate_service (CORBA_ORB orb, PortableServer_POA poa, CORBA_Environment *ev) { Examples_BadCall ref = CORBA_OBJECT_NIL; ref = impl_Examples_BadCall__create (poa, ev); if (etk_raised_exception(ev)) return CORBA_OBJECT_NIL; return ref; }
CosNaming_NamingContext etk_get_name_service (CORBA_ORB orb, CORBA_Environment *ev) { CORBA_char *str=NULL; CORBA_Object ref = (CORBA_Object) CORBA_ORB_resolve_initial_references(orb, "NameService", ev); if (etk_raised_exception(ev)) return CORBA_OBJECT_NIL; return (CosNaming_NamingContext) ref; }
static void client_run(EchoApp_Echo echo_service, CORBA_Environment *ev) { char filebuffer[1024+1]; g_print("Type messages to the server\n" "a signal dot in line will terminate input\n"); while ( fgets(filebuffer, 1024, stdin) ) { if ( filebuffer[0] == '.' && filebuffer[1] == '\n' ) break; /* chop the newline off */ filebuffer[strlen(filebuffer)-1] = '\0'; /* using the echoString method in the Echo object * this is defined in the echo.h header, compiled from * echo.idl */ EchoApp_Echo_echoString(echo_service, filebuffer, ev); if (etk_raised_exception(ev)) 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 (etk_raised_exception(ev)) return; }
void etk_export_object_to_stream (CORBA_ORB orb, CORBA_Object servant, FILE *stream, CORBA_Environment *ev) { CORBA_char *objref = NULL; /* write objref to file */ objref = CORBA_ORB_object_to_string (orb, servant, ev); if (etk_raised_exception(ev)) return; /* print ior to terminal */ fprintf (stream, "%s\n", objref); fflush (stream); CORBA_free (objref); }
CORBA_Object etk_name_service_resolve (CosNaming_NamingContext name_service, gchar *id_vec[], CORBA_Environment *ev) { CORBA_Object retval = CORBA_OBJECT_NIL; gint i = 0; gint len = id_vec_len (id_vec); /* Allocate a CosNaming::Name (sequence of CosNaming::NameComponent) */ CosNaming_Name *name = CosNaming_Name__alloc(); g_assert (id_vec_len (id_vec) > 0); name->_buffer = CORBA_sequence_CosNaming_NameComponent_allocbuf(len); name->_maximum = len; name->_length = 0; /* Relinquish ownership of the NameComponent to the * sequence. When CORBA_free is called on it later, the * NameComponent will be freed */ CORBA_sequence_set_release (name, TRUE); /* iterate components of name and create sub-context * (directory) if needed */ for (i = 0; i < len; ++i) { name->_length = i+1; name->_buffer[i].id = CORBA_string_dup(id_vec[i]); name->_buffer[i].kind = CORBA_string_dup(""); /* don't know what 'kind' shall be good for */ } retval = CosNaming_NamingContext_resolve (name_service, name, ev); if (etk_raised_exception (ev)) { CORBA_free (name); return CORBA_OBJECT_NIL; } return retval; }
/* binds @servant object reference to unique @name at * @name_service. If error occures @ev points to exception object on * return. */ void etk_name_service_bind (CosNaming_NamingContext name_service, CORBA_Object servant, gchar *id_vec[], CORBA_Environment *ev) { gint i = 0; gint len = id_vec_len (id_vec); /* Allocate a CosNaming::Name (sequence of CosNaming::NameComponent) */ CosNaming_Name *name = CosNaming_Name__alloc(); name->_buffer = CORBA_sequence_CosNaming_NameComponent_allocbuf(len); name->_maximum = len; name->_length = 0; /* Relinquish ownership of the NameComponent to the * sequence. When CORBA_free is called on it later, the * NameComponent will be freed */ CORBA_sequence_set_release (name, TRUE); /* iterate components of name and create sub-context * (directory) if needed */ for (i = 0; i < len; ++i) { name->_length = i+1; name->_buffer[i].id = CORBA_string_dup(id_vec[i]); name->_buffer[i].kind = CORBA_string_dup(""); /* don't know what 'kind' shall be good for */ if (name->_length < len) { /* create a sub-context */ CosNaming_NamingContext nc = CosNaming_NamingContext_bind_new_context (name_service, name, ev); if (etk_raised_exception_is_a (ev, ex_CosNaming_NamingContext_AlreadyBound)) { /* ignore - ctx allread exists, this * is not dramatic */ CORBA_exception_free (ev); } else if (etk_raised_exception (ev)) { /* critical - unexpected exception */ CORBA_free (name); return; } } else { /* Bind object to last context - use 'rebind' * operation in case the name has been * registered allready in context - note, this * might interfere with other service choosing * same name */ CosNaming_NamingContext_rebind (name_service, name, servant, ev); if (etk_raised_exception(ev)) { /* critical - can not bind object */ CORBA_free (name); return; } } } CORBA_free (name); return; }