当前位置: 首页>>代码示例>>C++>>正文


C++ Bottle::addVocab方法代码示例

本文整理汇总了C++中Bottle::addVocab方法的典型用法代码示例。如果您正苦于以下问题:C++ Bottle::addVocab方法的具体用法?C++ Bottle::addVocab怎么用?C++ Bottle::addVocab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bottle的用法示例。


在下文中一共展示了Bottle::addVocab方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: respond

bool Behavior::respond(const Bottle &command,Bottle &reply){
    bool ok = false; // command executed successfully

    switch (command.get(0).asVocab()) {
    case VOCAB_QUIT:
        reply.addVocab(VOCAB_OK);
        ok = true;
        OK_MSG = 1;
        break;
    case VOCAB_STOP:
        reply.addVocab(VOCAB_OK);
        ok = true;
        next_state=IDLE;
        OK_MSG = 1;
        break;
    case VOCAB_CONT:
        reply.addVocab(VOCAB_OK);
        ok = true;
        next_state=ATTENTION;
        OK_MSG = 1;
        break;
    default:
        printf("VOCAB default\n ");
        reply.addVocab(VOCAB_FAILED);
    }

    ok = RFModule::respond(command,reply); // will add message 'not recognized' if not recognized

    return ok;
}
开发者ID:xufango,项目名称:contrib_bk,代码行数:30,代码来源:behavior.cpp

示例2: respond

    bool respond(const Bottle& command, Bottle& reply)
    {
        LockGuard lg(mutex);
        int cmd=command.get(0).asVocab();

        if (cmd==Vocab::encode("stop"))
        {
            state=idle;
            reply.addVocab(Vocab::encode("ack"));
            return true;
        }
        else if (cmd==Vocab::encode("start"))
        {
            if (command.size()>=5)
            {
                initRect.x=command.get(1).asInt();
                initRect.y=command.get(2).asInt();
                initRect.width=command.get(3).asInt();
                initRect.height=command.get(4).asInt();                
                state=init;
                reply.addVocab(Vocab::encode("ack"));
            }
            else
                reply.addVocab(Vocab::encode("nack"));
            return true;
        }
        else
            return RFModule::respond(command,reply);
    }
开发者ID:pattacini,项目名称:icub-contrib,代码行数:29,代码来源:main.cpp

示例3: respond

 virtual bool respond(const Bottle &command, Bottle &reply)
 {
     bool ret;
     if (command.size()!=0)
     {
         switch (command.get(0).asVocab())
         {
             case yarp::os::createVocab('h','e','l','p'):
             {                    
                 cout << "Available commands:"          << endl;
                 cout<<"Queue command:\n";
                 cout<<"[ctpq] [time] seconds [off] j [pos] (list)\n";
                 cout<<"New command, execute now (erase queue):\n";
                 cout<<"[ctpq] [time] seconds [off] j [pos] (list)\n";
                 cout<<"Load sequence from file:\n";
                 cout<<"[ctpf] filename\n";
                 reply.addVocab(Vocab::encode("ack"));
                 return true;
             }
             case VCTP_CMD_NOW:
                 {
                     ret=handlectpm(command, reply);
                     return ret;
                 }
             case VCTP_CMD_QUEUE:
                 {
                     ret=handle_ctp_queue(command, reply);
                     return ret;
                 }
             case VCTP_CMD_FILE:
                 {
                     ret=handle_ctp_file(command, reply);
                     return ret;
                 }
             case VCTP_WAIT:
                 {
                     ret=handle_wait(command, reply);
                 }
             default:
                 return RFModule::respond(command,reply);
         }
     }
     else
     {
         reply.addVocab(Vocab::encode("nack"));
         return false;
     }
 }
开发者ID:robotology,项目名称:icub-main,代码行数:48,代码来源:main.cpp

示例4: respond

    // rpcPort commands handler
    bool respond(const Bottle &      command,
                 Bottle &      reply)
    {
        // This method is called when a command string is sent via RPC

        // Get command string
        string receivedCmd = command.get(0).asString().c_str();
        reply.clear();  // Clear reply bottle
        
        if (receivedCmd == "help")
        {
            reply.addVocab(Vocab::encode("many"));
            reply.addString("Available commands are:");
            reply.addString("help");
            reply.addString("quit");
        }
        else if (receivedCmd == "quit")
        {
            reply.addString("Quitting.");
            return false; //note also this
        }
        else
            reply.addString("Invalid command, type [help] for a list of accepted commands.");

        return true;
    }
开发者ID:GiuliaP,项目名称:iRRLS,代码行数:27,代码来源:parametricEstimator.cpp

示例5: unregisterName

Contact NameServer::unregisterName(const ConstString& name) {
    Contact prev = queryName(name);
    if (prev.isValid()) {
        if (prev.getPort()!=-1) {
            NameRecord& rec = getNameRecord(prev.getRegName());
            if (rec.isReusablePort()) {
                HostRecord& host = getHostRecord(prev.getHost());
                host.release(prev.getPort());
            }
            if (rec.isReusableIp()) {
                if (rec.getAddress().getCarrier()=="mcast") {
                    mcastRecord.releaseAddress(rec.getAddress().getHost().c_str());
                }
            }
            rec.clear();
            tmpNames.release(name);

            Bottle event;
            event.addVocab(Vocab::encode("del"));
            event.addString(name.c_str());
            onEvent(event);
        }
    }

    return queryName(name);
}
开发者ID:apaikan,项目名称:yarp,代码行数:26,代码来源:NameServer.cpp

示例6: respond

    bool respond(const Bottle &command, Bottle &reply)
    {
        LockGuard lg(mutex);
        int cmd=command.get(0).asVocab();
        int ack=Vocab::encode("ack");
        int nack=Vocab::encode("nack");

        if (cmd==Vocab::encode("start"))
        {
            if (command.size()>=3)
            {
                actionTag=command.get(1).asString();
                objectTag=command.get(2).asString();
                gate=1;
                if (command.size()>=4)
                {
                    int g=command.get(3).asInt();
                    if (g>0)
                        gate=g;
                }
                reply.addVocab(ack);
            }
            else
                reply.addVocab(nack);
            return true;
        }
        else if (cmd==Vocab::encode("stop"))
        {
            actionTag="none";
            objectTag="none";
            gate=0;
            reply.addVocab(ack);
            return true;
        }
        else if (cmd==Vocab::encode("get"))
        {
            reply.addVocab(ack);
            reply.addString(actionTag);
            reply.addString(objectTag);
            reply.addInt(gate);
            return true;
        }
        else
            return RFModule::respond(command,reply);
    }
开发者ID:caomw,项目名称:wysiwyd,代码行数:45,代码来源:main.cpp

示例7: handle_ctp_file

    bool handle_ctp_file(const Bottle &cmd, Bottle &reply)
    {
        if (cmd.size()<2)
            return false;

        string fileName=rf->findFile(cmd.get(1).asString());
        bool ret = velThread.go(fileName);
        if (ret)
        {
            reply.addVocab(Vocab::encode("ack"));
        }
        else
        {
            reply.addVocab(Vocab::encode("nack"));
            reply.addString("Unable to load file");
        }
        return ret;
    }
开发者ID:robotology,项目名称:icub-main,代码行数:18,代码来源:main.cpp

示例8: respond

    bool respond(const Bottle& command, Bottle& reply) 
    {
        reply.clear(); 
        
        if (command.get(0).isInt())
        {
            if (command.get(0).asInt()==0)
            {
                fprintf(stderr,"Asking recalibration...\n");
                if (inv_dyn)
                {
                    inv_dyn->suspend();
                    inv_dyn->calibrateOffset(); 
                    inv_dyn->resume();
                }
                fprintf(stderr,"Recalibration complete.\n");
                reply.addString("Recalibrated");
                return true;
            }
        }

        if (command.get(0).isString())
        {
            if (command.get(0).asString()=="help")
            {
                reply.addVocab(Vocab::encode("many"));
                reply.addString("Available commands:");
                reply.addString("calib all");
                reply.addString("calib arms");
                reply.addString("calib legs");
                reply.addString("calib feet");
                return true;
            }
            else if (command.get(0).asString()=="calib")
            {
                fprintf(stderr,"Asking recalibration...\n");
                if (inv_dyn)
                {
                    calib_enum calib_code=CALIB_ALL;
                          if (command.get(1).asString()=="all")  calib_code=CALIB_ALL;
                    else  if (command.get(1).asString()=="arms") calib_code=CALIB_ARMS;
                    else  if (command.get(1).asString()=="legs") calib_code=CALIB_LEGS;
                    else  if (command.get(1).asString()=="feet") calib_code=CALIB_FEET;

                    inv_dyn->suspend();
                    inv_dyn->calibrateOffset(calib_code);
                    inv_dyn->resume();
                }
                fprintf(stderr,"Recalibration complete.\n");
                reply.addString("Recalibrated");
                return true;
            }
        }

        reply.addString("Unknown command");
        return true;
    }
开发者ID:apaikan,项目名称:icub-main,代码行数:57,代码来源:main.cpp

示例9: main

int main(int argc, char *argv[]) {
    if (argc<=1) {
        printf("This is a very simple database\n");
        printf("Call as: %s --name /database\n", argv[0]);
        printf("Then you can test it by running:\n");
        printf("  yarp rpc /database\n");
        printf("And typing things like:\n");
        printf("  set x 24\n");
        printf("  get x\n");
        printf("  get y\n");
        printf("  rm x\n");
        printf("  get x\n");
        printf("  set \"my favorite numbers\" (5 10 16)\n");
        printf("  get \"my favorite numbers\"\n");
    }

    Network yarp;

    Property option;
    option.fromCommand(argc,argv);

    Property state;

    Port port;
    port.open(option.check("name",Value("/database")).asString());

    while (true) {
        Bottle cmd;
        Bottle response;
        port.read(cmd,true);  // true -> will reply

        Bottle tmp;
        tmp.add(cmd.get(1));
        std::string key = tmp.toString();

        switch (Vocab::encode(cmd.get(0).toString())) {
        case VOCAB_SET:
            state.put(key,cmd.get(2));
            break;
        case VOCAB_GET:
            break;
        case VOCAB_REMOVE:
            state.unput(key);
            break;
        }
        Value& v = state.find(key);
        response.addVocab(v.isNull()?VOCAB_NOT:VOCAB_IS);
        response.add(cmd.get(1));
        if (!v.isNull()) {
            response.add(v);
        }
        port.reply(response);
    }

    return 0;
}
开发者ID:ale-git,项目名称:yarp,代码行数:56,代码来源:database.cpp

示例10: handle_wait

 bool handle_wait(const Bottle &cmd, Bottle &reply)
 {
     cerr<<"Warning command not implemented yet"<<endl;
     reply.addVocab(Vocab::encode("ack"));
     return true;
     //ActionItem *action;
     //bool ret=parseWaitCmd(cmd, reply, &action);
     //if (ret)
     //   posPort.queue(action);
 }
开发者ID:robotology,项目名称:icub-main,代码行数:10,代码来源:main.cpp

示例11: handle_ctp_queue

 bool handle_ctp_queue(const Bottle &cmd, Bottle &reply)
 {
     ActionItem *action;
     bool ret=parsePosCmd(cmd, reply, &action);
     if (ret)
     {
         posPort.queue(action);
         reply.addVocab(Vocab::encode("ack"));
     }
     return ret;
 }
开发者ID:robotology,项目名称:icub-main,代码行数:11,代码来源:main.cpp

示例12: respond

    bool respond(const Bottle &command, Bottle &reply)
    {
        int ack =Vocab::encode("ack");
        int nack=Vocab::encode("nack");

        if (command.size()>0)
        {
            if (command.get(0).asString() == "get")
            {
                if (command.get(1).asString() == "motionGain")
                {
                    reply.addVocab(ack);
                    reply.addDouble(motionGain);
                }
                else
                {
                    reply.addVocab(nack);
                }
            }
            else if (command.get(0).asString() == "set")
            {
                if (command.get(1).asString() == "motionGain")
                {
                    reply.addVocab(ack);
                    motionGain = command.get(2).asDouble();
                    reply.addDouble(motionGain);
                }
                else if (command.get(1).asString() == "behavior")
                {
                    if (command.get(2).asString() == "avoidance")
                    {
                        reply.addVocab(ack);
                        motionGain = -1.0;
                        reply.addDouble(motionGain);
                    }
                    else if (command.get(2).asString() == "catching")
                    {
                        reply.addVocab(ack);
                        motionGain = 1.0;
                        reply.addDouble(motionGain);
                    }
                    else
                    {
                        reply.addVocab(nack);
                    }
                }
                else
                {
                    reply.addVocab(nack);
                }
            }
        }

        return true;
    }
开发者ID:robotology,项目名称:peripersonal-space,代码行数:55,代码来源:demoAvoidance.cpp

示例13: respond

    bool respond(const Bottle &command, Bottle &reply)
    {
        string cmd=command.get(0).asString().c_str();
        int ack=Vocab::encode("ack");
        int nack=Vocab::encode("nack");

        if (cmd=="clear")
        {
            LockGuard lg(mutex);
            contour.clear();
            floodPoints.clear();
            go=flood3d=flood=false;
            reply.addVocab(ack);
        }
        else if ((cmd=="go") || (cmd=="flood3d"))
        {
            if (portSFM.getOutputCount()==0)
                reply.addVocab(nack);
            else
            {
                LockGuard lg(mutex);
                if (cmd=="go")
                {
                    if (contour.size()>2)
                    {
                        flood=false;
                        go=true;
                        reply.addVocab(ack);
                    }
                    else
                        reply.addVocab(nack);
                }
                else if (cmd=="flood3d")
                {
                    if (command.size()>=2)
                        spatial_distance=command.get(1).asDouble();

                    contour.clear();
                    floodPoints.clear();
                    flood=false;
                    flood3d=true;
                    reply.addVocab(ack);
                }
            }
        }
        else if (cmd=="flood")
        {
            if (command.size()>=2)
                color_distance=command.get(1).asInt();

            contour.clear();
            floodPoints.clear();
            flood=true;
            reply.addVocab(ack);
        }
        else
            RFModule::respond(command,reply);

        return true;
    }
开发者ID:giuliavezzani,项目名称:ipopt-works,代码行数:60,代码来源:3d-points.cpp

示例14: respond

    bool respond(const Bottle &command, Bottle &reply)
    {
	/* This method is called when a command string is sent via RPC */
    	reply.clear();  // Clear reply bottle

	/* Get command string */
	string receivedCmd = command.get(0).asString().c_str();
	int responseCode;   //Will contain Vocab-encoded response

	if (receivedCmd == "merge") {        
	    int ok = MergePointclouds();
	    if (ok>=0) { 
		    responseCode = Vocab::encode("ack");
	    } else {
	        fprintf(stdout,"Couldnt merge pointclouds. \n");
	        responseCode = Vocab::encode("nack");
	        return false;
	    }
	    reply.addVocab(responseCode);
            return true;

	} else if (receivedCmd == "save") {
	    saving = true;
	    responseCode = Vocab::encode("ack");
	    reply.addVocab(responseCode);
            return true;

	} else if (receivedCmd == "view") {
	    visualizing = true;
	    responseCode = Vocab::encode("ack");
	    reply.addVocab(responseCode);
            return true;

	}else if (receivedCmd == "help"){
		reply.addVocab(Vocab::encode("many"));		
		reply.addString("Available commands are:");
		reply.addString("merge - Merges all pointclouds on the path folder, or the new ones if 'cloud_merged' already exists.");
		reply.addString("view - Activates visualization. (XXX visualizer does not close). Default off");
		reply.addString("save - Activates saving the resulting merged point cloud.");
		//reply.addString("verbose ON/OFF - Sets active the printouts of the program, for debugging or visualization.");
		reply.addString("help - produces this help.");
		reply.addString("quit - closes the module.");
		
		responseCode = Vocab::encode("ack");
		reply.addVocab(responseCode);
		return true;

	} else if (receivedCmd == "quit") {
		responseCode = Vocab::encode("ack");
		reply.addVocab(responseCode);
		closing = true;
		return true;
        }
    reply.addString("Invalid command, type [help] for a list of accepted commands.");
    
    return true;	
    }
开发者ID:tanismar,项目名称:merge-point-clouds,代码行数:57,代码来源:merge_point_clouds.cpp

示例15: basicRespond

bool Module::basicRespond(const Bottle& command, Bottle& reply) {
    switch (command.get(0).asVocab()) {
    case VOCAB3('s','e','t'):
        state.put(command.get(1).toString(),command.get(2));
        reply.addVocab(Vocab::encode("ack"));
        return true;
        break;
    case VOCAB3('g','e','t'):
        reply.add(state.check(command.get(1).toString(),Value(0)));
        return true;
        break;
    case VOCAB4('q','u','i','t'):
    case VOCAB4('e','x','i','t'):
    case VOCAB3('b','y','e'):
        reply.addVocab(Vocab::encode("bye"));
        stopFlag = true;
        interruptModule();
        return true;
    default:
        reply.add("command not recognized");
        return false;
    }
    return false;
}
开发者ID:JoErNanO,项目名称:yarp,代码行数:24,代码来源:Module.cpp


注:本文中的Bottle::addVocab方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。