本文整理汇总了C++中yarp::os::Bottle类的典型用法代码示例。如果您正苦于以下问题:C++ Bottle类的具体用法?C++ Bottle怎么用?C++ Bottle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bottle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertList
/*! @brief Convert a YARP list into a %JavaScript object.
@param[in] jct The %JavaScript engine context.
@param[in,out] theData The output object.
@param[in] inputValue The value to be processed. */
static void
convertList(JSContext * jct,
JS::MutableHandleValue theData,
const yarp::os::Bottle & inputValue)
{
ODL_ENTER(); //####
ODL_P2("jct = ", jct, "inputValue = ", &inputValue); //####
JSObject * valueArray = JS_NewArrayObject(jct, 0);
if (valueArray)
{
JS::RootedObject arrayRooted(jct);
JS::RootedValue anElement(jct);
JS::RootedId aRootedId(jct);
arrayRooted = valueArray;
for (int ii = 0, mm = inputValue.size(); mm > ii; ++ii)
{
yarp::os::Value aValue(inputValue.get(ii));
convertValue(jct, &anElement, aValue);
if (JS_IndexToId(jct, ii, &aRootedId))
{
JS_SetPropertyById(jct, arrayRooted, aRootedId, anElement);
}
}
theData.setObject(*valueArray);
}
ODL_EXIT(); //####
} // convertList
示例2: defined
bool
RandomRequestHandler::processRequest(const YarpString & request,
const yarp::os::Bottle & restOfInput,
const YarpString & senderChannel,
yarp::os::ConnectionWriter * replyMechanism)
{
#if (! defined(ODL_ENABLE_LOGGING_))
# if MAC_OR_LINUX_
# pragma unused(request,senderChannel)
# endif // MAC_OR_LINUX_
#endif // ! defined(ODL_ENABLE_LOGGING_)
ODL_OBJENTER(); //####
ODL_S3s("request = ", request, "restOfInput = ", restOfInput.toString(), //####
"senderChannel = ", senderChannel); //####
ODL_P1("replyMechanism = ", replyMechanism); //####
bool result = true;
try
{
int count;
_response.clear();
if (0 < restOfInput.size())
{
yarp::os::Value number(restOfInput.get(0));
if (number.isInt())
{
count = number.asInt();
}
else
{
count = -1;
}
}
else
{
count = 1;
}
if (count > 0)
{
for (int ii = 0; ii < count; ++ii)
{
_response.addDouble(yarp::os::Random::uniform());
}
}
else
{
ODL_LOG("! (count > 0)"); //####
}
sendResponse(replyMechanism);
}
catch (...)
{
ODL_LOG("Exception caught"); //####
throw;
}
ODL_OBJEXIT_B(result); //####
return result;
} // RandomRequestHandler::processRequest
示例3: encode
void GaussianAE::encode(yarp::os::Bottle &b) const
{
LabelledAE::encode(b);
b.addInt32(_gaei[0]);
b.addInt32(_gaei[1]);
b.addInt32(_gaei[2]);
}
示例4: parse_respond_string
/**
* Parser for string commands. It is called by virtual bool respond().
* @param command the bottle containing the user command
* @param reply the bottle which will be returned to the RPC client
* @return true if the command was successfully parsed
*/
bool parse_respond_string(const yarp::os::Bottle& command, yarp::os::Bottle& reply)
{
if (command.get(0).isString() && command.get(0).asString() == "getLoc")
{
std::string s = std::string("Current Location is: ") + m_localization_data.toString();
reply.addString(s);
}
else if (command.get(0).isString() && command.get(0).asString() == "initLoc")
{
yarp::dev::Map2DLocation loc;
loc.map_id = command.get(1).asString();
loc.x = command.get(2).asDouble();
loc.y = command.get(3).asDouble();
loc.theta = command.get(4).asDouble();
initializeLocalization(loc);
std::string s = std::string("Localization initialized to: ") + loc.toString();
reply.addString(s);
}
else
{
reply.addString("Unknown command.");
}
return true;
}
示例5: parse_respond_vocab
/**
* Parser for VOCAB commands. It is called by virtual bool respond().
* @param command the bottle containing the user command
* @param reply the bottle which will be returned to the RPC client
* @return true if the command was successfully parsed
*/
bool parse_respond_vocab(const yarp::os::Bottle& command, yarp::os::Bottle& reply)
{
int request = command.get(1).asVocab();
if (request == VOCAB_NAV_GET_CURRENT_POS)
{
//plannerThread->setNewAbsTarget(loc);
reply.addVocab(VOCAB_OK);
reply.addString(m_localization_data.map_id);
reply.addDouble(m_localization_data.x);
reply.addDouble(m_localization_data.y);
reply.addDouble(m_localization_data.theta);
}
else if (request == VOCAB_NAV_SET_INITIAL_POS)
{
yarp::dev::Map2DLocation loc;
loc.map_id = command.get(2).asString();
loc.x = command.get(3).asDouble();
loc.y = command.get(4).asDouble();
loc.theta = command.get(5).asDouble();
initializeLocalization(loc);
reply.addVocab(VOCAB_OK);
}
else
{
reply.addVocab(VOCAB_ERR);
}
return true;
}
示例6: worked
bool yarp::dev::ServerInertial::getInertial(yarp::os::Bottle &bot)
{
if (IMU==NULL)
{
return false;
}
else
{
int nchannels;
IMU->getChannels (&nchannels);
yarp::sig::Vector indata(nchannels);
bool worked(false);
worked=IMU->read(indata);
if (worked)
{
bot.clear();
// Euler+accel+gyro+magn orientation values
for (int i = 0; i < nchannels; i++)
bot.addDouble (indata[i]);
}
else
{
bot.clear(); //dummy info.
}
return(worked);
}
}
示例7: listSubscriptions
bool SubscriberOnSql::listSubscriptions(const ConstString& port,
yarp::os::Bottle& reply) {
mutex.wait();
sqlite3_stmt *statement = NULL;
char *query = NULL;
if (ConstString(port)!="") {
query = sqlite3_mprintf("SELECT s.srcFull, s.DestFull, EXISTS(SELECT topic FROM topics WHERE topic = s.src), EXISTS(SELECT topic FROM topics WHERE topic = s.dest), s.mode FROM subscriptions s WHERE s.src = %Q OR s.dest= %Q ORDER BY s.src, s.dest",port.c_str(),port.c_str());
} else {
query = sqlite3_mprintf("SELECT s.srcFull, s.destFull, EXISTS(SELECT topic FROM topics WHERE topic = s.src), EXISTS(SELECT topic FROM topics WHERE topic = s.dest), s.mode FROM subscriptions s ORDER BY s.src, s.dest");
}
if (verbose) {
printf("Query: %s\n", query);
}
int result = sqlite3_prepare_v2(SQLDB(implementation),query,-1,&statement,
NULL);
if (result!=SQLITE_OK) {
const char *msg = sqlite3_errmsg(SQLDB(implementation));
if (msg!=NULL) {
fprintf(stderr,"Error: %s\n", msg);
}
}
reply.addString("subscriptions");
while (result == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) {
char *src = (char *)sqlite3_column_text(statement,0);
char *dest = (char *)sqlite3_column_text(statement,1);
int srcTopic = sqlite3_column_int(statement,2);
int destTopic = sqlite3_column_int(statement,3);
char *mode = (char *)sqlite3_column_text(statement,4);
Bottle& b = reply.addList();
b.addString("subscription");
Bottle bsrc;
bsrc.addString("src");
bsrc.addString(src);
Bottle bdest;
bdest.addString("dest");
bdest.addString(dest);
b.addList() = bsrc;
b.addList() = bdest;
if (mode!=NULL) {
if (mode[0]!='\0') {
Bottle bmode;
bmode.addString("mode");
bmode.addString(mode);
b.addList() = bmode;
}
}
if (srcTopic||destTopic) {
Bottle btopic;
btopic.addString("topic");
btopic.addInt(srcTopic);
btopic.addInt(destTopic);
b.addList() = btopic;
}
}
sqlite3_finalize(statement);
sqlite3_free(query);
mutex.post();
return true;
}
示例8: bottleToVector
bool skinManager::bottleToVector(const yarp::os::Bottle& b, yarp::sig::Vector& v){
for(int i=0; i<b.size(); i++)
if(b.get(i).isDouble() || b.get(i).isInt())
v.push_back(b.get(i).asDouble());
else
return false;
return true;
}
示例9:
void wysiwyd::wrdac::SubSystem_Reactable::SendOSC(yarp::os::Bottle &oscMsg)
{
yarp::os::Bottle cmd;
cmd.addString("osc");
for(int i=0; i<oscMsg.size(); i++)
cmd.add(oscMsg.get(i));
std::cout<<"OSC>>"<<cmd.toString().c_str()<<std::endl;
portRTrpc.write(cmd);
}
示例10: respClass
void WorldRpcInterface::respClass( const yarp::os::Bottle& command, yarp::os::Bottle& reply, int& n )
{
KinematicModel::CompositeObject* object = getObject( command, reply, n );
if ( object )
{
//model->clearWorldObject(object);
model->removeWorldObject(object);
int type = command.get(n).asVocab();
QColor collidingColor,freeColor;
switch (type)
{
case VOCAB_OBSTACLE:
freeColor = Qt::blue;
freeColor = freeColor.lighter();
collidingColor = freeColor;
freeColor.setAlphaF(0.5);
collidingColor.setAlphaF(0.5);
object->setResponseClass(model->OBSTACLE());
object->setFreeColor( freeColor );
object->setCollidingColor( collidingColor );
reply.addString("Changed object type to 'obstacle'.");
break;
case VOCAB_TARGET:
freeColor = Qt::green;
freeColor = freeColor.lighter();
collidingColor = freeColor;
freeColor.setAlphaF(1.0);
collidingColor.setAlphaF(0.5);
object->setResponseClass(model->TARGET());
object->setFreeColor( freeColor );
object->setCollidingColor( collidingColor );
reply.addString("Changed object type to 'target'.");
break;
default:
reply.addString("Unknown definition, use 'obs' or 'tgt'.");
}
model->appendObject( object );
}
}
示例11: onRead
void YarpManager::onRead(yarp::os::Bottle& b) {
std::string name = b.get(0).asString().c_str();
int value = b.get(1).asInt();
if(name == "acuity") setAcuity(value);
else if(name == "fov") setFov(value);
else if(name == "brightness") setBrightness(value);
else if(name == "threshold") setTreshold(value);
else std::cout<<"Bottle message incorrect"<<std::endl;
}
示例12: findFileBase
void findFileBase(Property& config, const char *name,
bool isDir,
Bottle& output, bool justTop) {
ConstString cap =
config.check("capability_directory",Value("app")).asString();
Bottle defCaps =
config.findGroup("default_capability").tail();
// check current directory
if (ConstString(name)==""&&isDir) {
output.addString(getPwd());
if (justTop) return;
}
ConstString str = check(getPwd(),"","",name,isDir);
if (str!="") {
output.addString(str);
if (justTop) return;
}
if (configFilePath!="") {
ConstString str = check(configFilePath.c_str(),"","",name,isDir);
if (str!="") {
output.addString(str);
if (justTop) return;
}
}
// check app dirs
for (int i=0; i<apps.size(); i++) {
str = check(root.c_str(),cap,apps.get(i).asString().c_str(),
name,isDir);
if (str!="") {
output.addString(str);
if (justTop) return;
}
}
// check ROOT/app/default/
for (int i=0; i<defCaps.size(); i++) {
str = check(root.c_str(),cap,defCaps.get(i).asString().c_str(),
name,isDir);
if (str!="") {
output.addString(str);
if (justTop) return;
}
}
if (justTop) {
if (!quiet) {
fprintf(RTARGET,"||| did not find %s\n", name);
}
}
}
示例13: cmdQuery
virtual bool cmdQuery(yarp::os::Bottle& cmd,
yarp::os::Bottle& reply,
yarp::os::Contact& remote) {
reply.addString("old");
ConstString name = cmd.get(1).asString();
Contact c = Network::queryName(name);
if (c.isValid()) {
appendEntry(reply,c);
}
return true;
}
示例14: merge
int merge(yarp::os::Bottle& mergeArg, folderType fType, bool verbose)
{
ConstString contextName;
if (mergeArg.size() >1 )
contextName=mergeArg.get(1).asString().c_str();
if (contextName=="")
{
printf("No %s name provided\n", fType==CONTEXTS ? "context" : "robot");
return 0;
}
yarp::os::ResourceFinder rf;
rf.setVerbose(verbose);
if (mergeArg.size() >2 )
{
for (int i=2; i<mergeArg.size(); ++i)
{
ConstString fileName=mergeArg.get(i).asString();
if(fileName != "")
{
ResourceFinderOptions opts;
opts.searchLocations=ResourceFinderOptions::User;
ConstString userFileName=rf.findPath((getFolderStringName(fType) + PATH_SEPARATOR +contextName + PATH_SEPARATOR + fileName).c_str(), opts);
ConstString hiddenFileName=rf.findPath((getFolderStringNameHidden(fType) + PATH_SEPARATOR +contextName+ PATH_SEPARATOR + fileName).c_str(), opts);
opts.searchLocations=ResourceFinderOptions::Installed;
ConstString installedFileName=rf.findPath((getFolderStringName(fType) + PATH_SEPARATOR +contextName+ PATH_SEPARATOR + fileName).c_str(), opts);
if (userFileName!="" && hiddenFileName != "" && installedFileName !="")
fileMerge(installedFileName, userFileName, hiddenFileName);
else if (userFileName!="" && installedFileName !="")
printf("Need to use mergetool\n");
else
printf("Could not merge file %s\n", fileName.c_str());
}
}
}
else
{
ResourceFinderOptions opts;
opts.searchLocations=ResourceFinderOptions::User;
ConstString userPath=rf.findPath((getFolderStringName(fType) + PATH_SEPARATOR +contextName).c_str(), opts);
ConstString hiddenUserPath=rf.findPath((getFolderStringNameHidden(fType) + PATH_SEPARATOR +contextName).c_str(), opts);
opts.searchLocations=ResourceFinderOptions::Installed;
ConstString installedPath=rf.findPath((getFolderStringName(fType) + PATH_SEPARATOR +contextName).c_str(), opts);
recursiveMerge(installedPath, userPath, hiddenUserPath);
}
return 0;
}
示例15: defined
bool
TruncateFloatFilterInputHandler::handleInput(const yarp::os::Bottle & input,
const YarpString & senderChannel,
yarp::os::ConnectionWriter * replyMechanism,
const size_t numBytes)
{
#if (! defined(ODL_ENABLE_LOGGING_))
# if MAC_OR_LINUX_
# pragma unused(senderChannel,replyMechanism,numBytes)
# endif // MAC_OR_LINUX_
#endif // ! defined(ODL_ENABLE_LOGGING_)
ODL_OBJENTER(); //####
ODL_S2s("senderChannel = ", senderChannel, "got ", input.toString()); //####
ODL_P1("replyMechanism = ", replyMechanism); //####
ODL_I1("numBytes = ", numBytes); //####
bool result = true;
try
{
yarp::os::Bottle outBottle;
for (int ii = 0, mm = input.size(); mm > ii; ++ii)
{
yarp::os::Value aValue(input.get(ii));
if (aValue.isInt())
{
outBottle.addInt(aValue.asInt());
}
else if (aValue.isDouble())
{
outBottle.addInt(static_cast<int>(aValue.asDouble()));
}
}
if ((0 < outBottle.size()) && _outChannel)
{
if (! _outChannel->write(outBottle))
{
ODL_LOG("(! _outChannel->write(message))"); //####
#if defined(MpM_StallOnSendProblem)
Stall();
#endif // defined(MpM_StallOnSendProblem)
}
}
}
catch (...)
{
ODL_LOG("Exception caught"); //####
throw;
}
ODL_OBJEXIT_B(result); //####
return result;
} // TruncateFloatFilterInputHandler::handleInput