00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <pthread.h>
00036 #include <orbit/orbit.h>
00037
00038 #include "sensix.h"
00039 #include "sense_impl.h"
00040 #include "corba_discovery.h"
00041 #include "discovery_service.h"
00042 #include "corba_util.h"
00043 #include "sense_serv.h"
00044
00045 #include "sense-skelimpl.c"
00046
00047
00048 pthread_mutex_t orb_mutex = PTHREAD_MUTEX_INITIALIZER;
00049 CORBA_ORB global_orb = CORBA_OBJECT_NIL;
00050 PortableServer_POA root_poa = CORBA_OBJECT_NIL;
00051
00052
00053 pthread_mutex_t ancestor_mutex = PTHREAD_MUTEX_INITIALIZER;
00054 bool_t ancestors_running = false;
00055
00056
00057 void ancestors_shutdown(int sig)
00058 {
00059 CORBA_Environment local_ev[1];
00060 CORBA_exception_init(local_ev);
00061
00062 pthread_mutex_lock(&ancestor_mutex);
00063 ancestors_running = false;
00064 pthread_mutex_unlock(&ancestor_mutex);
00065
00066 if (global_orb != CORBA_OBJECT_NIL) {
00067 CORBA_ORB_shutdown(global_orb, FALSE, local_ev);
00068 abort_if_exception(local_ev, "caught exception");
00069 }
00070 }
00071
00072
00073 static void server_init(int *argc_ptr, char *argv[], CORBA_ORB *orb,
00074 PortableServer_POA *poa, CORBA_Environment *ev)
00075 {
00076 PortableServer_POAManager poa_manager = CORBA_OBJECT_NIL;
00077
00078 CORBA_Environment local_ev[1];
00079 CORBA_exception_init(local_ev);
00080
00081 (*orb) = CORBA_ORB_init(argc_ptr, argv, "orbit-local-mt-orb", ev);
00082 if (raised_exception(ev))
00083 goto failed_orb;
00084
00085 (*poa) = (PortableServer_POA)
00086 CORBA_ORB_resolve_initial_references(*orb, "RootPOA", ev);
00087 if (raised_exception(ev))
00088 goto failed_poa;
00089
00090 poa_manager = PortableServer_POA__get_the_POAManager(*poa, ev);
00091 if (raised_exception(ev))
00092 goto failed_poamanager;
00093
00094 PortableServer_POAManager_activate(poa_manager, ev);
00095 if (raised_exception(ev))
00096 goto failed_activation;
00097
00098 CORBA_Object_release((CORBA_Object) poa_manager, ev);
00099 return;
00100
00101 failed_activation:
00102 failed_poamanager:
00103 CORBA_Object_release((CORBA_Object)poa_manager, local_ev);
00104 failed_poa:
00105 CORBA_ORB_destroy(*orb, local_ev);
00106 failed_orb:
00107 return;
00108 }
00109
00110
00111 static void server_run(CORBA_ORB orb, CORBA_Environment *ev)
00112 {
00113 CORBA_ORB_run(orb, ev);
00114 if (raised_exception(ev))
00115 return;
00116 }
00117
00118
00119 static void server_cleanup(CORBA_ORB orb, PortableServer_POA poa,
00120 CORBA_Object ref, CORBA_Environment *ev)
00121 {
00122 PortableServer_ObjectId *objid = NULL;
00123
00124 objid = PortableServer_POA_reference_to_id(poa, ref, ev);
00125 if (raised_exception(ev))
00126 return;
00127
00128 PortableServer_POA_deactivate_object(poa, objid, ev);
00129 if (raised_exception(ev))
00130 return;
00131
00132 PortableServer_POA_destroy(poa, TRUE, FALSE, ev);
00133 if (raised_exception(ev))
00134 return;
00135
00136 CORBA_free(objid);
00137
00138 CORBA_Object_release((CORBA_Object)poa, ev);
00139 if (raised_exception(ev))
00140 return;
00141
00142 CORBA_Object_release(ref, ev);
00143 if (raised_exception(ev))
00144 return;
00145
00146 if (orb != CORBA_OBJECT_NIL) {
00147 CORBA_ORB_destroy(orb, ev);
00148 if (raised_exception(ev))
00149 return;
00150 }
00151 }
00152
00153
00154 static CORBA_Object server_activate_service(CORBA_ORB orb,
00155 PortableServer_POA poa,
00156 CORBA_Environment *ev)
00157 {
00158 gov_lanl_isr_sensix_SensoryResponse ref = CORBA_OBJECT_NIL;
00159
00160 ref = impl_gov_lanl_isr_sensix_SensoryResponse__create(poa, ev);
00161 if (raised_exception(ev))
00162 return CORBA_OBJECT_NIL;
00163
00164 return ref;
00165 }
00166
00167
00168
00169 void *ancestors_server(void *arguments)
00170 {
00171 struct args *a;
00172 CORBA_Object servant = CORBA_OBJECT_NIL;
00173 CORBA_Environment ev[1];
00174
00175 if (arguments == NULL)
00176 die("", "");
00177 a = (struct args*)arguments;
00178
00179 pthread_mutex_lock(&orb_mutex);
00180
00181 CORBA_exception_init(ev);
00182
00183 server_init(&(a->argc), a->argv, &global_orb, &root_poa, ev);
00184 abort_if_exception(ev, "Ancestors server failed ORB init");
00185
00186 servant = server_activate_service(global_orb, root_poa, ev);
00187 abort_if_exception(ev, "Ancestors server failed activating service");
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 register_object(0, servant, global_orb, ev);
00198 abort_if_exception(ev, "Ancestors server failed registering service");
00199
00200 log_info("%s: SENSIX server for ancestors\n", APP);
00201 pthread_mutex_unlock(&orb_mutex);
00202
00203 server_run(global_orb, ev);
00204 abort_if_exception(ev, "Ancestors server failed entering main loop");
00205
00206 pthread_mutex_lock(&orb_mutex);
00207 pthread_mutex_unlock(&orb_mutex);
00208
00209 server_cleanup(global_orb, root_poa, servant, ev);
00210 if (raised_exception(ev))
00211 log_error("%s: Ancestors server cleanup failed - %s\n",
00212 APP, CORBA_exception_id(ev));
00213
00214 log_info("%s: Ancestors server closing\n", APP);
00215 return NULL;
00216 }