Changeset 607 for trunk/zoo-project/zoo-kernel/service.h
- Timestamp:
- Mar 12, 2015, 3:14:52 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service.h
r601 r607 160 160 */ 161 161 #define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*) 162 /** 163 * The memory size to create a services 164 */ 165 #define SERVICES_SIZE SERVICE_SIZE+sizeof(services*) 166 /** 167 * The memory size to create a registry 168 */ 169 #define REGISTRY_SIZE SERVICES_SIZE+sizeof(char*) 162 170 163 171 #define SHMSZ 27 … … 174 182 /** 175 183 * KVP linked list 176 *177 * Deal with WPS KVP (name,value).178 * A map is defined as:179 * - name : a key,180 * - value: a value,181 * - next : a pointer to the next map if any.182 184 */ 183 185 typedef struct map{ 184 char* name; 185 char* value; 186 struct map* next; 186 char* name; //!< the key 187 char* value; //!< the value 188 struct map* next; //!< the pointer to the next map if any or NULL 187 189 } map; 188 190 … … 197 199 * 198 200 * Small object to store WPS KVP set. 199 * Maps is defined as:200 * - a name,201 * - a content map,202 * - a pointer to the next maps if any.203 201 */ 204 202 typedef struct maps{ 205 char* name; 206 struct map* content; 207 struct maps* next; 203 char* name; //!< the maps name 204 struct map* content; //!< the content map 205 struct maps* next; //!< the pointer to the next maps if any or NULL 208 206 } maps; 209 207 … … 455 453 * 456 454 * Used to store informations about formats, such as mimeType, encoding ... 457 *458 * An iotype is defined as :459 * - a content map,460 * - a pointer to the next iotype if any.461 455 */ 462 456 typedef struct iotype{ 463 struct map* content; 464 struct iotype* next; 457 struct map* content; //!< the content map 458 struct iotype* next; //!< the pointer to the next iotype if any or NULL 465 459 } iotype; 466 460 … … 469 463 * 470 464 * The elements are used to store metadata informations defined in the ZCFG. 471 *472 * An elements is defined as:473 * - a name,474 * - a content map,475 * - a metadata map,476 * - a format (possible values are LiteralData, ComplexData or477 * BoundingBoxData),478 * - a default iotype,479 * - a pointer to the next elements id any.480 465 */ 481 466 typedef struct elements{ 482 char* name; 483 struct map* content; 484 struct map* metadata; 485 char* format; 486 struct iotype* defaults; 487 struct iotype* supported; 488 struct elements* next; 467 char* name; //!< the name 468 struct map* content; //!< the content map 469 struct map* metadata; //!< the metadata map 470 char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData 471 struct iotype* defaults; //!< the default iotype 472 struct iotype* supported; //!< the supported iotype 473 struct elements* next; //!< the pointer to the next element if any (or NULL) 489 474 } elements; 490 475 491 476 /** 492 477 * Metadata informations about a full Service. 493 *494 * An element is defined as:495 * - a name,496 * - a content map,497 * - a metadata map,498 * - an inputs elements499 * - an outputs elements500 478 */ 501 479 typedef struct service{ 502 char* name; 503 struct map* content; 504 struct map* metadata; 505 struct elements* inputs; 506 struct elements* outputs; 480 char* name; //!< the name 481 struct map* content; //!< the content map 482 struct map* metadata; //!< the metadata map 483 struct elements* inputs; //!< the inputs elements 484 struct elements* outputs; //!< the outputs elements 507 485 } service; 508 486 509 487 /** 510 * Multiple services chained list.488 * Services chained list. 511 489 */ 512 490 typedef struct services{ 513 struct service* content; 514 struct services* next; 491 struct service* content; //!< the content service pointer 492 struct services* next; //!< the pointer to the next services* 515 493 } services; 494 495 /** 496 * Profile registry. 497 */ 498 typedef struct registry{ 499 char *name; //!< the name 500 struct services* content; //!< the content services pointer 501 struct registry* next; //!< the next registry pointer 502 } registry; 516 503 517 504 /** … … 1221 1208 tmp->metadata=NULL; 1222 1209 addMapToMap(&tmp->metadata,e->metadata); 1223 tmp->format=zStrdup(e->format); 1210 if(e->format!=NULL) 1211 tmp->format=zStrdup(e->format); 1212 else 1213 tmp->format=NULL; 1224 1214 if(e->defaults!=NULL){ 1225 1215 tmp->defaults=(iotype*)malloc(IOTYPE_SIZE); … … 1324 1314 fprintf(stderr,"\noutputs:\n"); 1325 1315 dumpElementsAsYAML(s->outputs); 1316 } 1317 } 1318 1319 /** 1320 * Duplicate a service 1321 * 1322 * @param s the service to clone 1323 * @return the allocated service containing a copy of the serfvice s 1324 */ 1325 static service* dupService(service* s){ 1326 service *res=(service*)malloc(SERVICE_SIZE); 1327 res->name=zStrdup(s->name); 1328 res->content=NULL; 1329 addMapToMap(&res->content,s->content); 1330 res->metadata=NULL; 1331 addMapToMap(&res->metadata,s->metadata); 1332 res->inputs=dupElements(s->inputs); 1333 res->outputs=dupElements(s->outputs); 1334 return res; 1335 } 1336 1337 /** 1338 * Print the registry on stderr. 1339 * 1340 * @param r the registry 1341 */ 1342 static void dumpRegistry(registry* r){ 1343 registry* p=r; 1344 while(p!=NULL){ 1345 fprintf(stderr,"%s \n",p->name); 1346 services* s=p->content; 1347 s=p->content; 1348 while(s!=NULL){ 1349 dumpService(s->content); 1350 s=s->next; 1351 } 1352 p=p->next; 1353 } 1354 } 1355 1356 /** 1357 * Add a service to the registry 1358 * 1359 * @param reg the resgitry to add the service 1360 * @param name the registry name to update 1361 * @param content the service to add 1362 */ 1363 static bool addServiceToRegistry(registry** reg,char* name,service* content){ 1364 registry *l=*reg; 1365 int isInitial=-1; 1366 if(l==NULL){ 1367 l=(registry*)malloc(REGISTRY_SIZE); 1368 isInitial=1; 1369 } 1370 if(l!=NULL){ 1371 int hasLevel=-1; 1372 while(isInitial<0 && l!=NULL){ 1373 if(l->name!=NULL && strcasecmp(name,l->name)==0){ 1374 hasLevel=1; 1375 break; 1376 } 1377 l=l->next; 1378 } 1379 if(hasLevel<0){ 1380 if(isInitial<0) 1381 l=(registry*)malloc(REGISTRY_SIZE); 1382 l->name=zStrdup(name); 1383 l->content=NULL; 1384 l->next=NULL; 1385 } 1386 if(l->content==NULL){ 1387 l->content=(services*)malloc(SERVICES_SIZE); 1388 l->content->content=dupService(content); 1389 l->content->next=NULL; 1390 } 1391 else{ 1392 services* s=l->content; 1393 while(s->next!=NULL) 1394 s=s->next; 1395 s->next=(services*)malloc(SERVICES_SIZE); 1396 s->next->content=dupService(content); 1397 s->next->next=NULL; 1398 } 1399 l->next=NULL; 1400 if(isInitial>0) 1401 *reg=l; 1402 else{ 1403 registry *r=*reg; 1404 while(r->next!=NULL) 1405 r=r->next; 1406 r->next=l; 1407 r->next->next=NULL; 1408 } 1409 return true; 1410 } 1411 else 1412 return false; 1413 } 1414 1415 /** 1416 * Free memory allocated for the registry 1417 * 1418 * @param r the registry 1419 */ 1420 static void freeRegistry(registry** r){ 1421 registry* lr=*r; 1422 while(lr!=NULL){ 1423 services* s=lr->content; 1424 free(lr->name); 1425 while(s!=NULL){ 1426 service* s1=s->content; 1427 s=s->next; 1428 if(s1!=NULL){ 1429 freeService(&s1); 1430 free(s1); 1431 s1=NULL; 1432 } 1433 } 1434 lr=lr->next; 1435 } 1436 } 1437 1438 /** 1439 * Access a service in the registry 1440 * 1441 * @param r the registry 1442 * @param level the regitry to search ("concept", "generic" or "implementation") 1443 * @param sname the service name 1444 * @return the service pointer if a corresponding service was found or NULL 1445 */ 1446 static service* getServiceFromRegistry(registry* r,char *level,char* sname){ 1447 registry *lr=r; 1448 while(lr!=NULL){ 1449 if(strcasecmp(lr->name,level)==0){ 1450 services* s=lr->content; 1451 while(s!=NULL){ 1452 if(s->content!=NULL && strcasecmp(s->content->name,sname)==0) 1453 return s->content; 1454 s=s->next; 1455 } 1456 break; 1457 } 1458 lr=lr->next; 1459 } 1460 return NULL; 1461 } 1462 1463 /** 1464 * Apply inheritance to an out map from a reference in map 1465 * 1466 * @param out the map to update 1467 * @param in the reference map (containing inherited properties) 1468 */ 1469 static void inheritMap(map** out,map* in){ 1470 map* content=in; 1471 while(content!=NULL && *out!=NULL){ 1472 map* cmap=getMap(*out,content->name); 1473 if(cmap==NULL) 1474 addToMap(*out,content->name,content->value); 1475 content=content->next; 1476 } 1477 } 1478 1479 /** 1480 * Apply inheritance to an out iotype from a reference in iotype 1481 * 1482 * @param out the iotype to update 1483 * @param in the reference iotype (containing inherited properties) 1484 */ 1485 static void inheritIOType(iotype** out,iotype* in){ 1486 iotype* io=in; 1487 iotype* oio=*out; 1488 if(io!=NULL){ 1489 if(*out==NULL){ 1490 *out=(iotype*)malloc(IOTYPE_SIZE); 1491 (*out)->content=NULL; 1492 addMapToMap(&(*out)->content,io->content); 1493 (*out)->next=NULL; 1494 oio=*out; 1495 inheritIOType(&oio->next,io->next); 1496 }else{ 1497 inheritIOType(&oio->next,io->next); 1498 } 1499 } 1500 } 1501 1502 /** 1503 * Apply inheritance to an out elements from a reference in elements 1504 * 1505 * @param out the elements to update 1506 * @param in the reference elements (containing inherited properties) 1507 */ 1508 static void inheritElements(elements** out,elements* in){ 1509 elements* content=in; 1510 while(content!=NULL && *out!=NULL){ 1511 elements* cmap=getElements(*out,content->name); 1512 if(cmap==NULL) 1513 addToElements(out,content); 1514 else{ 1515 inheritMap(&cmap->content,content->content); 1516 inheritMap(&cmap->metadata,content->metadata); 1517 if(cmap->format==NULL && content->format!=NULL) 1518 cmap->format=zStrdup(content->format); 1519 inheritIOType(&cmap->defaults,content->defaults); 1520 if(cmap->supported==NULL) 1521 inheritIOType(&cmap->supported,content->supported); 1522 else{ 1523 iotype* p=content->supported; 1524 while(p!=NULL){ 1525 addMapToIoType(&cmap->supported,p->content); 1526 p=p->next; 1527 } 1528 } 1529 } 1530 content=content->next; 1531 } 1532 } 1533 1534 /** 1535 * Apply inheritance to a service based on a registry 1536 * 1537 * @param r the registry storing profiles hierarchy 1538 * @param s the service to update depending on its inheritance 1539 */ 1540 static void inheritance(registry *r,service** s){ 1541 if(r==NULL) 1542 return; 1543 service* ls=*s; 1544 if(ls->content==NULL) 1545 return; 1546 map* profile=getMap(ls->content,"extend"); 1547 map* level=getMap(ls->content,"level"); 1548 if(profile!=NULL&&level!=NULL){ 1549 service* s1; 1550 if(strncasecmp(level->value,"profile",7)==0) 1551 s1=getServiceFromRegistry(r,"generic",profile->value); 1552 else 1553 s1=getServiceFromRegistry(r,level->value,profile->value); 1554 1555 inheritMap(&ls->content,s1->content); 1556 inheritMap(&ls->metadata,s1->metadata); 1557 if(ls->inputs==NULL && s1->inputs!=NULL){ 1558 ls->inputs=dupElements(s1->inputs); 1559 }else{ 1560 inheritElements(&ls->inputs,s1->inputs); 1561 } 1562 if(ls->outputs==NULL && s1->outputs!=NULL){ 1563 ls->outputs=dupElements(s1->outputs); 1564 }else 1565 inheritElements(&ls->outputs,s1->outputs); 1326 1566 } 1327 1567 }
Note: See TracChangeset
for help on using the changeset viewer.