/*! @brief Set the IP address for the endpoint.
 @param[in,out] workingContact The connection information that is to be filled in.
 @param[in] endpointName The desired endpoint name.
 @param[in] portNumber The port number to be applied to the connection.
 @returns @c true if the connection information has been constructed and @c false otherwise. */
static bool
setEndpointIPAddress(yarp::os::Contact & workingContact,
                     const YarpString &  endpointName,
                     const int           portNumber)
{
    ODL_ENTER(); //####
    ODL_P1("workingContact = ", &workingContact); //####
    ODL_S1s("endpointName = ", endpointName); //####
    ODL_I1("portNumber = ", portNumber); //####
#if defined(MpM_ReportContactDetails)
    DumpContactToLog("enter setEndpointIPAddress", workingContact); //####
#endif // defined(MpM_ReportContactDetails)
    bool result = false;

    try
    {
        yarp::os::Contact aContact = yarp::os::Network::registerName(endpointName);
        YarpString        ipAddress = aContact.getHost();

        ODL_S1s("ipAddress = ", ipAddress); //####
        yarp::os::Network::unregisterName(endpointName);
        workingContact = workingContact.addSocket(CHANNEL_CARRIER_, ipAddress, portNumber);
#if defined(MpM_ReportContactDetails)
        DumpContactToLog("after addSocket", workingContact); //####
#endif // defined(MpM_ReportContactDetails)
        result = workingContact.isValid();
    }
    catch (...)
    {
        ODL_LOG("Exception caught"); //####
        throw;
    }
    ODL_EXIT_B(result); //####
    return result;
} // setEndpointIPAddress
Exemplo n.º 2
0
bool NameClient::setContact(const yarp::os::Contact& contact) {
    if (!contact.isValid()) {
        fake = true;
    }
    address = contact;
    mode = "yarp";
    isSetup = true;
    return true;
}