| 1 | #! /usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | ## Copyright 2005, 2006, 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | ## |
|---|
| 5 | ## This file is part of the OSSIE Waveform Developer. |
|---|
| 6 | ## |
|---|
| 7 | ## OSSIE Waveform Developer is free software; you can redistribute it and/or modify |
|---|
| 8 | ## it under the terms of the GNU General Public License as published by |
|---|
| 9 | ## the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | ## (at your option) any later version. |
|---|
| 11 | ## |
|---|
| 12 | ## OSSIE Waveform Developer is distributed in the hope that it will be useful, |
|---|
| 13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | ## GNU General Public License for more details. |
|---|
| 16 | ## |
|---|
| 17 | ## You should have received a copy of the GNU General Public License |
|---|
| 18 | ## along with OSSIE Waveform Developer; if not, write to the Free Software |
|---|
| 19 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | import sys, os, shutil |
|---|
| 22 | from WaveDev.wavedev.datatypemap import * |
|---|
| 23 | from WaveDev.wavedev.cfg import LoadConfiguration |
|---|
| 24 | from datetime import date |
|---|
| 25 | |
|---|
| 26 | try: |
|---|
| 27 | from WaveDev.wavedev.errorMsg import * |
|---|
| 28 | except ImportError: |
|---|
| 29 | print "ERROR: basic_ports/genStructure.py could not import WaveDev module" |
|---|
| 30 | print " - Is /sdr/tools included in ossie.pth?" |
|---|
| 31 | sys.exit(0) |
|---|
| 32 | |
|---|
| 33 | class genAll: |
|---|
| 34 | def __init__(self, path, wavedevPath, active_wave): |
|---|
| 35 | if path[len(path)-1] != '/': |
|---|
| 36 | path = path + '/' |
|---|
| 37 | self.path = path |
|---|
| 38 | if len(wavedevPath) > 0 and wavedevPath[len(wavedevPath)-1] != '/': |
|---|
| 39 | wavedevPath = wavedevPath + '/' |
|---|
| 40 | self.wavedevPath = wavedevPath |
|---|
| 41 | self.active_wave = active_wave |
|---|
| 42 | LoadConfiguration(self) |
|---|
| 43 | |
|---|
| 44 | ############################################################################## |
|---|
| 45 | ## genDirs - this function generates the directory structure for the generated |
|---|
| 46 | ## code for the waveform; puts required files in main folder |
|---|
| 47 | ############################################################################## |
|---|
| 48 | def genDirs(self): |
|---|
| 49 | if os.path.exists(self.path) == False: |
|---|
| 50 | errorMsg(self,"Waveform already exists - exiting") |
|---|
| 51 | exit(1) |
|---|
| 52 | |
|---|
| 53 | if os.path.exists(self.path+self.active_wave.name) == False: |
|---|
| 54 | os.mkdir(self.path + self.active_wave.name) |
|---|
| 55 | |
|---|
| 56 | shutil.copy(self.wavedevPath + 'generate/reconf',self.path + self.active_wave.name) |
|---|
| 57 | os.chmod(self.path + self.active_wave.name + '/reconf', '0755') |
|---|
| 58 | for x in os.listdir(self.wavedevPath + 'generate/basic_xml/'): |
|---|
| 59 | if not os.path.isdir(x): |
|---|
| 60 | shutil.copy(self.wavedevPath + 'generate/basic_xml/' + x,self.path + self.active_wave.name) |
|---|
| 61 | |
|---|
| 62 | for x in self.active_wave.components: |
|---|
| 63 | if x.generate: |
|---|
| 64 | if os.path.exists(self.path+x.name) == False: |
|---|
| 65 | os.mkdir(self.path+x.name) |
|---|
| 66 | if x.AssemblyController != True: |
|---|
| 67 | shutil.copy(self.wavedevPath + 'generate/reconf',self.path + x.name) |
|---|
| 68 | os.chmod(self.path + x.name + '/reconf', 0755) |
|---|
| 69 | for f in os.listdir(self.wavedevPath + 'generate/basic_xml/'): |
|---|
| 70 | if not os.path.isdir(f): |
|---|
| 71 | shutil.copy(self.wavedevPath + 'generate/basic_xml/' + f,self.path + x.name) |
|---|
| 72 | if self.licensefile != "": |
|---|
| 73 | shutil.copy(self.licensefile,self.path + x.name + '/LICENSE') |
|---|
| 74 | |
|---|
| 75 | ############################################################################## |
|---|
| 76 | ## writeMakefiles - generates the make file for the waveform and then calls |
|---|
| 77 | ## writeCompMakefile for each seperate component |
|---|
| 78 | ############################################################################## |
|---|
| 79 | def writeMakefiles(self,DevMan_flag): |
|---|
| 80 | output = open(self.path + self.active_wave.name + '/Makefile.am','w') |
|---|
| 81 | |
|---|
| 82 | Flags = ["-Wall"] |
|---|
| 83 | self.info2str(output,"AM_CXXFLAGS = ",Flags,1) |
|---|
| 84 | |
|---|
| 85 | tstr = "ossieName = " + self.active_wave.name + '\n\n' |
|---|
| 86 | output.write(tstr) |
|---|
| 87 | |
|---|
| 88 | tstr = "SUBDIRS = " |
|---|
| 89 | for c in self.active_wave.components: |
|---|
| 90 | if c.AssemblyController == True and c.generate: |
|---|
| 91 | tstr += c.name + '\n\n' |
|---|
| 92 | output.write(tstr) |
|---|
| 93 | |
|---|
| 94 | # tstr = "waveformdir = $(prefix)/dom/waveforms/$(ossieName)\n" |
|---|
| 95 | tstr = "waveformdir = $(prefix)/waveforms/" + self.active_wave.name + "\n" |
|---|
| 96 | output.write(tstr) |
|---|
| 97 | |
|---|
| 98 | waveform_data = [] |
|---|
| 99 | waveform_data.append(self.active_wave.name + ".sad.xml") |
|---|
| 100 | waveform_data.append(self.active_wave.name + "_DAS.xml") |
|---|
| 101 | # If there is only one node - then install device manager files as well |
|---|
| 102 | if DevMan_flag: |
|---|
| 103 | waveform_data.append("DeviceManager.dcd.xml") |
|---|
| 104 | waveform_data.append("DeviceManager.spd.xml") |
|---|
| 105 | waveform_data.append("DeviceManager.scd.xml") |
|---|
| 106 | waveform_data.append("DeviceManager.prf.xml") |
|---|
| 107 | waveform_data.append("DomainManager.dmd.xml") |
|---|
| 108 | waveform_data.append("DomainManager.spd.xml") |
|---|
| 109 | waveform_data.append("DomainManager.scd.xml") |
|---|
| 110 | waveform_data.append("DomainManager.prf.xml") |
|---|
| 111 | |
|---|
| 112 | self.info2str(output,"dist_waveform_DATA = ", waveform_data,1) |
|---|
| 113 | |
|---|
| 114 | output.close() |
|---|
| 115 | |
|---|
| 116 | for c in self.active_wave.components: |
|---|
| 117 | if c.generate: |
|---|
| 118 | tmpPath = self.path + c.name |
|---|
| 119 | self.writeCompMakefile(c,tmpPath) |
|---|
| 120 | |
|---|
| 121 | ############################################################################## |
|---|
| 122 | ## writeCompMakefilee - generates the make file for an indivdual component |
|---|
| 123 | ############################################################################## |
|---|
| 124 | def writeCompMakefile(self,comp,compPath): |
|---|
| 125 | if compPath[len(compPath)-1] != '/': |
|---|
| 126 | compPath = compPath + '/' |
|---|
| 127 | |
|---|
| 128 | Flags = ["-Wall"] |
|---|
| 129 | |
|---|
| 130 | # Flags = ["-Wall"] |
|---|
| 131 | output = open(compPath + 'Makefile.am','w') |
|---|
| 132 | self.info2str(output,"AM_CXXFLAGS = ",Flags,1) |
|---|
| 133 | |
|---|
| 134 | # tstr = "LDADD = $(libdir)/libossiecf.la $(libdir)/libossieparser.la $(libdir)/libossieidl.la $(libdir)/libstandardInterfaces.la\n" |
|---|
| 135 | # output.write(tstr) |
|---|
| 136 | |
|---|
| 137 | tstr = "bin_PROGRAMS = " + comp.name + "\n\n" |
|---|
| 138 | output.write(tstr) |
|---|
| 139 | |
|---|
| 140 | tstr = comp.name + "_SOURCES = " + comp.name + ".cpp " + comp.name + ".h main.cpp\n\n" |
|---|
| 141 | output.write(tstr) |
|---|
| 142 | tstr = "ossieName = " + comp.name + "\n" |
|---|
| 143 | output.write(tstr) |
|---|
| 144 | |
|---|
| 145 | tstr = "xmldir = $(prefix)/dom/xml/$(ossieName)\n" |
|---|
| 146 | output.write(tstr) |
|---|
| 147 | |
|---|
| 148 | tstr = "bindir = $(prefix)/dom/bin\n" |
|---|
| 149 | output.write(tstr) |
|---|
| 150 | |
|---|
| 151 | tstr2 = comp.name |
|---|
| 152 | |
|---|
| 153 | xmlData = [] |
|---|
| 154 | xmlData.append(tstr2 + ".prf.xml") |
|---|
| 155 | xmlData.append(tstr2 + ".scd.xml") |
|---|
| 156 | xmlData.append(tstr2 + ".spd.xml") |
|---|
| 157 | self.info2str(output,"dist_xml_DATA = ",xmlData,1,wrapFlag=True) |
|---|
| 158 | |
|---|
| 159 | output.close() |
|---|
| 160 | |
|---|
| 161 | def info2str(self, outfile, staticStr, mylist, extraLine=0,wrapFlag=False): |
|---|
| 162 | tstr = staticStr |
|---|
| 163 | mycount = 0 |
|---|
| 164 | wrap = False |
|---|
| 165 | if len(mylist) > 5 or wrapFlag == True: |
|---|
| 166 | wrap = True |
|---|
| 167 | |
|---|
| 168 | for x in mylist: |
|---|
| 169 | tstr = tstr + x + " " |
|---|
| 170 | mycount += 1 |
|---|
| 171 | if mycount%2 == 0 and wrap and mylist.index(x) != len(mylist)-1: |
|---|
| 172 | tstr = tstr + "\\\n" |
|---|
| 173 | |
|---|
| 174 | tstr = tstr + "\n" |
|---|
| 175 | for x in range(extraLine): |
|---|
| 176 | tstr = tstr + "\n" |
|---|
| 177 | |
|---|
| 178 | outfile.write(tstr) |
|---|
| 179 | |
|---|
| 180 | ############################################################################## |
|---|
| 181 | ## genConfigureACFiles - calls writeConfAC for appropriate locations |
|---|
| 182 | ############################################################################## |
|---|
| 183 | def genConfigureACFiles(self,installPath): |
|---|
| 184 | if installPath[-1] == '/': |
|---|
| 185 | installPath = installPath[0:-1] |
|---|
| 186 | |
|---|
| 187 | tmpPath = self.path + self.active_wave.name + '/' |
|---|
| 188 | self.writeConfAC(tmpPath,self.active_wave.name,self.active_wave.ace,True,installPath) |
|---|
| 189 | |
|---|
| 190 | for c in self.active_wave.components: |
|---|
| 191 | if c.AssemblyController == True or not c.generate: |
|---|
| 192 | continue |
|---|
| 193 | tmpPath = self.path + c.name + '/' |
|---|
| 194 | self.writeConfAC(tmpPath,c.name,c.ace,False,installPath) |
|---|
| 195 | |
|---|
| 196 | ############################################################################## |
|---|
| 197 | ## writeConfAC - generates configure.ac files for autoconf |
|---|
| 198 | ############################################################################## |
|---|
| 199 | def writeConfAC(self,genPath,name,aceFlag,wavFlag,installPath="/sdr"): |
|---|
| 200 | if genPath[len(genPath)-1] != '/': |
|---|
| 201 | genPath = genPath + '/' |
|---|
| 202 | |
|---|
| 203 | output = open(genPath + 'configure.ac','w') |
|---|
| 204 | tstr = "# Generated by WaveDev/wavedev/generate/templates/basic_ports/\n" |
|---|
| 205 | output.write(tstr) |
|---|
| 206 | tstr = "AC_INIT(" + name + ", 0.8.0)\nAM_INIT_AUTOMAKE\n\n" |
|---|
| 207 | output.write(tstr) |
|---|
| 208 | tstr = "AC_CONFIG_MACRO_DIR([m4])\nLT_INIT\n" |
|---|
| 209 | output.write(tstr) |
|---|
| 210 | #tstr = 'AC_PREFIX_DEFAULT("/sdr")\n\n' |
|---|
| 211 | tstr = 'AC_PREFIX_DEFAULT("' + installPath + '")\n\n' |
|---|
| 212 | output.write(tstr) |
|---|
| 213 | tstr = "AC_PROG_CXX\nAC_PROG_INSTALL\nAC_PROG_LIBTOOL\nAC_PROG_MAKE_SET\n\n" |
|---|
| 214 | output.write(tstr) |
|---|
| 215 | tstr = "AC_HEADER_SYS_WAIT\n\nAC_FUNC_FORK\n\n" |
|---|
| 216 | output.write(tstr) |
|---|
| 217 | #tstr = "AC_CORBA_ORB\n\n" |
|---|
| 218 | #output.write(tstr) |
|---|
| 219 | |
|---|
| 220 | tstr = 'AC_LANG_PUSH([C++])\n\n' |
|---|
| 221 | output.write(tstr) |
|---|
| 222 | |
|---|
| 223 | tstr = 'AC_CHECK_LIB([omniORB4], [main], [], [AC_MSG_ERROR([cannot find omniORBi4 library])])\n' |
|---|
| 224 | output.write(tstr) |
|---|
| 225 | tstr = 'AC_CHECK_LIB([omnithread], [main], [], [AC_MSG_ERROR([cannot find omnithread library])])\n' |
|---|
| 226 | output.write(tstr) |
|---|
| 227 | tstr = 'AC_CHECK_LIB([omniDynamic4], [main], [], [AC_MSG_ERROR([cannot find omniDynamic4 library])])\n' |
|---|
| 228 | output.write(tstr) |
|---|
| 229 | tstr = 'AC_CHECK_HEADERS([omniORB4/CORBA.h], [], [AC_MSG_ERROR([cannot find omniORB4 header files])])\n\n' |
|---|
| 230 | output.write(tstr) |
|---|
| 231 | tstr = 'AC_CHECK_LIB([ossieidl], [main], [], [AC_MSG_ERROR([cannot find ossieidl])])\n' |
|---|
| 232 | output.write(tstr) |
|---|
| 233 | tstr = 'AC_CHECK_LIB([ossieparser], [main], [], [AC_MSG_ERROR([cannot find ossieparser])])\n'; |
|---|
| 234 | output.write(tstr) |
|---|
| 235 | tstr = 'AC_CHECK_LIB([ossiecf], [main], [], [AC_MSG_ERROR([cannot find ossiecf])])\n' |
|---|
| 236 | output.write(tstr) |
|---|
| 237 | tstr = 'AC_CHECK_LIB([standardInterfaces], [main], [], [AC_MSG_ERROR([cannot find standardInterfaces])])\n' |
|---|
| 238 | output.write(tstr) |
|---|
| 239 | tstr = 'AC_CHECK_HEADERS([standardinterfaces/complexShort.h], [], [AC_MSG_ERROR([cannot find standardInterfaces header files])])\n\n' |
|---|
| 240 | output.write(tstr) |
|---|
| 241 | |
|---|
| 242 | # if False: |
|---|
| 243 | # tstr = 'AC_CHECK_LIB([sigproc], [main], [], [AC_MSG_ERROR([cannot find sigproc library])])\n' |
|---|
| 244 | # output.write(tstr) |
|---|
| 245 | # tstr = 'AC_CHECK_HEADERS([sigproc/SigProc.h], [], [AC_MSG_ERROR([cannot find sigproc library header files])])\n\n' |
|---|
| 246 | # output.write(tstr) |
|---|
| 247 | |
|---|
| 248 | tstr = 'AC_LANG_POP\n\n' |
|---|
| 249 | output.write(tstr) |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | tstr = 'export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"\n' |
|---|
| 253 | output.write(tstr) |
|---|
| 254 | # tstr = "PKG_CHECK_MODULES(OSSIE, ossie >= 0.6.0,,exit)\n" |
|---|
| 255 | # output.write(tstr) |
|---|
| 256 | tstr = 'CXXFLAGS="$CXXFLAGS $OSSIE_CFLAGS"\n' |
|---|
| 257 | output.write(tstr) |
|---|
| 258 | # tstr = 'IDL_FLAGS="$OSSIE_CFLAGS"\nAC_SUBST(IDL_FLAGS)\n\n' |
|---|
| 259 | # output.write(tstr) |
|---|
| 260 | |
|---|
| 261 | if aceFlag == True: |
|---|
| 262 | tstr = 'PKG_CHECK_MODULES(ACE, ACE >= 5.4.7)\n' |
|---|
| 263 | tstr = tstr + 'AC_SUBST(ACE_CFLAGS)\nAC_SUBST(ACE_LIBS)\nLIBS="$LIBS $ACE_LIBS"\n\n' |
|---|
| 264 | output.write(tstr) |
|---|
| 265 | |
|---|
| 266 | tstr = 'LIBS="$LIBS $OSSIE_LIBS"\n\n' |
|---|
| 267 | output.write(tstr) |
|---|
| 268 | |
|---|
| 269 | # tstr = 'AC_SUBST(SI_PATH)\n\n' |
|---|
| 270 | # output.write(tstr) |
|---|
| 271 | |
|---|
| 272 | tstr = "AC_CONFIG_FILES(Makefile" |
|---|
| 273 | if wavFlag == True: |
|---|
| 274 | for x in self.active_wave.components: |
|---|
| 275 | if x.AssemblyController and x.generate: |
|---|
| 276 | tstr2 = " " + x.name + "/Makefile" |
|---|
| 277 | tstr = tstr + tstr2 |
|---|
| 278 | |
|---|
| 279 | tstr = tstr + ")\n\n" |
|---|
| 280 | output.write(tstr) |
|---|
| 281 | |
|---|
| 282 | tstr = "AC_OUTPUT\n" |
|---|
| 283 | output.write(tstr) |
|---|
| 284 | |
|---|
| 285 | output.close() |
|---|
| 286 | |
|---|
| 287 | ############################################################################## |
|---|
| 288 | ## This function generates the cpp and h files for each component: |
|---|
| 289 | ## component.h, component.cpp, main.cpp, port_impl.h, and port_impl.cpp |
|---|
| 290 | ############################################################################## |
|---|
| 291 | def genCompFiles(self,comp): |
|---|
| 292 | #for x in self.active_wave.components: |
|---|
| 293 | # generate the .h files for each component |
|---|
| 294 | inputH = open(self.wavedevPath + 'generate/templates/basic_ports/sampleComp.h','r') |
|---|
| 295 | outputH = open(self.path + comp.name + "/" + comp.name + ".h",'w') |
|---|
| 296 | self.addPreamble(outputH,comp.name) |
|---|
| 297 | for line in inputH.readlines(): |
|---|
| 298 | l_out = line.replace("__CLASS_DEF__",comp.name.upper()+"_IMPL_H") |
|---|
| 299 | l_out = l_out.replace("__Class_name__",comp.name+"_i") |
|---|
| 300 | if l_out.find("__SI_BASES__") != -1: |
|---|
| 301 | self.writeInterfaceBaseIncludes(outputH,comp) |
|---|
| 302 | continue |
|---|
| 303 | if l_out.find("__USES_SI__") != -1: |
|---|
| 304 | self.writeInterfaceUIncludes(outputH,comp) |
|---|
| 305 | continue |
|---|
| 306 | if l_out.find("__PROVIDES_SI__") != -1: |
|---|
| 307 | self.writeInterfacePIncludes(outputH,comp) |
|---|
| 308 | continue |
|---|
| 309 | if l_out.find("__PORT_DECL__") != -1: |
|---|
| 310 | self.writePortDecl(outputH,comp) |
|---|
| 311 | continue |
|---|
| 312 | if l_out.find("__CORBA_SIMPLE_PROP_DECL__") != -1: |
|---|
| 313 | self.writeCORBASimplepropDeclarations(outputH,comp) |
|---|
| 314 | continue |
|---|
| 315 | if l_out.find("__CORBA_SIMPLE_SEQUENCE_PROP_DECL__") != -1: |
|---|
| 316 | self.writeCORBASimpleSequencepropDeclarations(outputH,comp) |
|---|
| 317 | continue |
|---|
| 318 | if l_out.find("__ACE_INCLUDES__") != -1: |
|---|
| 319 | if comp.ace == True: |
|---|
| 320 | l_out = '#include "ace/Task.h"\n' |
|---|
| 321 | else: |
|---|
| 322 | continue |
|---|
| 323 | if l_out.find("__ACE_INHERIT__") != -1: |
|---|
| 324 | if comp.ace == True: |
|---|
| 325 | l_out = l_out.replace("__ACE_INHERIT__",", public ACE_Task<ACE_MT_SYNCH>") |
|---|
| 326 | else: |
|---|
| 327 | l_out = l_out.replace("__ACE_INHERIT__","") |
|---|
| 328 | if l_out.find("__ACE_SVC_DECL__") != -1: |
|---|
| 329 | if comp.ace == True: |
|---|
| 330 | l_out = l_out.replace("__ACE_SVC_DECL__",'int svc(void);') |
|---|
| 331 | else: |
|---|
| 332 | continue |
|---|
| 333 | if l_out.find("__FRIEND_DECL__") != -1: |
|---|
| 334 | l_out = l_out.replace("__FRIEND_DECL__","") |
|---|
| 335 | self.writeFriendDecl(outputH,comp) |
|---|
| 336 | continue |
|---|
| 337 | |
|---|
| 338 | outputH.write(l_out) |
|---|
| 339 | |
|---|
| 340 | inputH.close() |
|---|
| 341 | outputH.close() |
|---|
| 342 | |
|---|
| 343 | # generate the .cpp files for each component |
|---|
| 344 | inputCPP = open(self.wavedevPath + 'generate/templates/basic_ports/sampleComp.cpp','r') |
|---|
| 345 | outputCPP = open(self.path + comp.name + "/" + comp.name + ".cpp",'w') |
|---|
| 346 | self.addPreamble(outputCPP,comp.name) |
|---|
| 347 | for line in inputCPP.readlines(): |
|---|
| 348 | l_out = line.replace("__IncludeFile__",comp.name) |
|---|
| 349 | l_out = l_out.replace("__ComponentName__",comp.name) |
|---|
| 350 | l_out = l_out.replace("__Class_name__",comp.name +"_i") |
|---|
| 351 | #l_out = l_out.replace("__NS_name__","ossie" + comp.name+"Resource") |
|---|
| 352 | if l_out.find("__CONSTRUCTORS__") != -1: |
|---|
| 353 | self.writePortConstructors(outputCPP,comp) |
|---|
| 354 | continue |
|---|
| 355 | if l_out.find("__IS_ASSEMBLY_CONTROLLER__") != -1: |
|---|
| 356 | self.writeAssemblyController(outputCPP,comp) |
|---|
| 357 | continue |
|---|
| 358 | if l_out.find("__PORT_DESTRUCTORS__") != -1: |
|---|
| 359 | self.writePortDestructors(outputCPP,comp) |
|---|
| 360 | continue |
|---|
| 361 | if l_out.find("__SIMPLE_SEQUENCE_POINTER_DESTRUCTORS__") != -1: |
|---|
| 362 | self.writeSimpleSequencePointerDestructors(outputCPP,comp) |
|---|
| 363 | continue |
|---|
| 364 | if l_out.find("__PORT_INST__") != -1: |
|---|
| 365 | self.writePortInst(outputCPP,comp) |
|---|
| 366 | continue |
|---|
| 367 | if l_out.find("__GET_PORT__") != -1: |
|---|
| 368 | self.writeGetPort(outputCPP,comp) |
|---|
| 369 | continue |
|---|
| 370 | if l_out.find("__READ_PROPS__") !=-1: |
|---|
| 371 | self.writeReadProps(outputCPP,comp) |
|---|
| 372 | continue |
|---|
| 373 | if l_out.find("__PROCESS_DATA_DECLARATIONS__") != -1: |
|---|
| 374 | self.writeProcessDataDeclaration(outputCPP,comp) |
|---|
| 375 | continue |
|---|
| 376 | if l_out.find("__PROCESS_DATA_LOOP__") != -1: |
|---|
| 377 | self.writeProcessDataLoop(outputCPP,comp) |
|---|
| 378 | continue |
|---|
| 379 | if l_out.find("__ACE_SVC_PORTS__") != -1: |
|---|
| 380 | self.writeACESvcPorts(outputCPP,comp) |
|---|
| 381 | continue |
|---|
| 382 | if l_out.find("__ACE_SVC_DEF__") != -1: |
|---|
| 383 | if comp.ace == True: |
|---|
| 384 | self.writeACESvcDef(outputCPP,comp,'component') |
|---|
| 385 | continue |
|---|
| 386 | outputCPP.write(l_out) |
|---|
| 387 | |
|---|
| 388 | inputCPP.close() |
|---|
| 389 | outputCPP.close() |
|---|
| 390 | |
|---|
| 391 | # generate the main.cpp files for each component |
|---|
| 392 | inputMain = open(self.wavedevPath + 'generate/templates/basic_ports/sampleMain.cpp','r') |
|---|
| 393 | outputMain = open(self.path + comp.name + "/main.cpp",'w') |
|---|
| 394 | self.addPreamble(outputMain,comp.name) |
|---|
| 395 | |
|---|
| 396 | for line in inputMain.readlines(): |
|---|
| 397 | l_out = line.replace("__IncludeFile__",comp.name) |
|---|
| 398 | l_out = l_out.replace("__ComponentName__",comp.name) |
|---|
| 399 | l_out = l_out.replace("__Class_name__",comp.name+"_i") |
|---|
| 400 | l_out = l_out.replace("__CLASS_VAR__",comp.name.lower()) |
|---|
| 401 | if l_out.find("__CLASS_VAR_ACE__") != -1: |
|---|
| 402 | if comp.ace == True: |
|---|
| 403 | l_out = l_out.replace("__CLASS_VAR_ACE__",comp.name.lower()) |
|---|
| 404 | else: |
|---|
| 405 | continue |
|---|
| 406 | outputMain.write(l_out) |
|---|
| 407 | |
|---|
| 408 | inputMain.close() |
|---|
| 409 | outputMain.close() |
|---|
| 410 | |
|---|
| 411 | # generate the Doxygen documentation.txt file |
|---|
| 412 | inputDoc = open(self.wavedevPath + 'generate/templates/basic_ports/sampleDocumentation.txt','r') |
|---|
| 413 | outputDoc = open(self.path + comp.name + '/documentation.txt','w') |
|---|
| 414 | self.addPreamble(outputDoc, comp.name) |
|---|
| 415 | |
|---|
| 416 | for line in inputDoc.readlines(): |
|---|
| 417 | l_out = line.replace("__ComponentName__", comp.name) |
|---|
| 418 | outputDoc.write(l_out) |
|---|
| 419 | inputDoc.close() |
|---|
| 420 | outputDoc.close() |
|---|
| 421 | |
|---|
| 422 | # generate the Doxygen configure file |
|---|
| 423 | inputDoxy = open(self.wavedevPath + 'generate/templates/basic_ports/sampleDoxyfile','r') |
|---|
| 424 | outputDoxy = open(self.path + comp.name + '/Doxyfile','w') |
|---|
| 425 | |
|---|
| 426 | for line in inputDoxy.readlines(): |
|---|
| 427 | l_out = line.replace("__ComponentName__", comp.name) |
|---|
| 428 | outputDoxy.write(l_out) |
|---|
| 429 | inputDoxy.close() |
|---|
| 430 | outputDoxy.close() |
|---|
| 431 | |
|---|
| 432 | #-------------------------------------------------------------------------------------------- |
|---|
| 433 | ############################################################################################# |
|---|
| 434 | |
|---|
| 435 | |
|---|
| 436 | ##code for generating port_impl.h and .cpp files has been temporarily |
|---|
| 437 | ##commented out. this code should be rewritten to put port_impl |
|---|
| 438 | ##functionality into the appropriate .cpp function |
|---|
| 439 | ## # generate the port_impl.h file |
|---|
| 440 | ## inputPortImpl = open(self.wavedevPath + 'generate/port_impl.h','r') |
|---|
| 441 | ## outputPortImpl = open(self.path + comp.name + "/port_impl.h",'w') |
|---|
| 442 | ## self.addPreamble(outputPortImpl,comp.name) |
|---|
| 443 | ## portSample = open(self.wavedevPath + 'generate/port_sample.h','r') |
|---|
| 444 | ## for line in inputPortImpl.readlines(): |
|---|
| 445 | ## l_out = line.replace("__IncludeFile__",comp.name) |
|---|
| 446 | ## if l_out.find("__ACE_INCLUDES__") != -1: |
|---|
| 447 | ## if comp.ace == True: |
|---|
| 448 | ## l_out = '#include "ace/Task.h"\n' |
|---|
| 449 | ## else: |
|---|
| 450 | ## continue |
|---|
| 451 | ## if l_out.find("__PORT_DECL__") != -1: |
|---|
| 452 | ## self.writePortImplDecl(outputPortImpl,portSample,comp) |
|---|
| 453 | ## continue |
|---|
| 454 | ## outputPortImpl.write(l_out) |
|---|
| 455 | ## |
|---|
| 456 | ## inputPortImpl.close() |
|---|
| 457 | ## outputPortImpl.close() |
|---|
| 458 | ## portSample.close() |
|---|
| 459 | ## |
|---|
| 460 | ## # generate the port_impl.cpp file |
|---|
| 461 | ## inputPortImpl = open(self.wavedevPath + 'generate/port_impl.cpp','r') |
|---|
| 462 | ## outputPortImpl = open(self.path + comp.name + "/port_impl.cpp",'w') |
|---|
| 463 | ## self.addPreamble(outputPortImpl,comp.name) |
|---|
| 464 | ## portSample = open(self.wavedevPath + 'generate/port_sample.cpp','r') |
|---|
| 465 | ## for line in inputPortImpl.readlines(): |
|---|
| 466 | ## l_out = line |
|---|
| 467 | ## if l_out.find("__PORT_DEF__") != -1: |
|---|
| 468 | ## self.writePortImplDef(outputPortImpl,portSample,comp) |
|---|
| 469 | ## continue |
|---|
| 470 | ## outputPortImpl.write(l_out) |
|---|
| 471 | ## |
|---|
| 472 | ## inputPortImpl.close() |
|---|
| 473 | ## outputPortImpl.close() |
|---|
| 474 | ## portSample.close() |
|---|
| 475 | |
|---|
| 476 | # Copy some required files into the main directory |
|---|
| 477 | # os.system('cp ' + self.wavedevPath + 'generate/basic_xml/* ' + self.path) |
|---|
| 478 | # os.system('cp ' + self.wavedevPath + 'generate/wavLoader.py ' + self.path) |
|---|
| 479 | #################################################################################################### |
|---|
| 480 | #--------------------------------------------------------------------------------------------------- |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | #---------------------------------------------------------------------------------- |
|---|
| 485 | ################################################################################### |
|---|
| 486 | def writeInterfaceBaseIncludes(self,output,c): |
|---|
| 487 | """ This function writes the corba declarations of the base types for the ports""" |
|---|
| 488 | compShort = 0 |
|---|
| 489 | compFloat = 0 |
|---|
| 490 | compDouble = 0 |
|---|
| 491 | compChar = 0 |
|---|
| 492 | compLong = 0 |
|---|
| 493 | |
|---|
| 494 | realShort = 0 |
|---|
| 495 | realFloat = 0 |
|---|
| 496 | realDouble = 0 |
|---|
| 497 | realChar = 0 |
|---|
| 498 | realLong = 0 |
|---|
| 499 | |
|---|
| 500 | for x in c.ports: |
|---|
| 501 | if x.interface.name == "complexShort" and compShort == 0: |
|---|
| 502 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 503 | output.write(ts) |
|---|
| 504 | compShort += 1 |
|---|
| 505 | elif x.interface.name == "complexFloat" and compFloat == 0: |
|---|
| 506 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 507 | output.write(ts) |
|---|
| 508 | compFloat += 1 |
|---|
| 509 | elif x.interface.name == "complexDouble" and compDouble == 0: |
|---|
| 510 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 511 | output.write(ts) |
|---|
| 512 | compDouble += 1 |
|---|
| 513 | elif x.interface.name == "complexChar" and compChar == 0: |
|---|
| 514 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 515 | output.write(ts) |
|---|
| 516 | compChar += 1 |
|---|
| 517 | elif x.interface.name == "complexLong" and compLong == 0: |
|---|
| 518 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 519 | output.write(ts) |
|---|
| 520 | compLong += 1 |
|---|
| 521 | |
|---|
| 522 | elif x.interface.name == "realShort" and realShort == 0: |
|---|
| 523 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 524 | output.write(ts) |
|---|
| 525 | realShort += 1 |
|---|
| 526 | elif x.interface.name == "realFloat" and realFloat == 0: |
|---|
| 527 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 528 | output.write(ts) |
|---|
| 529 | realFloat += 1 |
|---|
| 530 | elif x.interface.name == "realDouble" and realDouble == 0: |
|---|
| 531 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 532 | output.write(ts) |
|---|
| 533 | realDouble += 1 |
|---|
| 534 | elif x.interface.name == "realChar" and realChar == 0: |
|---|
| 535 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 536 | output.write(ts) |
|---|
| 537 | realChar += 1 |
|---|
| 538 | elif x.interface.name == "realLong" and realLong == 0: |
|---|
| 539 | ts = '#include "standardinterfaces/' + x.interface.name + '.h"\n' |
|---|
| 540 | output.write(ts) |
|---|
| 541 | realLong += 1 |
|---|
| 542 | |
|---|
| 543 | else: |
|---|
| 544 | continue |
|---|
| 545 | ################################################################################### |
|---|
| 546 | #---------------------------------------------------------------------------------- |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | #---------------------------------------------------------------------------------- |
|---|
| 550 | ################################################################################### |
|---|
| 551 | def writeInterfaceUIncludes(self,output,c): |
|---|
| 552 | """ This function writes the corba declarations of the uses ports to the component header file""" |
|---|
| 553 | compShort = 0 |
|---|
| 554 | compFloat = 0 |
|---|
| 555 | compDouble = 0 |
|---|
| 556 | compChar = 0 |
|---|
| 557 | compLong = 0 |
|---|
| 558 | |
|---|
| 559 | realShort = 0 |
|---|
| 560 | realFloat = 0 |
|---|
| 561 | realDouble = 0 |
|---|
| 562 | realChar = 0 |
|---|
| 563 | realLong = 0 |
|---|
| 564 | |
|---|
| 565 | for x in c.ports: |
|---|
| 566 | if x.type == "Uses": |
|---|
| 567 | if x.interface.name == "complexShort" and compShort == 0: |
|---|
| 568 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 569 | output.write(ts) |
|---|
| 570 | compShort += 1 |
|---|
| 571 | elif x.interface.name == "complexFloat" and compFloat == 0: |
|---|
| 572 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 573 | output.write(ts) |
|---|
| 574 | compFloat += 1 |
|---|
| 575 | elif x.interface.name == "complexDouble" and compDouble == 0: |
|---|
| 576 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 577 | output.write(ts) |
|---|
| 578 | compDouble += 1 |
|---|
| 579 | elif x.interface.name == "complexChar" and compChar == 0: |
|---|
| 580 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 581 | output.write(ts) |
|---|
| 582 | compChar += 1 |
|---|
| 583 | elif x.interface.name == "complexLong" and compLong == 0: |
|---|
| 584 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 585 | output.write(ts) |
|---|
| 586 | compLong += 1 |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | elif x.interface.name == "realShort" and realShort == 0: |
|---|
| 590 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 591 | output.write(ts) |
|---|
| 592 | realShort += 1 |
|---|
| 593 | elif x.interface.name == "realFloat" and realFloat == 0: |
|---|
| 594 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 595 | output.write(ts) |
|---|
| 596 | realFloat += 1 |
|---|
| 597 | elif x.interface.name == "realDouble" and realDouble == 0: |
|---|
| 598 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 599 | output.write(ts) |
|---|
| 600 | realDouble += 1 |
|---|
| 601 | elif x.interface.name == "realChar" and realChar == 0: |
|---|
| 602 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 603 | output.write(ts) |
|---|
| 604 | realChar += 1 |
|---|
| 605 | elif x.interface.name == "realLong" and realLong == 0: |
|---|
| 606 | ts = '#include "standardinterfaces/' + x.interface.name + '_u.h"\n'; |
|---|
| 607 | output.write(ts) |
|---|
| 608 | realLong += 1 |
|---|
| 609 | |
|---|
| 610 | else: |
|---|
| 611 | continue |
|---|
| 612 | |
|---|
| 613 | ################################################################################## |
|---|
| 614 | #---------------------------------------------------------------------------------- |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | #---------------------------------------------------------------------------------- |
|---|
| 618 | ################################################################################### |
|---|
| 619 | def writeInterfacePIncludes(self,output,c): |
|---|
| 620 | """ This function writes the corba declarations of the provides ports to the component header file""" |
|---|
| 621 | compShort = 0; |
|---|
| 622 | compFloat = 0; |
|---|
| 623 | compDouble = 0; |
|---|
| 624 | compChar = 0; |
|---|
| 625 | compLong = 0; |
|---|
| 626 | |
|---|
| 627 | realShort = 0; |
|---|
| 628 | realFloat = 0; |
|---|
| 629 | realDouble = 0; |
|---|
| 630 | realChar = 0; |
|---|
| 631 | realLong = 0; |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | inCount = 0; |
|---|
| 635 | for x in c.ports: |
|---|
| 636 | if x.type == "Provides": |
|---|
| 637 | if x.interface.name == "complexShort" and compShort == 0: |
|---|
| 638 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 639 | output.write(ts) |
|---|
| 640 | compShort += 1 |
|---|
| 641 | elif x.interface.name == "complexFloat" and compFloat == 0: |
|---|
| 642 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 643 | output.write(ts) |
|---|
| 644 | compFloat += 1 |
|---|
| 645 | elif x.interface.name == "complexDouble" and compDouble == 0: |
|---|
| 646 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 647 | output.write(ts) |
|---|
| 648 | compDouble += 1 |
|---|
| 649 | elif x.interface.name == "complexChar" and compChar == 0: |
|---|
| 650 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 651 | output.write(ts) |
|---|
| 652 | compChar += 1 |
|---|
| 653 | elif x.interface.name == "complexLong" and compLong == 0: |
|---|
| 654 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 655 | output.write(ts) |
|---|
| 656 | compLong += 1 |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | elif x.interface.name == "realShort" and realShort == 0: |
|---|
| 660 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 661 | output.write(ts) |
|---|
| 662 | realShort += 1 |
|---|
| 663 | elif x.interface.name == "realFloat" and realFloat == 0: |
|---|
| 664 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 665 | output.write(ts) |
|---|
| 666 | realFloat += 1 |
|---|
| 667 | elif x.interface.name == "realDouble" and realDouble == 0: |
|---|
| 668 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 669 | output.write(ts) |
|---|
| 670 | realDouble += 1 |
|---|
| 671 | elif x.interface.name == "realShort" and realShort == 0: |
|---|
| 672 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 673 | output.write(ts) |
|---|
| 674 | realShort += 1 |
|---|
| 675 | elif x.interface.name == "realChar" and realChar == 0: |
|---|
| 676 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 677 | output.write(ts) |
|---|
| 678 | realChar += 1 |
|---|
| 679 | elif x.interface.name == "realLong" and realLong == 0: |
|---|
| 680 | ts = '#include "standardinterfaces/' + x.interface.name + '_p.h"\n'; |
|---|
| 681 | output.write(ts) |
|---|
| 682 | realLong += 1 |
|---|
| 683 | |
|---|
| 684 | else: |
|---|
| 685 | continue |
|---|
| 686 | |
|---|
| 687 | ################################################################################### |
|---|
| 688 | #--------------------------------------------------------------------------------- |
|---|
| 689 | |
|---|
| 690 | #-------------------------------------------------------------------------------- |
|---|
| 691 | ################################################################################## |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | # def writePortImplDecl(self, output,portSample,c): |
|---|
| 695 | # """ This function writes port implementation declarations for the port_impl.h file""" |
|---|
| 696 | # intList = [] |
|---|
| 697 | # for x in c.ports: |
|---|
| 698 | # if x.interface.filename in intList: |
|---|
| 699 | # continue |
|---|
| 700 | # ts = '#include "' + x.interface.filename + '.h"\n' |
|---|
| 701 | # intList.append(x.interface.filename) |
|---|
| 702 | # output.write(ts) |
|---|
| 703 | # ts = '\n';output.write(ts); |
|---|
| 704 | # intList = [] |
|---|
| 705 | # for x in c.ports: |
|---|
| 706 | # if x.interface.name in intList: |
|---|
| 707 | # continue |
|---|
| 708 | # portSample.seek(0) |
|---|
| 709 | # intList.append(x.interface.name) |
|---|
| 710 | # for line in portSample.readlines(): |
|---|
| 711 | # l_out = line.replace("__IN_PORT__",x.p_cname) |
|---|
| 712 | # l_out = l_out.replace("__INT_TYPE__",x.interface.name) |
|---|
| 713 | # l_out = l_out.replace("__NAME_SPACE__",x.interface.nameSpace) |
|---|
| 714 | # l_out = l_out.replace("__OUT_PORT__",x.u_cname) |
|---|
| 715 | # l_out = l_out.replace("__IN_CLASS__",x.p_cname) |
|---|
| 716 | # l_out = l_out.replace("__OUT_CLASS__",x.u_cname) |
|---|
| 717 | # if l_out.find("__OPERATION__") != -1: |
|---|
| 718 | # self.writeOperation(output,x.interface) |
|---|
| 719 | # continue |
|---|
| 720 | # if l_out.find("__ACE_INHERIT__") != -1: |
|---|
| 721 | # if c.ace == True: |
|---|
| 722 | # l_out = l_out.replace("__ACE_INHERIT__",", public ACE_Task<ACE_MT_SYNCH>") |
|---|
| 723 | # else: |
|---|
| 724 | # l_out = l_out.replace("__ACE_INHERIT__","") |
|---|
| 725 | # if l_out.find("__ACE_SVC_DECL__") != -1: |
|---|
| 726 | # if c.ace == True: |
|---|
| 727 | # l_out = l_out.replace("__ACE_SVC_DECL__",'int svc(void);') |
|---|
| 728 | # else: |
|---|
| 729 | # continue |
|---|
| 730 | # if l_out.find("__COMP_ARG__") != -1: |
|---|
| 731 | # if c.type == "resource": |
|---|
| 732 | # l_out = l_out.replace("__COMP_ARG__",c.name+"_i *_"+c.name.lower()) |
|---|
| 733 | # else: |
|---|
| 734 | # l_out = l_out.replace("__COMP_ARG__","") |
|---|
| 735 | # if l_out.find("__COMP_REF_DECL__") != -1: |
|---|
| 736 | # if c.type == "resource": |
|---|
| 737 | # l_out = l_out.replace("__COMP_REF_DECL__",c.name+"_i *"+c.name.lower()+";") |
|---|
| 738 | # else: |
|---|
| 739 | # l_out = l_out.replace("__COMP_REF_DECL__","") |
|---|
| 740 | # |
|---|
| 741 | # output.write(l_out) |
|---|
| 742 | |
|---|
| 743 | ################################################################################################################# |
|---|
| 744 | #---------------------------------------------------------------------------------------------------------------- |
|---|
| 745 | |
|---|
| 746 | |
|---|
| 747 | #availableTypes = ["boolean", "char", "double", "float", "short", "long","objref", "octet", "string", "ulong","ushort"] |
|---|
| 748 | |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | #--------------------------------------------------------------------------------- |
|---|
| 752 | ################################################################################# |
|---|
| 753 | |
|---|
| 754 | def writeCORBASimplepropDeclarations(self,output,c): |
|---|
| 755 | simpleCount = 0; |
|---|
| 756 | for x in c.properties: |
|---|
| 757 | tmp_type = getDatatype(str(x.type)) |
|---|
| 758 | |
|---|
| 759 | if x.elementType == "Simple": |
|---|
| 760 | ts = " "*8 + "CORBA::" + tmp_type + " simple_" + str(simpleCount) + "_value;\n"; |
|---|
| 761 | output.write(ts) |
|---|
| 762 | simpleCount += 1; |
|---|
| 763 | else: |
|---|
| 764 | continue |
|---|
| 765 | |
|---|
| 766 | ################################################################################### |
|---|
| 767 | #---------------------------------------------------------------------------------- |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | #-------------------------------------------------------------------------------- |
|---|
| 771 | ################################################################################# |
|---|
| 772 | |
|---|
| 773 | def writeCORBASimpleSequencepropDeclarations(self,output,c): |
|---|
| 774 | simplesequenceCount = 0; |
|---|
| 775 | for x in c.properties: |
|---|
| 776 | tmp_type = getDatatype(str(x.type)) |
|---|
| 777 | |
|---|
| 778 | if x.elementType == "SimpleSequence": |
|---|
| 779 | ts = " "*8 + "CORBA::" + tmp_type + "Seq *simplesequence_" + str(simplesequenceCount) + ";\n" |
|---|
| 780 | output.write(ts) |
|---|
| 781 | simplesequenceCount = simplesequenceCount + 1 |
|---|
| 782 | else: |
|---|
| 783 | continue |
|---|
| 784 | |
|---|
| 785 | ################################################################################ |
|---|
| 786 | #------------------------------------------------------------------------------- |
|---|
| 787 | |
|---|
| 788 | |
|---|
| 789 | #-------------------------------------------------------------------------------------------------------------- |
|---|
| 790 | ############################################################################################################### |
|---|
| 791 | |
|---|
| 792 | # def writePortImplDef(self,output,portSample,c): |
|---|
| 793 | # """ This function writes port implementation definitions for the port_impl.cpp file""" |
|---|
| 794 | # intList = [] |
|---|
| 795 | # for x in c.ports: |
|---|
| 796 | # if x.interface.name in intList: |
|---|
| 797 | # continue |
|---|
| 798 | # portSample.seek(0) |
|---|
| 799 | # intList.append(x.interface.name) |
|---|
| 800 | # for line in portSample.readlines(): |
|---|
| 801 | # l_out = line.replace("__IN_PORT__",x.p_cname) |
|---|
| 802 | # l_out = l_out.replace("__INT_TYPE__",x.interface.name) |
|---|
| 803 | # l_out = l_out.replace("__NAME_SPACE__",x.interface.nameSpace) |
|---|
| 804 | # l_out = l_out.replace("__OUT_PORT__",x.u_cname) |
|---|
| 805 | # if l_out.find("__OPERATION__") != -1: |
|---|
| 806 | # l_out = l_out.replace("__OPERATION__",'') |
|---|
| 807 | # l_out = l_out.replace("\n",'') |
|---|
| 808 | # self.writeOperation(output,x.interface,prefix=l_out,cppFlag=True,in_name=c.name,using_ace=c.ace) |
|---|
| 809 | # continue |
|---|
| 810 | # if l_out.find("__ACE_SVC_DEF__") != -1: |
|---|
| 811 | # if c.ace == True: |
|---|
| 812 | # self.writeACESvcDef(output,x,'port') |
|---|
| 813 | # continue |
|---|
| 814 | # if l_out.find("__COMP_ARG__") != -1: |
|---|
| 815 | # if c.type == "resource": |
|---|
| 816 | # l_out = l_out.replace("__COMP_ARG__",c.name+"_i *_"+c.name.lower()) |
|---|
| 817 | # else: |
|---|
| 818 | # l_out = l_out.replace("__COMP_ARG__","") |
|---|
| 819 | # if l_out.find("__COMP_REF_DEF__") != -1: |
|---|
| 820 | # if c.type == "resource": |
|---|
| 821 | # l_out = l_out.replace("__COMP_REF_DEF__",c.name.lower()+" = _"+c.name.lower()+";") |
|---|
| 822 | # else: |
|---|
| 823 | # l_out = l_out.replace("__COMP_REF_DEF__","") |
|---|
| 824 | # output.write(l_out) |
|---|
| 825 | ############################################################################################################### |
|---|
| 826 | #------------------------------------------------------------------------------------------------------------- |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | #-------------------------------------------------------------------------------------------------------------- |
|---|
| 830 | ############################################################################################################### |
|---|
| 831 | |
|---|
| 832 | def writePortDecl(self, output,c): |
|---|
| 833 | """ This function writes the corba declarations of the ports to the component header file""" |
|---|
| 834 | inCount = 0; outCount=0; |
|---|
| 835 | for x in c.ports: |
|---|
| 836 | if x.type == "Provides": |
|---|
| 837 | ts = " "*8 + "standardInterfaces_i::" + x.interface.name + "_p *dataIn_" + str(inCount) + ";\n"; |
|---|
| 838 | output.write(ts) |
|---|
| 839 | inCount += 1 |
|---|
| 840 | elif x.type == "Uses": |
|---|
| 841 | ts = " "*8 + "standardInterfaces_i::" + x.interface.name + "_u *dataOut_" + str(outCount) + ";\n"; |
|---|
| 842 | output.write(ts) |
|---|
| 843 | outCount += 1 |
|---|
| 844 | else: |
|---|
| 845 | continue |
|---|
| 846 | |
|---|
| 847 | ############################################################################################################### |
|---|
| 848 | #------------------------------------------------------------------------------------------------------------- |
|---|
| 849 | |
|---|
| 850 | |
|---|
| 851 | #-------------------------------------------------------------------------------------------------------------- |
|---|
| 852 | ############################################################################################################### |
|---|
| 853 | |
|---|
| 854 | # def writePortInst(self,output,c): |
|---|
| 855 | # """ This function writes the port instantiations to the component cpp file""" |
|---|
| 856 | # inCount = 0; outCount=0; |
|---|
| 857 | # for x in c.ports: |
|---|
| 858 | # if x.type == "Provides": |
|---|
| 859 | # ts = " "*4 + "inPort" + str(inCount) + "_servant" + " = new " + x.cname + "(this);\n" |
|---|
| 860 | # output.write(ts) |
|---|
| 861 | # ts = " "*4 + "inPort" + str(inCount) + "_var = inPort" + str(inCount)+ "_servant->_this();\n" |
|---|
| 862 | # output.write(ts) |
|---|
| 863 | # inCount += 1 |
|---|
| 864 | # ts = "\n"; output.write(ts) |
|---|
| 865 | # for x in c.ports: |
|---|
| 866 | # if x.type == "Uses": |
|---|
| 867 | # ts = " "*4 + "outPort" + str(outCount) + "_servant" + " = new " + x.cname + "(this);\n" |
|---|
| 868 | # output.write(ts) |
|---|
| 869 | # ts = " "*4 + "outPort" + str(outCount) + "_var = outPort" + str(outCount)+ "_servant->_this();\n" |
|---|
| 870 | # ts += " "*4 + "outPort" + str(outCount) + "_active = false;\n" |
|---|
| 871 | # output.write(ts) |
|---|
| 872 | # outCount += 1 |
|---|
| 873 | # ts = "\n"; output.write(ts) |
|---|
| 874 | # ts = " "*4 + "component_alive = true;\n"; output.write(ts) |
|---|
| 875 | |
|---|
| 876 | #--------------------------------------------------------------------------------- |
|---|
| 877 | ################################################################################## |
|---|
| 878 | |
|---|
| 879 | def writeGetPort(self,output,c): |
|---|
| 880 | """ This function writes the getPort functionality to the component cpp file""" |
|---|
| 881 | inCount = 0; outCount=0; |
|---|
| 882 | flag = True |
|---|
| 883 | for x in c.ports: |
|---|
| 884 | if x.type == "Uses": |
|---|
| 885 | ts = " "*4 + "p = dataOut_" + str(outCount) + "->getPort(portName);\n"; output.write(ts) |
|---|
| 886 | outCount += 1; |
|---|
| 887 | elif x.type == "Provides": |
|---|
| 888 | ts = " "*4 + "p = dataIn_" + str(inCount) + "->getPort(portName);\n"; output.write(ts) |
|---|
| 889 | inCount += 1; |
|---|
| 890 | else: |
|---|
| 891 | continue |
|---|
| 892 | |
|---|
| 893 | ts = "\n"; output.write(ts) |
|---|
| 894 | ts = " "*4 + "if (!CORBA::is_nil(p))\n"; output.write(ts) |
|---|
| 895 | ts = " "*8 + "return p._retn();\n\n"; output.write(ts) |
|---|
| 896 | |
|---|
| 897 | ts = " "*4 + '/*exception*/\n'; output.write(ts) |
|---|
| 898 | ts = " "*4 + 'throw CF::PortSupplier::UnknownPort();\n'; output.write(ts) |
|---|
| 899 | ################################################################################# |
|---|
| 900 | #---------------------------------------------------------------------------------- |
|---|
| 901 | |
|---|
| 902 | |
|---|
| 903 | ################################################################################# |
|---|
| 904 | # NOTE: At the moment, all components are self-starting, unless they are designated as an AssemblyController |
|---|
| 905 | def writeAssemblyController(self,output,c): |
|---|
| 906 | if c.AssemblyController == True: |
|---|
| 907 | output.write("\n") |
|---|
| 908 | else: |
|---|
| 909 | ts = " "*4 + 'start();\n'; |
|---|
| 910 | output.write(ts) |
|---|
| 911 | |
|---|
| 912 | #--------------------------------------------------------------------------------- |
|---|
| 913 | ############################################################################### |
|---|
| 914 | |
|---|
| 915 | def writePortConstructors(self,output,c): |
|---|
| 916 | inCount = 0; |
|---|
| 917 | outCount = 0; |
|---|
| 918 | for x in c.ports: |
|---|
| 919 | if x.type == "Uses": |
|---|
| 920 | ts = " "*4 + 'dataOut_' + str(outCount) + ' = new standardInterfaces_i::'; |
|---|
| 921 | ts = ts + str(x.interface.name) + '_u("' + x.name + '");\n'; |
|---|
| 922 | output.write(ts) |
|---|
| 923 | outCount += 1; |
|---|
| 924 | elif x.type == "Provides": |
|---|
| 925 | ts = " "*4 + 'dataIn_' + str(inCount) + ' = new standardInterfaces_i::'; |
|---|
| 926 | ts = ts + str(x.interface.name) + '_p("' + x.name + '");\n'; |
|---|
| 927 | output.write(ts) |
|---|
| 928 | inCount += 1; |
|---|
| 929 | else: |
|---|
| 930 | continue |
|---|
| 931 | |
|---|
| 932 | ################################################################################### |
|---|
| 933 | #---------------------------------------------------------------------------------- |
|---|
| 934 | |
|---|
| 935 | #--------------------------------------------------------------------------------- |
|---|
| 936 | ################################################################################## |
|---|
| 937 | def writePortDestructors(self,output,c): |
|---|
| 938 | inCount = 0; |
|---|
| 939 | outCount = 0; |
|---|
| 940 | for x in c.ports: |
|---|
| 941 | if x.type == "Uses": |
|---|
| 942 | ts = " "*4 + 'delete dataOut_' + str(outCount) + ';\n'; |
|---|
| 943 | output.write(ts) |
|---|
| 944 | outCount += 1; |
|---|
| 945 | |
|---|
| 946 | elif x.type == "Provides": |
|---|
| 947 | ts = " "*4 + 'delete dataIn_' + str(inCount) + ';\n'; |
|---|
| 948 | output.write(ts) |
|---|
| 949 | inCount += 1; |
|---|
| 950 | else: |
|---|
| 951 | continue |
|---|
| 952 | ################################################################################## |
|---|
| 953 | #------------------------------------------------------------------------------- |
|---|
| 954 | |
|---|
| 955 | #---------------------------------------------------------------------------------- |
|---|
| 956 | ################################################################################### |
|---|
| 957 | |
|---|
| 958 | def writeSimpleSequencePointerDestructors(self,output,c): |
|---|
| 959 | simplesequenceCount = 0; |
|---|
| 960 | for x in c.properties: |
|---|
| 961 | tmp_type = str(x.type) |
|---|
| 962 | |
|---|
| 963 | if x.elementType == "SimpleSequence": |
|---|
| 964 | ts = " "*4 + "delete []simplesequence_" + str(simplesequenceCount) + ";\n" |
|---|
| 965 | output.write(ts) |
|---|
| 966 | simplesequenceCount += 1; |
|---|
| 967 | else: |
|---|
| 968 | continue |
|---|
| 969 | |
|---|
| 970 | ################################################################################### |
|---|
| 971 | #-------------------------------------------------------------------------------- |
|---|
| 972 | |
|---|
| 973 | #---------------------------------------------------------------------------------- |
|---|
| 974 | ################################################################################### |
|---|
| 975 | |
|---|
| 976 | def writeReadProps(self,output,c): |
|---|
| 977 | """write the code that will read properties from the prf file""" |
|---|
| 978 | simpleCount = 0; |
|---|
| 979 | simplesequenceCount = 0; |
|---|
| 980 | #make sure there are properties first |
|---|
| 981 | |
|---|
| 982 | ts = " "*4 + 'static int init = 0;\n' |
|---|
| 983 | output.write(ts) |
|---|
| 984 | ts = " "*4 + "if( init == 0 ) {\n" |
|---|
| 985 | ts = ts + " "*8 + "if( props.length() == 0 ) {\n" |
|---|
| 986 | ts = ts + " "*12 + 'std::cout << "configure called with invalid props.length - " << props.length() << std::endl;\n' |
|---|
| 987 | ts = ts + " "*12 + "return;\n" |
|---|
| 988 | ts = ts + " "*8 + "}\n" |
|---|
| 989 | output.write(ts) |
|---|
| 990 | |
|---|
| 991 | |
|---|
| 992 | ts = " "*8 + "propertySet.length(props.length());\n" |
|---|
| 993 | ts = ts + " "*8 + "for( int j=0; j < props.length(); j++ ) {\n" |
|---|
| 994 | ts = ts + " "*12 + "propertySet[j].id = CORBA::string_dup(props[j].id);\n" |
|---|
| 995 | ts = ts + " "*12 + "propertySet[j].value = props[j].value;\n" |
|---|
| 996 | ts = ts + " "*8 + "}\n" |
|---|
| 997 | ts = ts + " "*8 + "init = 1;\n" |
|---|
| 998 | ts = ts + " "*4 + "}\n\n" |
|---|
| 999 | |
|---|
| 1000 | output.write(ts) |
|---|
| 1001 | |
|---|
| 1002 | ts = " "*4 + 'std::cout << "props length : " << props.length() << std::endl;\n\n' |
|---|
| 1003 | ts = ts + " "*4 + "for ( int i = 0; i <props.length(); i++)\n" |
|---|
| 1004 | ts = ts + " "*4 + "{\n"; |
|---|
| 1005 | output.write(ts) |
|---|
| 1006 | ts = " "*8 + 'std::cout << "Property id : " << props[i].id << std::endl;\n\n' |
|---|
| 1007 | output.write(ts) |
|---|
| 1008 | |
|---|
| 1009 | for p in c.properties: |
|---|
| 1010 | |
|---|
| 1011 | ts = " "*8 + 'if (strcmp(props[i].id, "' + p.id + '") == 0)\n' + " "*8 + "{\n"; |
|---|
| 1012 | output.write(ts) |
|---|
| 1013 | |
|---|
| 1014 | if p.elementType == "Simple": |
|---|
| 1015 | tmp_type = getDatatype(p.type) |
|---|
| 1016 | if tmp_type == "": |
|---|
| 1017 | print "ERROR: " + p.type + " is not supported in basic_ports/genStructure\n" |
|---|
| 1018 | |
|---|
| 1019 | ts = " "*12 + "CORBA::" + str(tmp_type) + " simple_temp;\n"; |
|---|
| 1020 | output.write(ts) |
|---|
| 1021 | ts = " "*12 + "props[i].value >>= simple_temp;\n"; |
|---|
| 1022 | ts = ts + " "*12 + "simple_" + str(simpleCount) + "_value = simple_temp;\n"; |
|---|
| 1023 | ts = ts + " "*12 + "for( int k = 0; k < propertySet.length(); k++ ) {\n" |
|---|
| 1024 | ts = ts + " "*16 + "if( strcmp(propertySet[k].id, props[i].id) == 0 ) {\n" |
|---|
| 1025 | ts = ts + " "*20 + "propertySet[i].value = props[i].value;\n" |
|---|
| 1026 | ts = ts + " "*20 + "break;\n" |
|---|
| 1027 | ts = ts + " "*16 + "}\n" |
|---|
| 1028 | ts = ts + " "*12 + "}\n" |
|---|
| 1029 | ts = ts + " "*8 + "}\n\n" |
|---|
| 1030 | output.write(ts) |
|---|
| 1031 | simpleCount += 1; |
|---|
| 1032 | |
|---|
| 1033 | elif p.elementType == "SimpleSequence": |
|---|
| 1034 | tmp_type = getDatatype(p.type) |
|---|
| 1035 | if tmp_type == "": |
|---|
| 1036 | print "ERROR: " + p.type + " is not supported in basic_ports/genStructure\n" |
|---|
| 1037 | |
|---|
| 1038 | ts = " "*12 + "props[i].value >>= simplesequence_" + str(simplesequenceCount) + ";\n"; |
|---|
| 1039 | output.write(ts) |
|---|
| 1040 | |
|---|
| 1041 | ts = " "*8 + "}\n\n" # close the if statement |
|---|
| 1042 | output.write(ts) |
|---|
| 1043 | |
|---|
| 1044 | simplesequenceCount += 1; |
|---|
| 1045 | else: |
|---|
| 1046 | print "WARNING: properties other than simple and simple sequence are not supported yet" |
|---|
| 1047 | continue |
|---|
| 1048 | |
|---|
| 1049 | ts = " "*4 + "}\n"; |
|---|
| 1050 | output.write(ts) #closes the for loop |
|---|
| 1051 | |
|---|
| 1052 | ################################################################################# |
|---|
| 1053 | #-------------------------------------------------------------------------------- |
|---|
| 1054 | |
|---|
| 1055 | |
|---|
| 1056 | |
|---|
| 1057 | #-------------------------------------------------------------------------------- |
|---|
| 1058 | ################################################################################# |
|---|
| 1059 | |
|---|
| 1060 | |
|---|
| 1061 | def writeProcessDataDeclaration(self,output,c): |
|---|
| 1062 | """This function sets up the majority of the process data function (in the .cpp file) based on the port type""" |
|---|
| 1063 | |
|---|
| 1064 | outPort_present = False |
|---|
| 1065 | inPort_present = False |
|---|
| 1066 | inCount = 0; |
|---|
| 1067 | outCount = 0; |
|---|
| 1068 | #declare the output (uses) variables |
|---|
| 1069 | for x in c.ports: #assumes that you have at least one port |
|---|
| 1070 | if x.type == "Uses": |
|---|
| 1071 | |
|---|
| 1072 | if x.interface.name == "complexShort": |
|---|
| 1073 | ts = " "*4 + "PortTypes::ShortSequence I_out_" + str(outCount) + ", Q_out_" + str(outCount) + ";\n"; |
|---|
| 1074 | output.write(ts) |
|---|
| 1075 | outCount += 1; |
|---|
| 1076 | |
|---|
| 1077 | elif x.interface.name == "complexFloat": |
|---|
| 1078 | ts = " "*4 + "PortTypes::FloatSequence I_out_" + str(outCount) + ", Q_out_" + str(outCount) + ";\n"; |
|---|
| 1079 | output.write(ts) |
|---|
| 1080 | outCount += 1; |
|---|
| 1081 | |
|---|
| 1082 | elif x.interface.name == "complexDouble": |
|---|
| 1083 | ts = " "*4 + "PortTypes::DoubleSequence I_out_" + str(outCount) + ", Q_out_" + str(outCount) + ";\n"; |
|---|
| 1084 | output.write(ts) |
|---|
| 1085 | outCount += 1; |
|---|
| 1086 | |
|---|
| 1087 | elif x.interface.name == "complexChar": |
|---|
| 1088 | ts = " "*4 + "PortTypes::CharSequence I_out_" + str(outCount) + ", Q_out_" + str(outCount) + ";\n"; |
|---|
| 1089 | output.write(ts) |
|---|
| 1090 | outCount += 1; |
|---|
| 1091 | |
|---|
| 1092 | elif x.interface.name == "complexLong": |
|---|
| 1093 | ts = " "*4 + "PortTypes::LongSequence I_out_" + str(outCount) + ", Q_out_" + str(outCount) + ";\n"; |
|---|
| 1094 | output.write(ts) |
|---|
| 1095 | outCount += 1; |
|---|
| 1096 | |
|---|
| 1097 | |
|---|
| 1098 | elif x.interface.name == "realShort": |
|---|
| 1099 | ts = " "*4 + "PortTypes::ShortSequence I_out_" + str(outCount) + ";\n"; |
|---|
| 1100 | output.write(ts) |
|---|
| 1101 | outCount += 1; |
|---|
| 1102 | elif x.interface.name == "realFloat": |
|---|
| 1103 | ts = " "*4 + "PortTypes::FloatSequence I_out_" + str(outCount) + ";\n"; |
|---|
| 1104 | output.write(ts) |
|---|
| 1105 | outCount += 1; |
|---|
| 1106 | elif x.interface.name == "realDouble": |
|---|
| 1107 | ts = " "*4 + "PortTypes::DoubleSequence I_out_" + str(outCount) + ";\n"; |
|---|
| 1108 | output.write(ts) |
|---|
| 1109 | outCount += 1; |
|---|
| 1110 | |
|---|
| 1111 | elif x.interface.name == "realChar": |
|---|
| 1112 | ts = " "*4 + "PortTypes::CharSequence I_out_" + str(outCount) + ";\n"; |
|---|
| 1113 | output.write(ts) |
|---|
| 1114 | outCount += 1; |
|---|
| 1115 | elif x.interface.name == "realLong": |
|---|
| 1116 | ts = " "*4 + "PortTypes::LongSequence I_out_" + str(outCount) + ";\n"; |
|---|
| 1117 | output.write(ts) |
|---|
| 1118 | outCount += 1; |
|---|
| 1119 | |
|---|
| 1120 | |
|---|
| 1121 | |
|---|
| 1122 | else: |
|---|
| 1123 | print "\nInterfaces other than complex and real Short, Float, Char, long and Double are not supported yet in the process data function generation!!\n See writeProcessDataDeclaration in genStructure.\n" |
|---|
| 1124 | #declare input values short, shortsequence, float, floatSequence, unsupported |
|---|
| 1125 | continue |
|---|
| 1126 | ts = "\n"; |
|---|
| 1127 | output.write(ts) |
|---|
| 1128 | |
|---|
| 1129 | #declare input (provides) values based on interface type |
|---|
| 1130 | for x in c.ports: |
|---|
| 1131 | if x.type == "Provides": |
|---|
| 1132 | |
|---|
| 1133 | if x.interface.name == "complexShort": |
|---|
| 1134 | ts = "\n" + " "*4 + "PortTypes::ShortSequence *I_in_"+str(inCount)+"(NULL), *Q_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1135 | output.write(ts) |
|---|
| 1136 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length, Q_in_" + str(inCount) + "_length;\n"; |
|---|
| 1137 | output.write(ts) |
|---|
| 1138 | inCount += 1; |
|---|
| 1139 | |
|---|
| 1140 | elif x.interface.name == "complexFloat": |
|---|
| 1141 | ts = "\n" + " "*4 + "PortTypes::FloatSequence *I_in_"+str(inCount)+"(NULL), *Q_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1142 | output.write(ts) |
|---|
| 1143 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length, Q_in_" + str(inCount) + "_length;\n"; |
|---|
| 1144 | output.write(ts) |
|---|
| 1145 | inCount += 1; |
|---|
| 1146 | |
|---|
| 1147 | elif x.interface.name == "complexDouble": |
|---|
| 1148 | ts = "\n" + " "*4 + "PortTypes::DoubleSequence *I_in_"+str(inCount)+"(NULL), *Q_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1149 | output.write(ts) |
|---|
| 1150 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length, Q_in_" + str(inCount) + "_length;\n"; |
|---|
| 1151 | output.write(ts) |
|---|
| 1152 | inCount += 1; |
|---|
| 1153 | |
|---|
| 1154 | elif x.interface.name == "complexChar": |
|---|
| 1155 | ts = "\n" + " "*4 + "PortTypes::CharSequence *I_in_"+str(inCount)+"(NULL), *Q_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1156 | output.write(ts) |
|---|
| 1157 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length, Q_in_" + str(inCount) + "_length;\n"; |
|---|
| 1158 | output.write(ts) |
|---|
| 1159 | inCount += 1; |
|---|
| 1160 | |
|---|
| 1161 | elif x.interface.name == "complexLong": |
|---|
| 1162 | ts = "\n" + " "*4 + "PortTypes::LongSequence *I_in_"+str(inCount)+"(NULL), *Q_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1163 | output.write(ts) |
|---|
| 1164 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length, Q_in_" + str(inCount) + "_length;\n"; |
|---|
| 1165 | output.write(ts) |
|---|
| 1166 | inCount += 1; |
|---|
| 1167 | |
|---|
| 1168 | |
|---|
| 1169 | elif x.interface.name == "realShort": |
|---|
| 1170 | ts = "\n" + " "*4 + "PortTypes::ShortSequence *I_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1171 | output.write(ts) |
|---|
| 1172 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length;\n"; |
|---|
| 1173 | output.write(ts) |
|---|
| 1174 | inCount += 1; |
|---|
| 1175 | |
|---|
| 1176 | elif x.interface.name == "realFloat": |
|---|
| 1177 | ts = "\n" + " "*4 + "PortTypes::FloatSequence *I_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1178 | output.write(ts) |
|---|
| 1179 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length;\n"; |
|---|
| 1180 | output.write(ts) |
|---|
| 1181 | inCount += 1; |
|---|
| 1182 | |
|---|
| 1183 | elif x.interface.name == "realDouble": |
|---|
| 1184 | ts = "\n" + " "*4 + "PortTypes::DoubleSequence *I_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1185 | output.write(ts) |
|---|
| 1186 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length;\n"; |
|---|
| 1187 | output.write(ts) |
|---|
| 1188 | inCount += 1; |
|---|
| 1189 | |
|---|
| 1190 | elif x.interface.name == "realChar": |
|---|
| 1191 | ts = "\n" + " "*4 + "PortTypes::CharSequence *I_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1192 | output.write(ts) |
|---|
| 1193 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length;\n"; |
|---|
| 1194 | output.write(ts) |
|---|
| 1195 | inCount += 1; |
|---|
| 1196 | |
|---|
| 1197 | elif x.interface.name == "realLong": |
|---|
| 1198 | ts = "\n" + " "*4 + "PortTypes::LongSequence *I_in_"+str(inCount)+"(NULL);\n"; |
|---|
| 1199 | output.write(ts) |
|---|
| 1200 | ts = " "*4 + "CORBA::UShort I_in_" + str(inCount) + "_length;\n"; |
|---|
| 1201 | output.write(ts) |
|---|
| 1202 | inCount += 1; |
|---|
| 1203 | |
|---|
| 1204 | |
|---|
| 1205 | else: |
|---|
| 1206 | print "\nInterfaces other than real/complex Float, short, Long, char, and double are not supported yet in the process data function generation!!\nSee writeProcessDataDeclaration in genStructure." |
|---|
| 1207 | #only one provides port is supported at this point |
|---|
| 1208 | continue |
|---|
| 1209 | |
|---|
| 1210 | ################################################################################### |
|---|
| 1211 | #---------------------------------------------------------------------------------- |
|---|
| 1212 | |
|---|
| 1213 | #--------------------------------------------------------------------------------- |
|---|
| 1214 | ################################################################################# |
|---|
| 1215 | |
|---|
| 1216 | |
|---|
| 1217 | def writeProcessDataLoop(self,output,c): |
|---|
| 1218 | """This function sets up the majority of the process data function (in the .cpp file) based on the port type""" |
|---|
| 1219 | inCount = 0; |
|---|
| 1220 | outCount = 0; |
|---|
| 1221 | ts = " "*4 + "while(continue_processing())\n" + " "*4 + "{\n"; |
|---|
| 1222 | output.write(ts) |
|---|
| 1223 | |
|---|
| 1224 | #define input (provides) values input to them and get length on each loop |
|---|
| 1225 | for x in c.ports: |
|---|
| 1226 | if x.type == "Provides": |
|---|
| 1227 | if x.interface.name == "complexShort": |
|---|
| 1228 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+", Q_in_"+str(inCount) + ");\n\n"; |
|---|
| 1229 | output.write(ts) |
|---|
| 1230 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n"; |
|---|
| 1231 | output.write(ts) |
|---|
| 1232 | ts = " "*8 + "Q_in_" + str(inCount) + "_length = Q_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1233 | output.write(ts) |
|---|
| 1234 | inCount += 1; |
|---|
| 1235 | |
|---|
| 1236 | elif x.interface.name == "complexFloat": |
|---|
| 1237 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+", Q_in_"+str(inCount) + ");\n\n"; |
|---|
| 1238 | output.write(ts) |
|---|
| 1239 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n"; |
|---|
| 1240 | output.write(ts) |
|---|
| 1241 | ts = " "*8 + "Q_in_" + str(inCount) + "_length = Q_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1242 | output.write(ts) |
|---|
| 1243 | inCount += 1; |
|---|
| 1244 | |
|---|
| 1245 | elif x.interface.name == "complexDouble": |
|---|
| 1246 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+", Q_in_"+str(inCount) + ");\n\n"; |
|---|
| 1247 | output.write(ts) |
|---|
| 1248 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n"; |
|---|
| 1249 | output.write(ts) |
|---|
| 1250 | ts = " "*8 + "Q_in_" + str(inCount) + "_length = Q_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1251 | output.write(ts) |
|---|
| 1252 | inCount += 1; |
|---|
| 1253 | |
|---|
| 1254 | elif x.interface.name == "complexChar": |
|---|
| 1255 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+", Q_in_"+str(inCount) + ");\n\n"; |
|---|
| 1256 | output.write(ts) |
|---|
| 1257 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n"; |
|---|
| 1258 | output.write(ts) |
|---|
| 1259 | ts = " "*8 + "Q_in_" + str(inCount) + "_length = Q_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1260 | output.write(ts) |
|---|
| 1261 | inCount += 1; |
|---|
| 1262 | |
|---|
| 1263 | elif x.interface.name == "complexLong": |
|---|
| 1264 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+", Q_in_"+str(inCount) + ");\n\n"; |
|---|
| 1265 | output.write(ts) |
|---|
| 1266 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n"; |
|---|
| 1267 | output.write(ts) |
|---|
| 1268 | ts = " "*8 + "Q_in_" + str(inCount) + "_length = Q_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1269 | output.write(ts) |
|---|
| 1270 | inCount += 1; |
|---|
| 1271 | |
|---|
| 1272 | elif x.interface.name == "realShort": |
|---|
| 1273 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+");\n\n"; |
|---|
| 1274 | output.write(ts) |
|---|
| 1275 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1276 | output.write(ts) |
|---|
| 1277 | inCount += 1; |
|---|
| 1278 | |
|---|
| 1279 | elif x.interface.name == "realFloat": |
|---|
| 1280 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+");\n\n"; |
|---|
| 1281 | output.write(ts) |
|---|
| 1282 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1283 | output.write(ts) |
|---|
| 1284 | inCount += 1; |
|---|
| 1285 | |
|---|
| 1286 | elif x.interface.name == "realDouble": |
|---|
| 1287 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+");\n\n"; |
|---|
| 1288 | output.write(ts) |
|---|
| 1289 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1290 | output.write(ts) |
|---|
| 1291 | inCount += 1; |
|---|
| 1292 | |
|---|
| 1293 | elif x.interface.name == "realChar": |
|---|
| 1294 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+");\n\n"; |
|---|
| 1295 | output.write(ts) |
|---|
| 1296 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1297 | output.write(ts) |
|---|
| 1298 | inCount += 1; |
|---|
| 1299 | elif x.interface.name == "realLong": |
|---|
| 1300 | ts = " "*8 + "dataIn_"+str(inCount)+"->getData(I_in_"+str(inCount)+");\n\n"; |
|---|
| 1301 | output.write(ts) |
|---|
| 1302 | ts = " "*8 + "I_in_" + str(inCount) + "_length = I_in_" + str(inCount) + "->length();\n\n"; |
|---|
| 1303 | output.write(ts) |
|---|
| 1304 | inCount += 1; |
|---|
| 1305 | |
|---|
| 1306 | |
|---|
| 1307 | else: |
|---|
| 1308 | print "\nInterfaces other than complex/real Short, Float, Char, Long and Double are not supported yet in the process data function generation!!\nSee writeProcessDataLoop in genStructure.\n" |
|---|
| 1309 | continue |
|---|
| 1310 | |
|---|
| 1311 | for x in c.ports: |
|---|
| 1312 | if x.type == "Uses": |
|---|
| 1313 | if x.interface.name == "complexShort" or x.interface.name == "complexFloat" or x.interface.name == "complexDouble" or x.interface.name == "complexChar" or x.interface.name == "complexLong": |
|---|
| 1314 | ts = " "*8 + "I_out_" + str(outCount) + ".length(); //must define length of output\n"; |
|---|
| 1315 | output.write(ts) |
|---|
| 1316 | ts = " "*8 + "Q_out_" + str(outCount) + ".length(); //must define length of output\n\n"; |
|---|
| 1317 | output.write(ts) |
|---|
| 1318 | outCount += 1; |
|---|
| 1319 | |
|---|
| 1320 | |
|---|
| 1321 | |
|---|
| 1322 | elif x.interface.name == "realShort" or x.interface.name == "realFloat" or x.interface.name == "realDouble" or x.interface.name == "realChar" or x.interface.name == "realLong": |
|---|
| 1323 | ts = " "*8 + "I_out_" + str(outCount) + ".length(); //must define length of output\n\n"; |
|---|
| 1324 | output.write(ts) |
|---|
| 1325 | outCount += 1; |
|---|
| 1326 | |
|---|
| 1327 | else: |
|---|
| 1328 | print "\nInterfaces other than complex/real Short, Float, Char, Long and Double are not supported yet in the process data function generation!!\nSee writeProcessDataLoop in genStructure.\n" |
|---|
| 1329 | #declare input values short, shortsequence, float, floatSequence, unsupported |
|---|
| 1330 | continue |
|---|
| 1331 | |
|---|
| 1332 | ts = " "*8 + "/*insert code here to do work*/\n\n\n\n\n\n\n"; |
|---|
| 1333 | output.write(ts) |
|---|
| 1334 | |
|---|
| 1335 | inCount = 0; |
|---|
| 1336 | for x in c.ports: |
|---|
| 1337 | if x.type == "Provides": |
|---|
| 1338 | if x.interface.name == "complexShort" or x.interface.name == "complexFloat" or x.interface.name == "complexDouble" or x.interface.name == "complexChar" or x.interface.name == "complexLong": |
|---|
| 1339 | ts = " "*8 + "dataIn_" + str(inCount) + "->bufferEmptied();\n"; |
|---|
| 1340 | output.write(ts) |
|---|
| 1341 | inCount += 1; |
|---|
| 1342 | |
|---|
| 1343 | elif x.interface.name == "realShort" or x.interface.name == "realFloat" or x.interface.name == "realDouble" or x.interface.name == "realChar" or x.interface.name == "realLong": |
|---|
| 1344 | ts = " "*8 + "dataIn_" + str(inCount) + "->bufferEmptied();\n"; |
|---|
| 1345 | output.write(ts) |
|---|
| 1346 | inCount += 1; |
|---|
| 1347 | |
|---|
| 1348 | else: |
|---|
| 1349 | print "\nInterfaces other than complexand real Short, Char, long, FLoat and Double are not supported yet in the process data function generation!!\nSee writeProcessDataLoop in genStructure.\n" |
|---|
| 1350 | continue |
|---|
| 1351 | |
|---|
| 1352 | outCount = 0; |
|---|
| 1353 | for x in c.ports: #assumes that you have at least one port |
|---|
| 1354 | if x.type == "Uses": |
|---|
| 1355 | if x.interface.name == "complexShort" or x.interface.name == "complexFloat" or x.interface.name == "complexDouble" or x.interface.name == "complexChar" or x.interface.name == "complexLong": |
|---|
| 1356 | ts = " "*8 + "dataOut_" + str(outCount) + "->pushPacket(I_out_" + str(outCount) + ", Q_out_" + str(outCount) + ");\n"; |
|---|
| 1357 | output.write(ts) |
|---|
| 1358 | outCount += 1; |
|---|
| 1359 | |
|---|
| 1360 | elif x.interface.name == "realShort" or x.interface.name == "realFloat" or x.interface.name == "realDouble" or x.interface.name == "realChar" or x.interface.name == "realLong": |
|---|
| 1361 | |
|---|
| 1362 | ts = " "*8 + "dataOut_" + str(outCount) + "->pushPacket(I_out_" + str(outCount) + ");\n"; |
|---|
| 1363 | output.write(ts) |
|---|
| 1364 | outCount += 1; |
|---|
| 1365 | |
|---|
| 1366 | else: |
|---|
| 1367 | print "\nInterfaces other than complex and real Short, Float, char, long, and Double are not supported yet in the process data function generation!!\nSee writeProcessDataLoop in genStructure.\n" |
|---|
| 1368 | continue |
|---|
| 1369 | #declare input values short, shortsequence, float, floatSequence, unsupported |
|---|
| 1370 | #close while loop |
|---|
| 1371 | |
|---|
| 1372 | ts = " "*4 + "}\n"; output.write(ts) |
|---|
| 1373 | |
|---|
| 1374 | ################################################################################## |
|---|
| 1375 | #--------------------------------------------------------------------------------- |
|---|
| 1376 | |
|---|
| 1377 | |
|---|
| 1378 | |
|---|
| 1379 | |
|---|
| 1380 | def writeACESvcDef(self, output,c,type): |
|---|
| 1381 | """ This function writes the implementation of the svn() function for a given component""" |
|---|
| 1382 | if type == 'component': |
|---|
| 1383 | ts = 'int ' + c.name + '_i::svc(void)\n{\n' |
|---|
| 1384 | output.write(ts) |
|---|
| 1385 | ts = " "*4 + '/* Start outgoing port threads */\n' |
|---|
| 1386 | output.write(ts) |
|---|
| 1387 | outCount=0; |
|---|
| 1388 | for x in c.ports: |
|---|
| 1389 | if x.type == "Uses": |
|---|
| 1390 | ts = " "*4 + "outPort" + str(outCount) + "_servant->activate();\n"; output.write(ts) |
|---|
| 1391 | outCount += 1 |
|---|
| 1392 | ts = "\n"; output.write(ts) |
|---|
| 1393 | ts = " "*4 + 'std::vector<double> d1_data_double;\n'; output.write(ts) |
|---|
| 1394 | ts = " "*4 + 'std::vector<float> d1_data_float;\n'; output.write(ts) |
|---|
| 1395 | ts = " "*4 + 'std::vector<short> d1_data_short;\n'; output.write(ts) |
|---|
| 1396 | ts = " "*4 + 'std::vector<float> d2_data_double;\n'; output.write(ts) |
|---|
| 1397 | ts = " "*4 + 'std::vector<double> d2_data_float;\n'; output.write(ts) |
|---|
| 1398 | ts = " "*4 + 'std::vector<short> d2_data_short;\n'; output.write(ts) |
|---|
| 1399 | ts = " "*4 + 'ACE_Message_Block *mb;\n'; output.write(ts) |
|---|
| 1400 | ts = " "*4 + '/* Main function loop */\n'; output.write(ts) |
|---|
| 1401 | ts = " "*4 + 'while(component_alive)\n' + " "*4 + '{\n'; output.write(ts) |
|---|
| 1402 | ts = " "*8 + "ACE_Time_Value getq_time_out = ACE_OS::gettimeofday();\n"; output.write(ts) |
|---|
| 1403 | ts = " "*8 + "getq_time_out += 1;\n"; output.write(ts) |
|---|
| 1404 | ts = " "*8 + "if(getq(mb, &getq_time_out) >= 0) {\n"; output.write(ts) |
|---|
| 1405 | ts = " "*12 + "unsigned int buffer_size=mb->length();\n"; output.write(ts) |
|---|
| 1406 | ts = " "*12 + "unsigned short data_type;\n"; output.write(ts) |
|---|
| 1407 | ts = " "*12 + "ACE_OS::memmove( (char*)&data_type, mb->rd_ptr(), sizeof(unsigned short));\n"; output.write(ts) |
|---|
| 1408 | ts = " "*12 + "mb->rd_ptr(sizeof(unsigned short));\n"; output.write(ts) |
|---|
| 1409 | ts = " "*12 + "buffer_size=buffer_size - sizeof(unsigned short);\n"; output.write(ts) |
|---|
| 1410 | ts = " "*12 + "unsigned int packet_size = 0;\n"; output.write(ts) |
|---|
| 1411 | ts = " "*12 + "std::vector<double> data_I;\n"; output.write(ts) |
|---|
| 1412 | ts = " "*12 + "std::vector<double> data_Q;\n"; output.write(ts) |
|---|
| 1413 | ts = " "*12 + "// I've arbitrarily decided to use doubles as my working type inside the component\n"; output.write(ts) |
|---|
| 1414 | ts = " "*12 + "// the working type is implementation-specific\n"; output.write(ts) |
|---|
| 1415 | ts = " "*12 + "switch(data_type) {\n"; output.write(ts) |
|---|
| 1416 | ts = " "*16 + "case 1:\n"; output.write(ts) |
|---|
| 1417 | ts = " "*20 + "// this is for complex double\n"; output.write(ts) |
|---|
| 1418 | ts = " "*20 + "packet_size=buffer_size/(sizeof(double)*2);\n"; output.write(ts) |
|---|
| 1419 | ts = " "*20 + "{\n"; output.write(ts) |
|---|
| 1420 | ts = " "*24 + "std::vector <double> vals(packet_size*2);\n"; output.write(ts) |
|---|
| 1421 | ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts) |
|---|
| 1422 | ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts) |
|---|
| 1423 | ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts) |
|---|
| 1424 | ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts) |
|---|
| 1425 | ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts) |
|---|
| 1426 | ts = " "*28 + "data_Q[i] = vals[i+packet_size];\n"; output.write(ts) |
|---|
| 1427 | ts = " "*24 + "}\n"; output.write(ts) |
|---|
| 1428 | ts = " "*20 + "}\n"; output.write(ts) |
|---|
| 1429 | ts = " "*20 + "break;\n"; output.write(ts) |
|---|
| 1430 | ts = " "*16 + "case 2:\n"; output.write(ts) |
|---|
| 1431 | ts = " "*20 + "// this is for complex float\n"; output.write(ts) |
|---|
| 1432 | ts = " "*20 + "packet_size=buffer_size/(sizeof(float)*2);\n"; output.write(ts) |
|---|
| 1433 | ts = " "*20 + "{\n"; output.write(ts) |
|---|
| 1434 | ts = " "*24 + "std::vector <float> vals(packet_size*2);\n"; output.write(ts) |
|---|
| 1435 | ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts) |
|---|
| 1436 | ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts) |
|---|
| 1437 | ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts) |
|---|
| 1438 | ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts) |
|---|
| 1439 | ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts) |
|---|
| 1440 | ts = " "*28 + "data_Q[i] = vals[i+packet_size];\n"; output.write(ts) |
|---|
| 1441 | ts = " "*24 + "}\n"; output.write(ts) |
|---|
| 1442 | ts = " "*20 + "}\n"; output.write(ts) |
|---|
| 1443 | ts = " "*20 + "break;\n"; output.write(ts) |
|---|
| 1444 | ts = " "*16 + "case 3:\n"; output.write(ts) |
|---|
| 1445 | ts = " "*20 + "// this is for complex short\n"; output.write(ts) |
|---|
| 1446 | ts = " "*20 + "packet_size=buffer_size/(sizeof(short)*2);\n"; output.write(ts) |
|---|
| 1447 | ts = " "*20 + "{\n"; output.write(ts) |
|---|
| 1448 | ts = " "*24 + "std::vector <short> vals(packet_size*2);\n"; output.write(ts) |
|---|
| 1449 | ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts) |
|---|
| 1450 | ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts) |
|---|
| 1451 | ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts) |
|---|
| 1452 | ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts) |
|---|
| 1453 | ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts) |
|---|
| 1454 | ts = " "*28 + "data_Q[i] = vals[i+packet_size];\n"; output.write(ts) |
|---|
| 1455 | ts = " "*24 + "}\n"; output.write(ts) |
|---|
| 1456 | ts = " "*20 + "}\n"; output.write(ts) |
|---|
| 1457 | ts = " "*20 + "break;\n"; output.write(ts) |
|---|
| 1458 | ts = " "*16 + "case 4:\n"; output.write(ts) |
|---|
| 1459 | ts = " "*20 + "// this is for real double\n"; output.write(ts) |
|---|
| 1460 | ts = " "*20 + "packet_size=buffer_size/(sizeof(double));\n"; output.write(ts) |
|---|
| 1461 | ts = " "*20 + "{\n"; output.write(ts) |
|---|
| 1462 | ts = " "*24 + "std::vector <double> vals(packet_size);\n"; output.write(ts) |
|---|
| 1463 | ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts) |
|---|
| 1464 | ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts) |
|---|
| 1465 | ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts) |
|---|
| 1466 | ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts) |
|---|
| 1467 | ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts) |
|---|
| 1468 | ts = " "*28 + "data_Q[i] = 0;\n"; output.write(ts) |
|---|
| 1469 | ts = " "*24 + "}\n"; output.write(ts) |
|---|
| 1470 | ts = " "*20 + "}\n"; output.write(ts) |
|---|
| 1471 | ts = " "*20 + "break;\n"; output.write(ts) |
|---|
| 1472 | ts = " "*16 + "case 5:\n"; output.write(ts) |
|---|
| 1473 | ts = " "*20 + "// this is for real float\n"; output.write(ts) |
|---|
| 1474 | ts = " "*20 + "packet_size=buffer_size/(sizeof(float));\n"; output.write(ts) |
|---|
| 1475 | ts = " "*20 + "{\n"; output.write(ts) |
|---|
| 1476 | ts = " "*24 + "std::vector <float> vals(packet_size);\n"; output.write(ts) |
|---|
| 1477 | ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts) |
|---|
| 1478 | ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts) |
|---|
| 1479 | ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts) |
|---|
| 1480 | ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts) |
|---|
| 1481 | ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts) |
|---|
| 1482 | ts = " "*28 + "data_Q[i] = 0;\n"; output.write(ts) |
|---|
| 1483 | ts = " "*24 + "}\n"; output.write(ts) |
|---|
| 1484 | ts = " "*20 + "}\n"; output.write(ts) |
|---|
| 1485 | ts = " "*20 + "break;\n"; output.write(ts) |
|---|
| 1486 | ts = " "*16 + "case 6:\n"; output.write(ts) |
|---|
| 1487 | ts = " "*20 + "// this is for real short\n"; output.write(ts) |
|---|
| 1488 | ts = " "*20 + "packet_size=buffer_size/(sizeof(short));\n"; output.write(ts) |
|---|
| 1489 | ts = " "*20 + "{\n"; output.write(ts) |
|---|
| 1490 | ts = " "*24 + "std::vector <short> vals(packet_size);\n"; output.write(ts) |
|---|
| 1491 | ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts) |
|---|
| 1492 | ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts) |
|---|
| 1493 | ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts) |
|---|
| 1494 | ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts) |
|---|
| 1495 | ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts) |
|---|
| 1496 | ts = " "*28 + "data_Q[i] = 0;\n"; output.write(ts) |
|---|
| 1497 | ts = " "*24 + "}\n"; output.write(ts) |
|---|
| 1498 | ts = " "*20 + "}\n"; output.write(ts) |
|---|
| 1499 | ts = " "*20 + "break;\n"; output.write(ts) |
|---|
| 1500 | ts = " "*12 + "}\n"; output.write(ts) |
|---|
| 1501 | #ts = " "*8 + "}\n"; output.write(ts) |
|---|
| 1502 | ts = " "*12 + "mb->release();\n"; output.write(ts) |
|---|
| 1503 | ts = " "*12 + "/*******************************************************************\n"; output.write(ts) |
|---|
| 1504 | ts = " "*24 + "Insert functional code here\n"; output.write(ts) |
|---|
| 1505 | ts = " "*12 + "*******************************************************************/\n\n"; output.write(ts) |
|---|
| 1506 | ts = " "*12 + "/******************************************************************/\n\n"; output.write(ts) |
|---|
| 1507 | ts = " "*12 + "// Prepare data for output\n"; output.write(ts) |
|---|
| 1508 | ts = " "*12 + "d1_data_double.resize(packet_size);\n"; output.write(ts) |
|---|
| 1509 | ts = " "*12 + "d1_data_float.resize(packet_size);\n"; output.write(ts) |
|---|
| 1510 | ts = " "*12 + "d1_data_short.resize(packet_size);\n"; output.write(ts) |
|---|
| 1511 | ts = " "*12 + "d2_data_double.resize(packet_size*2);\n"; output.write(ts) |
|---|
| 1512 | ts = " "*12 + "d2_data_float.resize(packet_size*2);\n"; output.write(ts) |
|---|
| 1513 | ts = " "*12 + "d2_data_short.resize(packet_size*2);\n\n"; output.write(ts) |
|---|
| 1514 | ts = " "*12 + "for (unsigned int i=0; i<packet_size; i++) {\n"; output.write(ts) |
|---|
| 1515 | ts = " "*16 + "d1_data_double[i] = data_I[i];\n"; output.write(ts) |
|---|
| 1516 | ts = " "*16 + "d1_data_float[i] = data_I[i];\n"; output.write(ts) |
|---|
| 1517 | ts = " "*16 + "d1_data_short[i] = (short)data_I[i];\n"; output.write(ts) |
|---|
| 1518 | ts = " "*16 + "d2_data_double[i] = data_I[i];\n"; output.write(ts) |
|---|
| 1519 | ts = " "*16 + "d2_data_double[i+packet_size] = data_Q[i];\n"; output.write(ts) |
|---|
| 1520 | ts = " "*16 + "d2_data_float[i] = data_I[i];\n"; output.write(ts) |
|---|
| 1521 | ts = " "*16 + "d2_data_float[i+packet_size] = data_Q[i];\n"; output.write(ts) |
|---|
| 1522 | ts = " "*16 + "d2_data_short[i] = (short)data_I[i];\n"; output.write(ts) |
|---|
| 1523 | ts = " "*16 + "d2_data_short[i+packet_size] = (short)data_Q[i];\n"; output.write(ts) |
|---|
| 1524 | ts = " "*12 + "}\n"; output.write(ts) |
|---|
| 1525 | |
|---|
| 1526 | outCount=0 |
|---|
| 1527 | |
|---|
| 1528 | for x in c.ports: |
|---|
| 1529 | if x.type == "Uses": |
|---|
| 1530 | ts = " "*12 + "if (outPort" + str(outCount) + "_active) {\n"; output.write(ts) |
|---|
| 1531 | if x.interface.name == 'realDouble': |
|---|
| 1532 | DATA_TYPE_BEING_USED = 'double' |
|---|
| 1533 | VECTOR_COUNT = '1' |
|---|
| 1534 | VECTOR_NAME = 'd1_data_double' |
|---|
| 1535 | if x.interface.name == 'realFloat': |
|---|
| 1536 | DATA_TYPE_BEING_USED = 'float' |
|---|
| 1537 | VECTOR_COUNT = '1' |
|---|
| 1538 | VECTOR_NAME = 'd1_data_float' |
|---|
| 1539 | if x.interface.name == 'realShort': |
|---|
| 1540 | DATA_TYPE_BEING_USED = 'short' |
|---|
| 1541 | VECTOR_COUNT = '1' |
|---|
| 1542 | VECTOR_NAME = 'd1_data_short' |
|---|
| 1543 | if x.interface.name == 'complexDouble': |
|---|
| 1544 | DATA_TYPE_BEING_USED = 'double' |
|---|
| 1545 | VECTOR_COUNT = '2' |
|---|
| 1546 | VECTOR_NAME = 'd2_data_double' |
|---|
| 1547 | if x.interface.name == 'complexFloat': |
|---|
| 1548 | DATA_TYPE_BEING_USED = 'float' |
|---|
| 1549 | VECTOR_COUNT = '2' |
|---|
| 1550 | VECTOR_NAME = 'd2_data_float' |
|---|
| 1551 | if x.interface.name == 'complexShort': |
|---|
| 1552 | DATA_TYPE_BEING_USED = 'short' |
|---|
| 1553 | VECTOR_COUNT = '2' |
|---|
| 1554 | VECTOR_NAME = 'd2_data_short' |
|---|
| 1555 | ts = " "*16 + "ACE_Message_Block *message = new ACE_Message_Block (packet_size*" + VECTOR_COUNT + "*sizeof(" + DATA_TYPE_BEING_USED + "));\n"; output.write(ts) |
|---|
| 1556 | ts = " "*16 + "message->copy((const char*)&" + VECTOR_NAME + "[0], packet_size*" + VECTOR_COUNT + "*sizeof(" + DATA_TYPE_BEING_USED + "));\n"; output.write(ts) |
|---|
| 1557 | ts = " "*16 + "if (outPort" + str(outCount) + "_servant->putq(message) == -1) {\n"; output.write(ts) |
|---|
| 1558 | ts = " "*20 + "// this is where a message for issues with the putq would appear\n"; output.write(ts) |
|---|
| 1559 | ts = " "*16 + "}\n"; output.write(ts) |
|---|
| 1560 | ts = " "*12 + "}\n"; output.write(ts) |
|---|
| 1561 | outCount += 1 |
|---|
| 1562 | ts = " "*8 + "}\n"; output.write(ts) |
|---|
| 1563 | ts = " "*8 + "/* Polling rate, slow CPU spinning */\n"; output.write(ts) |
|---|
| 1564 | ts = " "*8 + "ACE_OS::sleep (ACE_Time_Value (1));\n"; output.write(ts) |
|---|
| 1565 | ts = " "*4 + '}\n\n' + " "*4 + 'return 0;\n}\n'; output.write(ts) |
|---|
| 1566 | |
|---|
| 1567 | if type == 'port': |
|---|
| 1568 | #ts = 'int ' + c.u_cname + '::svc(void)\n{\n'; output.write(ts) |
|---|
| 1569 | #ts = " "*4 + 'ACE_Message_Block *mb;\n\n'; output.write(ts) |
|---|
| 1570 | #ts = " "*4 + 'while(1)\n' + " "*4 + '{\n' + " "*8 + 'if (getq(mb) == -1)\n' |
|---|
| 1571 | #output.write(ts) |
|---|
| 1572 | #ts = " "*8 + '{\n' + " "*12 + 'ACE_ERROR_RETURN ((LM_ERROR, ' + r'"%p\n",' |
|---|
| 1573 | #ts = ts + ' "getq"), -1);\n' |
|---|
| 1574 | #output.write(ts) |
|---|
| 1575 | #ts = " "*8 + '}\n\n' + " "*8 + '/* _complexShort->pushPacket(); */\n\n' |
|---|
| 1576 | #output.write(ts) |
|---|
| 1577 | #ts = " "*8 + '/* Release message block */\n' + " "*8 + 'mb->release();\n' |
|---|
| 1578 | #output.write(ts) |
|---|
| 1579 | #ts = " "*4 + '}\n' + " "*4 + 'return 0;\n}\n' |
|---|
| 1580 | #output.write(ts) |
|---|
| 1581 | # the following stuff is a work in progress |
|---|
| 1582 | # it needs to be reconciled with the contents of the actual port |
|---|
| 1583 | # This will be interesting for control ports instead of data ports |
|---|
| 1584 | # in the case of control ports, it will likely need a slightly different structure |
|---|
| 1585 | #print c.interface.name |
|---|
| 1586 | ts = 'int ' + c.u_cname + '::svc(void)\n{\n'; output.write(ts) |
|---|
| 1587 | ts = " "*4 + 'ACE_Message_Block *mb;\n'; output.write(ts) |
|---|
| 1588 | if c.interface.name == 'realDouble': |
|---|
| 1589 | DATA_TYPE_BEING_USED = 'double' |
|---|
| 1590 | DATA_TYPE_USED = 'Double' |
|---|
| 1591 | ARGUMENT_LIST_FOR_PUSH = ' I' |
|---|
| 1592 | if c.interface.name == 'realFloat': |
|---|
| 1593 | DATA_TYPE_BEING_USED = 'float' |
|---|
| 1594 | DATA_TYPE_USED = 'Float' |
|---|
| 1595 | ARGUMENT_LIST_FOR_PUSH = ' I' |
|---|
| 1596 | if c.interface.name == 'realShort': |
|---|
| 1597 | DATA_TYPE_BEING_USED = 'short' |
|---|
| 1598 | DATA_TYPE_USED = 'Short' |
|---|
| 1599 | ARGUMENT_LIST_FOR_PUSH = ' I' |
|---|
| 1600 | if c.interface.name == 'complexDouble': |
|---|
| 1601 | DATA_TYPE_BEING_USED = 'double' |
|---|
| 1602 | DATA_TYPE_USED = 'Double' |
|---|
| 1603 | ARGUMENT_LIST_FOR_PUSH = ' I, Q' |
|---|
| 1604 | if c.interface.name == 'complexFloat': |
|---|
| 1605 | DATA_TYPE_BEING_USED = 'float' |
|---|
| 1606 | DATA_TYPE_USED = 'Float' |
|---|
| 1607 | ARGUMENT_LIST_FOR_PUSH = ' I, Q' |
|---|
| 1608 | if c.interface.name == 'complexShort': |
|---|
| 1609 | DATA_TYPE_BEING_USED = 'short' |
|---|
| 1610 | DATA_TYPE_USED = 'Short' |
|---|
| 1611 | ARGUMENT_LIST_FOR_PUSH = ' I, Q' |
|---|
| 1612 | ts = " "*4 + 'vector < ' + DATA_TYPE_BEING_USED + ' > vals;\n'; output.write(ts) |
|---|
| 1613 | ts = " "*4 + 'PortTypes::' + DATA_TYPE_USED + 'Sequence ' + ARGUMENT_LIST_FOR_PUSH +';\n\n'; output.write(ts) |
|---|
| 1614 | ts = " "*4 + 'while(1)\n' + " "*8 + '{\n'; output.write(ts) |
|---|
| 1615 | ts = " "*8 + 'ACE_Time_Value getq_time_out = ACE_OS::gettimeofday();\n'; output.write(ts) |
|---|
| 1616 | ts = " "*8 + 'getq_time_out += 1;\n'; output.write(ts) |
|---|
| 1617 | ts = " "*8 + 'if(getq(mb, &getq_time_out) >= 0) {\n'; output.write(ts) |
|---|
| 1618 | ts = " "*12 + 'unsigned int buffer_size=mb->length();\n'; output.write(ts) |
|---|
| 1619 | if c.interface.name == 'realDouble': |
|---|
| 1620 | NUMBER_OF_VECTORS = '1' |
|---|
| 1621 | if c.interface.name == 'realFloat': |
|---|
| 1622 | NUMBER_OF_VECTORS = '1' |
|---|
| 1623 | if c.interface.name == 'realShort': |
|---|
| 1624 | NUMBER_OF_VECTORS = '1' |
|---|
| 1625 | if c.interface.name == 'complexDouble': |
|---|
| 1626 | NUMBER_OF_VECTORS = '2' |
|---|
| 1627 | if c.interface.name == 'complexFloat': |
|---|
| 1628 | NUMBER_OF_VECTORS = '2' |
|---|
| 1629 | if c.interface.name == 'complexShort': |
|---|
| 1630 | NUMBER_OF_VECTORS = '2' |
|---|
| 1631 | ts = " "*12 + 'unsigned int packet_size=buffer_size/(sizeof(' + DATA_TYPE_BEING_USED + ')*' + NUMBER_OF_VECTORS + ');\n'; output.write(ts) |
|---|
| 1632 | ts = " "*12 + 'vals.resize(packet_size*' + NUMBER_OF_VECTORS + ');\n'; output.write(ts) |
|---|
| 1633 | if c.interface.name == 'realDouble': |
|---|
| 1634 | ts = " "*12 + 'I.length(packet_size);\n'; output.write(ts) |
|---|
| 1635 | if c.interface.name == 'realFloat': |
|---|
| 1636 | ts = " "*12 + 'I.length(packet_size);\n'; output.write(ts) |
|---|
| 1637 | if c.interface.name == 'realShort': |
|---|
| 1638 | ts = " "*12 + 'I.length(packet_size);\n'; output.write(ts) |
|---|
| 1639 | if c.interface.name == 'complexDouble': |
|---|
| 1640 | ts = " "*12 + 'I.length(packet_size);\n'+" "*12 + 'Q.length(packet_size);\n'; output.write(ts) |
|---|
| 1641 | if c.interface.name == 'complexFloat': |
|---|
| 1642 | ts = " "*12 + 'I.length(packet_size);\n'+" "*12 + 'Q.length(packet_size);\n'; output.write(ts) |
|---|
| 1643 | if c.interface.name == 'complexShort': |
|---|
| 1644 | ts = " "*12 + 'I.length(packet_size);\n'+" "*12 + 'Q.length(packet_size);\n'; output.write(ts) |
|---|
| 1645 | ts = " "*12 + 'ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n'; output.write(ts) |
|---|
| 1646 | ts = " "*12 + 'for (unsigned int i=0; i<packet_size; i++) {\n'; output.write(ts) |
|---|
| 1647 | if c.interface.name == 'realDouble': |
|---|
| 1648 | ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts) |
|---|
| 1649 | if c.interface.name == 'realFloat': |
|---|
| 1650 | ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts) |
|---|
| 1651 | if c.interface.name == 'realShort': |
|---|
| 1652 | ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts) |
|---|
| 1653 | if c.interface.name == 'complexDouble': |
|---|
| 1654 | ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts) |
|---|
| 1655 | ts = " "*16 + 'Q[i]=vals[i+packet_size];\n'; output.write(ts) |
|---|
| 1656 | if c.interface.name == 'complexFloat': |
|---|
| 1657 | ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts) |
|---|
| 1658 | ts = " "*16 + 'Q[i]=vals[i+packet_size];\n'; output.write(ts) |
|---|
| 1659 | if c.interface.name == 'complexShort': |
|---|
| 1660 | ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts) |
|---|
| 1661 | ts = " "*16 + 'Q[i]=vals[i+packet_size];\n'; output.write(ts) |
|---|
| 1662 | ts = " "*12 + '}\n'; output.write(ts) |
|---|
| 1663 | ts = " "*12 + 'for (unsigned int i = 0; i < outPorts.size(); i++) {\n'; output.write(ts) |
|---|
| 1664 | ts = " "*16 + 'outPorts[i].port_var->pushPacket( ' + ARGUMENT_LIST_FOR_PUSH + ' );\n'; output.write(ts) |
|---|
| 1665 | ts = " "*12 + '}\n'; output.write(ts) |
|---|
| 1666 | ts = " "*12 + 'mb->release();\n'; output.write(ts) |
|---|
| 1667 | ts = " "*8 + '}\n'; output.write(ts) |
|---|
| 1668 | ts = " "*4 + '}\n' + " "*4 + 'return 0;\n}\n' |
|---|
| 1669 | output.write(ts) |
|---|
| 1670 | |
|---|
| 1671 | |
|---|
| 1672 | def writeFriendDecl(self,output,c): |
|---|
| 1673 | friendList = [] |
|---|
| 1674 | for p in c.ports: |
|---|
| 1675 | if p.type == "Uses": |
|---|
| 1676 | if p.u_cname not in friendList: |
|---|
| 1677 | friendList.append(p.u_cname) |
|---|
| 1678 | if p.type == "Provides": |
|---|
| 1679 | if p.p_cname not in friendList: |
|---|
| 1680 | friendList.append(p.p_cname) |
|---|
| 1681 | |
|---|
| 1682 | for x in friendList: |
|---|
| 1683 | ts = " "*4 + "friend class " + x + ";\n" |
|---|
| 1684 | output.write(ts) |
|---|
| 1685 | |
|---|
| 1686 | |
|---|
| 1687 | def addPreamble(self,outFile,name): |
|---|
| 1688 | inFile = open(self.sourcepreamble,'r') |
|---|
| 1689 | for line in inFile.readlines(): |
|---|
| 1690 | l_out = line.replace("__COMP_NAME__",name) |
|---|
| 1691 | l_out = l_out.replace("__YEAR__",date.today().year.__str__()) |
|---|
| 1692 | l_out = l_out.replace("__DEVELOPER__",self.developer) |
|---|
| 1693 | outFile.write(l_out) |
|---|
| 1694 | |
|---|
| 1695 | inFile.close() |
|---|
| 1696 | |
|---|
| 1697 | |
|---|
| 1698 | def cleanUp(self): |
|---|
| 1699 | # Move the AssemblyController to the waveform Dir |
|---|
| 1700 | for c in self.active_wave.components: |
|---|
| 1701 | if c.AssemblyController == True and c.generate: |
|---|
| 1702 | os.system('mv ' + self.path + c.name + ' ' + self.path + self.active_wave.name) |
|---|
| 1703 | |
|---|
| 1704 | |
|---|