00001 #ifndef _CORBATRACE_H
00002 #define _CORBATRACE_H
00003
00004 #include <cstring>
00005 #include <string>
00006 #include <vector>
00007
00008 #include <cstdio>
00009
00010
00011
00012
00013 namespace CORBA {
00014 char* string_dup(const char* s);
00015 }
00016
00017 namespace Steelworks {
00018
00019 struct Ring {
00020 long no;
00021 long reqNumber;
00022
00023 Ring():no(0),reqNumber(0) {}
00024 Ring(const Ring& r) {
00025 no = r.no;
00026 reqNumber = r.reqNumber;
00027 }
00028 };
00029 typedef std::vector<Ring> RingSet;
00030
00031 struct Stack {
00032 long x, y;
00033 double height;
00034 double maxDiameter;
00035 RingSet rings;
00036
00037 Stack():x(0),y(0),height(0.0),maxDiameter(0.0) {}
00038 Stack(const Stack& s) {
00039 x = s.x;
00040 y = s.y;
00041 height = s.height;
00042 maxDiameter = s.maxDiameter;
00043 rings = s.rings;
00044 }
00045 };
00046 typedef std::vector<Stack> StackSet;
00047
00048 struct Pallet {
00049 long number;
00050 StackSet stacks;
00051
00052 Pallet():number(0){}
00053 Pallet(const Pallet& p) {
00054 number = p.number;
00055 stacks = p.stacks;
00056 }
00057 };
00058
00059 namespace IDLConsts {
00060
00061 static const long CRANE_POS_UNLOAD = 0;
00062 static const long CRANE_POS_OVEN = 1;
00063 static const long CRANE_POS_BATH = 2;
00064 static const long CRANE_POS_STORAGE = 3;
00065 static const long CRANE_POS_TRANSMISSION = 4;
00066
00067
00068 static const long CRANE_SUBPOS_STORE_PLACE_1 = 1;
00069 static const long CRANE_SUBPOS_STORE_PLACE_2 = 2;
00070 static const long CRANE_SUBPOS_STORE_PLACE_3 = 3;
00071 static const long CRANE_SUBPOS_FAN_PLACE = 4;
00072 static const long CRANE_SUBPOS_POLYMER_BATH = 5;
00073 static const long CRANE_SUBPOS_WATER_BATH = 6;
00074
00075
00076 static const long PAL_POS_CRANE = 0;
00077 static const long PAL_POS_OVEN = 1;
00078 static const long PAL_POS_BATH = 2;
00079 static const long PAL_POS_STORAGE = 3;
00080 static const long PAL_POS_TRANSMISSION = 4;
00081 static const long PAL_POS_BIGSTORAGE = 5;
00082 static const long PAL_POS_HARDNESSTEST = 6;
00083
00084
00085 static const long PAL_SUBPOS_STORE_PLACE_1 = 1;
00086 static const long PAL_SUBPOS_STORE_PLACE_2 = 2;
00087 static const long PAL_SUBPOS_STORE_PLACE_3 = 3;
00088 static const long PAL_SUBPOS_FAN_PLACE = 4;
00089 static const long PAL_SUBPOS_POLYMER_BATH = 5;
00090 static const long PAL_SUBPOS_WATER_BATH = 6;
00091
00092
00093
00094 static const long VEHICLE_POS_ROW1 = 0;
00095 static const long VEHICLE_POS_ROW2 = 1;
00096 static const long VEHICLE_POS_ROW3 = 2;
00097 static const long VEHICLE_POS_ROW4 = 3;
00098 static const long VEHICLE_POS_UNLOAD = 4;
00099
00100
00101 static const long STORAGE_EMPTY = 0;
00102 static const long STORAGE_PARKING = 1;
00103 static const long STORAGE_AIRCOOLING = 2;
00104 static const long STORAGE_VENTILATOR = 3;
00105 };
00106
00107 struct Request {
00108 Request() {}
00109 Request(const Request& r) {*this = r;}
00110 Request& operator=(const Request& r) {
00111 number = r.number;
00112 startTime = strdup(r.startTime);
00113 treatment = strdup(r.treatment);
00114 steelType = strdup(r.steelType);
00115 numberOfRings = r.numberOfRings;
00116 diameter = r.diameter;
00117 height = r.height;
00118 weight = r.weight;
00119 numberOfRings = r.numberOfRings;
00120 comment = strdup(r.comment);
00121 }
00122
00123 ~Request() {
00124 if (startTime!=0) free(startTime);
00125 if (treatment!=0) free(treatment);
00126 if (steelType!=0) free(steelType);
00127 if (comment!=0) free(comment);
00128 }
00129
00130 long number;
00131 char* startTime;
00132 char* treatment;
00133 char* steelType;
00134 long numberOfRings;
00135 double diameter;
00136 double height;
00137 double weight;
00138 char* comment;
00139 };
00140 }
00141
00142 class ListenerWrapper{
00143 ListenerWrapper* remote;
00144 ListenerWrapper():remote(0){}
00145
00146 friend ListenerWrapper* listener();
00147 public:
00148 static void initialize(){}
00149
00150 void factorySetState(bool state){
00151 #ifdef _CORBATRACE_DEBUG
00152 if (remote) remote->factorySetState(state);
00153 else printf("factory set state to %s\n",state?"works":"does not work");
00154 #endif
00155 }
00156
00157 void newRequest(const Steelworks::Request& req) {
00158 #ifdef _CORBATRACE_DEBUG
00159 if (remote) remote->newRequest(req);
00160 else printf("new request %d %s %s %s %d\n", req.number, req.startTime, req.treatment, req.steelType, req.numberOfRings);
00161 #endif
00162 printf(".");
00163 }
00164
00165 void doneRequest(long number, const char* endTime) {
00166 #ifdef _CORBATRACE_DEBUG
00167 if (remote) remote->doneRequest(number, endTime);
00168 else printf("done request %d %s\n", number, endTime);
00169 #endif
00170 printf(".");
00171 }
00172
00173 void setNumberOfRings(long reqNumber, long newNumber) {
00174 #ifdef _CORBATRACE_DEBUG
00175 if (remote) remote->setNumberOfRings(reqNumber, newNumber);
00176 else printf("set number of rings %d %d\n", reqNumber, newNumber);
00177 #endif
00178 printf(".");
00179 }
00180
00181
00182 void doneRing(long reqNumber) {
00183 #ifdef _CORBATRACE_DEBUG
00184 if (remote) remote->doneRing(reqNumber);
00185 else printf("done ring %d\n", reqNumber);
00186 #endif
00187 printf(".");
00188 }
00189
00190 void moveVehicle(long number,long newPosition){
00191 #ifdef _CORBATRACE_DEBUG
00192 if (remote) remote->moveVehicle(number,newPosition);
00193 else printf("move vehicle %d %d\n",number,newPosition);
00194 #endif
00195 }
00196
00197 void shift(long numberOfRow) {
00198 #ifdef _CORBATRACE_DEBUG
00199 if (remote) remote->shift(numberOfRow);
00200 else printf("row %d shifted", numberOfRow);
00201 #endif
00202 printf(".");
00203 }
00204
00205 void newPallet(const Steelworks::Pallet& p){
00206 #ifdef _CORBATRACE_DEBUG
00207 if (remote) remote->newPallet(p);
00208 else printf("new pallet %d\n", p.number);
00209 #endif
00210 printf(".");
00211 }
00212
00213 void movePallet(long number, long newPosition){
00214 #ifdef _CORBATRACE_DEBUG
00215 if (remote) remote->movePallet(number,newPosition);
00216 else printf("move pallet %d %d\n",number,newPosition);
00217 #endif
00218 }
00219
00220 void palletChangesOwner(long palletNumber, long newOwner, long newSubOwner){
00221 #ifdef _CORBATRACE_DEBUG
00222 if (remote) remote->palletChangesOwner(palletNumber, newOwner, newSubOwner);
00223 else printf("palletChangesOwner %d-%d-%d\n", palletNumber, newOwner, newSubOwner);
00224 #endif
00225 }
00226
00227 void deletePallet(long number){
00228 #ifdef _CORBATRACE_DEBUG
00229 if (remote) remote->deletePallet(number);
00230 else printf("delete pallet %d\n",number);
00231 #endif
00232 printf(".");
00233 }
00234
00235 void craneSetState(bool moves){
00236 #ifdef _CORBATRACE_DEBUG
00237 if (remote) remote->craneSetState(moves);
00238 else printf("crane set state to %s\n",moves?"moves":"does not move");
00239 #endif
00240 }
00241
00242 void craneMoveTo(long newPosition, long subPosition) {
00243 #ifdef _CORBATRACE_DEBUG
00244 if (remote) remote->craneMoveTo(newPosition, subPosition);
00245 else printf("crane moves to position %d-%d\n", newPosition, subPosition);
00246 #endif
00247 printf(".");
00248 }
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 void ovenSetState(long number, long newState){
00259 #ifdef _CORBATRACE_DEBUG
00260 if (remote)
00261 remote->ovenSetState(number,newState);
00262 else
00263 printf("oven set state %d %d\n",number,newState);
00264 #endif
00265 printf(".");
00266 }
00267
00268 void storageSetState(long storageNumber, long state) {
00269 #ifdef _CORBATRACE_DEBUG
00270 if (remote)
00271 remote->storageSetState(storageNumber, state);
00272 else
00273 printf("set storage %d to state %d\n", storageNumber, state);
00274 #endif
00275 printf(".");
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 void transmissionMoveTo(long position) {
00311 #ifdef _CORBATRACE_DEBUG
00312 if (remote) remote->transmissionMoveTo(position);
00313 else printf("transmission moves to %d\n", position);
00314 #endif
00315 printf(".");
00316 }
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 void setTime(const char* time){
00335 #ifdef _CORBATRACE_DEBUG
00336 if (remote)
00337 remote->setTime(time);
00338 else
00339 printf("set time %s\n",time);
00340 #endif
00341 printf(".");
00342 }
00343
00344 void setDay(long day){
00345 #ifdef _CORBATRACE_DEBUG
00346 if (remote)
00347 remote->setDay(day);
00348 else
00349 printf("set day %d\n",day);
00350 #endif
00351 }
00352
00353 void stop() {
00354 #ifdef _CORBATRACE_DEBUG
00355 if (remote)
00356 remote->stop();
00357 else
00358 printf("simulation finsihed");
00359 #endif
00360 printf(".");
00361 }
00362 };
00363
00364 inline ListenerWrapper *listener(){
00365 static ListenerWrapper li;
00366 return &li;
00367 }
00368
00369 #endif
00370