示例#1
0
    def create_proxies(self):
        result = ""
        for iface, num in get_name_number(self.component.requires):
            if communication_is_ice(iface):
                module = self.component.idsl_pool.module_providing_interface(
                    iface.name)
                proxy_type = iface.name
                if module is not None:
                    proxy_type = f"{module['name']}::{iface.name}"
                if self.component.language.lower() == "cpp":
                    result += f"{proxy_type}Prx {iface.name.lower()}{num}_proxy;\n"
                else:
                    result += f"{proxy_type}PrxPtr {iface.name.lower()}{num}_proxy;\n"

        for iface, num in get_name_number(self.component.publishes):
            if communication_is_ice(iface):
                module = self.component.idsl_pool.module_providing_interface(
                    iface.name)
                proxy_type = iface.name
                if module is not None:
                    proxy_type = f"{module['name']}::{iface.name}"
                if self.component.language.lower() == "cpp":
                    result += f"{proxy_type}Prx {iface.name.lower()}{num}_pubproxy;\n"
                else:
                    result += f"{proxy_type}PrxPtr {iface.name.lower()}{num}_pubproxy;\n"
        return result
示例#2
0
    def require_and_publish_proxies_creation(self):
        result = ""
        cont = 0
        for interface, num in get_name_number(self.component.requires):
            if communication_is_ice(interface):
                name = interface.name
                if self.component.language.lower() == 'cpp':
                    prx_type = name
                    if prx_type not in CPP_TYPES and '::' not in prx_type:
                        module = self.component.idsl_pool.module_providing_interface(name)
                        prx_type = f"{module['name']}::{prx_type}"
                    result += name.lower() + num + "_proxy = (*(" + prx_type + "Prx*)mprx[\"" + name + "Proxy" + num + "\"]);\n"
                else:
                    result += name.lower() + num + "_proxy = std::get<" + str(cont) + ">(tprx);\n"
            cont = cont + 1

        for interface, num in get_name_number(self.component.publishes):
            if communication_is_ice(interface):
                name = interface.name
                prx_type = name
                if prx_type not in CPP_TYPES and '::' not in prx_type:
                    module = self.component.idsl_pool.module_providing_interface(name)
                    prx_type = f"{module['name']}::{prx_type}"
                if self.component.language.lower() == 'cpp':
                    result += name.lower() + num + "_pubproxy = (*(" + prx_type + "Prx*)mprx[\"" + name + "Pub" + num + "\"]);\n"
                else:
                    result += name.lower() + num + "_pubproxy = std::get<" + str(cont) + ">(tprx);\n"
            cont = cont + 1
        return result
示例#3
0
 def require_and_publish_proxies_creation(self):
     result = ""
     cont = 0
     for interface, num in get_name_number(self.component.requires):
         result += self.get_proxy_string(interface,
                                         num,
                                         cont,
                                         is_publication=False)
         cont = cont + 1
     for interface, num in get_name_number(self.component.publishes):
         result += self.get_proxy_string(interface,
                                         num,
                                         cont,
                                         is_publication=True)
         cont = cont + 1
     return result
示例#4
0
    def subscribes_to(self):
        result = ""
        for interface, num in get_name_number(self.component.subscribesTo):
            name = interface.name
            if communication_is_ice(interface):
                if self.component.language.lower() == "cpp":
                    change1 = "IceStorm::TopicPrx"
                    change2 = "Ice::ObjectPrx"
                    change3 = " new <NORMAL>I"
                    change4 = "Ice::ObjectPrx"
                else:
                    change1 = "std::shared_ptr<IceStorm::TopicPrx>"
                    change2 = "Ice::ObjectPrxPtr"
                    change3 = " std::make_shared <<NORMAL>I>"
                    change4 = "auto"

                module = self.component.idsl_pool.module_providing_interface(
                    name)
                proxy_type = utils.get_type_string(name, module['name'])
                result += SUBSCRIBESTO_STR.replace(
                    "<CHANGE1>",
                    change1).replace("<CHANGE2>", change2).replace(
                        "<CHANGE3>",
                        change3).replace("<CHANGE4>", change4).replace(
                            "<NORMAL>",
                            name).replace("<LOWER>", name.lower()).replace(
                                "<PROXYNAME>",
                                name.lower() + num).replace(
                                    "<PROXYNUMBER>",
                                    num).replace("<PTR_TYPE>", proxy_type)
        return result
 def test_get_name_number(self):
     self.assertCountEqual(
         parsing_utils.get_name_number(['AGMExecutiveTopic', 'HumanPose']),
         [['AGMExecutiveTopic', ''], ['HumanPose', '']])
     self.assertCountEqual(
         parsing_utils.get_name_number(
             ['AGMExecutiveTopic', 'HumanPose', 'HumanPose']),
         [['AGMExecutiveTopic', ''], ['HumanPose', ''], ['HumanPose', '1']])
     self.assertCountEqual(
         parsing_utils.get_name_number(
             ['HumanPose', 'HumanPose', 'HumanPose']),
         [['HumanPose', ''], ['HumanPose', '1'], ['HumanPose', '2']])
     self.assertRaises(AssertionError, parsing_utils.get_name_number,
                       "lapatochada")
     self.assertRaises(AssertionError, parsing_utils.get_name_number,
                       ["lapatochada", 8, 3.9])
示例#6
0
 def config_requires_proxies(self):
     result = ""
     for interface, num in get_name_number(self.component.requires):
         if communication_is_ice(interface):
             port = 0
             if interface.name == 'DifferentialRobot': port = 10004
             if interface.name == 'Laser': port = 10003
             result += interface.name + num + "Proxy = " + interface.name.lower(
             ) + ":tcp -h localhost -p " + str(port) + "\n"
     if result != "":
         result = '# Proxies for required interfaces\n' + result + '\n\n'
     return result
示例#7
0
 def publish_proxy_creation(self):
     result = ""
     for iface, num in get_name_number(self.component.publishes):
         if communication_is_ice(iface):
             name = iface.name
             module = self.component.idsl_pool.module_providing_interface(
                 iface.name)
             result += Template(PUBLISHES_STR).substitute(
                 iface_name=name,
                 iface_name_lower=name.lower(),
                 module_name=module['name'])
     return result
示例#8
0
 def publishes_proxies(self):
     result = ""
     for pb, num in get_name_number(self.component.publishes):
         if isinstance(pb, str):
             pub = pb
         else:
             pub = pb[0]
         if communication_is_ice(pb):
             result += "self." + pub.lower() + num + "_proxy = mprx[\"" + pub + "Pub" + num + "\"]\n"
         else:
             result += "self." + pub.lower() + "_proxy = Publisher" + pub + "()\n"
     return result
示例#9
0
 def requires_proxies(self):
     result = ""
     for req, num in get_name_number(self.component.requires):
         if isinstance(req, str):
             rq = req
         else:
             rq = req[0]
         if communication_is_ice(req):
             result += "self." + rq.lower() + num + "_proxy = mprx[\"" + rq + "Proxy" + num + "\"]\n"
         else:
             result += "self." + rq.lower() + "_proxy = ServiceClient" + rq + "()\n"
     return result
示例#10
0
 def require_proxy_creation(self):
     result = ""
     for iface, num in get_name_number(self.component.requires):
         if communication_is_ice(iface):
             name = iface.name
             module = self.component.idsl_pool.module_providing_interface(
                 iface.name)
             result += Template(REQUIRE_STR).substitute(
                 iface_name=name,
                 module_name=module['name'],
                 iface_name_lower=name.lower(),
                 num=num)
     return result
示例#11
0
 def config_requires_proxies(self):
     result = ""
     for interface, num in get_name_number(self.component.requires):
         if communication_is_ice(interface):
             port = 0
             if interface.name == 'DifferentialRobot': port = 10004
             elif interface.name == 'Laser': port = 10003
             elif RCPortChecker:
                 port = get_existing_port(interface.name)
             else:
                 port = random.randint(10001, 19000)
             result += interface.name + num + "Proxy = " + interface.name.lower(
             ) + ":tcp -h localhost -p " + str(port) + "\n"
     if result != "":
         result = '# Proxies for required interfaces\n' + result + '\n\n'
     return result
示例#12
0
 def proxy_ptr(self, interfaces, prefix=''):
     result = ""
     for interface, num in get_name_number(interfaces):
         if communication_is_ice(interface):
             ptr = ""
             if self.component.language.lower() != "cpp":
                 ptr = "Ptr"
             name = interface.name
             module = self.component.idsl_pool.module_providing_interface(
                 name)
             proxy_type = utils.get_type_string(name, module['name'])
             result += Template(PROXY_PTR_STR).substitute(
                 prx_type=proxy_type,
                 ptr=ptr,
                 lower=name.lower(),
                 num=num,
                 prefix=prefix)
     return result
示例#13
0
 def specificworker_creation(self):
     result = ""
     if self.component.language.lower() == "cpp":
         var_name = 'm'
     else:
         var_name = 't'
         proxy_list = [
             interface.name.lower() + num + "_proxy"
             for interface, num in get_name_number(self.component.requires)
         ]
         proxy_list += [
             interface.name.lower() + "_pubproxy"
             for interface in self.component.publishes
         ]
         if proxy_list:
             result += "tprx = std::make_tuple(" + ",".join(
                 proxy_list) + ");\n"
         else:
             result += "tprx = std::tuple<>();\n"
     result += "SpecificWorker *worker = new SpecificWorker({}prx, startup_check_flag);\n".format(
         var_name)
     return result
示例#14
0
 def interface_specific_comment(self):
     result = ""
     interfaces_by_type = {
         "requires": self.component.requires,
         "publishes": self.component.publishes,
         "implements": self.component.implements,
         "subscribesTo": self.component.subscribesTo
     }
     for interface_type, interfaces in interfaces_by_type.items():
         for interface, num in p_utils.get_name_number(interfaces):
             if p_utils.communication_is_ice(interface):
                 proxy_methods_calls = ""
                 module = self.component.idsl_pool.module_providing_interface(
                     interface.name)
                 if interface_type in ["publishes", "requires"]:
                     if interface_type == 'publishes':
                         action = "publish calling"
                         pub = "pub"
                     else:
                         action = "call"
                         pub = ""
                     proxy_reference = "this->" + interface.name.lower(
                     ) + num + f"_{pub}proxy->"
                     for method in module['interfaces'][0]['methods']:
                         proxy_methods_calls += f"// {proxy_reference}{method}(...)\n"
                     if proxy_methods_calls:
                         result += Template(
                             PROXY_METHODS_COMMENT_STR).substitute(
                                 module_name=module['name'],
                                 methods=proxy_methods_calls,
                                 action=action)
                 structs_str = ""
                 for struct in module['structs']:
                     structs_str += f"// {struct['name'].replace('/', '::')}\n"
                 if structs_str:
                     result += Template(
                         INTERFACE_TYPES_COMMENT_STR).substitute(
                             module_name=module['name'], types=structs_str)
     return result
示例#15
0
 def requires(self):
     result = ""
     for interface, num in get_name_number(self.component.requires):
         name = interface.name
         if communication_is_ice(interface):
             module = self.component.idsl_pool.module_providing_interface(
                 name)
             proxy_type = utils.get_type_string(name, module['name'])
             if self.component.language.lower() == "cpp":
                 cpp = "<PROXYNAME>_proxy = <PROXY_TYPE>Prx::uncheckedCast( communicator()->stringToProxy( proxy ) );"
             else:
                 cpp = "<PROXYNAME>_proxy = Ice::uncheckedCast<<PROXY_TYPE>Prx>( communicator()->stringToProxy( proxy ) );"
             result += REQUIRE_STR.replace("<C++_VERSION>", cpp).replace(
                 "<NORMAL>", name).replace("<LOWER>", name.lower()).replace(
                     "<PROXYNAME>",
                     name.lower() + num).replace("<PROXYNUMBER>",
                                                 num).replace(
                                                     '<PROXY_TYPE>',
                                                     proxy_type)
         if self.component.language.lower() == "cpp":
             result += "mprx[\"" + name + "Proxy" + num + "\"] = (::IceProxy::Ice::Object*)(&" + name.lower(
             ) + num + "_proxy);//Remote server proxy creation example\n"
     return result
示例#16
0
			needIce = True
			needStorm = True
	if needStorm:
		cog.outl("""
<TABHERE># Topic Manager
<TABHERE>proxy = ic.getProperties().getProperty("TopicManager.Proxy")
<TABHERE>obj = ic.stringToProxy(proxy)
<TABHERE>try:
<TABHERE><TABHERE>topicManager = IceStorm.TopicManagerPrx.checkedCast(obj)
<TABHERE>except Ice.ConnectionRefusedException as e:
<TABHERE><TABHERE>print('Cannot connect to IceStorm! ('+proxy+')')
<TABHERE><TABHERE>status = 1""")
except:
	pass

for req, num in get_name_number(component['requires']):
	if communication_is_ice(req):
		w = REQUIRE_STR.replace("<NORMAL>", req).replace("<LOWER>", req.lower()).replace("<NUM>",num)
		cog.outl(w)

for pub, num in get_name_number(component['publishes']):
	if communication_is_ice(pub):
		w = PUBLISHES_STR.replace("<NORMAL>", pub).replace("<LOWER>", pub.lower())
		cog.outl(w)

cog.outl("<TABHERE>if status == 0:")
cog.outl("<TABHERE><TABHERE>worker = SpecificWorker(mprx)")
cog.outl("<TABHERE><TABHERE>worker.setParams(parameters)")
cog.outl("<TABHERE>else:")
cog.outl("<TABHERE><TABHERE>print(\"Error getting required connections, check config file\")")
cog.outl("<TABHERE><TABHERE>sys.exit(-1)")