root/ossiedev/branches/0.7.x/tools/WaveDev/wavedev/generate/genNode.py @ 9384

Revision 9384, 52.3 KB (checked in by stedwar2, 4 years ago)

Updated to work with OEF v1.1.2.

  • Property svn:eol-style set to native
Line 
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
21import sys, os, shutil
22from WaveDev.wavedev.errorMsg import *
23from WaveDev.wavedev.cfg import LoadConfiguration
24from WaveDev.wavedev.chmod import chmod
25from datetime import date
26
27class genAll:
28  def __init__(self, path, wavedevPath, node):
29    if path[len(path)-1] != '/':
30        path = path + '/'
31    self.path = path
32    if wavedevPath[len(wavedevPath)-1] != '/':
33        wavedevPath = wavedevPath + '/'
34    self.wavedevPath = wavedevPath
35    self.path = path
36    self.node = node
37    LoadConfiguration(self)
38
39  ##############################################################################
40  ## genDirs - this function generates the directory structure for the generated
41  ##           code for the waveform; puts required files in main folder
42  ##############################################################################
43  def genDirs(self):
44    if os.path.exists(self.path) == False:
45       errorMsg(self,"Node already exists - exiting")
46       exit(1)
47
48    if os.path.exists(self.path+self.node.name) == False:
49        os.mkdir(self.path + self.node.name)
50
51    shutil.copy(self.wavedevPath + 'generate/reconf',self.path + self.node.name)
52    chmod(self.path + self.node.name + '/reconf', 0755)
53
54  ##############################################################################
55  ## writeMakefiles - generates the make file for the waveform and then calls
56  ##                  writeCompMakefile for each seperate component
57  ##############################################################################
58  def writeMakefile(self):
59    output = open(self.path + self.node.name + '/Makefile.am','w')
60
61    Flags = ["-Wall"]
62    self.info2str(output,"AM_CXXFLAGS = ",Flags,1)
63
64    tstr = "ossieName = " + self.node.name + '\n\n'
65    output.write(tstr)
66
67    tstr = "waveformdir = $(prefix)/nodes/$(ossieName)\n"
68    output.write(tstr)
69
70    waveform_data = []
71    waveform_data.append("DeviceManager.dcd.xml")
72    waveform_data.append("DeviceManager.spd.xml")
73    waveform_data.append("DeviceManager.scd.xml")
74    waveform_data.append("DeviceManager.prf.xml")
75
76    self.info2str(output,"dist_waveform_DATA = ", waveform_data,1)
77
78    output.close()
79
80  def info2str(self, outfile, staticStr, mylist, extraLine=0,wrapFlag=False):
81    tstr = staticStr
82    mycount = 0
83    wrap = False
84    if len(mylist) > 5 or wrapFlag == True:
85        wrap = True
86
87    for x in mylist:
88      tstr = tstr + x + " "
89      mycount += 1
90      if mycount%2 == 0 and wrap and mylist.index(x) != len(mylist)-1:
91        tstr = tstr + "\\\n"
92
93    tstr = tstr + "\n"
94    for x in range(extraLine):
95      tstr = tstr + "\n"
96
97    outfile.write(tstr)
98
99  ##############################################################################
100  ## genConfigureACFiles - calls writeConfAC for appropriate locations
101  ##############################################################################
102  def genConfigureACFiles(self,installPath="/sdr/sca"):
103    if installPath[-1] == '/':
104        installPath = installPath[0:-1]
105
106    tmpPath = self.path + self.node.name + '/'
107    self.writeConfAC(tmpPath,self.node.name,False,False,installPath)
108
109  ##############################################################################
110  ## writeConfAC - generates configure.ac files for autoconf
111  ##############################################################################
112  def writeConfAC(self, genPath, name, aceFlag, wavFlag, installPath):
113     if genPath[len(genPath)-1] != '/':
114        genPath = genPath + '/'
115
116     output = open(genPath + 'configure.ac','w')
117     tstr = "AC_INIT(" + name + ", 0.5.0)\n\n"
118     tstr += "AM_INIT_AUTOMAKE\n\n"
119     tstr += 'AC_PREFIX_DEFAULT("' + installPath + '")\n\n'
120     tstr += "AC_PROG_INSTALL\n"
121     tstr += "INSTALL_DATA=\"/usr/bin/install -c -m 644\"\n"
122     tstr += "AC_SUBST(INSTALL_DATA)\n\n"
123     tstr += "AC_CONFIG_FILES(Makefile)\n\n"
124     tstr += "AC_OUTPUT\n"
125     output.write(tstr)
126     output.close()
127
128  ##############################################################################
129  ## This function generates the cpp and h files for each component:
130  ## component.h, component.cpp, main.cpp, port_impl.h, and port_impl.cpp
131  ##############################################################################
132  def genCompFiles(self,comp):
133      #for x in self.active_wave.components:
134        # generate the .h files for each component
135        inputH = open(self.wavedevPath + 'generate/sampleComp.h','r')
136        outputH = open(self.path + comp.name + "/" + comp.name + ".h",'w')
137        self.addPreamble(outputH,comp.name)
138        for line in inputH.readlines():
139          l_out = line.replace("__CLASS_DEF__",comp.name.upper()+"_IMPL_H")
140          l_out = l_out.replace("__Class_name__",comp.name+"_i")
141          if l_out.find("__PORT_DECL__") != -1:
142              self.writePortDecl(outputH,comp)
143              continue
144          if l_out.find("__ACE_INCLUDES__") != -1:
145              if comp.ace == True:
146                  l_out = '#include "ace/Task.h"\n'
147              else:
148                  continue
149          if l_out.find("__ACE_INHERIT__") != -1:
150              if comp.ace == True:
151                  l_out = l_out.replace("__ACE_INHERIT__",", public ACE_Task<ACE_MT_SYNCH>")
152              else:
153                  l_out = l_out.replace("__ACE_INHERIT__","")
154          if l_out.find("__ACE_SVC_DECL__") != -1:
155              if comp.ace == True:
156                  l_out = l_out.replace("__ACE_SVC_DECL__",'int svc(void);\n        size_t queue_size;')
157              else:
158                  continue
159          if l_out.find("__FRIEND_DECL__") != -1:
160              l_out = l_out.replace("__FRIEND_DECL__","")
161              self.writeFriendDecl(outputH,comp)
162              continue
163
164          outputH.write(l_out)
165
166        inputH.close()
167        outputH.close()
168
169        # generate the .cpp files for each component
170        inputCPP = open(self.wavedevPath + 'generate/sampleComp.cpp','r')
171        outputCPP = open(self.path + comp.name + "/" + comp.name + ".cpp",'w')
172        self.addPreamble(outputCPP,comp.name)
173        for line in inputCPP.readlines():
174          l_out = line.replace("__IncludeFile__",comp.name)
175          l_out = l_out.replace("__Class_name__",comp.name+"_i")
176          #l_out = l_out.replace("__NS_name__","ossie" + comp.name+"Resource")
177          if l_out.find("__PORT_INST__") != -1:
178              self.writePortInst(outputCPP,comp)
179              continue
180          if l_out.find("__GET_PORT__") != -1:
181              self.writeGetPort(outputCPP,comp)
182              continue
183          if l_out.find("__DEL_PORT__") != -1:
184              self.writeDelPort(outputCPP,comp)
185              continue
186          if l_out.find("__ACE_SVC_PORTS__") != -1:
187              self.writeACESvcPorts(outputCPP,comp)
188              continue
189          if l_out.find("__ACE_SVC_DEF__") != -1:
190              if comp.ace == True:
191                  self.writeACESvcDef(outputCPP,comp,'component',comp.timing, comp)
192              continue
193          outputCPP.write(l_out)
194
195        inputCPP.close()
196        outputCPP.close()
197
198        # generate the main.cpp files for each component
199        inputMain = open(self.wavedevPath + 'generate/sampleMain.cpp','r')
200        outputMain = open(self.path + comp.name + "/main.cpp",'w')
201        self.addPreamble(outputMain,comp.name)
202
203        for line in inputMain.readlines():
204          l_out = line.replace("__IncludeFile__",comp.name)
205          l_out = l_out.replace("__Class_name__",comp.name+"_i")
206          l_out = l_out.replace("__CLASS_VAR__",comp.name.lower())
207          if l_out.find("__CLASS_VAR_ACE__") != -1:
208              if comp.ace == True:
209                  l_out = l_out.replace("__CLASS_VAR_ACE__",comp.name.lower())
210              else:
211                  continue
212          if l_out.find("__NAME_SPACE__") != -1:
213              ns_list = []
214              for p in comp.ports:
215                  if p.interface.nameSpace not in ns_list:
216                      ns_list.append(p.interface.nameSpace)
217              l_out = ''
218              for tmpns in ns_list:
219                  l_out += 'using namespace ' + tmpns + ';\n'
220
221          outputMain.write(l_out)
222
223        inputMain.close()
224        outputMain.close()
225
226        # generate the port_impl.h file
227        inputPortImpl = open(self.wavedevPath + 'generate/port_impl.h','r')
228        outputPortImpl = open(self.path + comp.name + "/port_impl.h",'w')
229        self.addPreamble(outputPortImpl,comp.name)
230        portSample_p = open(self.wavedevPath + 'generate/port_sample_p.h','r')
231        portSample_u = open(self.wavedevPath + 'generate/port_sample_u.h','r')
232        for line in inputPortImpl.readlines():
233            l_out = line.replace("__IncludeFile__",comp.name)
234            if l_out.find("__ACE_INCLUDES__") != -1:
235              if comp.ace == True:
236                  l_out = '#include "ace/Task.h"\n'
237              else:
238                  continue
239            if l_out.find("__TIMING_DECL_AND_INCLUDES__") != -1:
240              if comp.timing == True:
241                  l_out = 'using namespace std;\n#ifndef time_signal_message_H\n#define time_signal_message_H\ntypedef struct {\n\tchar component_name[255];\n\tchar port_name[255];\n\tchar function_name[255];\n\tchar description[255];\n\tlong time_s;\n\tlong time_us;\n\tlong number_samples;\n} time_signal_message;\n#endif\n'
242              else:
243                  l_out = ''
244            if l_out.find("__PORT_DECL__") != -1:
245              self.writePortImplDecl(outputPortImpl,portSample_p,portSample_u,comp)
246              continue
247            outputPortImpl.write(l_out)
248
249        inputPortImpl.close()
250        outputPortImpl.close()
251        portSample_p.close()
252        portSample_u.close()
253
254        # generate the port_impl.cpp file
255        inputPortImpl = open(self.wavedevPath + 'generate/port_impl.cpp','r')
256        outputPortImpl = open(self.path + comp.name + "/port_impl.cpp",'w')
257        self.addPreamble(outputPortImpl,comp.name)
258        portSample_p = open(self.wavedevPath + 'generate/port_sample_p.cpp','r')
259        portSample_u = open(self.wavedevPath + 'generate/port_sample_u.cpp','r')
260        for line in inputPortImpl.readlines():
261            l_out = line
262            if l_out.find("__PORT_DEF__") != -1:
263              self.writePortImplDef(outputPortImpl,portSample_p,portSample_u,comp)
264              continue
265            outputPortImpl.write(l_out)
266
267        inputPortImpl.close()
268        outputPortImpl.close()
269        portSample_p.close()
270        portSample_u.close()
271
272    # Copy some required files into the main directory
273    #  os.system('cp generate/basic_xml/* ' + self.path)
274    #  os.system('cp generate/wavLoader.py ' + self.path)
275
276  def writePortImplDecl(self, output,portSample_p,portSample_u,c):
277    """ This function writes port implementation declarations for the port_impl.h file"""
278    intList = []
279    for x in c.ports:
280        if x.interface.filename in intList:
281            continue
282        ts = '#include "' + x.interface.filename + '.h"\n'
283        intList.append(x.interface.filename)
284        output.write(ts)
285    ts = '\n';output.write(ts);
286    intList = []
287    for x in c.ports:
288        if x.interface.name in intList:
289            continue
290        if x.type == "Uses":
291            portSample = portSample_u
292        else:
293            portSample = portSample_p
294        portSample.seek(0)
295        intList.append(x.interface.name)
296        for line in portSample.readlines():
297            l_out = line.replace("__IN_PORT__",x.p_cname)
298            l_out = l_out.replace("__INT_TYPE__",x.interface.name)
299            l_out = l_out.replace("__NAME_SPACE__",x.interface.nameSpace)
300            l_out = l_out.replace("__OUT_PORT__",x.u_cname)
301            l_out = l_out.replace("__IN_CLASS__",x.p_cname)
302            l_out = l_out.replace("__OUT_CLASS__",x.u_cname)
303            if l_out.find("__OPERATION__") != -1:
304              self.writeOperation(output,x.interface,port=c)
305              continue
306            if l_out.find("__ACE_INHERIT__") != -1:
307              if c.ace == True:
308                  l_out = l_out.replace("__ACE_INHERIT__",", public ACE_Task<ACE_MT_SYNCH>")
309              else:
310                  l_out = l_out.replace("__ACE_INHERIT__","")
311            if l_out.find("__TIMING_BUFFER_LENGTH__") != -1:
312              if (c.timing==True):
313                if (x.interface.name=='timingStatus'):
314                  l_out = l_out.replace("__TIMING_BUFFER_LENGTH__",'#define NUMBER_TIMING_MESSAGE_BUFFER        100')
315                else:
316                  l_out = l_out.replace("__TIMING_BUFFER_LENGTH__", '');
317              else:
318                l_out = l_out.replace("__TIMING_BUFFER_LENGTH__", '');
319            if l_out.find("__TIMING_DECL__") != -1:
320              if (c.timing==True):
321                if (x.interface.name=='timingStatus'):
322                  l_out = l_out.replace("__TIMING_DECL__",'void send_timing_message(string component_name, string port_name, string function_name, string description, long number_samples);')
323                else:
324                  l_out = l_out.replace("__TIMING_DECL__",'')
325              else:
326                l_out = l_out.replace("__TIMING_DECL__",'')
327            if l_out.find("__TIMING_VAR__") != -1:
328              if (c.timing==True):
329                if (x.interface.name=='timingStatus'):
330                  l_out = l_out.replace("__TIMING_VAR__",'time_signal_message message_buffer[NUMBER_TIMING_MESSAGE_BUFFER];\n    int message_buffer_write_idx;\n    omni_mutex writing_to_timing_buffer;\n    omni_semaphore *data_is_ready;')
331                else:
332                  l_out = l_out.replace("__TIMING_VAR__",'')
333              else:
334                l_out = l_out.replace("__TIMING_VAR__",'')
335            if l_out.find("__ACE_SVC_DECL__") != -1:
336              if (c.ace == True):
337                  l_out = l_out.replace("__ACE_SVC_DECL__",'int svc(void);')
338              else:
339                  l_out = l_out.replace("__ACE_SVC_DECL__",'')
340            if l_out.find("__COMP_ARG__") != -1:
341                if c.type == "resource":
342                    l_out = l_out.replace("__COMP_ARG__",c.name+"_i *_"+c.name.lower())
343                else:
344                    l_out = l_out.replace("__COMP_ARG__","")
345            if l_out.find("__COMP_REF_DECL__") != -1:
346                if c.type == "resource":
347                    l_out = l_out.replace("__COMP_REF_DECL__",c.name+"_i *"+c.name.lower()+";")
348                else:
349                    l_out = l_out.replace("__COMP_REF_DECL__","")
350
351            output.write(l_out)
352
353  def writePortImplDef(self,output,portSample_p,portSample_u,c):
354    """ This function writes port implementation definitions for the port_impl.cpp file"""
355    intList = []
356    for x in c.ports:
357        if x.interface.name in intList:
358            continue
359        if x.type == "Uses":
360            portSample = portSample_u
361        else:
362            portSample = portSample_p
363        portSample.seek(0)
364        intList.append(x.interface.name)
365        for line in portSample.readlines():
366            l_out = line.replace("__IN_PORT__",x.p_cname)
367            l_out = l_out.replace("__INT_TYPE__",x.interface.name)
368            l_out = l_out.replace("__NAME_SPACE__",x.interface.nameSpace)
369            l_out = l_out.replace("__OUT_PORT__",x.u_cname)
370            if l_out.find("__OPERATION__") != -1:
371              l_out = l_out.replace("__OPERATION__",'')
372              l_out = l_out.replace("\n",'')
373              self.writeOperation(output,x.interface,prefix=l_out,cppFlag=True,in_name=c.name.lower(),using_ace=c.ace,comp=c,port=x)
374              continue
375            if l_out.find("__ACE_SVC_DEF__") != -1:
376              if c.ace == True:
377                  self.writeACESvcDef(output,x,'port',c.timing, c)
378              continue
379            if l_out.find("__TIMING_MESSAGE_DEF__") != -1:
380              if (c.timing == True) & (x.interface.name=='timingStatus'):
381                  self.writeTimingMessageDef(output,x,'port')
382              continue
383            if l_out.find("__COMP_ARG__") != -1:
384                if c.type == "resource":
385                    l_out = l_out.replace("__COMP_ARG__",c.name+"_i *_"+c.name.lower())
386                else:
387                    l_out = l_out.replace("__COMP_ARG__","")
388            if l_out.find("__COMP_REF_DEF__") != -1:
389                if c.type == "resource":
390                    l_out = l_out.replace("__COMP_REF_DEF__",c.name.lower()+" = _"+c.name.lower()+";")
391                else:
392                    l_out = l_out.replace("__COMP_REF_DEF__","")
393            if l_out.find("__INIT_VARS_DEF__") != -1:
394                if (c.type == "resource") & (x.interface.name=='timingStatus'):
395                    l_out = l_out.replace("__INIT_VARS_DEF__","message_buffer_write_idx = 0;\n    data_is_ready = new omni_semaphore(0);")
396                else:
397                    l_out = l_out.replace("__INIT_VARS_DEF__","")
398            output.write(l_out)
399
400  def writePortDecl(self, output,c):
401    """ This function writes the corba declarations of the ports to the component header file"""
402    inCount = 0; outCount=0;
403    for x in c.ports:
404        if x.type == "Provides":
405            ts = " "*8 + x.cname + " " + "*inPort" + str(inCount) + "_servant;\n"
406            output.write(ts)
407            inCount += 1
408    ts = "\n"; output.write(ts)
409    for x in c.ports:
410        if x.type == "Uses":
411            ts = " "*8 + x.cname + " " + "*outPort" + str(outCount) + "_servant;\n"
412            output.write(ts)
413            outCount += 1
414    ts = "\n"; output.write(ts)
415    inCount = 0; outCount=0;
416    for x in c.ports:
417        if x.type == "Provides":
418            ts = " "*8 + x.interface.nameSpace + "::" + x.interface.name + "_var " + "inPort" + str(inCount) + "_var;\n"
419            output.write(ts)
420            inCount += 1
421    ts = "\n"; output.write(ts)
422    for x in c.ports:
423        if x.type == "Uses":
424            ts = " "*8 + "CF::Port_var " + "outPort" + str(outCount) + "_var;\n"
425            ts += " "*8 + "bool outPort" + str(outCount) + "_active;\n"
426            ts += " "*8 + "size_t outPort" + str(outCount) + "_queue_size;\n"
427            output.write(ts)
428            outCount += 1
429    ts = " "*8 + "bool component_alive;\n\n" + " "*8 + "string naming_service_name;\n"; output.write(ts)
430
431  def writePortInst(self,output,c):
432    """ This function writes the port instantiations to the component cpp file"""
433    inCount = 0; outCount=0;
434    for x in c.ports:
435        if x.type == "Provides":
436            ts = " "*4 + "inPort" + str(inCount) + "_servant" + " = new " + x.cname + "(this);\n"
437            output.write(ts)
438            ts = " "*4 + "inPort" + str(inCount) + "_var = inPort" + str(inCount)+ "_servant->_this();\n"
439            output.write(ts)
440            inCount += 1
441    ts = "\n"; output.write(ts)
442    for x in c.ports:
443        if x.type == "Uses":
444            ts = " "*4 + "outPort" + str(outCount) + "_servant" + " = new " + x.cname + "(this);\n"
445            output.write(ts)
446            ts = " "*4 + "outPort" + str(outCount) + "_var = outPort" + str(outCount)+ "_servant->_this();\n"
447            ts += " "*4 + "outPort" + str(outCount) + "_active = false;\n"
448            ts += " "*4 + "outPort" + str(outCount) + "_queue_size = DEFAULT_QUEUE_BLOCK_SIZE;\n"
449            output.write(ts)
450            outCount += 1
451    ts = "\n"; output.write(ts)
452    ts = " "*4 + "queue_size = DEFAULT_QUEUE_BLOCK_SIZE;\n\n" + " "*4 + "component_alive = true;\n\n" + " "*4 + "naming_service_name = label;\n"; output.write(ts)
453
454  def writeGetPort(self,output,c):
455    """ This function writes the getPort functionality to the component cpp file"""
456    inCount = 0; outCount=0;
457    flag = True
458    for x in c.ports:
459        if x.type == "Provides":
460            if flag:
461                ts = " "*4 + 'if (strcmp(_id,"' + x.name + '") == 0) {\n'
462            else:
463                ts = " "*4 + 'else if (strcmp(_id,"' + x.name + '") == 0) {\n'
464            output.write(ts)
465#            ts = " "*8 + "return inPort" + str(inCount) + "_var;\n"
466            ts = " "*8 + "return " + x.interface.nameSpace + "::" + x.interface.name
467            ts += "::_duplicate(inPort" + str(inCount) + "_var);\n"
468            ts += " "*4 + "}\n"
469            output.write(ts)
470            inCount += 1
471    ts = "\n"; output.write(ts)
472    for x in c.ports:
473        if x.type == "Uses":
474            if flag:
475                ts = " "*4 + 'if (strcmp(_id,"' + x.name + '") == 0) {\n'
476            else:
477                ts = " "*4 + 'else if (strcmp(_id,"' + x.name + '") == 0) {\n'
478            output.write(ts)
479            ts = " "*8 + "outPort" + str(outCount) + "_active = true;\n"
480            ts += " "*8 + "return CF::Port::_duplicate(outPort" + str(outCount) + "_var);\n"
481            ts += " "*4 + "}\n"
482            output.write(ts)
483            outCount += 1
484    ts = "\n"; output.write(ts)
485    ts = " "*4 + 'return NULL;\n'; output.write(ts)
486
487  def writeDelPort(self,output,c):
488    """ This function writes the destructor functionality (for ports) to the component cpp file"""
489    inCount = 0; outCount=0;
490    flag = True
491    for x in c.ports:
492        if x.type == "Provides":
493            ts = " "*4 + "delete inPort" + str(inCount) + "_servant;\n"
494            output.write(ts)
495            inCount += 1
496    ts = "\n"; output.write(ts)
497    for x in c.ports:
498        if x.type == "Uses":
499            ts = " "*4 + "delete outPort" + str(outCount) + "_servant;\n"
500            output.write(ts)
501            outCount += 1
502    ts = "\n"; output.write(ts)
503
504##  def writeACESvcPorts(self,output,c):
505##    """ This function writes the svc port functionality to the component cpp file"""
506##    outCount=0;
507##    for x in c.ports:
508##        if x.type == "Uses":
509##            ts = " "*4 + "outPort" + str(outCount) + "_servant->activate();\n"
510##            output.write(ts)
511##            outCount += 1
512##    ts = "\n"; output.write(ts)
513
514  def writeACESvcDef(self, output,c,type,timing_flag, comp=''):
515    """ This function writes the implementation of the svn() function for a given component"""
516    if type == 'component':
517        ts = 'int ' + c.name + '_i::svc(void)\n{\n'
518        output.write(ts)
519        ts = " "*4 + '/* Start outgoing port threads */\n'
520        output.write(ts)
521        outCount=0;
522        for x in c.ports:
523            if x.type == "Uses":
524                ts = " "*4 + "outPort" + str(outCount) + "_servant->activate();\n"; output.write(ts)
525                outCount += 1
526        ts = "\n"; output.write(ts)
527        ts = " "*4 + 'std::vector<double> d1_data_double;\n'; output.write(ts)
528        ts = " "*4 + 'std::vector<float> d1_data_float;\n'; output.write(ts)
529        ts = " "*4 + 'std::vector<short> d1_data_short;\n'; output.write(ts)
530        ts = " "*4 + 'std::vector<float> d2_data_double;\n'; output.write(ts)
531        ts = " "*4 + 'std::vector<double> d2_data_float;\n'; output.write(ts)
532        ts = " "*4 + 'std::vector<short> d2_data_short;\n'; output.write(ts)
533        ts = " "*4 + 'ACE_Message_Block *mb;\n'; output.write(ts)
534        ts = " "*4 + '/* Main function loop */\n'; output.write(ts)
535        ts = " "*4 + 'while(component_alive)\n' + " "*4 + '{\n'; output.write(ts)
536        ts = " "*8 + "ACE_Time_Value getq_time_out = ACE_OS::gettimeofday();\n"; output.write(ts)
537        ts = " "*8 + "getq_time_out += 1;\n"; output.write(ts)
538        ts = " "*8 + "if(getq(mb, &getq_time_out) >= 0) {\n"; output.write(ts)
539        ts = " "*12 + "unsigned int buffer_size=mb->length();\n"; output.write(ts)
540        ts = " "*12 + "unsigned short data_type;\n"; output.write(ts)
541        ts = " "*12 + "ACE_OS::memmove( (char*)&data_type, mb->rd_ptr(), sizeof(unsigned short));\n"; output.write(ts)
542        ts = " "*12 + "mb->rd_ptr(sizeof(unsigned short));\n"; output.write(ts)
543        ts = " "*12 + "buffer_size=buffer_size - sizeof(unsigned short);\n"; output.write(ts)
544        ts = " "*12 + "unsigned int packet_size = 0;\n"; output.write(ts)
545        ts = " "*12 + "std::vector<double> data_I;\n"; output.write(ts)
546        ts = " "*12 + "std::vector<double> data_Q;\n"; output.write(ts)
547        ts = " "*12 + "// I've arbitrarily decided to use doubles as my working type inside the component\n"; output.write(ts)
548        ts = " "*12 + "//       the working type is implementation-specific\n"; output.write(ts)
549        ts = " "*12 + "switch(data_type) {\n"; output.write(ts)
550        ts = " "*16 + "case 1:\n"; output.write(ts)
551        ts = " "*20 + "// this is for complex double\n"; output.write(ts)
552        ts = " "*20 + "packet_size=buffer_size/(sizeof(double)*2);\n"; output.write(ts)
553        ts = " "*20 + "{\n"; output.write(ts)
554        ts = " "*24 + "std::vector <double> vals(packet_size*2);\n"; output.write(ts)
555        ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts)
556        ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts)
557        ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts)
558        ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts)
559        ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts)
560        ts = " "*28 + "data_Q[i] = vals[i+packet_size];\n"; output.write(ts)
561        ts = " "*24 + "}\n"; output.write(ts)
562        ts = " "*20 + "}\n"; output.write(ts)
563        ts = " "*20 + "break;\n"; output.write(ts)
564        ts = " "*16 + "case 2:\n"; output.write(ts)
565        ts = " "*20 + "// this is for complex float\n"; output.write(ts)
566        ts = " "*20 + "packet_size=buffer_size/(sizeof(float)*2);\n"; output.write(ts)
567        ts = " "*20 + "{\n"; output.write(ts)
568        ts = " "*24 + "std::vector <float> vals(packet_size*2);\n"; output.write(ts)
569        ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts)
570        ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts)
571        ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts)
572        ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts)
573        ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts)
574        ts = " "*28 + "data_Q[i] = vals[i+packet_size];\n"; output.write(ts)
575        ts = " "*24 + "}\n"; output.write(ts)
576        ts = " "*20 + "}\n"; output.write(ts)
577        ts = " "*20 + "break;\n"; output.write(ts)
578        ts = " "*16 + "case 3:\n"; output.write(ts)
579        ts = " "*20 + "// this is for complex short\n"; output.write(ts)
580        ts = " "*20 + "packet_size=buffer_size/(sizeof(short)*2);\n"; output.write(ts)
581        ts = " "*20 + "{\n"; output.write(ts)
582        ts = " "*24 + "std::vector <short> vals(packet_size*2);\n"; output.write(ts)
583        ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts)
584        ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts)
585        ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts)
586        ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts)
587        ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts)
588        ts = " "*28 + "data_Q[i] = vals[i+packet_size];\n"; output.write(ts)
589        ts = " "*24 + "}\n"; output.write(ts)
590        ts = " "*20 + "}\n"; output.write(ts)
591        ts = " "*20 + "break;\n"; output.write(ts)
592        ts = " "*16 + "case 4:\n"; output.write(ts)
593        ts = " "*20 + "// this is for real double\n"; output.write(ts)
594        ts = " "*20 + "packet_size=buffer_size/(sizeof(double));\n"; output.write(ts)
595        ts = " "*20 + "{\n"; output.write(ts)
596        ts = " "*24 + "std::vector <double> vals(packet_size);\n"; output.write(ts)
597        ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts)
598        ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts)
599        ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts)
600        ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts)
601        ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts)
602        ts = " "*28 + "data_Q[i] = 0;\n"; output.write(ts)
603        ts = " "*24 + "}\n"; output.write(ts)
604        ts = " "*20 + "}\n"; output.write(ts)
605        ts = " "*20 + "break;\n"; output.write(ts)
606        ts = " "*16 + "case 5:\n"; output.write(ts)
607        ts = " "*20 + "// this is for real float\n"; output.write(ts)
608        ts = " "*20 + "packet_size=buffer_size/(sizeof(float));\n"; output.write(ts)
609        ts = " "*20 + "{\n"; output.write(ts)
610        ts = " "*24 + "std::vector <float> vals(packet_size);\n"; output.write(ts)
611        ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts)
612        ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts)
613        ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts)
614        ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts)
615        ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts)
616        ts = " "*28 + "data_Q[i] = 0;\n"; output.write(ts)
617        ts = " "*24 + "}\n"; output.write(ts)
618        ts = " "*20 + "}\n"; output.write(ts)
619        ts = " "*20 + "break;\n"; output.write(ts)
620        ts = " "*16 + "case 6:\n"; output.write(ts)
621        ts = " "*20 + "// this is for real short\n"; output.write(ts)
622        ts = " "*20 + "packet_size=buffer_size/(sizeof(short));\n"; output.write(ts)
623        ts = " "*20 + "{\n"; output.write(ts)
624        ts = " "*24 + "std::vector <short> vals(packet_size);\n"; output.write(ts)
625        ts = " "*24 + "ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n"; output.write(ts)
626        ts = " "*24 + "data_I.resize(packet_size);\n"; output.write(ts)
627        ts = " "*24 + "data_Q.resize(packet_size);\n"; output.write(ts)
628        ts = " "*24 + "for (unsigned int i = 0; i<packet_size; i++) {\n"; output.write(ts)
629        ts = " "*28 + "data_I[i] = vals[i];\n"; output.write(ts)
630        ts = " "*28 + "data_Q[i] = 0;\n"; output.write(ts)
631        ts = " "*24 + "}\n"; output.write(ts)
632        ts = " "*20 + "}\n"; output.write(ts)
633        ts = " "*20 + "break;\n"; output.write(ts)
634        ts = " "*12 + "}\n"; output.write(ts)
635        #ts = " "*8 + "}\n"; output.write(ts)
636        ts = " "*12 + "mb->release();\n"; output.write(ts)
637        ts = " "*12 + "/*******************************************************************\n"; output.write(ts)
638        ts = " "*24 + "Insert functional code here\n"; output.write(ts)
639        ts = " "*12 + "*******************************************************************/\n\n"; output.write(ts)
640        ts = " "*12 + "/******************************************************************/\n\n"; output.write(ts)
641        ts = " "*12 + "// Prepare data for output\n"; output.write(ts)
642        ts = " "*12 + "d1_data_double.resize(packet_size);\n"; output.write(ts)
643        ts = " "*12 + "d1_data_float.resize(packet_size);\n"; output.write(ts)
644        ts = " "*12 + "d1_data_short.resize(packet_size);\n"; output.write(ts)
645        ts = " "*12 + "d2_data_double.resize(packet_size*2);\n"; output.write(ts)
646        ts = " "*12 + "d2_data_float.resize(packet_size*2);\n"; output.write(ts)
647        ts = " "*12 + "d2_data_short.resize(packet_size*2);\n\n"; output.write(ts)
648        ts = " "*12 + "for (unsigned int i=0; i<packet_size; i++) {\n"; output.write(ts)
649        ts = " "*16 + "d1_data_double[i] = data_I[i];\n"; output.write(ts)
650        ts = " "*16 + "d1_data_float[i] = data_I[i];\n"; output.write(ts)
651        ts = " "*16 + "d1_data_short[i] = (short)data_I[i];\n"; output.write(ts)
652        ts = " "*16 + "d2_data_double[i] = data_I[i];\n"; output.write(ts)
653        ts = " "*16 + "d2_data_double[i+packet_size] = data_Q[i];\n"; output.write(ts)
654        ts = " "*16 + "d2_data_float[i] = data_I[i];\n"; output.write(ts)
655        ts = " "*16 + "d2_data_float[i+packet_size] = data_Q[i];\n"; output.write(ts)
656        ts = " "*16 + "d2_data_short[i] = (short)data_I[i];\n"; output.write(ts)
657        ts = " "*16 + "d2_data_short[i+packet_size] = (short)data_Q[i];\n"; output.write(ts)
658        ts = " "*12 + "}\n"; output.write(ts)
659        outCount=0;
660        for x in c.ports:
661            if (x.type == "Uses") & ((x.interface.name == 'realDouble')|(x.interface.name == 'realFloat')|(x.interface.name == 'realShort')|(x.interface.name == 'complexDouble')|(x.interface.name == 'complexFloat')|(x.interface.name == 'complexShort')):
662                ts = " "*12 + "if (outPort" + str(outCount) + "_active) {\n"; output.write(ts)
663                if x.interface.name == 'realDouble':
664                        DATA_TYPE_BEING_USED = 'double'
665                        VECTOR_COUNT = '1'
666                        VECTOR_NAME = 'd1_data_double'
667                if x.interface.name == 'realFloat':
668                        DATA_TYPE_BEING_USED = 'float'
669                        VECTOR_COUNT = '1'
670                        VECTOR_NAME = 'd1_data_float'
671                if x.interface.name == 'realShort':
672                        DATA_TYPE_BEING_USED = 'short'
673                        VECTOR_COUNT = '1'
674                        VECTOR_NAME = 'd1_data_short'
675                if x.interface.name == 'complexDouble':
676                        DATA_TYPE_BEING_USED = 'double'
677                        VECTOR_COUNT = '2'
678                        VECTOR_NAME = 'd2_data_double'
679                if x.interface.name == 'complexFloat':
680                        DATA_TYPE_BEING_USED = 'float'
681                        VECTOR_COUNT = '2'
682                        VECTOR_NAME = 'd2_data_float'
683                if x.interface.name == 'complexShort':
684                        DATA_TYPE_BEING_USED = 'short'
685                        VECTOR_COUNT = '2'
686                        VECTOR_NAME = 'd2_data_short'
687                ts = " "*16 + "ACE_Message_Block *message = new ACE_Message_Block (packet_size*" + VECTOR_COUNT + "*sizeof(" + DATA_TYPE_BEING_USED + "));\n"; output.write(ts)
688                ts = " "*16 + "message->copy((const char*)&" + VECTOR_NAME + "[0], packet_size*" + VECTOR_COUNT + "*sizeof(" + DATA_TYPE_BEING_USED + "));\n"; output.write(ts)
689                ts = " "*16 + "size_t message_length = packet_size*" + VECTOR_COUNT + "*sizeof(" + DATA_TYPE_BEING_USED + ");\n"; output.write(ts)
690                ts = " "*16 + "size_t available_space = outPort" + str(outCount) + "_servant->msg_queue()->message_bytes();\n"; output.write(ts)
691                ts = " "*16 + "if (available_space<=(outPort" + str(outCount) + "_queue_size+message_length)) {\n"; output.write(ts)
692                ts = " "*20 + "outPort" + str(outCount) + "_queue_size+=QUEUE_BLOCK_SIZE;\n"; output.write(ts)
693                ts = " "*20 + "outPort" + str(outCount) + "_servant->water_marks (ACE_IO_Cntl_Msg::SET_HWM, outPort" + str(outCount) + "_queue_size);\n"; output.write(ts)
694                ts = " "*16 + "}\n"; output.write(ts)
695                ts = " "*16 + "if (outPort" + str(outCount) + "_servant->putq(message) == -1) {\n"; output.write(ts)
696                ts = " "*20 + "//  this is where a message for issues with the putq would appear\n"; output.write(ts)
697                ts = " "*16 + "}\n"; output.write(ts)
698                ts = " "*12 + "}\n"; output.write(ts)
699                outCount += 1
700        ts = " "*8 + "}\n"; output.write(ts)
701        ts = " "*8 + "/* Polling rate, slow CPU spinning */\n"; output.write(ts)
702        ts = " "*8 + "//ACE_OS::sleep (ACE_Time_Value (1));\n"; output.write(ts)
703        ts = " "*4 + '}\n\n' + " "*4 + 'return 0;\n}\n'; output.write(ts)
704
705    if type == 'port':
706        #ts = 'int ' + c.u_cname + '::svc(void)\n{\n'; output.write(ts)
707        #ts = " "*4 + 'ACE_Message_Block *mb;\n\n'; output.write(ts)
708        #ts = " "*4 + 'while(1)\n' + " "*4 + '{\n' + " "*8 + 'if (getq(mb) == -1)\n'
709        #output.write(ts)
710        #ts = " "*8 + '{\n' + " "*12 + 'ACE_ERROR_RETURN ((LM_ERROR, ' + r'"%p\n",'
711        #ts = ts + ' "getq"), -1);\n'
712        #output.write(ts)
713        #ts = " "*8 + '}\n\n' + " "*8 + '/* _complexShort->pushPacket(); */\n\n'
714        #output.write(ts)
715        #ts = " "*8 + '/* Release message block */\n' + " "*8 + 'mb->release();\n'
716        #output.write(ts)
717        #ts = " "*4 + '}\n' + " "*4 + 'return 0;\n}\n'
718        #output.write(ts)
719                # the following stuff is a work in progress
720                #       it needs to be reconciled with the contents of the actual port
721                #       This will be interesting for control ports instead of data ports
722                #       in the case of control ports, it will likely need a slightly different structure
723        #print c.interface.name
724        ts = 'int ' + c.u_cname + '::svc(void)\n{\n'; output.write(ts)
725        if ((c.interface.name == 'realDouble')|(c.interface.name == 'realFloat')|(c.interface.name == 'realShort')|(c.interface.name == 'complexDouble')|(c.interface.name == 'complexFloat')|(c.interface.name == 'complexShort')):
726                ts = " "*4 + 'ACE_Message_Block *mb;\n'; output.write(ts)
727                if c.interface.name == 'realDouble':
728                        DATA_TYPE_BEING_USED = 'double'
729                        DATA_TYPE_USED = 'Double'
730                        ARGUMENT_LIST_FOR_PUSH = ' I'
731                if c.interface.name == 'realFloat':
732                        DATA_TYPE_BEING_USED = 'float'
733                        DATA_TYPE_USED = 'Float'
734                        ARGUMENT_LIST_FOR_PUSH = ' I'
735                if c.interface.name == 'realShort':
736                        DATA_TYPE_BEING_USED = 'short'
737                        DATA_TYPE_USED = 'Short'
738                        ARGUMENT_LIST_FOR_PUSH = ' I'
739                if c.interface.name == 'complexDouble':
740                        DATA_TYPE_BEING_USED = 'double'
741                        DATA_TYPE_USED = 'Double'
742                        ARGUMENT_LIST_FOR_PUSH = ' I, Q'
743                if c.interface.name == 'complexFloat':
744                        DATA_TYPE_BEING_USED = 'float'
745                        DATA_TYPE_USED = 'Float'
746                        ARGUMENT_LIST_FOR_PUSH = ' I, Q'
747                if c.interface.name == 'complexShort':
748                        DATA_TYPE_BEING_USED = 'short'
749                        DATA_TYPE_USED = 'Short'
750                        ARGUMENT_LIST_FOR_PUSH = ' I, Q'
751                ts = " "*4 + 'vector < ' + DATA_TYPE_BEING_USED + ' > vals;\n'; output.write(ts)
752                ts = " "*4 + 'PortTypes::' + DATA_TYPE_USED + 'Sequence ' + ARGUMENT_LIST_FOR_PUSH +';\n\n'; output.write(ts)
753                ts = " "*4 + 'while(1)\n' + " "*8 + '{\n'; output.write(ts)
754                ts = " "*8 + 'ACE_Time_Value getq_time_out = ACE_OS::gettimeofday();\n'; output.write(ts)
755                ts = " "*8 + 'getq_time_out += 1;\n'; output.write(ts)
756                ts = " "*8 + 'if(getq(mb, &getq_time_out) >= 0) {\n'; output.write(ts)
757                portCount = 0
758                if c.interface.name == 'realDouble':
759                        NUMBER_OF_VECTORS = '1'
760                if c.interface.name == 'realFloat':
761                        NUMBER_OF_VECTORS = '1'
762                if c.interface.name == 'realShort':
763                        NUMBER_OF_VECTORS = '1'
764                if c.interface.name == 'complexDouble':
765                        NUMBER_OF_VECTORS = '2'
766                if c.interface.name == 'complexFloat':
767                        NUMBER_OF_VECTORS = '2'
768                if c.interface.name == 'complexShort':
769                        NUMBER_OF_VECTORS = '2'
770                for individual_port in comp.ports:
771                        if individual_port.type == "Uses":
772                                if individual_port.interface.name == 'timingStatus':
773                                        ts = " "*12 + "if (" + comp.name.lower() + "->outPort" + str(portCount) + '_active) {\n'; output.write(ts)
774                                        ts = " "*16 + comp.name.lower() + "->outPort" + str(portCount) + '_servant->send_timing_message(' + comp.name.lower() + '->naming_service_name, "' + c.name + '", "pushPacket", "begin", mb->length()/(sizeof('+ DATA_TYPE_BEING_USED +')*'+ NUMBER_OF_VECTORS +'));\n'; output.write(ts)
775                                        ts = " "*12 + '}\n'; output.write(ts)
776                                portCount += 1
777                ts = " "*12 + 'unsigned int buffer_size=mb->length();\n'; output.write(ts)
778                ts = " "*12 + 'unsigned int packet_size=buffer_size/(sizeof(' + DATA_TYPE_BEING_USED + ')*' + NUMBER_OF_VECTORS + ');\n'; output.write(ts)
779                ts = " "*12 + 'vals.resize(packet_size*' + NUMBER_OF_VECTORS + ');\n'; output.write(ts)
780                if c.interface.name == 'realDouble':
781                        ts = " "*12 + 'I.length(packet_size);\n'; output.write(ts)
782                if c.interface.name == 'realFloat':
783                        ts = " "*12 + 'I.length(packet_size);\n'; output.write(ts)
784                if c.interface.name == 'realShort':
785                        ts = " "*12 + 'I.length(packet_size);\n'; output.write(ts)
786                if c.interface.name == 'complexDouble':
787                        ts = " "*12 + 'I.length(packet_size);\n'+" "*12 + 'Q.length(packet_size);\n'; output.write(ts)
788                if c.interface.name == 'complexFloat':
789                        ts = " "*12 + 'I.length(packet_size);\n'+" "*12 + 'Q.length(packet_size);\n'; output.write(ts)
790                if c.interface.name == 'complexShort':
791                        ts = " "*12 + 'I.length(packet_size);\n'+" "*12 + 'Q.length(packet_size);\n'; output.write(ts)
792                ts = " "*12 + 'ACE_OS::memmove( (char*)&vals[0], mb->rd_ptr(), buffer_size);\n'; output.write(ts)
793                ts = " "*12 + 'for (unsigned int i=0; i<packet_size; i++) {\n'; output.write(ts)
794                if c.interface.name == 'realDouble':
795                        ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts)
796                if c.interface.name == 'realFloat':
797                        ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts)
798                if c.interface.name == 'realShort':
799                        ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts)
800                if c.interface.name == 'complexDouble':
801                        ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts)
802                        ts = " "*16 + 'Q[i]=vals[i+packet_size];\n'; output.write(ts)
803                if c.interface.name == 'complexFloat':
804                        ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts)
805                        ts = " "*16 + 'Q[i]=vals[i+packet_size];\n'; output.write(ts)
806                if c.interface.name == 'complexShort':
807                        ts = " "*16 + 'I[i]=vals[i];\n'; output.write(ts)
808                        ts = " "*16 + 'Q[i]=vals[i+packet_size];\n'; output.write(ts)
809                ts = " "*12 + '}\n'; output.write(ts)
810                ts = " "*12 + 'for (unsigned int i = 0; i < outPorts.size(); i++) {\n'; output.write(ts)
811                ts = " "*16 + 'outPorts[i].port_var->pushPacket( ' + ARGUMENT_LIST_FOR_PUSH + ' );\n'; output.write(ts)
812                ts = " "*12 + '}\n'; output.write(ts)
813                portCount = 0
814                for individual_port in comp.ports:
815                        if individual_port.type == "Uses":
816                                if individual_port.interface.name == 'timingStatus':
817                                        ts = " "*12 + "if (" + comp.name.lower() + "->outPort" + str(portCount) + '_active) {\n'; output.write(ts)
818                                        ts = " "*16 + comp.name.lower() + "->outPort" + str(portCount) + '_servant->send_timing_message(' + comp.name.lower() + '->naming_service_name, "' + c.name + '", "pushPacket", "end", mb->length()/(sizeof('+ DATA_TYPE_BEING_USED +')*'+ NUMBER_OF_VECTORS +'));\n'; output.write(ts)
819                                        ts = " "*12 + '}\n'; output.write(ts)
820                                portCount += 1
821                ts = " "*12 + 'mb->release();\n'; output.write(ts)
822                ts = " "*8 + '}\n'; output.write(ts)
823                ts = " "*4 + '}\n' + " "*4 + 'return 0;\n}\n'
824                output.write(ts)
825        else:
826                if timing_flag & (c.interface.name=='timingStatus'):
827                        ts = " "*4 + 'dataOut_timingStatus_i *output_port = this;\n'; output.write(ts)
828                        ts = " "*4 + 'int message_buffer_read_idx = 0;\n'; output.write(ts)
829                        ts = " "*4 + '\n'; output.write(ts)
830                        ts = " "*4 + 'while(1) {\n'; output.write(ts)
831                        ts = " "*8 + 'output_port->data_is_ready->wait();\n'; output.write(ts)
832                        ts = " "*8 + 'for (unsigned int i = 0; i < output_port->outPorts.size(); i++) {\n'; output.write(ts)
833                        ts = " "*12 + 'output_port->outPorts[i].port_var->send_timing_event(output_port->message_buffer[message_buffer_read_idx].component_name,\n'; output.write(ts)
834                        ts = " "*16 + 'output_port->message_buffer[message_buffer_read_idx].port_name,\n'; output.write(ts)
835                        ts = " "*16 + 'output_port->message_buffer[message_buffer_read_idx].function_name,\n'; output.write(ts)
836                        ts = " "*16 + 'output_port->message_buffer[message_buffer_read_idx].description,\n'; output.write(ts)
837                        ts = " "*16 + 'output_port->message_buffer[message_buffer_read_idx].time_s,\n'; output.write(ts)
838                        ts = " "*16 + 'output_port->message_buffer[message_buffer_read_idx].time_us,\n'; output.write(ts)
839                        ts = " "*16 + 'output_port->message_buffer[message_buffer_read_idx].number_samples);\n'; output.write(ts)
840                        ts = " "*8 + '}\n'; output.write(ts)
841                        ts = " "*8 + 'message_buffer_read_idx++;\n'; output.write(ts)
842                        ts = " "*8 + 'message_buffer_read_idx = message_buffer_read_idx%NUMBER_TIMING_MESSAGE_BUFFER;\n'; output.write(ts)
843                        ts = " "*4 + '}\n'; output.write(ts)
844                        ts = " "*4 + 'return 0;\n'; output.write(ts)
845                        ts = '}\n'; output.write(ts)
846                else:
847                        ts = " "*4 + 'return 0;\n' + '}\n'; output.write(ts)
848
849  def writeTimingMessageDef(self, output,c,type):
850    if type == 'port':
851        ts = 'void ' + c.u_cname + '::send_timing_message(string component_name, string port_name, string function_name, string description, long number_samples) {\n'; output.write(ts)
852        ts = " "*4 + 'writing_to_timing_buffer.lock();\n'; output.write(ts)
853        ts = " "*4 + 'struct timeval tv;\n'; output.write(ts)
854        ts = " "*4 + 'struct timezone tz;\n'; output.write(ts)
855        ts = " "*4 + 'gettimeofday(&tv, &tz);\n'; output.write(ts)
856        ts = " "*4 + 'strcpy(message_buffer[message_buffer_write_idx].component_name, component_name.c_str());\n'; output.write(ts)
857        ts = " "*4 + 'strcpy(message_buffer[message_buffer_write_idx].port_name, port_name.c_str());\n'; output.write(ts)
858        ts = " "*4 + 'strcpy(message_buffer[message_buffer_write_idx].function_name, function_name.c_str());\n'; output.write(ts)
859        ts = " "*4 + 'strcpy(message_buffer[message_buffer_write_idx].description, description.c_str());\n'; output.write(ts)
860        ts = " "*4 + 'message_buffer[message_buffer_write_idx].time_s = tv.tv_sec;\n'; output.write(ts)
861        ts = " "*4 + 'message_buffer[message_buffer_write_idx].time_us = tv.tv_usec;\n'; output.write(ts)
862        ts = " "*4 + 'message_buffer[message_buffer_write_idx].number_samples = number_samples;\n'; output.write(ts)
863        ts = " "*4 + 'message_buffer_write_idx++;\n'; output.write(ts)
864        ts = " "*4 + 'message_buffer_write_idx = message_buffer_write_idx%NUMBER_TIMING_MESSAGE_BUFFER;\n'; output.write(ts)
865        ts = " "*4 + 'writing_to_timing_buffer.unlock();\n'; output.write(ts)
866        ts = " "*4 + 'data_is_ready->post();\n'; output.write(ts)
867        ts = '}\n'; output.write(ts)
868
869  def writeOperation(self,output,i,prefix='',cppFlag=False,in_name='',using_ace=False,comp='',port=''):
870    """ Writes the declaration or definition of an operation (pushPacket) to
871        the port_impl.h and port_impl.cpp files respectively """
872    ocount = 0
873    for o in i.operations:
874
875
876        ocount += 1
877        if cppFlag:
878            if ocount > 1:
879                ts = "\n" + o.returnType + ' ' + prefix + o.name + '('
880                tscxx = "\n" + o.cxxReturnType + ' ' + prefix + o.name + '('
881            else:
882                ts = o.returnType + ' ' + prefix + o.name + '('
883                tscxx = o.cxxReturnType + ' ' + prefix + o.name + '('
884        else:
885            ts = prefix + " "*4 + o.returnType + ' ' + o.name + '('
886            tscxx = prefix + " "*4 + o.cxxReturnType + ' ' + o.name + '('
887
888        first = True
889        for p in o.params:
890            _USE_AMPERSAND_ = ''
891            _USE_CONST_ = 'const '
892            _USE__OUT_ = ''
893            if p.direction == 'out':
894                if len(p.dataType) > 8 and p.dataType[-8:] != 'Sequence':
895                    _USE_CONST_ = ''
896                    _USE_AMPERSAND_ = '&'
897                if len(p.dataType) <= 8:
898                    _USE_CONST_ = ''
899                    _USE_AMPERSAND_ = '&'
900            if p.direction == 'in' and len(p.dataType) > 8 and p.dataType[-8:] == 'Sequence':
901                _USE_AMPERSAND_ = '&'
902            if p.direction == 'inout' and len(p.dataType) > 8 and p.dataType[-8:] == 'Sequence':
903                _USE_CONST_ = ''
904                _USE_AMPERSAND_ = '&'
905            if p.direction == 'out' and len(p.dataType) > 8 and p.dataType[-8:] == 'Sequence':
906                _USE__OUT_ = '_out'
907
908            if not first:
909                ts += ','
910                tscxx += ','
911            else:
912                first = False
913            ts += _USE_CONST_ + p.dataType + _USE__OUT_ + ' ' + _USE_AMPERSAND_ + p.name
914            tscxx += p.cxxType + ' ' + p.name
915        #if len(o.params) != 0:
916        if cppFlag:
917            ts += ')\n'
918            tscxx += ')\n'
919        else:
920            ts += ');\n'
921            tscxx += ');\n'
922#        output.write(ts)
923        output.write(tscxx)
924
925        if cppFlag:
926                #ts = "{\n" + " "*4 + "unsigned int len = " + "hello" + ".length();\n"; output.write(ts)
927                #ts = "{\n\n" + " "*4 + "/* Data flow and processing goes here */\n\n"; output.write(ts)
928                if using_ace:
929                        if len(o.params)>0:
930                                if _USE__OUT_ == '' :
931                                        if ((o.params[0].dataType == 'PortTypes::DoubleSequence')|(o.params[0].dataType == 'PortTypes::FloatSequence')|(o.params[0].dataType == 'PortTypes::ShortSequence')):
932                                                portCount = 0
933                                                ts = "{\n"; output.write(ts)
934                                                for individual_port in comp.ports:
935                                                        if individual_port.type == "Uses":
936                                                                if individual_port.interface.name == 'timingStatus':
937                                                                        ts = " "*4 + "if (" + comp.name.lower() + "->outPort" + str(portCount) + '_active) {\n'; output.write(ts)
938                                                                        ts = " "*8 + comp.name.lower() + "->outPort" + str(portCount) + '_servant->send_timing_message(' + comp.name.lower() + '->naming_service_name, "' + port.name + '", "' + o.name + '", "begin", I.length());\n'; output.write(ts)
939                                                                        ts = " "*4 + '}\n'; output.write(ts)
940                                                                portCount += 1
941                                                ts = " "*4 + "unsigned int len = " + o.params[0].name + ".length();\n"; output.write(ts)
942                                                if o.params[0].dataType == 'PortTypes::DoubleSequence':
943                                                        TYPE_NAME = 'double';
944                                                if o.params[0].dataType == 'PortTypes::FloatSequence':
945                                                        TYPE_NAME = 'float';
946                                                if o.params[0].dataType == 'PortTypes::ShortSequence':
947                                                        TYPE_NAME = 'short';
948                                                if len(o.params) == 1:
949                                                        NUMBER_VECS = '1'
950                                                        if o.params[0].dataType == 'PortTypes::DoubleSequence':
951                                                                DATA_TYPE = '4';
952                                                        if o.params[0].dataType == 'PortTypes::FloatSequence':
953                                                                DATA_TYPE = '5';
954                                                        if o.params[0].dataType == 'PortTypes::ShortSequence':
955                                                                DATA_TYPE = '6';
956                                                if len(o.params) == 2:
957                                                        NUMBER_VECS = '2'
958                                                        if o.params[0].dataType == 'PortTypes::DoubleSequence':
959                                                                DATA_TYPE = '1';
960                                                        if o.params[0].dataType == 'PortTypes::FloatSequence':
961                                                                DATA_TYPE = '2';
962                                                        if o.params[0].dataType == 'PortTypes::ShortSequence':
963                                                                DATA_TYPE = '3';
964                                                ts = " "*4 + "vector <" + TYPE_NAME + "> data_in(len*" + NUMBER_VECS + ");\n"; output.write(ts)
965                                                ts = " "*4 + "char *buffer;\n"; output.write(ts)
966                                                ts = " "*4 + "buffer = new char[len*" + NUMBER_VECS + "*sizeof(" + TYPE_NAME + ")+sizeof(unsigned short)];\n\n"; output.write(ts)
967                                                ts = " "*4 + "for (unsigned int i = 0; i<len; i++) {\n"; output.write(ts)
968                                                if len(o.params) == 1:
969                                                        ts = " "*8 + "data_in[i] = " + o.params[0].name + "[i];\n"; output.write(ts)
970                                                if len(o.params) == 2:
971                                                        ts = " "*8 + "data_in[i] = " + o.params[0].name + "[i];\n"; output.write(ts)
972                                                        ts = " "*8 + "data_in[i+len] = " + o.params[1].name + "[i];\n"; output.write(ts)
973                                                ts = " "*4 + "}\n"; output.write(ts)
974                                                ts = " "*4 + "unsigned short data_type = " + DATA_TYPE + ";\n"; output.write(ts)
975                                                ts = " "*4 + "memcpy(buffer, &data_type, sizeof(unsigned short));\n"; output.write(ts)
976                                                ts = " "*4 + "memcpy(&buffer[sizeof(unsigned short)], (char *)&data_in[0], len*" + NUMBER_VECS + "*sizeof(" + TYPE_NAME + ")+sizeof(unsigned short));\n"; output.write(ts)
977                                                ts = "\n" + " "*4 + "ACE_Message_Block *message = new ACE_Message_Block (len*" + NUMBER_VECS + "*sizeof(" + TYPE_NAME + ")+sizeof(unsigned short));\n"; output.write(ts)
978                                                ts = " "*4 + "message->copy((const char*)&buffer[0], len*" + NUMBER_VECS + "*sizeof(" + TYPE_NAME + ")+sizeof(unsigned short));\n"; output.write(ts)
979                                                ts = " "*4 + "size_t message_length = len*" + NUMBER_VECS + "*sizeof(" + TYPE_NAME + ")+sizeof(unsigned short);\n"; output.write(ts)
980                                                ts = " "*4 + "size_t available_space = " + in_name + "->msg_queue()->message_bytes();\n"; output.write(ts)
981                                                ts = " "*4 + "if (available_space<=(" + in_name + "->queue_size+message_length)) {\n"; output.write(ts)
982                                                ts = " "*8 + "" + in_name + "->queue_size+=QUEUE_BLOCK_SIZE;\n"; output.write(ts)
983                                                ts = " "*8 + "" + in_name + "->water_marks (ACE_IO_Cntl_Msg::SET_HWM," + in_name + "->queue_size);\n"; output.write(ts)
984                                                ts = " "*4 + "}\n"; output.write(ts)
985                                                ts = " "*4 + "if (" + in_name + "->putq(message) == -1) {\n"; output.write(ts)
986                                                ts = " "*8 + "// this is where there would be a message about the putq failing\n"; output.write(ts)
987                                                ts = " "*4 + "}\n"; output.write(ts)
988                                                portCount = 0
989                                                for individual_port in comp.ports:
990                                                        if individual_port.type == "Uses":
991                                                                if individual_port.interface.name == 'timingStatus':
992                                                                        ts = " "*4 + "if (" + comp.name.lower() + "->outPort" + str(portCount) + '_active) {\n'; output.write(ts)
993                                                                        ts = " "*8 + comp.name.lower() + "->outPort" + str(portCount) + '_servant->send_timing_message(' + comp.name.lower() + '->naming_service_name, "' + port.name + '", "' + o.name + '", "end", I.length());\n'; output.write(ts)
994                                                                        ts = " "*4 + '}\n'; output.write(ts)
995                                                                portCount += 1
996                                                ts = " "*4 + "\ndelete buffer;\n}\n"; output.write(ts)
997                                                #ts += " "*4 + "/* if using ACE:\n\n" + " "*7
998                                                #ts += "ACE_Message_Block *mb;\n" + " "*7 + "putq(mb);\n"
999                                                #ts += " "*4 + "*/\n\n}\n"
1000                                                #output.write(ts)
1001                                        else:
1002                                                ts = "{\n\n}\n"; output.write(ts)
1003                                else:
1004                                        ts = "{\n\n}\n"; output.write(ts)
1005                        else:
1006                                ts = "{\n\n}\n"; output.write(ts)
1007                else:
1008                        ts = "{\n\n}\n"; output.write(ts)
1009
1010  def writeFriendDecl(self,output,c):
1011      friendList = []
1012      for p in c.ports:
1013          if p.type == "Uses":
1014              if p.u_cname not in friendList:
1015                  friendList.append(p.u_cname)
1016          if p.type == "Provides":
1017              if p.p_cname not in friendList:
1018                  friendList.append(p.p_cname)
1019
1020      for x in friendList:
1021          ts = " "*4 + "friend class " + x + ";\n"
1022          output.write(ts)
1023
1024
1025  def addPreamble(self,outFile,name):
1026      inFile = open(self.sourcepreamble,'r')
1027      for line in inFile.readlines():
1028          l_out = line.replace("__COMP_NAME__",name)
1029          l_out = l_out.replace("__YEAR__",date.today().year.__str__())
1030          l_out = l_out.replace("__DEVELOPER__",self.developer)
1031          outFile.write(l_out)
1032
1033      inFile.close()
1034
1035
1036  def cleanUp(self):
1037      # Move the AssemblyController to the waveform Dir
1038      for c in self.active_wave.components:
1039        if c.AssemblyController == True and c.generate:
1040            shutil.move(self.path + c.name, self.path + self.active_wav.name)
Note: See TracBrowser for help on using the browser.