コード例 #1
0
Contact YarpNameSpace::registerContact(const Contact& contact) {
    NameClient& nic = HELPER(this);
    Contact address = nic.registerName(contact.getName().c_str(),
                                       contact);
    if (address.isValid()) {
        NestedContact nc;
        nc.fromString(address.getRegName().c_str());
        std::string cat = nc.getCategory();
        if (nc.getNestedName()!="") {
            //bool service = (cat.find("1") != std::string::npos);
            bool publish = (cat.find('+') != std::string::npos);
            bool subscribe = (cat.find('-') != std::string::npos);
            ContactStyle style;
            Contact c1(nc.getFullName());
            Contact c2(std::string("topic:/") + nc.getNestedName());
            if (subscribe) {
                style.persistenceType = ContactStyle::END_WITH_TO_PORT;
                connectPortToTopic(c2, c1, style);
            }
            if (publish) {
                style.persistenceType = ContactStyle::END_WITH_FROM_PORT;
                connectPortToTopic(c1, c2, style);
            }
        }
    }
    return address;
}
コード例 #2
0
Contact YarpNameSpace::unregisterName(const std::string& name) {
    NestedContact nc;
    nc.fromString(name);
    std::string cat = nc.getCategory();
    if (nc.getNestedName()!="") {
        //bool service = (cat.find("1") != std::string::npos);
        bool publish = (cat.find('+') != std::string::npos);
        bool subscribe = (cat.find('-') != std::string::npos);
        ContactStyle style;
        Contact c1(nc.getFullName());
        Contact c2(std::string("topic:/") + nc.getNestedName());
        if (subscribe) {
            disconnectPortFromTopic(c2, c1, style);
        }
        if (publish) {
            disconnectPortFromTopic(c1, c2, style);
        }
    }
    NameClient& nic = HELPER(this);
    return nic.unregisterName(name);
}