Ejemplo n.º 1
0
 def write_provided_intf(self, file):
     for c in self.m_components:
         for p in c.ports():
             if p.provided() == True:
                 file.write('/* Provided port %s: %s v%u.%u */\n' %
                            (p.name(), p.interface(), p.versionMajor(),
                             p.versionMinor()))
                 intf = match.interface(self.m_interfaces, p.interface(),
                                        p.versionMajor(), p.versionMinor())
                 latest = match.latest_interface(self.m_interfaces,
                                                 p.interface())
                 if intf == latest:
                     name = self.base_name_interface(intf)
                 else:
                     name = self.name_interface(intf)
                 file.write('const %s_t %s = {\n' %
                            (name, self.name_port(p)))
                 file.write('   XC_INTERFACE_INIT (\n')
                 file.write('      "%s", /* name */\n' % (intf.name()))
                 file.write('      %u, /* major version */\n' %
                            (intf.versionMajor()))
                 file.write('      %u  /* minor version */\n' %
                            (intf.versionMinor()))
                 file.write('   )')
                 for m in intf.methods():
                     file.write(',\n')
                     file.write('   __queue_%s' %
                                (self.name_provided_method(p, m)))
                 file.write('\n};\n\n')
Ejemplo n.º 2
0
 def write_required_ports_init (self, comp, file):
    for p in comp.ports():
       if p.provided() == True:
          continue;
       i = match.interface (self.m_interfaces, p.interface(), p.versionMajor(), p.versionMinor());
       file.write ('      /* Port %s for required interface %s. */\n'%(p.name(),i.name()));
       file.write ('      XC_DECLARE_REQUIRED_PORT (\n');
       file.write ('         "%s", /* name */\n'%(p.name()));
       file.write ('         (xc_interface_t *) &%s, /* interface spec */\n'%(self.name_port(p)));
       if p.runtime() == False:
          file.write ('         &%s, /* handle */\n'%(self.name_port_handle(p)));
       else:
          file.write ('         NULL, /* handle */\n');
       if p.component() is None or p.component() == '':
          file.write ('         NULL, /* component */\n');
       else:
          file.write ('         "%s", /* component */\n'%(p.component()));
       if p.port() is None or p.port() == '':
          file.write ('         NULL, /* port */\n');
       else:
          file.write ('         "%s", /* port */\n'%(p.port()));
       file.write ('         NULL, /* reserved */\n'); # TODO: pass encoded interface spec
       if p.register() == True:
          file.write ('         %s,\n'%(self.name_port_register(p)));
       else:
          file.write ('         NULL,\n');
       if p.unregister() == True:
          file.write ('         %s,\n'%(self.name_port_unregister(p)));
       else:
          file.write ('         NULL,\n');
       file.write ('         %s /* flags */\n'%(self.port_flags(p)));
       file.write ('      ),\n');
Ejemplo n.º 3
0
 def write_port_decls(self, p, file):
     if p.register() == True:
         file.write('\n/* %s port register(). */\n' % (p.name()))
         file.write('extern xc_result_t\n')
         file.write('%s (\n' % (self.name_port_register(p)))
         file.write('   xc_handle_t componentHandle,\n')
         file.write('   xc_handle_t importHandle\n')
         file.write(');\n')
     if p.unregister() == True:
         file.write('\n/* %s port unregister(). */\n' % (p.name()))
         file.write('extern xc_result_t\n')
         file.write('%s (\n' % (self.name_port_unregister(p)))
         file.write('   xc_handle_t componentHandle,\n')
         file.write('   xc_handle_t importHandle\n')
         file.write(');\n')
     i = match.interface(self.m_interfaces, p.interface(), p.versionMajor(),
                         p.versionMinor())
     if p.provided() == True:
         for m in i.methods():
             file.write('\n/* %s.%s implementation for port %s */\n' %
                        (i.name(), m.name(), p.name()))
             file.write('extern xc_result_t\n')
             file.write('%s %s;\n' % (self.name_provided_method(
                 p, m), self.proto_method(m, '')))
     else:
         if p.runtime() == False:
             file.write('\n/* Handle for the loadtime port %s */\n' %
                        (p.name()))
             file.write('extern xc_handle_t %s;\n\n' %
                        (self.name_port_handle(p)))
Ejemplo n.º 4
0
 def write_provided_intf (self, file):
    for c in self.m_components:
       for p in c.ports():
          if p.provided() == True:
             file.write ('/* Provided port %s: %s v%u.%u */\n'%(
                p.name(),
                p.interface(),
                p.versionMajor(),
                p.versionMinor()));
             intf = match.interface (self.m_interfaces, p.interface(), p.versionMajor(), p.versionMinor());
             latest = match.latest_interface (self.m_interfaces, p.interface());
             if intf == latest:
                name = self.base_name_interface(intf);
             else:
                name = self.name_interface(intf);
             file.write ('const %s_t %s = {\n'%(name, self.name_port (p)));
             file.write ('   XC_INTERFACE_INIT (\n');
             file.write ('      "%s", /* name */\n'%(intf.name()));
             file.write ('      %u, /* major version */\n'%(intf.versionMajor()));
             file.write ('      %u  /* minor version */\n'%(intf.versionMinor()));
             file.write ('   )');
             for m in intf.methods():
                file.write (',\n');
                file.write ('   __queue_%s'%(self.name_provided_method(p,m)));
             file.write ('\n};\n\n');
Ejemplo n.º 5
0
 def write_port_decls (self, p, file):
    if p.register() == True:
       file.write ('\n/* %s port register(). */\n'%(p.name()));
       file.write ('extern xc_result_t\n');
       file.write ('%s (\n'%(self.name_port_register(p)));
       file.write ('   xc_handle_t componentHandle,\n');
       file.write ('   xc_handle_t importHandle\n');
       file.write (');\n');
    if p.unregister() == True:
       file.write ('\n/* %s port unregister(). */\n'%(p.name()));
       file.write ('extern xc_result_t\n');
       file.write ('%s (\n'%(self.name_port_unregister(p)));
       file.write ('   xc_handle_t componentHandle,\n');
       file.write ('   xc_handle_t importHandle\n');
       file.write (');\n');
    i = match.interface (self.m_interfaces, p.interface(), p.versionMajor(), p.versionMinor());
    if p.provided() == True:
       for m in i.methods():
          file.write ('\n/* %s.%s implementation for port %s */\n'%(i.name(),m.name(),p.name()));
          file.write ('extern xc_result_t\n');
          file.write ('%s %s;\n'%(self.name_provided_method(p, m), self.proto_method(m, '')));
    else:
       if p.runtime() == False:
          file.write ('\n/* Handle for the loadtime port %s */\n'%(p.name()));
          file.write ('extern xc_handle_t %s;\n\n'%(self.name_port_handle(p)));
Ejemplo n.º 6
0
 def source_write_fill_import_object (self, p, file):
    file.write ('         PyObject *oFunc;\n');
    file.write ('         oFunc = PyLong_FromUnsignedLong (importHandle);\n');
    file.write ('         PyObject_SetAttrString (oResult, "__import_handle", oFunc);\n');
    intf = match.interface (self.m_interfaces, p.interface(), p.versionMajor(), p.versionMinor());
    for m in intf.methods():
       file.write ('         oFunc = PyCFunction_NewEx (&%s_%s_def, oResult, NULL);\n'%(
          self.name_interface(intf),self.name_method(m)
       ));
       file.write ('         result = PyObject_SetAttrString (oResult, "%s", oFunc);\n'%(m.name()));
Ejemplo n.º 7
0
 def write_provided_ports_init (self, comp, file):
    for p in comp.ports():
       if p.provided() == False:
          continue;
       i = match.interface (self.m_interfaces, p.interface(), p.versionMajor(), p.versionMinor());
       file.write ('      /* Port %s for provided interface %s. */\n'%(p.name(),i.name()));
       file.write ('      XC_DECLARE_PROVIDED_PORT (\n');
       file.write ('         "%s",\n'%(p.name()));
       file.write ('         (xc_interface_t *) &%s,\n'%(self.name_port(p)));
       file.write ('         sizeof (%s),\n'%(self.name_port(p)));
       file.write ('         NULL,\n'); # FIXME: remove in framework (used to be proto)
       file.write ('         NULL,\n'); # TODO: pass encoded interface spec
       self.write_provided_port_register (p, file);
       self.write_provided_port_unregister (p, file);
       file.write ('      ),\n');
Ejemplo n.º 8
0
 def source_write_fill_import_object(self, p, file):
     file.write('         PyObject *oFunc;\n')
     file.write(
         '         oFunc = PyLong_FromUnsignedLong (importHandle);\n')
     file.write(
         '         PyObject_SetAttrString (oResult, "__import_handle", oFunc);\n'
     )
     intf = match.interface(self.m_interfaces, p.interface(),
                            p.versionMajor(), p.versionMinor())
     for m in intf.methods():
         file.write(
             '         oFunc = PyCFunction_NewEx (&%s_%s_def, oResult, NULL);\n'
             % (self.name_interface(intf), self.name_method(m)))
         file.write(
             '         result = PyObject_SetAttrString (oResult, "%s", oFunc);\n'
             % (m.name()))
Ejemplo n.º 9
0
 def write_required_intf (self, file):
    for c in self.m_components:
       for p in c.ports():
          if p.provided() == False:
             file.write ('/* Required port %s: %s v%u.%u */\n'%(
                p.name(),
                p.interface(),
                p.versionMajor(),
                p.versionMinor()));
             intf = match.interface (self.m_interfaces, p.interface(), p.versionMajor(), p.versionMinor());
             file.write ('const xc_interface_t %s =\n'%(self.name_port (p)));
             file.write ('   XC_INTERFACE_INIT (\n');
             file.write ('      "%s", /* name */\n'%(intf.name()));
             file.write ('      %u, /* major version */\n'%(intf.versionMajor()));
             file.write ('      %u  /* minor version */\n'%(intf.versionMinor()));
             file.write ('   );\n\n');
             if p.runtime() == False:
                file.write ('/* Handle for the loadtime import from port %s */\n'%(p.name()));
                file.write ('xc_handle_t %s = XC_INVALID_HANDLE;\n\n'%(self.name_port_handle(p)));
Ejemplo n.º 10
0
 def write_provided_ports_init(self, comp, file):
     for p in comp.ports():
         if p.provided() == False:
             continue
         i = match.interface(self.m_interfaces, p.interface(),
                             p.versionMajor(), p.versionMinor())
         file.write('      /* Port %s for provided interface %s. */\n' %
                    (p.name(), i.name()))
         file.write('      XC_DECLARE_PROVIDED_PORT (\n')
         file.write('         "%s",\n' % (p.name()))
         file.write('         (xc_interface_t *) &%s,\n' %
                    (self.name_port(p)))
         file.write('         sizeof (%s),\n' % (self.name_port(p)))
         file.write('         NULL,\n')
         # FIXME: remove in framework (used to be proto)
         file.write('         NULL,\n')
         # TODO: pass encoded interface spec
         self.write_provided_port_register(p, file)
         self.write_provided_port_unregister(p, file)
         file.write('      ),\n')
Ejemplo n.º 11
0
 def write_required_ports_init(self, comp, file):
     for p in comp.ports():
         if p.provided() == True:
             continue
         i = match.interface(self.m_interfaces, p.interface(),
                             p.versionMajor(), p.versionMinor())
         file.write('      /* Port %s for required interface %s. */\n' %
                    (p.name(), i.name()))
         file.write('      XC_DECLARE_REQUIRED_PORT (\n')
         file.write('         "%s", /* name */\n' % (p.name()))
         file.write(
             '         (xc_interface_t *) &%s, /* interface spec */\n' %
             (self.name_port(p)))
         if p.runtime() == False:
             file.write('         &%s, /* handle */\n' %
                        (self.name_port_handle(p)))
         else:
             file.write('         NULL, /* handle */\n')
         if p.component() is None or p.component() == '':
             file.write('         NULL, /* component */\n')
         else:
             file.write('         "%s", /* component */\n' %
                        (p.component()))
         if p.port() is None or p.port() == '':
             file.write('         NULL, /* port */\n')
         else:
             file.write('         "%s", /* port */\n' % (p.port()))
         file.write('         NULL, /* reserved */\n')
         # TODO: pass encoded interface spec
         if p.register() == True:
             file.write('         %s,\n' % (self.name_port_register(p)))
         else:
             file.write('         NULL,\n')
         if p.unregister() == True:
             file.write('         %s,\n' % (self.name_port_unregister(p)))
         else:
             file.write('         NULL,\n')
         file.write('         %s /* flags */\n' % (self.port_flags(p)))
         file.write('      ),\n')
Ejemplo n.º 12
0
 def write_required_intf(self, file):
     for c in self.m_components:
         for p in c.ports():
             if p.provided() == False:
                 file.write('/* Required port %s: %s v%u.%u */\n' %
                            (p.name(), p.interface(), p.versionMajor(),
                             p.versionMinor()))
                 intf = match.interface(self.m_interfaces, p.interface(),
                                        p.versionMajor(), p.versionMinor())
                 file.write('const xc_interface_t %s =\n' %
                            (self.name_port(p)))
                 file.write('   XC_INTERFACE_INIT (\n')
                 file.write('      "%s", /* name */\n' % (intf.name()))
                 file.write('      %u, /* major version */\n' %
                            (intf.versionMajor()))
                 file.write('      %u  /* minor version */\n' %
                            (intf.versionMinor()))
                 file.write('   );\n\n')
                 if p.runtime() == False:
                     file.write(
                         '/* Handle for the loadtime import from port %s */\n'
                         % (p.name()))
                     file.write('xc_handle_t %s = XC_INVALID_HANDLE;\n\n' %
                                (self.name_port_handle(p)))
Ejemplo n.º 13
0
    def write_queued_message_structs(self, file):
        for c in self.m_components:
            for p in c.ports():
                self.source_write_port_prologue(c, p, file)
                if p.provided() == True:
                    intf = match.interface(self.m_interfaces, p.interface(),
                                           p.versionMajor(), p.versionMinor())
                    for m in intf.methods():
                        args = len(m.arguments())
                        if args > 0:
                            file.write('/* %s: %s() */\n' %
                                       (intf.name(), m.name()))
                            file.write('struct __%s_message {\n' %
                                       (self.name_provided_method(p, m)))
                            file.write('   %s __queued_message;\n' %
                                       (self.name_queued_message_struct()))
                            for a in m.arguments():
                                if a.direction() == 'in':
                                    file.write('   %s %s;\n' %
                                               (self.queue_arg_type(a),
                                                self.name_argument(a)))
                            file.write('};\n\n')

                            file.write('static void\n')
                            file.write('__free_%s (\n' %
                                       (self.name_provided_method(p, m)))
                            file.write('   void *_message\n')
                            file.write(') {\n')
                            file.write(
                                '   struct __%s_message *message = _message;\n'
                                % (self.name_provided_method(p, m)))
                            file.write('   %s *header = _message;\n' %
                                       (self.name_queued_message_struct()))
                            for a in m.arguments():
                                if a.direction() == 'in':
                                    free_expr = self.queue_free_arg_expr(
                                        a, 'message->%s' %
                                        (self.name_argument(a)))
                                    if free_expr != '':
                                        file.write('   %s\n' % (free_expr))
                            self.source_write_free_message(m, file)
                            file.write('}\n\n')

                        self.write_queue_method_call(p, m, file)

                        file.write('static xc_result_t\n')
                        file.write('__queue_%s ' %
                                   (self.name_provided_method(p, m)))
                        file.write(self.proto_method(m, ''))
                        file.write(' {\n')
                        if args > 0:
                            file.write('   struct __%s_message *message;\n' %
                                       (self.name_provided_method(p, m)))
                        else:
                            file.write('   %s *message;\n' %
                                       (self.name_queued_message_struct()))
                        file.write('   %s *header;\n' %
                                   (self.name_queued_message_struct()))
                        file.write('   xc_result_t result = XC_OK;\n')
                        file.write(
                            '   message = malloc (sizeof (*message));\n')
                        file.write('   header = (%s *) message;\n' %
                                   (self.name_queued_message_struct()))
                        file.write('   if (message != NULL) {\n')
                        self.source_write_init_queued_call(m, file)
                        file.write('      header->handler = __call_%s;\n' %
                                   (self.name_provided_method(p, m)))
                        if args > 0:
                            file.write('      header->free = __free_%s;\n' %
                                       (self.name_provided_method(p, m)))
                        else:
                            file.write('      header->free = free;\n')
                        for a in m.arguments():
                            if a.direction() == 'in':
                                file.write(
                                    self.queue_copy_arg_expr(a, '      '))
                        self.write_queue_copy_args_epilogue(m, file)
                        file.write('      if (result == XC_OK) {\n')
                        file.write('         pthread_mutex_lock (&__lock);\n')
                        file.write(
                            '         XC_CLIST_ADDTAIL (&__queued_messages, message);\n'
                        )
                        file.write('         xc_sem_signal (&__sem);\n')
                        file.write(
                            '         pthread_mutex_unlock (&__lock);\n')
                        file.write('      }\n')
                        file.write('      else {\n')
                        file.write('         __free_%s (message);\n' %
                                   (self.name_provided_method(p, m)))
                        file.write('      }\n')
                        file.write('   }\n')
                        file.write('   else {\n')
                        file.write('      result = XC_ERR_NOMEM;\n')
                        file.write('   }\n')
                        file.write('   return result;\n')
                        file.write('}\n\n')
Ejemplo n.º 14
0
   def write_queued_message_structs (self, file):
      for c in self.m_components:
         for p in c.ports():
            self.source_write_port_prologue (c, p, file);
            if p.provided() == True:
               intf = match.interface (self.m_interfaces, p.interface(), p.versionMajor(), p.versionMinor());
               for m in intf.methods():
                  args = len(m.arguments());
                  if args > 0:
                     file.write('/* %s: %s() */\n'%(intf.name(), m.name()));
                     file.write('struct __%s_message {\n'%(self.name_provided_method(p,m)));
                     file.write('   %s __queued_message;\n'%(self.name_queued_message_struct()));
                     for a in m.arguments():
                        if a.direction() == 'in':
                           file.write('   %s %s;\n'%(self.queue_arg_type(a), self.name_argument(a)));
                     file.write('};\n\n');

                     file.write('static void\n');
                     file.write('__free_%s (\n'%(self.name_provided_method(p,m)));
                     file.write('   void *_message\n');
                     file.write(') {\n');
                     file.write('   struct __%s_message *message = _message;\n'%(self.name_provided_method(p,m)));
                     file.write('   %s *header = _message;\n'%(self.name_queued_message_struct()));
                     for a in m.arguments():
                        if a.direction() == 'in':
                           free_expr = self.queue_free_arg_expr (a, 'message->%s'%(self.name_argument(a)));
                           if free_expr != '':
                              file.write('   %s\n'%(free_expr));
                     self.source_write_free_message (m, file);
                     file.write('}\n\n');

                  self.write_queue_method_call (p, m, file);

                  file.write('static xc_result_t\n');
                  file.write('__queue_%s '%(self.name_provided_method(p,m)));
                  file.write(self.proto_method(m, ''));
                  file.write(' {\n');
                  if args > 0:
                     file.write('   struct __%s_message *message;\n'%(self.name_provided_method(p,m)));
                  else:
                     file.write('   %s *message;\n'%(self.name_queued_message_struct()));
                  file.write('   %s *header;\n'%(self.name_queued_message_struct()));
                  file.write('   xc_result_t result = XC_OK;\n');
                  file.write('   message = malloc (sizeof (*message));\n');
                  file.write('   header = (%s *) message;\n'%(self.name_queued_message_struct()));
                  file.write('   if (message != NULL) {\n');
                  self.source_write_init_queued_call (m, file);
                  file.write('      header->handler = __call_%s;\n'%(self.name_provided_method(p,m)));
                  if args > 0:
                     file.write('      header->free = __free_%s;\n'%(self.name_provided_method(p,m)));
                  else:
                     file.write('      header->free = free;\n');
                  for a in m.arguments():
                     if a.direction() == 'in':
                        file.write(self.queue_copy_arg_expr(a, '      '));
                  self.write_queue_copy_args_epilogue (m, file);
                  file.write('      if (result == XC_OK) {\n');
                  file.write('         pthread_mutex_lock (&__lock);\n');
                  file.write('         XC_CLIST_ADDTAIL (&__queued_messages, message);\n');
                  file.write('         xc_sem_signal (&__sem);\n');
                  file.write('         pthread_mutex_unlock (&__lock);\n');
                  file.write('      }\n');
                  file.write('      else {\n');
                  file.write('         __free_%s (message);\n'%(self.name_provided_method(p,m)));
                  file.write('      }\n');
                  file.write('   }\n');
                  file.write('   else {\n');
                  file.write('      result = XC_ERR_NOMEM;\n');
                  file.write('   }\n');
                  file.write('   return result;\n');
                  file.write('}\n\n');