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 <stdlib.h>
00036 #include <unistd.h>
00037 #include <string.h>
00038 #include <pthread.h>
00039 #include <orbit/orbit.h>
00040 #include "sensix.h"
00041 #include "sense_impl.h"
00042 #include "corba_discovery.h"
00043 #include "discovery_service.h"
00044 #include "corba_util.h"
00045 #include "sense.h"
00046 #include "parser.h"
00047
00048
00049
00050
00051
00052
00053
00054 extern pthread_mutex_t orb_mutex;
00055 extern CORBA_ORB global_orb;
00056
00057
00058 pthread_mutex_t sibling_mutex = PTHREAD_MUTEX_INITIALIZER;
00059 bool_t siblings_running = false;
00060
00061
00062 static void siblings_run(gov_lanl_isr_sensix_SensoryRequest sensix_service,
00063 CORBA_Environment *ev)
00064 {
00065 pthread_mutex_lock(&sibling_mutex);
00066 while(siblings_running) {
00067 pthread_mutex_unlock(&sibling_mutex);
00068
00069 {
00070
00071 unsigned char cmd = SUMMA;
00072
00073
00074
00075 gov_lanl_isr_sensix_Functor f =
00076 gov_lanl_isr_sensix_FunctorFactory_generate(sensix_service, cmd, ev);
00077 switch (cmd) {
00078 case (ALPHA):
00079
00080 break;
00081 case (BETA):
00082
00083 break;
00084 }
00085
00086 gov_lanl_isr_sensix_SensoryResponse r;
00087
00088
00089 gov_lanl_isr_sensix_SensoryRequest_apply(sensix_service, f, r, ev);
00090 if (raised_exception(ev))
00091 return;
00092 }
00093
00094 pthread_mutex_lock(&sibling_mutex);
00095 }
00096 pthread_mutex_unlock(&sibling_mutex);
00097 }
00098
00099
00100 void siblings_shutdown(int sig)
00101 {
00102 pthread_mutex_lock(&sibling_mutex);
00103 siblings_running = false;
00104 pthread_mutex_unlock(&sibling_mutex);
00105 }
00106
00107
00108 void *siblings_client(void *arguments)
00109 {
00110 struct args *a;
00111 CORBA_Environment ev[1];
00112 gov_lanl_isr_sensix_SensoryRequest sensix_service = CORBA_OBJECT_NIL;
00113
00114 if (arguments == NULL)
00115 die("Siblings thread", "nil arguments");
00116 a = (struct args*)arguments;
00117
00118 pthread_mutex_lock(&orb_mutex);
00119 pthread_mutex_unlock(&orb_mutex);
00120
00121 siblings_running = true;
00122 CORBA_exception_init(ev);
00123 log_info("%s: SENSIX client for siblings\n", APP);
00124
00125 sensix_service = (gov_lanl_isr_sensix_SensoryRequest)
00126 discover_object(0, global_orb, ev);
00127 if (raised_exception(ev)) {
00128 CORBA_exception_free(ev);
00129 goto cleanup;
00130 }
00131
00132 siblings_run(sensix_service, ev);
00133 abort_if_exception(ev, "Sensix service not reachable");
00134
00135 cleanup:
00136 pthread_mutex_lock(&orb_mutex);
00137 CORBA_Object_release(sensix_service, ev);
00138 if (raised_exception(ev))
00139 log_error("%s: Siblings client cleanup failed - %s\n",
00140 APP, CORBA_exception_id(ev));
00141 pthread_mutex_unlock(&orb_mutex);
00142
00143 log_info("%s: Siblings client closing\n", APP);
00144 return NULL;
00145 }
00146
00147
00148
00149
00150
00151
00152
00153 static bool_t _desc_running = false;
00154 static pthread_mutex_t desc_mutex = PTHREAD_MUTEX_INITIALIZER;
00155
00156
00157 void descendants_shutdown(int sig)
00158 {
00159 pthread_mutex_lock(&desc_mutex);
00160 _desc_running = false;
00161 pthread_mutex_unlock(&desc_mutex);
00162 }
00163
00164
00165 void *descendants_client(void *arguments)
00166 {
00167 enum parser parser = MANTIS;
00168 char *str_parser = "Mantis";
00169 struct args *a;
00170
00171 if (arguments == NULL)
00172 die("", "");
00173 a = (struct args*)arguments;
00174
00175 if (a->argc > 2)
00176 die("too many arguments", "");
00177 if (a->argc == 2) {
00178 str_parser = a->argv[1];
00179
00180 if (strcasecmp(a->argv[1], "mantis") == 0)
00181 parser = MANTIS;
00182 else if (strcasecmp(a->argv[1], "tinyos") == 0)
00183 parser = TINYOS;
00184 }
00185 log_info("%s: SENSIX client for %s motes\n", APP, str_parser);
00186
00187 _desc_running = true;
00188 pthread_mutex_lock(&desc_mutex);
00189 while (_desc_running) {
00190 pthread_mutex_unlock(&desc_mutex);
00191
00192 {
00193
00194 sleep(10);
00195 }
00196
00197 pthread_mutex_lock(&desc_mutex);
00198 }
00199 pthread_mutex_unlock(&desc_mutex);
00200
00201 log_info("%s: %s descendants client closing\n", APP, str_parser);
00202 return NULL;
00203 }
00204