root/WaveDev/trunk/WaveDev/wavedev/generate/templates/py_comp/genStructure.py @ 3526

Revision 3526, 46.4 KB (checked in by DrewCormier, 6 years ago)

replaces CLASS_NAME with the component name where appropriate in the WorkModule?.py file

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