1172 # in retreive, publish, init, cleanup |
1173 # in retreive, publish, init, cleanup |
1173 locstrs = map(lambda x:"_".join(map(str,x)), |
1174 locstrs = map(lambda x:"_".join(map(str,x)), |
1174 [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls]) |
1175 [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls]) |
1175 |
1176 |
1176 # Generate main, based on template |
1177 # Generate main, based on template |
1177 plc_main_code = targets.code("plc_common_main") % { |
1178 if self.BeremizRoot.getEnable_Plugins(): |
1178 "calls_prototypes":"\n".join([( |
1179 plc_main_code = targets.code("plc_common_main") % { |
1179 "int __init_%(s)s(int argc,char **argv);\n"+ |
1180 "calls_prototypes":"\n".join([( |
1180 "void __cleanup_%(s)s();\n"+ |
1181 "int __init_%(s)s(int argc,char **argv);\n"+ |
1181 "void __retrieve_%(s)s();\n"+ |
1182 "void __cleanup_%(s)s();\n"+ |
1182 "void __publish_%(s)s();")%{'s':locstr} for locstr in locstrs]), |
1183 "void __retrieve_%(s)s();\n"+ |
1183 "retrieve_calls":"\n ".join([ |
1184 "void __publish_%(s)s();")%{'s':locstr} for locstr in locstrs]), |
1184 "__retrieve_%s();"%locstr for locstr in locstrs]), |
1185 "retrieve_calls":"\n ".join([ |
1185 "publish_calls":"\n ".join([ #Call publish in reverse order |
1186 "__retrieve_%s();"%locstr for locstr in locstrs]), |
1186 "__publish_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]), |
1187 "publish_calls":"\n ".join([ #Call publish in reverse order |
1187 "init_calls":"\n ".join([ |
1188 "__publish_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]), |
1188 "init_level=%d; "%(i+1)+ |
1189 "init_calls":"\n ".join([ |
1189 "if(res = __init_%s(argc,argv)){"%locstr + |
1190 "init_level=%d; "%(i+1)+ |
1190 #"printf(\"%s\"); "%locstr + #for debug |
1191 "if(res = __init_%s(argc,argv)){"%locstr + |
1191 "return res;}" for i,locstr in enumerate(locstrs)]), |
1192 #"printf(\"%s\"); "%locstr + #for debug |
1192 "cleanup_calls":"\n ".join([ |
1193 "return res;}" for i,locstr in enumerate(locstrs)]), |
1193 "if(init_level >= %d) "%i+ |
1194 "cleanup_calls":"\n ".join([ |
1194 "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
1195 "if(init_level >= %d) "%i+ |
1195 } |
1196 "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
|
1197 } |
|
1198 else: |
|
1199 plc_main_code = targets.code("plc_common_main") % { |
|
1200 "calls_prototypes":"\n", |
|
1201 "retrieve_calls":"\n", |
|
1202 "publish_calls":"\n", |
|
1203 "init_calls":"\n", |
|
1204 "cleanup_calls":"\n" |
|
1205 } |
1196 |
1206 |
1197 target_name = self.BeremizRoot.getTargetType().getcontent()["name"] |
1207 target_name = self.BeremizRoot.getTargetType().getcontent()["name"] |
1198 plc_main_code += targets.targetcode(target_name) |
1208 plc_main_code += targets.targetcode(target_name) |
1199 return plc_main_code |
1209 return plc_main_code |
1200 |
1210 |