/*! @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
Example #2
0
bool NameClient::setContact(const yarp::os::Contact& contact) {
    if (!contact.isValid()) {
        fake = true;
    }
    address = contact;
    mode = "yarp";
    isSetup = true;
    return true;
}
Example #3
0
  virtual bool cmdRegister(yarp::os::Bottle& cmd, 
			   yarp::os::Bottle& reply,
			   yarp::os::Contact& remote) {
    ConstString name = cmd.get(1).asString();
    ConstString carrier = cmd.get(2).asString();
    ConstString machine = cmd.get(3).asString();
    int number = cmd.get(4).asInt();
    if (name=="...") {
      name = "/tmp/";
      for (int i=0; i<20; i++) {
	double x = Rand::scalar('a','z'+1);
	name = name + (char)x;
      }
    }
    if (carrier==""||carrier=="...") {
      carrier = "tcp";
    }
    if (machine==""||machine=="...") {
      machine = remote.getHost();
    }
    if (number==0) {
      number = allocatePortNumber();
      if (number==0) {
	printf("Out of port numbers!\n");
      } else {
	lastNumber = number;
      }
    }
    if (numbers.find(number)==numbers.end()) {
      numbers[number] = 1;
    } else {
      numbers[number]++;
    }
    Entry entry;
    entry.name = name.c_str();
    entry.carrier = carrier.c_str();
    entry.machine = machine.c_str();
    entry.portNumber = number;
    names[name.c_str()] = entry;
    Bottle cmd2;
    cmd2.add("query");
    cmd2.add(name.c_str());
    return cmdQuery(cmd2,reply,remote);
  }