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

Revision 3619, 46.2 KB (checked in by DrewCormier, 6 years ago)

writeGetPort method has been replaced

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