Changeset 790 for trunk/zoo-project/zoo-kernel/service.c
- Timestamp:
- Dec 19, 2016, 6:01:06 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service.c
r757 r790 74 74 75 75 /** 76 * Dump a map to a file 76 * Dump a map to a file 77 77 * 78 78 * @param t the map to dump to file 79 * @param file the file to store the map79 * @param file the file pointer to store the map 80 80 */ 81 81 void dumpMapToFile(map* t,FILE* file){ … … 96 96 while(tmp!=NULL){ 97 97 fprintf(stderr,"MAP => [%s] \n",tmp->name); 98 fprintf(stderr," * CONTENT [%s] \n",tmp->name); 98 99 dumpMap(tmp->content); 100 fprintf(stderr," * CHILD [%s] \n",tmp->name); 101 dumpMaps(tmp->child); 99 102 tmp=tmp->next; 100 103 } … … 105 108 * 106 109 * @param m the map to dump 107 * @param file_path the full path to the file name to store the map 108 */ 109 void dumpMapsToFile(maps* m,char* file_path,int limit){ 110 FILE* file=fopen(file_path,"w+"); 110 * @param file the the file pointer to store the map 111 */ 112 void _dumpMapsToFile(maps* m,FILE* file,int limit){ 111 113 maps* tmp=m; 112 114 int cnt=0; 113 115 while(tmp!=NULL){ 114 116 fprintf(file,"[%s]\n",tmp->name); 115 dumpMapToFile(tmp->content,file); 117 if(tmp->child!=NULL){ 118 _dumpMapsToFile(tmp->child,file,limit); 119 }else 120 dumpMapToFile(tmp->content,file); 116 121 fflush(file); 117 122 tmp=tmp->next; … … 121 126 } 122 127 fflush(file); 128 } 129 130 /** 131 * Dump a maps to a file, see _dumpMapsToFile(). 132 * 133 * @param m the map to dump 134 * @param file_path the full path to the file name to store the map 135 * @param limit the number limiting the maps to be dumped 136 */ 137 void dumpMapsToFile(maps* m,char* file_path,int limit){ 138 FILE* file=fopen(file_path,"w+"); 139 _dumpMapsToFile(m,file,limit); 140 fflush(file); 123 141 fclose(file); 124 142 } … … 129 147 * @param name the key to add to the map 130 148 * @param value the corresponding value to add to the map 131 * @return the allocated map149 * @return a pointer to the allocated map 132 150 */ 133 151 map* createMap(const char* name,const char* value){ … … 136 154 tmp->value=zStrdup(value); 137 155 tmp->next=NULL; 156 return tmp; 157 } 158 159 /** 160 * Create a new maps with the given name 161 * 162 * @param name of the maps 163 * @return the allocated map 164 */ 165 maps* createMaps(const char* name){ 166 maps* tmp = (maps *) malloc (MAPS_SIZE); 167 tmp->name = zStrdup (name); 168 tmp->content = NULL; 169 tmp->child = NULL; 170 tmp->next = NULL; 138 171 return tmp; 139 172 } … … 283 316 freeMap(&_cursor->content); 284 317 free(_cursor->content); 318 } 319 if(_cursor->child!=NULL){ 320 freeMaps(&_cursor->child); 321 free(_cursor->child); 285 322 } 286 323 if(_cursor->next!=NULL){ … … 362 399 if(tmp->format!=NULL) 363 400 free(tmp->format); 401 if(tmp->child!=NULL){ 402 freeElements(&tmp->child); 403 free(tmp->child); 404 } 364 405 freeIOType(&tmp->defaults); 365 406 if(tmp->defaults!=NULL) … … 593 634 iotype* getIoTypeFromElement(elements* e,char *name, map* values){ 594 635 elements* cursor=e; 595 while(cursor!=NULL){ 596 if(strcasecmp(cursor->name,name)==0){ 597 if(contains(cursor->defaults->content,values)==true) 598 return cursor->defaults; 599 else{ 600 iotype* tmp=cursor->supported; 601 while(tmp!=NULL){ 602 if(contains(tmp->content,values)==true) 603 return tmp; 604 tmp=tmp->next; 636 if(values!=NULL) 637 while(cursor!=NULL){ 638 if(strcasecmp(cursor->name,name)==0 && (cursor->defaults!=NULL || cursor->supported!=NULL)){ 639 if(contains(cursor->defaults->content,values)==true) 640 return cursor->defaults; 641 else{ 642 iotype* tmp=cursor->supported; 643 while(tmp!=NULL){ 644 if(contains(tmp->content,values)==true) 645 return tmp; 646 tmp=tmp->next; 647 } 605 648 } 606 649 } 607 } 608 cursor=cursor->next; 609 } 650 cursor=cursor->next; 651 } 610 652 return NULL; 611 653 } … … 677 719 maps* res=NULL; 678 720 if(_cursor!=NULL){ 679 res=(maps*)malloc(MAPS_SIZE); 680 res->name=zStrdup(_cursor->name); 681 res->content=NULL; 682 res->next=NULL; 721 res=createMaps(_cursor->name); 683 722 map* mc=_cursor->content; 684 723 if(mc!=NULL){ 685 724 addMapToMap(&res->content,mc); 686 725 loadMapBinaries(&res->content,mc); 726 } 727 maps* mcs=_cursor->child; 728 if(mcs!=NULL){ 729 res->child=dupMaps(&mcs); 687 730 } 688 731 res->next=dupMaps(&_cursor->next); … … 709 752 _cursor=_cursor->next; 710 753 maps* tmp1=getMaps(*mo,tmp->name); 711 if(tmp1==NULL) 754 if(tmp1==NULL){ 712 755 _cursor->next=dupMaps(&tmp); 713 else 756 if(tmp->child!=NULL) 757 _cursor->next->child=dupMaps(&tmp->child); 758 else 759 _cursor->next->child=NULL; 760 } 761 else{ 714 762 addMapToMap(&tmp1->content,tmp->content); 763 if(tmp->child!=NULL) 764 tmp1->child=dupMaps(&tmp->child); 765 else 766 tmp1->child=NULL; 767 } 715 768 _cursor=*mo; 716 769 } … … 872 925 _ztmpm->value=zStrdup(value); 873 926 }else{ 874 maps *tmp=(maps*)malloc(MAPS_SIZE); 875 tmp->name=zStrdup(key); 927 maps *tmp=createMaps(key); 876 928 tmp->content=createMap(subkey,value); 877 tmp->next=NULL;878 929 addMapsToMaps(&_tmpm,tmp); 879 930 freeMaps(&tmp); … … 881 932 } 882 933 }else{ 883 maps *tmp=(maps*)malloc(MAPS_SIZE); 884 tmp->name=zStrdup(key); 934 maps *tmp=createMaps(key); 885 935 tmp->content=createMap(subkey,value); 886 tmp->next=NULL;887 936 addMapsToMaps(&m,tmp); 888 937 freeMaps(&tmp); 889 938 free(tmp); 890 939 } 940 } 941 942 /** 943 * Create an empty elements 944 * 945 * @return a pointer to the allocated elements 946 */ 947 elements* createEmptyElements(){ 948 elements* res=(elements*)malloc(ELEMENTS_SIZE); 949 res->name=NULL; 950 res->content=NULL; 951 res->metadata=NULL; 952 res->format=NULL; 953 res->defaults=NULL; 954 res->supported=NULL; 955 res->child=NULL; 956 res->next=NULL; 957 return res; 958 } 959 960 /** 961 * Create a named elements 962 * 963 * @param name the elements name 964 * @return a pointer to the allocated elements 965 */ 966 elements* createElements(char* name){ 967 elements* res=(elements*)malloc(ELEMENTS_SIZE); 968 res->name=zStrdup(name); 969 res->content=NULL; 970 res->metadata=NULL; 971 res->format=NULL; 972 res->defaults=NULL; 973 res->supported=NULL; 974 res->child=NULL; 975 res->next=NULL; 976 return res; 977 } 978 979 /** 980 * Set the name of an elements 981 * 982 * @param name the elements name 983 * @return a pointer to the allocated elements 984 */ 985 void setElementsName(elements** elem,char* name){ 986 elements* res=*elem; 987 res->name=zStrdup(name); 988 res->content=NULL; 989 res->metadata=NULL; 990 res->format=NULL; 991 res->defaults=NULL; 992 res->supported=NULL; 993 res->child=NULL; 994 res->next=NULL; 891 995 } 892 996 … … 921 1025 ioc++; 922 1026 } 1027 if(tmp->child!=NULL){ 1028 fprintf(stderr," > CHILD \n"); 1029 dumpElements(tmp->child); 1030 } 923 1031 fprintf(stderr,"------------------\n"); 924 1032 tmp=tmp->next; … … 931 1039 * @param e the elements to dump 932 1040 */ 933 void dumpElementsAsYAML(elements* e ){1041 void dumpElementsAsYAML(elements* e,int level){ 934 1042 elements* tmp=e; 935 1043 int i; 936 1044 while(tmp!=NULL){ 937 for(i=0;i<2 ;i++)1045 for(i=0;i<2+(4*level);i++) 938 1046 fprintf(stderr," "); 939 1047 fprintf(stderr,"%s:\n",tmp->name); 940 1048 map* mcurs=tmp->content; 941 1049 while(mcurs!=NULL){ 942 for(i=0;i<4 ;i++)1050 for(i=0;i<4+(4*level);i++) 943 1051 fprintf(stderr," "); 944 1052 _dumpMap(mcurs); … … 947 1055 mcurs=tmp->metadata; 948 1056 if(mcurs!=NULL){ 949 for(i=0;i<4 ;i++)1057 for(i=0;i<4+(4*level);i++) 950 1058 fprintf(stderr," "); 951 1059 fprintf(stderr,"MetaData:\n"); 952 1060 while(mcurs!=NULL){ 953 for(i=0;i<6 ;i++)1061 for(i=0;i<6+(4*level);i++) 954 1062 fprintf(stderr," "); 955 1063 _dumpMap(mcurs); … … 957 1065 } 958 1066 } 959 for(i=0;i<4 ;i++)1067 for(i=0;i<4+(4*level);i++) 960 1068 fprintf(stderr," "); 961 fprintf(stderr,"%s:\n",tmp->format); 1069 if(tmp->format!=NULL) 1070 fprintf(stderr,"%s:\n",tmp->format); 1071 else{ 1072 fprintf(stderr,"Child:\n"); 1073 if(tmp->child!=NULL) 1074 dumpElementsAsYAML(tmp->child,level+1); 1075 } 962 1076 iotype* tmpio=tmp->defaults; 963 1077 int ioc=0; 964 1078 while(tmpio!=NULL){ 965 for(i=0;i<6 ;i++)1079 for(i=0;i<6+(4*level);i++) 966 1080 fprintf(stderr," "); 967 1081 fprintf(stderr,"default:\n"); 968 1082 mcurs=tmpio->content; 969 1083 while(mcurs!=NULL){ 970 for(i=0;i<8 ;i++)1084 for(i=0;i<8+(4*level);i++) 971 1085 fprintf(stderr," "); 972 1086 if(strcasecmp(mcurs->name,"range")==0){ … … 982 1096 ioc=0; 983 1097 while(tmpio!=NULL){ 984 for(i=0;i<6 ;i++)1098 for(i=0;i<6+(4*level);i++) 985 1099 fprintf(stderr," "); 986 1100 fprintf(stderr,"supported:\n"); 987 1101 mcurs=tmpio->content; 988 1102 while(mcurs!=NULL){ 989 for(i=0;i<8 ;i++)1103 for(i=0;i<8+(4*level);i++) 990 1104 fprintf(stderr," "); 991 1105 if(strcasecmp(mcurs->name,"range")==0){ … … 1055 1169 else 1056 1170 tmp->supported=NULL; 1171 if(cursor->child!=NULL) 1172 tmp->child=dupElements(cursor->child); 1173 else 1174 tmp->child=NULL; 1057 1175 tmp->next=dupElements(cursor->next); 1058 1176 } … … 1075 1193 } 1076 1194 } 1077 1195 1196 /** 1197 * Set the name of a service 1198 * 1199 * @param name the service name 1200 */ 1201 void setServiceName(service** serv,char* name){ 1202 service* res=*serv; 1203 res->name=zStrdup(name); 1204 res->content=NULL; 1205 res->metadata=NULL; 1206 res->inputs=NULL; 1207 res->outputs=NULL; 1208 } 1209 1078 1210 /** 1079 1211 * Dump a service on stderr … … 1126 1258 if(s->inputs!=NULL){ 1127 1259 fprintf(stderr,"\ninputs:\n"); 1128 dumpElementsAsYAML(s->inputs );1260 dumpElementsAsYAML(s->inputs,0); 1129 1261 } 1130 1262 if(s->outputs!=NULL){ 1131 1263 fprintf(stderr,"\noutputs:\n"); 1132 dumpElementsAsYAML(s->outputs );1264 dumpElementsAsYAML(s->outputs,0); 1133 1265 } 1134 1266 }
Note: See TracChangeset
for help on using the changeset viewer.