Changeset 9 for trunk/zoo-kernel/service.h
- Timestamp:
- Sep 14, 2010, 2:04:55 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-kernel/service.h
r1 r9 40 40 #define true 1 41 41 #define false -1 42 42 43 #define SERVICE_ACCEPTED 0 43 44 #define SERVICE_STARTED 1 … … 45 46 #define SERVICE_SUCCEEDED 3 46 47 #define SERVICE_FAILED 4 48 47 49 #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*)) 48 #define MAP_SIZE (2*sizeof(char*))+sizeof(map*) 49 #define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+sizeof(maps*) 50 51 52 static char* mtoupper(char* str){ 50 #define MAP_SIZE (2*sizeof(char*))+sizeof(NULL) 51 #define IOTYPE_SIZE MAP_SIZE+sizeof(NULL) 52 #define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE 53 #define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*) 54 55 56 /* static char* mtoupper(char* str){ 53 57 char* tmp=strdup(str); 54 58 if(tmp){ … … 63 67 tmp[0]=0; 64 68 return tmp; 65 } 66 69 }*/ 70 71 /** 72 * \struct maps 73 * \brief linked list of map pointer 74 * 75 * Small object to store WPS KVP set. 76 */ 67 77 typedef struct maps{ 68 char* name; 69 struct map* content; 70 struct maps* next; 78 char* name; 79 struct map* content; 80 struct maps* next; 71 81 } maps; 72 82 83 /** 84 * \struct map 85 * \brief KVP linked list 86 * 87 * Deal with WPS KVP (name,value). 88 */ 73 89 typedef struct map{ 74 char* name; 75 char* value; 76 struct map* next; 90 char* name; /* The key */ 91 char* value; /* The value */ 92 struct map* next; /* Next couple */ 77 93 } map; 78 94 … … 83 99 #endif 84 100 85 static void *_dumpMap(map* t){101 static void _dumpMap(map* t){ 86 102 if(t!=NULL){ 87 103 fprintf(stderr,"[%s] => [%s] \n",t->name,t->value); … … 91 107 fflush(stderr); 92 108 } 93 return NULL; 94 } 95 96 static void* dumpMap(map* t){ 109 } 110 111 static void dumpMap(map* t){ 97 112 map* tmp=t; 98 113 while(tmp!=NULL){ … … 100 115 tmp=tmp->next; 101 116 } 102 return NULL;103 117 } 104 118 … … 112 126 } 113 127 114 static map* createMap(c har* name,char* value){128 static map* createMap(const char* name,const char* value){ 115 129 map* tmp=(map *)malloc(MAP_SIZE); 116 130 tmp->name=strdup(name); … … 130 144 } 131 145 132 static bool hasKey(map* m,c har *key){146 static bool hasKey(map* m,const char *key){ 133 147 map* tmp=m; 134 148 while(tmp!=NULL){ 135 if(str cmp(mtoupper(tmp->name),mtoupper(key))==0)149 if(strncasecmp(tmp->name,key,strlen(key))==0) 136 150 return true; 137 151 tmp=tmp->next; … … 143 157 } 144 158 145 static maps* getMaps(maps* m,c har *key){159 static maps* getMaps(maps* m,const char *key){ 146 160 maps* tmp=m; 147 161 while(tmp!=NULL){ 148 if(str cmp(mtoupper(tmp->name),mtoupper(key))==0)162 if(strncasecmp(tmp->name,key,strlen(key))==0){ 149 163 return tmp; 164 } 150 165 tmp=tmp->next; 151 166 } … … 153 168 } 154 169 155 static map* getMap(map* m,c har *key){170 static map* getMap(map* m,const char *key){ 156 171 map* tmp=m; 157 172 while(tmp!=NULL){ 158 if(str cmp(mtoupper(tmp->name),mtoupper(key))==0)173 if(strncasecmp(tmp->name,key,strlen(key))==0){ 159 174 return tmp; 175 } 160 176 tmp=tmp->next; 161 177 } … … 166 182 maps* _tmpm=getMaps(m,key); 167 183 if(_tmpm!=NULL){ 168 map* tmpm=getMap(_tmpm->content,mtoupper(subkey));169 return tmpm;184 map* _ztmpm=getMap(_tmpm->content,subkey); 185 return _ztmpm; 170 186 } 171 187 else return NULL; 172 188 } 173 189 174 static void *freeMap(map** mo){190 static void freeMap(map** mo){ 175 191 map* _cursor=*mo; 176 192 if(_cursor!=NULL){ 193 #ifdef DEBUG 194 fprintf(stderr,"freeMap\n"); 195 #endif 177 196 free(_cursor->name); 178 197 free(_cursor->value); … … 182 201 } 183 202 } 184 return NULL; 185 } 186 203 } 204 205 static void freeMaps(maps** mo){ 206 maps* _cursor=*mo; 207 fflush(stderr); 208 if(_cursor && _cursor!=NULL){ 209 #ifdef DEBUG 210 fprintf(stderr,"freeMaps\n"); 211 #endif 212 free(_cursor->name); 213 if(_cursor->content!=NULL){ 214 freeMap(&_cursor->content); 215 free(_cursor->content); 216 } 217 if(_cursor->next!=NULL){ 218 freeMaps(&_cursor->next); 219 free(_cursor->next); 220 } 221 } 222 } 187 223 188 224 typedef struct iotype{ … … 217 253 elements* tmp=e; 218 254 while(tmp!=NULL){ 219 mtoupper(key); 220 mtoupper(tmp->name); 221 if(strcmp(key,tmp->name)==0) 255 if(strncasecmp(key,tmp->name,strlen(key))==0) 222 256 return true; 223 257 tmp=tmp->next; … … 229 263 elements* tmp=m; 230 264 while(tmp!=NULL){ 231 mtoupper(tmp->name); 232 mtoupper(key); 233 if(strcmp(tmp->name,key)==0) 265 if(strncasecmp(tmp->name,key,strlen(tmp->name))==0) 234 266 return tmp; 235 267 tmp=tmp->next; … … 239 271 240 272 241 static void *freeIOType(iotype** i){273 static void freeIOType(iotype** i){ 242 274 iotype* _cursor=*i; 243 275 if(_cursor!=NULL){ 244 276 freeMap(&_cursor->content); 245 277 free(_cursor->content); 246 freeIOType(&_cursor->next); 247 free(_cursor->next); 248 } 249 return NULL; 278 if(_cursor->next!=NULL){ 279 freeIOType(&_cursor->next); 280 free(_cursor->next); 281 } 282 } 250 283 } 251 284 … … 253 286 elements* tmp=*e; 254 287 if(tmp!=NULL){ 255 #ifdef DEBUG256 fprintf(stderr,"FREE 1");257 #endif258 288 free(tmp->name); 259 289 freeMap(&tmp->content); 260 #ifdef DEBUG261 fprintf(stderr,"FREE 2");262 #endif263 290 free(tmp->content); 264 291 freeMap(&tmp->metadata); 265 #ifdef DEBUG266 fprintf(stderr,"FREE 3");267 #endif268 292 free(tmp->metadata); 269 #ifdef DEBUG270 fprintf(stderr,"FREE 4");271 #endif272 293 free(tmp->format); 273 294 freeIOType(&tmp->defaults); 274 #ifdef DEBUG275 fprintf(stderr,"FREE 5");276 #endif277 295 if(tmp->defaults!=NULL) 278 296 free(tmp->defaults); 279 297 freeIOType(&tmp->supported); 280 #ifdef DEBUG281 fprintf(stderr,"FREE 6");282 #endif283 298 if(tmp->supported!=NULL) 284 299 free(tmp->supported); 285 tmp=tmp->next;286 } 287 } 288 289 static void *freeService(service** s){300 freeElements(&tmp->next); 301 } 302 } 303 304 static void freeService(service** s){ 290 305 service* tmp=*s; 291 306 if(tmp!=NULL){ 307 if(tmp->name!=NULL) 308 free(tmp->name); 292 309 freeMap(&tmp->content); 293 310 if(tmp->content!=NULL) … … 305 322 } 306 323 307 static void* addMapToMap(map** mo,map* mi){ 308 map* tmp=mi; 309 map* _cursor=*mo; 310 while(tmp!=NULL){ 311 if(_cursor==NULL){ 312 *mo=(map*)malloc(MAP_SIZE); 313 *mo=createMap(tmp->name,tmp->value); 314 _cursor=*mo; 315 _cursor->next=NULL; 316 } 317 else{ 318 while(_cursor->next!=NULL) 319 _cursor=_cursor->next; 320 _cursor->next=createMap(tmp->name,tmp->value); 321 } 322 tmp=tmp->next; 323 } 324 return NULL; 325 } 326 327 static void* addMapsToMaps(maps** mo,maps* mi){ 328 maps* tmp=mi; 329 maps* _cursor=*mo; 330 while(tmp!=NULL){ 331 if(_cursor==NULL){ 332 *mo=(maps*)malloc(MAP_SIZE); 333 *mo=mi; 334 _cursor=*mo; 335 } 336 else{ 337 while(_cursor->next!=NULL) 338 _cursor=_cursor->next; 339 _cursor->next=tmp; 340 } 341 tmp=tmp->next; 342 } 343 return NULL; 344 } 345 346 static void* addMapToIotype(iotype** io,map* mi){ 347 iotype* tmp=*io; 348 while(tmp!=NULL){ 349 fprintf(stderr,">> CURRENT MAP"); 350 dumpMap(tmp->content); 351 tmp=tmp->next; 352 } 353 tmp=(iotype*)malloc(ELEMENTS_SIZE); 354 tmp->content=NULL; 355 tmp->next=NULL; 356 addMapToMap(&tmp->content,mi); 357 return NULL; 358 } 359 360 static void* addToMap(map* m,char* n,char* v){ 324 static void addToMap(map* m,const char* n,const char* v){ 361 325 if(hasKey(m,n)==false){ 362 326 map* _cursor=m; … … 367 331 else{ 368 332 map *tmp=getMap(m,n); 333 if(tmp->value!=NULL) 334 free(tmp->value); 369 335 tmp->value=strdup(v); 370 336 } 371 return NULL; 372 } 373 374 375 static void* dumpElements(elements* e){ 337 } 338 339 static void addMapToMap(map** mo,map* mi){ 340 map* tmp=mi; 341 map* _cursor=*mo; 342 if(tmp==NULL){ 343 if(_cursor!=NULL){ 344 while(_cursor!=NULL) 345 _cursor=_cursor->next; 346 _cursor=NULL; 347 }else 348 *mo=NULL; 349 } 350 while(tmp!=NULL){ 351 if(_cursor==NULL){ 352 if(*mo==NULL) 353 *mo=createMap(tmp->name,tmp->value); 354 else 355 addToMap(*mo,tmp->name,tmp->value); 356 } 357 else{ 358 #ifdef DEBUG 359 fprintf(stderr,"_CURSOR\n"); 360 dumpMap(_cursor); 361 #endif 362 while(_cursor!=NULL) 363 _cursor=_cursor->next; 364 _cursor=createMap(tmp->name,tmp->value); 365 _cursor->next=NULL; 366 } 367 tmp=tmp->next; 368 #ifdef DEBUG 369 fprintf(stderr,"MO\n"); 370 dumpMap(*mo); 371 #endif 372 } 373 } 374 375 static void addMapToIoType(iotype** io,map* mi){ 376 iotype* tmp=*io; 377 while(tmp!=NULL){ 378 #ifdef DEBUG 379 fprintf(stderr,">> CURRENT MAP"); 380 dumpMap(tmp->content); 381 #endif 382 tmp=tmp->next; 383 } 384 #ifdef DEBUG 385 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 386 fflush(stderr); 387 #endif 388 tmp=(iotype*)malloc(IOTYPE_SIZE); 389 #ifdef DEBUG 390 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 391 fflush(stderr); 392 #endif 393 tmp->content=NULL; 394 #ifdef DEBUG 395 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 396 fflush(stderr); 397 #endif 398 addMapToMap(&tmp->content,mi); 399 #ifdef DEBUG 400 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 401 fflush(stderr); 402 #endif 403 dumpMap(tmp->content); 404 tmp->next=NULL; 405 } 406 407 408 static maps* dupMaps(maps** mo){ 409 maps* _cursor=*mo; 410 maps* res=NULL; 411 if(_cursor!=NULL){ 412 res=(maps*)malloc(MAPS_SIZE); 413 res->name=strdup(_cursor->name); 414 res->content=NULL; 415 res->next=NULL; 416 map* mc=_cursor->content; 417 if(mc!=NULL){ 418 addMapToMap(&res->content,mc); 419 } 420 res->next=dupMaps(&_cursor->next); 421 } 422 return res; 423 } 424 425 static void addMapsToMaps(maps** mo,maps* mi){ 426 maps* tmp=mi; 427 maps* _cursor=*mo; 428 while(tmp!=NULL){ 429 if(_cursor==NULL){ 430 *mo=dupMaps(&mi); 431 (*mo)->next=NULL; 432 } 433 else{ 434 while(_cursor->next!=NULL) 435 _cursor=_cursor->next; 436 _cursor->next=dupMaps(&tmp); 437 } 438 tmp=tmp->next; 439 } 440 } 441 442 443 static void dumpElements(elements* e){ 376 444 elements* tmp=e; 377 445 while(tmp!=NULL){ … … 401 469 tmp=tmp->next; 402 470 } 403 return NULL; 404 } 405 471 } 406 472 407 473 static elements* dupElements(elements* e){ 408 if(e!=NULL){ 409 #ifdef DEBUG 474 elements* cursor=e; 475 elements* tmp=NULL; 476 if(cursor!=NULL){ 477 #ifdef DEBUG 478 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 410 479 dumpElements(e); 411 #endif 412 elements* tmp=(elements*)malloc(ELEMENTS_SIZE); 480 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 481 #endif 482 tmp=(elements*)malloc(ELEMENTS_SIZE); 413 483 tmp->name=strdup(e->name); 414 484 tmp->content=NULL; … … 418 488 tmp->format=strdup(e->format); 419 489 if(e->defaults!=NULL){ 420 tmp->defaults=(iotype*)malloc( MAP_SIZE);490 tmp->defaults=(iotype*)malloc(IOTYPE_SIZE); 421 491 tmp->defaults->content=NULL; 492 addMapToMap(&tmp->defaults->content,e->defaults->content); 422 493 tmp->defaults->next=NULL; 423 addMapToMap(&tmp->defaults->content,e->defaults->content); 424 while(e->defaults->next!=NULL){425 tmp->defaults->next=(iotype*)malloc(MAP_SIZE);426 addMapToMap(&tmp->defaults->next->content,e->defaults->content); 427 } 428 } 494 #ifdef DEBUG 495 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 496 dumpMap(tmp->defaults->content); 497 #endif 498 }else 499 tmp->defaults=NULL; 429 500 if(e->supported!=NULL){ 430 tmp->supported=(iotype*)malloc( MAP_SIZE);501 tmp->supported=(iotype*)malloc(IOTYPE_SIZE); 431 502 tmp->supported->content=NULL; 432 503 tmp->supported->next=NULL; 433 504 addMapToMap(&tmp->supported->content,e->supported->content); 505 iotype *etmp=*(&tmp->supported->next) ; 434 506 iotype *tmp2=e->supported->next; 435 507 while(tmp2!=NULL){ 436 tmp->supported->next=(iotype*)malloc(MAP_SIZE); 437 addMapToMap(&tmp->supported->next->content,tmp2->content); 508 etmp=(iotype*)malloc(IOTYPE_SIZE); 509 etmp->content=NULL; 510 addMapToMap(&etmp->content,tmp2->content); 511 etmp->next=NULL; 512 #ifdef DEBUG 513 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 514 dumpMap(tmp->defaults->content); 515 #endif 438 516 tmp2=tmp2->next; 517 etmp=etmp->next; 439 518 } 440 519 } 441 tmp->next=NULL; 442 return tmp; 443 } 444 return NULL; 445 } 446 447 static void* addToElements(elements* m,elements* e){ 448 elements* _cursor=m; 520 else 521 tmp->supported=NULL; 522 tmp->next=dupElements(cursor->next); 523 } 524 return tmp; 525 } 526 527 static void addToElements(elements** m,elements* e){ 528 elements* _cursor=*m; 449 529 elements* tmp=e; 450 530 if(_cursor==NULL){ 451 m=dupElements(tmp); 452 return NULL; 453 } 454 while(_cursor->next!=NULL) 455 _cursor=_cursor->next; 456 _cursor->next=dupElements(tmp); 457 return NULL; 458 } 459 460 static void* dumpService(service* s){ 531 *m=dupElements(tmp); 532 }else{ 533 while(_cursor->next!=NULL) 534 _cursor=_cursor->next; 535 _cursor->next=dupElements(tmp); 536 } 537 } 538 539 static void dumpService(service* s){ 461 540 fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name); 462 541 if(s->content!=NULL){ … … 475 554 } 476 555 fprintf(stderr,"++++++++++++++++++\n"); 477 return NULL; 478 } 479 480 static void* mapsToCharXXX(maps* m,char*** c){ 556 } 557 558 static void mapsToCharXXX(maps* m,char*** c){ 481 559 maps* tm=m; 482 560 int i=0; … … 506 584 } 507 585 memcpy(c,tmp,10*10*1024); 508 return NULL; 509 } 510 511 static void* charxxxToMaps(char*** c,maps**m){ 586 } 587 588 static void charxxxToMaps(char*** c,maps**m){ 512 589 maps* trorf=*m; 513 590 int i,j; … … 526 603 trorf->content=createMap(tmp[i][j],tmp[i][j+1]); 527 604 else 528 addMapToMap(&trorf->content,createMap(tmp[i][j],tmp[i][j+1]));605 addToMap(trorf->content,tmp[i][j],tmp[i][j+1]); 529 606 } 530 607 trorf=trorf->next; 531 608 } 532 609 m=&trorf; 533 return NULL;534 610 } 535 611
Note: See TracChangeset
for help on using the changeset viewer.