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 <unistd.h>
00036 #include <pthread.h>
00037 #include <UnitTest++.h>
00038
00039 #include "sensix.h"
00040 #include "sense_client.h"
00041 #include "sense_server.h"
00042 #include "sensing.h"
00043 #include "sensingC.h"
00044 #include "stacktrace.h"
00045
00046 using namespace sensix;
00047 using namespace sensix::sensing;
00048
00049 #define VERBOSE true
00050
00051
00052 static pthread_mutex_t l2_mutex = PTHREAD_MUTEX_INITIALIZER;
00053
00054 SUITE(TwoLevelCorba)
00055 {
00056 class Corba2Fixture;
00057
00058 struct _arguments {
00059 Corba2Fixture *cf;
00060 int which;
00061 int num_levels;
00062 unsigned char debug_level;
00063 };
00064
00065 void *run_corba(void *args);
00066
00067 class Corba2Fixture {
00068 public:
00069 SenseClient* sclient;
00070 SenseServer* sserver;
00071 pthread_t runc, runs;
00072 unsigned int ready;
00073
00074 Corba2Fixture() {
00075 _arguments args1, args2;
00076 args1.debug_level = 0;
00077 if (VERBOSE)
00078 args1.debug_level = 2;
00079 args2.debug_level = args1.debug_level;
00080 args1.num_levels = args2.num_levels = 2;
00081 args1.cf = args2.cf = this;
00082 ready = 0;
00083 enable_backtrace();
00084
00085 args1.which = 0;
00086 pthread_create(&runc, NULL, run_corba, (void*)&args1);
00087
00088 args2.which = 1;
00089 pthread_create(&runs, NULL, run_corba, (void*)&args2);
00090
00091 bool done = false;
00092 while (!done) {
00093 usleep(10);
00094 pthread_mutex_lock(&l2_mutex);
00095 if (ready >= 2)
00096 done = true;
00097 pthread_mutex_unlock(&l2_mutex);
00098 }
00099 }
00100
00101 ~Corba2Fixture() {
00102 sclient->shutdown();
00103 sserver->shutdown();
00104 pthread_join(runc, NULL);
00105 pthread_join(runs, NULL);
00106 }
00107 };
00108
00109
00110 void *run_corba(void *args) {
00111 if (args == NULL)
00112 return NULL;
00113 _arguments *ap = (_arguments*)args;
00114
00115 Corba2Fixture *fix = ap->cf;
00116 int which = ap->which;
00117 int num_levels = ap->num_levels;
00118
00119 switch (which) {
00120 case 0:
00121 try {
00122 fix->sclient = new SenseClient(30, num_levels, 0, NULL);
00123 pthread_mutex_lock(&l2_mutex);
00124 fix->ready++;
00125 pthread_mutex_unlock(&l2_mutex);
00126 } catch (CORBA::Exception &e) {
00127 printStackTrace("CORBA::", __FILE__, __LINE__);
00128 }
00129 break;
00130
00131 case 1:
00132 try {
00133 fix->sserver = new SenseServer(20, num_levels - 1, 0, NULL);
00134 pthread_mutex_lock(&l2_mutex);
00135 fix->ready++;
00136 pthread_mutex_unlock(&l2_mutex);
00137 fix->sserver->run();
00138 } catch (CORBA::Exception &e) {
00139 printStackTrace("CORBA::", __FILE__, __LINE__);
00140 }
00141 break;
00142 }
00143 return NULL;
00144 }
00145
00146
00147 TEST_FIXTURE(Corba2Fixture, startstop_test) {
00148 usleep(100);
00149 }
00150
00151 TEST_FIXTURE(Corba2Fixture, addcapability_test) {
00152 LocationImpl *li = new LocationImpl();
00153 Capability_ptr loc = (Capability_ptr)li;
00154 sserver->addCapability(GPS, loc);
00155 usleep(100);
00156 }
00157
00158 #if 0
00159 TEST_FIXTURE(Corba2Fixture, twoleveltask_test) {
00160 Capability_ptr loc = (Capability_ptr)(new LocationImpl());
00161 sserver->addCapability(SenseCorba.GPS, loc);
00162 usleep(100);
00163
00164 string cmd = "recite(spatialseries(sense(sensor=GPS)))";
00165 Sensory *f = SenseParser.senseParser(sclient->getPoa(), cmd);
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 CHECK(sclient->devolve(r) == 0);
00180 usleep(100);
00181
00182 Series* array = f->results();
00183 CHECK(array != NULL);
00184 CHECK_EQUAL((*array)[0].fresult(), 35.8880556);
00185 CHECK_EQUAL((*array)[1].fresult(), -106.3063889);
00186 CHECK_EQUAL((*array)[2].fresult(), 2255.52);
00187 }
00188 #endif
00189 }