コード例 #1
0
ファイル: MpiCarrier.cpp プロジェクト: JoErNanO/yarp
 bool MpiCarrier::expectSenderSpecifier(ConnectionState& proto) {
    // interpret everything that sendHeader wrote
    name = proto.getRoute().getToName();

    #ifdef MPI_DEBUG
    printf("[MpiCarrier @ %s] Waiting for header\n", route.c_str());
    #endif

    other = proto.is().readLine();
    proto.setRoute(proto.getRoute().addFromName(other));
    // Receiver
    route = name + "<-" + other;

    createStream(false);
    if (!MpiControl) return false;
    if (! MpiControl->isRunning())
        return false;

    ConstString other_id = proto.is().readLine();
    bool notLocal = comm->notLocal(other_id);

    port = proto.is().readLine();

    #ifdef MPI_DEBUG
    printf("[MpiCarrier @ %s] Header received\n", route.c_str());
    #endif

    return notLocal && proto.is().isOk();
}
コード例 #2
0
ファイル: LocalCarrier.cpp プロジェクト: apaikan/yarp
bool yarp::os::impl::LocalCarrier::expectExtraHeader(ConnectionState& proto) {
    portName = proto.getRoute().getToName();
    // switch over to some local structure to communicate
    peerMutex.wait();
    peer = manager.getSender(this);
    //printf("receiver %ld (%s) sees sender %ld (%s)\n",
    //       (long int) this, portName.c_str(),
    //       (long int) peer, peer->portName.c_str());
    proto.setRoute(proto.getRoute().addFromName(peer->portName));
    peerMutex.post();

    return true;
}
コード例 #3
0
ファイル: MpiCarrier.cpp プロジェクト: JoErNanO/yarp
 bool MpiCarrier::sendHeader(ConnectionState& proto) {
    // Send the "magic number" for this carrier
    ManagedBytes header(8);
    getHeader(header.bytes());
    proto.os().write(header.bytes());
    if (!proto.os().isOk()) return false;

    // Now we can do whatever we want, as long as somehow
    // we also send the name of the originating port

    name = proto.getRoute().getFromName();
    other = proto.getRoute().getToName();
    Bytes b2((char*)name.c_str(),name.length());
    proto.os().write(b2);
    proto.os().write('\r');
    proto.os().write('\n');

    // Sender
    route = name + "->" + other;

    createStream(true);

    if (!MpiControl) return false;
    if (! MpiControl->isRunning())
        return false;
    comm->openPort();
    char* port = comm->port_name;
    char* uid = comm->unique_id;

    #ifdef MPI_DEBUG
    printf("[MpiCarrier @ %s] setting up MpiPort '%s'\n", route.c_str(), port);
    #endif

    Bytes b4(uid,strlen(uid));
    proto.os().write(b4);
    proto.os().write('\r');
    proto.os().write('\n');

    Bytes b3(port,strlen(port));
    proto.os().write(b3);
    proto.os().write('\r');
    proto.os().write('\n');
    proto.os().flush();


    #ifdef MPI_DEBUG
    printf("[MpiCarrier @ %s] Header sent\n", route.c_str());
    #endif

    return proto.os().isOk();
}
コード例 #4
0
ファイル: AbstractCarrier.cpp プロジェクト: jgvictores/yarp
bool AbstractCarrier::expectSenderSpecifier(ConnectionState& proto)
{
    NetInt32 numberSrc;
    Bytes number((char*)&numberSrc, sizeof(NetInt32));
    int len = 0;
    YARP_SSIZE_T r = proto.is().readFull(number);
    if ((size_t)r!=number.length()) {
        YARP_DEBUG(Logger::get(), "did not get sender name length");
        return false;
    }
    len = NetType::netInt(number);
    if (len>1000) {
        len = 1000;
    }
    if (len<1) {
        len = 1;
    }
    ManagedBytes b(len+1);
    r = proto.is().readFull(Bytes(b.get(), len));
    if ((int)r!=len) {
        YARP_DEBUG(Logger::get(), "did not get sender name");
        return false;
    }
    ConstString s = b.get();
    Route route = proto.getRoute();
    route.setFromName(s);
    proto.setRoute(route);
    return true;
}
コード例 #5
0
ファイル: XmlRpcCarrier.cpp プロジェクト: JoErNanO/yarp
bool XmlRpcCarrier::shouldInterpretRosMessages(ConnectionState& proto) {
    // We need to set the interpretRos flag, which controls
    // whether ROS-style admin messages are treated as
    // admin messages or data messages in YARP.
    // In the future, they should always be data messages.
    // For now, they should be admin messages for all ports
    // except ports tagged as corresponding to ros nodes.

    bool nodelike = false;
    Contactable *port = proto.getContactable();
    Property opt;
    if (port) {
        Property *pport = port->acquireProperties(true);
        if (pport) {
            opt = *pport;
        }
        port->releaseProperties(pport);
    }
    if (opt.check("node_like")) {
        nodelike = true;
    }

    Name n(proto.getRoute().getCarrierName() + "://test");
    ConstString rospass = n.getCarrierModifier("ros");
    interpretRos = !nodelike;
    if (rospass=="1"||rospass=="on") {
        interpretRos = true;
    }
    if (rospass=="0"||rospass=="off") {
        interpretRos = false;
    }
    return interpretRos;
}
コード例 #6
0
ファイル: AbstractCarrier.cpp プロジェクト: BRKMYR/yarp
bool AbstractCarrier::expectSenderSpecifier(ConnectionState& proto) {
    NetInt32 numberSrc;
    Bytes number((char*)&numberSrc,sizeof(NetInt32));
    int len = 0;
    YARP_SSIZE_T r = proto.is().readFull(number);
    if ((size_t)r!=number.length()) {
        YARP_DEBUG(Logger::get(),"did not get sender name length");
        return false;
    }
    len = NetType::netInt(number);
    if (len>1000) len = 1000;
    if (len<1) len = 1;
    // expect a string -- these days null terminated, but not in YARP1
    ManagedBytes b(len+1);
    r = proto.is().readFull(Bytes(b.get(),len));
    if ((int)r!=len) {
        YARP_DEBUG(Logger::get(),"did not get sender name");
        return false;
    }
    // add null termination for YARP1
    b.get()[len] = '\0';
    String s = b.get();
    proto.setRoute(proto.getRoute().addFromName(s));
    return true;
}
コード例 #7
0
ファイル: TextCarrier.cpp プロジェクト: ale-git/yarp
bool yarp::os::impl::TextCarrier::expectSenderSpecifier(ConnectionState& proto)
{
    YARP_SPRINTF0(Logger::get(), debug, "TextCarrier::expectSenderSpecifier");
    Route route = proto.getRoute();
    route.setFromName(proto.is().readLine());
    proto.setRoute(route);
    return true;
}
コード例 #8
0
ファイル: XmlRpcCarrier.cpp プロジェクト: JoErNanO/yarp
bool XmlRpcCarrier::sendHeader(ConnectionState& proto) {
    shouldInterpretRosMessages(proto);
    ConstString target = "POST /RPC2";
    Name n(proto.getRoute().getCarrierName() + "://test");
    ConstString pathValue = n.getCarrierModifier("path");
    if (pathValue!="") {
        target = "POST /";
        target += pathValue;
        // on the wider web, we should provide real host names
        host = NetworkBase::queryName(proto.getRoute().getToName());
    }
    target += " HTTP/1.1\n";
    http = target;
    Bytes b((char*)target.c_str(),target.length());
    proto.os().write(b);
    return true;
}
コード例 #9
0
ファイル: HttpCarrier.cpp プロジェクト: giuliavezzani/yarp
bool yarp::os::impl::HttpCarrier::sendHeader(ConnectionState& proto) {
    ConstString target = "GET / HTTP/1.0\r\n";
    ConstString path = proto.getRoute().getToName();
    if (path.size()>=2) {
        target = "GET " + path + " HTTP/1.0\r\n";
    }
    Contact host = proto.getRoute().getToContact();
    if (host.getHost()!="") {
        target += "Host: ";
        target += host.getHost();
        target += "\r\n";
    }
    target += "\r\n";
    Bytes b((char*)target.c_str(),target.length());
    proto.os().write(b);
    return true;

}
コード例 #10
0
ファイル: McastCarrier.cpp プロジェクト: apaikan/yarp
bool yarp::os::impl::McastCarrier::becomeMcast(ConnectionState& proto, bool sender) {
#ifndef YARP_HAS_ACE
    return false;
#else
    YARP_UNUSED(sender);
    DgramTwoWayStream *stream = new DgramTwoWayStream();
    yAssert(stream!=YARP_NULLPTR);
    Contact remote = proto.getStreams().getRemoteAddress();
    Contact local;
    local = proto.getStreams().getLocalAddress();
    bool test = true;
    //(yarp::NameConfig::getEnv("YARP_MCAST_TEST")!="");
    /*
    if (test) {
        printf("  MULTICAST is being extended; some temporary status messages added\n");
        printf("  Local: %s\n", local.toString().c_str());
        printf("  Remote: %s\n", remote.toString().c_str());
    }
    */
    proto.takeStreams(YARP_NULLPTR); // free up port from tcp

    if (sender) {
        /*
            Multicast behavior seems a bit variable.
            We assume here that if packages need to be broadcast
            to targets via different network interfaces, that
            we'll need to send independently on those two
            interfaces.  This may or may not always be the case,
            the author doesn't know, so is being cautious.
        */
        key = proto.getRoute().getFromName();
        if (test) {
            key += "/net=";
            key += local.getHost();
        }
        YARP_DEBUG(Logger::get(),
                    ConstString("multicast key: ") + key);
        addSender(key);
    }

    bool ok = true;
    if (isElect()||!sender) {
        if (test) {
            ok = stream->join(mcastAddress,sender,local);
        } else {
            ok = stream->join(mcastAddress,sender);
        }
    }

    if (!ok) {
        delete stream;
        return false;
    }
    proto.takeStreams(stream);
    return true;
#endif
}
コード例 #11
0
ファイル: TextCarrier.cpp プロジェクト: ale-git/yarp
bool yarp::os::impl::TextCarrier::respondToHeader(ConnectionState& proto)
{
    std::string from = "Welcome ";
    from += proto.getRoute().getFromName();
    from += "\r\n";
    yarp::os::Bytes b2((char*)from.c_str(), from.length());
    proto.os().write(b2);
    proto.os().flush();
    return proto.os().isOk();
}
コード例 #12
0
ファイル: MjpegCarrier.cpp プロジェクト: AbuMussabRaja/yarp
bool MjpegCarrier::sendHeader(ConnectionState& proto) {
    Name n(proto.getRoute().getCarrierName() + "://test");
    ConstString pathValue = n.getCarrierModifier("path");
    ConstString target = "GET /?action=stream\n\n";
    if (pathValue!="") {
        target = "GET /";
        target += pathValue;
    }
    target += " HTTP/1.1\n";
    Contact host = proto.getRoute().getToContact();
    if (host.getHost()!="") {
        target += "Host: ";
        target += host.getHost();
        target += "\r\n";
    }
    target += "\n";
    Bytes b((char*)target.c_str(),target.length());
    proto.os().write(b);
    return true;
}
コード例 #13
0
ファイル: H264Carrier.cpp プロジェクト: robotology/yarp
// Now, the initial hand-shaking
bool H264Carrier::prepareSend(ConnectionState& proto)
{
     //get all parameters of this carrier
     Name n(proto.getRoute().getCarrierName() + "://test");

     cfgParams.crop.left = getIntParam(n, "cropLeft");
     cfgParams.crop.right = getIntParam(n, "cropRight");
     cfgParams.crop.top = getIntParam(n, "cropTop");
     cfgParams.crop.bottom = getIntParam(n, "cropBottom");
     cfgParams.fps_max = getIntParam(n, "max_fps");
     cfgParams.verbose = (getIntParam(n, "verbose") >0) ? true: false;

    return true;
}
コード例 #14
0
ファイル: LocalCarrier.cpp プロジェクト: claudiofantacci/yarp
bool yarp::os::impl::LocalCarrier::sendHeader(ConnectionState& proto) {
    portName = proto.getRoute().getFromName();

    manager.setSender(this);

    defaultSendHeader(proto);
    // now switch over to some local structure to communicate
    peerMutex.lock();
    peer = manager.getReceiver();
    //printf("sender %ld sees receiver %ld\n", (long int) this,
    //       (long int) peer);
    peerMutex.unlock();

    return true;
}
コード例 #15
0
ファイル: HumanCarrier.cpp プロジェクト: AbuMussabRaja/yarp
bool HumanCarrier::sendHeader(ConnectionState& proto) {
    // Send the "magic number" for this carrier
    ManagedBytes header(8);
    getHeader(header.bytes());
    proto.os().write(header.bytes());
    if (!proto.os().isOk()) return false;

    // Now we can do whatever we want, as long as somehow
    // we also send the name of the originating port

    // let's just send the port name in plain text terminated with a
    // carriage-return / line-feed
    ConstString from = proto.getRoute().getFromName();
    Bytes b2((char*)from.c_str(),from.length());
    proto.os().write(b2);
    proto.os().write('\r');
    proto.os().write('\n');
    proto.os().flush();
    return proto.os().isOk();
}
コード例 #16
0
ファイル: TcpRosCarrier.cpp プロジェクト: barbalberto/yarp
ConstString TcpRosCarrier::getRosType(ConnectionState& proto) {
    ConstString typ = "";
    ConstString rtyp = "";
    if (proto.getContactable()) {
        Type t = proto.getContactable()->getType(); 
        typ = t.getName();
        md5sum = t.readProperties().find("md5sum").asString();
        message_definition = t.readProperties().find("message_definition").asString();
        user_type = typ;
        if (typ=="yarp/image") {
            wire_type = "sensor_msgs/Image";
            rtyp = "";
        } else if (typ=="yarp/bottle") {
            rtyp = proto.getContactable()->getType().getNameOnWire();
            if (rtyp=="yarp/image") rtyp = "sensor_msgs/Image";
            wire_type = rtyp;
        } else if (typ!="") {
            rtyp = typ;
            wire_type = typ;
        }
    }
    Name n(proto.getRoute().getCarrierName() + "://test");
    ConstString mode = "topic";
    ConstString modeValue = n.getCarrierModifier("topic");
    if (modeValue=="") {
        mode = "service";
        modeValue = n.getCarrierModifier("service");
    }
    if (modeValue!="") {
        ConstString package = n.getCarrierModifier("package");
        if (package!="") {
            rtyp = package + "/" + modeValue;
        }
    }

    dbg_printf("USER TYPE %s\n", user_type.c_str());
    dbg_printf("WIRE TYPE %s\n", wire_type.c_str());

    return rtyp;
}
コード例 #17
0
ファイル: H264Carrier.cpp プロジェクト: robotology/yarp
bool H264Carrier::expectReplyToHeader(ConnectionState& proto)
{
    // I'm the receiver...

    cfgParams.remotePort = proto.getRoute().getToContact().getPort();

    auto* stream = new H264Stream(cfgParams);
    if (stream==nullptr) { return false; }

    yarp::os::Contact remote = proto.getStreams().getRemoteAddress();
    bool ok = stream->open(remote);

    //std::cout << "Remote contact info: host=" << proto.getRoute().getToContact().getHost() << " port= " << proto.getRoute().getToContact().getPort() <<std::endl;
    if (!ok)
    {
        delete stream;
        return false;
    }
    stream->start();

    proto.takeStreams(stream);
    return true;
}
コード例 #18
0
ファイル: McastCarrier.cpp プロジェクト: apaikan/yarp
bool yarp::os::impl::McastCarrier::sendHeader(ConnectionState& proto) {
    // need to do more than the default
    bool ok = defaultSendHeader(proto);
    if (!ok) return false;

    YARP_DEBUG(Logger::get(),"Adding extra mcast header");

    Contact addr;

    Contact alt = proto.getStreams().getLocalAddress();
    ConstString altKey =
        proto.getRoute().getFromName() +
        "/net=" + alt.getHost();
    McastCarrier *elect = getCaster().getElect(altKey);
    if (elect!=YARP_NULLPTR) {
        YARP_DEBUG(Logger::get(),"picking up peer mcast name");
        addr = elect->mcastAddress;
        mcastName = elect->mcastName;
    } else {

        // fetch an mcast address
        Contact target("...", "mcast", "...", 0);
        addr = NetworkBase::registerContact(target);
        mcastName = addr.getRegName();
        if (addr.isValid()) {
            // mark owner of mcast address
            NetworkBase::setProperty(proto.getRoute().getFromName().c_str(),
                                     "owns",
                                     Value(mcastName.c_str()));
        }
    }

    int ip[] = { 224, 3, 1, 1 };
    int port = 11000;
    if (addr.isValid()) {
        SplitString ss(addr.getHost().c_str(),'.');
        if (ss.size()!=4) {
            addr = Contact();
        } else {
            yAssert(ss.size()==4);
            for (int i=0; i<4; i++) {
                ip[i] = NetType::toInt(ss.get(i));
            }
            port = addr.getPort();
        }
    }

    if (!addr.isValid()) {
        YARP_ERROR(Logger::get(), "Name server not responding helpfully, setting mcast name arbitrarily.");
        YARP_ERROR(Logger::get(), "Only a single mcast address supported in this mode.");
        addr = Contact("/tmp/mcast", "mcast", "224.3.1.1", 11000);
    }

    ManagedBytes block(6);
    for (int i=0; i<4; i++) {
        ((unsigned char*)block.get())[i] = (unsigned char)ip[i];
    }
    block.get()[5] = (char)(port%256);
    block.get()[4] = (char)(port/256);
    proto.os().write(block.bytes());
    mcastAddress = addr;
    return true;
}
コード例 #19
0
ファイル: XmlRpcCarrier.cpp プロジェクト: JoErNanO/yarp
bool XmlRpcCarrier::expectSenderSpecifier(ConnectionState& proto) {
    proto.setRoute(proto.getRoute().addFromName("rpc"));
    return true;
}
コード例 #20
0
ファイル: TcpRosCarrier.cpp プロジェクト: barbalberto/yarp
bool TcpRosCarrier::expectReplyToHeader(ConnectionState& proto) {
    RosHeader header;

    char mlen[4];
    Bytes mlen_buf(mlen,4);

    int res = proto.is().readFull(mlen_buf);
    if (res<4) {
        printf("Fail %s %d\n", __FILE__, __LINE__);
        return false;
    }
    int len = NetType::netInt(mlen_buf);
    dbg_printf("Len %d\n", len);
    if (len>10000) {
        printf("not ready for serious messages\n");
        return false;
    }
    ManagedBytes m(len);
    res = proto.is().readFull(m.bytes());
    if (res!=len) {
        printf("Fail %s %d\n", __FILE__, __LINE__);
        return false;
    }
    header.readHeader(string(m.get(),m.length()));
    dbg_printf("Message header: %s\n", header.toString().c_str());
    ConstString rosname = "";
    if (header.data.find("type")!=header.data.end()) {
        rosname = header.data["type"].c_str();
    }
    dbg_printf("<incoming> Type of data is [%s]s\n", rosname.c_str());
    if (header.data.find("callerid")!=header.data.end()) {
        string name = header.data["callerid"];
        dbg_printf("<incoming> callerid is %s\n", name.c_str());
        dbg_printf("Route was %s\n", proto.getRoute().toString().c_str());
        proto.setRoute(proto.getRoute().addToName(name.c_str()));
        dbg_printf("Route is now %s\n", proto.getRoute().toString().c_str());
    }

    if (!isService) {
        isService = (header.data.find("request_type")!=header.data.end());
    }
    if (rosname!="" && (user_type != wire_type || user_type == "")) {
        kind = TcpRosStream::rosToKind(rosname.c_str()).c_str();
        TcpRosStream::configureTwiddler(twiddler,kind.c_str(),rosname.c_str(),false,false);
        translate = TCPROS_TRANSLATE_TWIDDLER;
    } else {
        rosname = "";
    }
    dbg_printf("tcpros %s mode\n", isService?"service":"topic");

    // we may be a pull stream
    sender = isService;

    processRosHeader(header);

    TcpRosStream *stream = new TcpRosStream(proto.giveStreams(),sender,
                                            sender,
                                            isService,raw,rosname.c_str());

    if (stream==NULL) { return false; }

    dbg_printf("Getting ready to hand off streams...\n");

    proto.takeStreams(stream);

    return proto.is().isOk();
}
コード例 #21
0
ファイル: AbstractCarrier.cpp プロジェクト: jgvictores/yarp
bool AbstractCarrier::defaultExpectIndex(ConnectionState& proto)
{
    Log& log = proto.getLog();
    YARP_DEBUG(Logger::get(), "expecting an index");
    YARP_SPRINTF1(Logger::get(),
                  debug,
                  "ConnectionState::expectIndex for %s",
                  proto.getRoute().toString().c_str());
    // expect index header
    char buf[8];
    Bytes header((char*)&buf[0], sizeof(buf));
    YARP_SSIZE_T r = proto.is().readFull(header);
    if ((size_t)r!=header.length()) {
        YARP_DEBUG(log, "broken index");
        return false;
    }
    int len = interpretYarpNumber(header);
    if (len<0) {
        YARP_DEBUG(log, "broken index - header is not a number");
        return false;
    }
    if (len!=10) {
        YARP_DEBUG(log, "broken index - header is wrong length");
        return false;
    }
    YARP_DEBUG(Logger::get(), "index coming in happily...");
    char buf2[10];
    Bytes indexHeader((char*)&buf2[0], sizeof(buf2));
    r = proto.is().readFull(indexHeader);
    if ((size_t)r!=indexHeader.length()) {
        YARP_DEBUG(log, "broken index, secondary header");
        return false;
    }
    YARP_DEBUG(Logger::get(), "secondary header came in happily...");
    int inLen = (unsigned char)(indexHeader.get()[0]);
    int outLen = (unsigned char)(indexHeader.get()[1]);
    // Big limit on number of blocks here!  Inherited from QNX.
    // should make it go away if it hurts someone.

    int total = 0;
    NetInt32 numberSrc;
    Bytes number((char*)&numberSrc, sizeof(NetInt32));
    for (int i=0; i<inLen; i++) {
        YARP_SSIZE_T l = proto.is().readFull(number);
        if ((size_t)l!=number.length()) {
            YARP_DEBUG(log, "bad input block length");
            return false;
        }
        int x = NetType::netInt(number);
        total += x;
    }
    for (int i2=0; i2<outLen; i2++) {
        YARP_SSIZE_T l = proto.is().readFull(number);
        if ((size_t)l!=number.length()) {
            YARP_DEBUG(log, "bad output block length");
            return false;
        }
        int x = NetType::netInt(number);
        total += x;
    }
    proto.setRemainingLength(total);
    YARP_SPRINTF1(Logger::get(),
                  debug,
                  "Total message length: %d",
                  total);
    return true;
}
コード例 #22
0
ファイル: TcpRosCarrier.cpp プロジェクト: barbalberto/yarp
bool TcpRosCarrier::expectSenderSpecifier(ConnectionState& proto) {
    proto.setRoute(proto.getRoute().addFromName("tcpros"));

    dbg_printf("Trying for tcpros header\n");
    ManagedBytes m(headerLen1);
    Bytes mrem(m.get()+4,m.length()-4);
    NetInt32 ni = headerLen2;
    memcpy(m.get(),(char*)(&ni), 4);
    dbg_printf("reading %d bytes\n", (int)mrem.length());
    int res = proto.is().readFull(mrem);
    dbg_printf("read %d bytes\n", res);
    if (res!=(int)mrem.length()) {
        if (res>=0) {
            fprintf(stderr,"TCPROS header failure, expected %d bytes, got %d bytes\n",
                    (int)mrem.length(),res);
        } else {
            fprintf(stderr,"TCPROS connection has gone terribly wrong\n");
        }
        return false;
    }
    RosHeader header;
    header.readHeader(string(m.get(),m.length()));
    dbg_printf("Got header %s\n", header.toString().c_str());

    ConstString rosname = "";
    if (header.data.find("type")!=header.data.end()) {
        rosname = header.data["type"].c_str();
    }
    ConstString rtyp = getRosType(proto);
    if (rtyp!="") {
        rosname = rtyp;
        header.data["type"] = rosname;
        header.data["md5sum"] = (md5sum!="")?md5sum:"*";
        if (message_definition!="") {
            header.data["message_definition"] = message_definition;
        }
    }
    dbg_printf("<outgoing> Type of data is %s\n", rosname.c_str());

    if (header.data.find("callerid")!=header.data.end()) {
        proto.setRoute(proto.getRoute().addFromName(header.data["callerid"].c_str()));
    } else {
        proto.setRoute(proto.getRoute().addFromName("tcpros"));
    }

    // Let's just ignore everything that is sane and holy, and
    // send the same header right back.
    // **UPDATE** Oh, ok, let's modify the callerid.  Begrudgingly.
    NestedContact nc(proto.getRoute().getToName());
    header.data["callerid"] = nc.getNodeName().c_str();

    string header_serial = header.writeHeader();
    string header_len(4,'\0');
    char *at = (char*)header_len.c_str();
    RosHeader::appendInt(at,header_serial.length());
    dbg_printf("Writing %s -- %d bytes\n", 
               RosHeader::showMessage(header_len).c_str(),
               (int)header_len.length());
    
    Bytes b1((char*)header_len.c_str(),header_len.length());
    proto.os().write(b1);
    dbg_printf("Writing %s -- %d bytes\n", 
               RosHeader::showMessage(header_serial).c_str(),
               (int)header_serial.length());
    Bytes b2((char*)header_serial.c_str(),header_serial.length());
    proto.os().write(b2);

    if (header.data.find("probe")!=header.data.end()) {
        dbg_printf("================PROBE===============\n");
        return false;
    }


    if (!isService) {
        isService = (header.data.find("service")!=header.data.end());
    }
    if (rosname!="" && (user_type != wire_type || user_type == "")) {
        if (wire_type!="sensor_msgs/Image") { // currently using a custom method for images
            kind = TcpRosStream::rosToKind(rosname.c_str()).c_str();
            TcpRosStream::configureTwiddler(twiddler,kind.c_str(),rosname.c_str(),true,true);
            translate = TCPROS_TRANSLATE_TWIDDLER;
        }
    } else {
        rosname = "";
    }
    sender = isService; 

    processRosHeader(header);

    if (isService) {
        TcpRosStream *stream = new TcpRosStream(proto.giveStreams(),sender,
                                                false,
                                                isService,raw,rosname.c_str());
        
        if (stream==NULL) { return false; }
        proto.takeStreams(stream);
        return proto.is().isOk();
    }

    return true;
}
コード例 #23
0
ファイル: HttpCarrier.cpp プロジェクト: giuliavezzani/yarp
bool yarp::os::impl::HttpCarrier::expectSenderSpecifier(ConnectionState& proto) {
    proto.setRoute(proto.getRoute().addFromName("web"));
    ConstString remainder = proto.is().readLine();
    if (!urlDone) {
        for (unsigned int i=0; i<remainder.length(); i++) {
            if (remainder[i]!=' ') {
                url += remainder[i];
            } else {
                break;
            }
        }
    }

    bool done = false;
    expectPost = false;
    contentLength = 0;
    while (!done) {
        ConstString result = proto.is().readLine();
        if (result == "") {
            done = true;
        } else {
            //printf(">>> %s\n", result.c_str());
            Bottle b;
            b.fromString(result.c_str());
            if (b.get(0).asString()=="Content-Length:") {
                //printf("]]] got length %d\n", b.get(1).asInt());
                contentLength = b.get(1).asInt();
            }
            if (b.get(0).asString()=="Content-Type:") {
                //printf("]]] got type %s\n", b.get(1).asString());
                if (b.get(1).asString()=="application/x-www-form-urlencoded") {
                    expectPost = true;
                }
            }
        }
    }

    if (expectPost) {
        //printf("[[[this is a post message of length %d]]]\n", contentLength);
        ManagedBytes blk(contentLength+1);
        Bytes start(blk.get(),contentLength);
        proto.is().readFull(start);
        blk.get()[contentLength] = '\0';
        //printf("message: %s\n", blk.get());
        input = blk.get();
    } else {
        //printf("message: %s\n", url.c_str());
        input = url;
    }
    prop.fromQuery(input.c_str());
    prop.put("REQUEST_URI",url.c_str());
    //printf("Property %s\n",prop.toString().c_str());

    Contact home = NetworkBase::getNameServerContact();
    Contact me = proto.getStreams().getLocalAddress();

    ConstString from = "<html><head><link href=\"http://";
    from += home.getHost();
    from += ":";
    from += NetType::toString(home.getPort());
    from += "/web/main.css\" rel=\"stylesheet\" type=\"text/css\"/></head><body bgcolor='#ffffcc'><h1>yarp port ";
    from += proto.getRoute().getToName();
    from += "</h1>\n";

    from += "<p>(<a href=\"http://";
    from += home.getHost();
    from += ":";
    from += NetType::toString(home.getPort());
    from += "/data=list\">All ports</a>)&nbsp;&nbsp;\n";

    from += "(<a href=\"http://";
    from += me.getHost();
    from += ":";
    from += NetType::toString(me.getPort());
    from += "/\">connections</a>)&nbsp;&nbsp;\n";

    from += "(<a href=\"http://";
    from += me.getHost();
    from += ":";
    from += NetType::toString(me.getPort());
    from += "/data=help\">help</a>)&nbsp;&nbsp;\n";

    from += "(<a href=\"http://";
    from += me.getHost();
    from += ":";
    from += NetType::toString(me.getPort());
    from += "/r\">read</a>)&nbsp;&nbsp;\n";

    from += "</p>\n";
    from += "<p>\n";
    from += "<form method=\"post\" action=\"http://";
    from += me.getHost();
    from += ":";
    from += NetType::toString(me.getPort());
    from += "/form\">";

    prefix = from;


    //Bytes b2((char*)from.c_str(),from.length());
    //proto.os().write(b2);
    //proto.os().flush();
    // Message gets finished by the stream

    return proto.os().isOk();
}
コード例 #24
0
ファイル: TcpRosCarrier.cpp プロジェクト: barbalberto/yarp
bool TcpRosCarrier::sendHeader(ConnectionState& proto) {
    dbg_printf("Route is %s\n", proto.getRoute().toString().c_str());
    Name n(proto.getRoute().getCarrierName() + "://test");
    ConstString mode = "topic";
    ConstString modeValue = n.getCarrierModifier("topic");
    if (modeValue=="") {
        mode = "service";
        modeValue = n.getCarrierModifier("service");
        isService = true;
    }
    if (modeValue=="") {
        printf("*** no topic or service specified!\n");
        mode = "topic";
        modeValue = "notopic";
        isService = false;
    }
    ConstString rawValue = n.getCarrierModifier("raw");
    if (rawValue=="2") {
        raw = 2;
        dbg_printf("ROS-native mode requested\n");
    } else if (rawValue=="1") {
        raw = 1;
        dbg_printf("Raw mode requested\n");
    } else if (rawValue=="0") {
        raw = 0;
        dbg_printf("Cooked mode requested\n");
    }

    RosHeader header;
    dbg_printf("Writing to %s\n", proto.getStreams().getRemoteAddress().toString().c_str()); 
    dbg_printf("Writing from %s\n", proto.getStreams().getLocalAddress().toString().c_str());

    ConstString rtyp = getRosType(proto);
    if (rtyp!="") {
        header.data["type"] = rtyp.c_str();
    }
    header.data[mode.c_str()] = modeValue.c_str();
    header.data["md5sum"] = (md5sum!="")?md5sum:"*";
    if (message_definition!="") {
        header.data["message_definition"] = message_definition;
    }
    NestedContact nc(proto.getRoute().getFromName());
    header.data["callerid"] = nc.getNodeName();
    header.data["persistent"] = "1";
    string header_serial = header.writeHeader();
    string header_len(4,'\0');
    char *at = (char*)header_len.c_str();
    RosHeader::appendInt(at,header_serial.length());
    dbg_printf("Writing %s -- %d bytes\n", 
               RosHeader::showMessage(header_len).c_str(),
               (int)header_len.length());

    Bytes b1((char*)header_len.c_str(),header_len.length());
    proto.os().write(b1);
    dbg_printf("Writing %s -- %d bytes\n", 
               RosHeader::showMessage(header_serial).c_str(),
               (int)header_serial.length());
    Bytes b2((char*)header_serial.c_str(),header_serial.length());
    proto.os().write(b2);

    return proto.os().isOk();
}