Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate *Vocab methods in favour of *Vocab32 #2650

Merged
merged 8 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/lua/tests/test_vocab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function test_vocab()
assert("number" == type(vocab))
assert(1684234849 == vocab)
assert("abcd" == yarp.decode(vocab))
vocab2 = yarp.createVocab('a','b','c','d')
vocab2 = yarp.createVocab32('a','b','c','d')
assert("number" == type(vocab2))
assert (vocab == vocab2)
end
Expand Down
30 changes: 30 additions & 0 deletions doc/release/master/vocab32_part2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
vocab32_part2 {#master}
-------------

## Libraries

### `os`

* `yarp::os::createVocab()` is deprecated in favour of `yarp::os::createVocab32()`
* `yarp::os::Vocab::encode()` is deprecated in favour of `yarp::os::Vocab32::encode()`
* `yarp::os::Vocab::decode()` is deprecated in favour of `yarp::os::Vocab32::decode()`
* `yarp::os::Value::isVocab()` is deprecated in favour of `yarp::os::Value::isVocab32()`
* `yarp::os::Value::asVocab()` is deprecated in favour of `yarp::os::Value::asVocab32()`
* `yarp::os::Value::makeVocab()` is deprecated in favour of `yarp::os::Value::makeVocab32()`
* `yarp::os::Bottle::addVocab()` is deprecated in favour of `yarp::os::Bottle::addVocab32()`
* `yarp::os::WireReader::getIsVocab()` is deprecated in favour of `yarp::os::WireReader::getIsVocab32()`


#### `Bottle`

* Added `addVocab32()` overloads accepting 4 chars and string


#### `Value`

* Added `makeVocab32()` overload accepting 4 chars


#### `idl/WireWriter`

* Add `addVocab32()` overloads accepting 4 chars and string
110 changes: 55 additions & 55 deletions example/dev/simple_motor_client/simple_motor_client.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/dll/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) {
SharedLibraryClassFactory<Hello> helloFactory2("hello","hello_there");
//SharedLibraryClassFactory<Hello> helloFactory2("hello","hello_there");
if (!helloFactory2.isValid()) {
printf("Library problem: (%s)\n", Vocab::decode(helloFactory2.getStatus()).c_str());
printf("Library problem: (%s)\n", Vocab32::decode(helloFactory2.getStatus()).c_str());
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion example/idl/thrift/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.12)
project(thrift_example)

find_package(YARP COMPONENTS os idl_tools REQUIRED)
set(CMAKE_CXX_FLAGS "-Weverything -Wno-c++98-compat -Wno-padded -Wno-shadow")
set(CMAKE_CXX_FLAGS "${YARP_CXX_FLAGS}")

set(THRIFT_FILES thrift/firstInterface/PointD.thrift
thrift/secondInterface/demo.thrift)
Expand Down
2 changes: 1 addition & 1 deletion example/idl/thrift/generated/src/PointD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ bool PointD::Editor::read(yarp::os::ConnectionReader& connection)
return true;
}
writer.writeListHeader(1);
writer.writeVocab(yarp::os::createVocab('o', 'k'));
writer.writeVocab32('o', 'k');
return true;
}

Expand Down
18 changes: 9 additions & 9 deletions example/idl/thrift/generated/src/PointDLists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ bool PointDLists::Editor::read(yarp::os::ConnectionReader& connection)
return true;
}
writer.writeListHeader(1);
writer.writeVocab(yarp::os::createVocab('o', 'k'));
writer.writeVocab32('o', 'k');
return true;
}

Expand Down Expand Up @@ -565,8 +565,8 @@ bool PointDLists::read_firstList(yarp::os::idl::WireReader& reader)
yarp::os::idl::WireState _etype3;
reader.readListBegin(_etype3, _size0);
firstList.resize(_size0);
for (auto& _elem4 : firstList) {
if (!reader.readNested(_elem4)) {
for (size_t _i4 = 0; _i4 < _size0; ++_i4) {
if (!reader.readNested(firstList[_i4])) {
reader.fail();
return false;
}
Expand Down Expand Up @@ -600,8 +600,8 @@ bool PointDLists::nested_read_firstList(yarp::os::idl::WireReader& reader)
yarp::os::idl::WireState _etype9;
reader.readListBegin(_etype9, _size6);
firstList.resize(_size6);
for (auto& _elem10 : firstList) {
if (!reader.readNested(_elem10)) {
for (size_t _i10 = 0; _i10 < _size6; ++_i10) {
if (!reader.readNested(firstList[_i10])) {
reader.fail();
return false;
}
Expand Down Expand Up @@ -635,8 +635,8 @@ bool PointDLists::read_secondList(yarp::os::idl::WireReader& reader)
yarp::os::idl::WireState _etype15;
reader.readListBegin(_etype15, _size12);
secondList.resize(_size12);
for (auto& _elem16 : secondList) {
if (!reader.readNested(_elem16)) {
for (size_t _i16 = 0; _i16 < _size12; ++_i16) {
if (!reader.readNested(secondList[_i16])) {
reader.fail();
return false;
}
Expand Down Expand Up @@ -670,8 +670,8 @@ bool PointDLists::nested_read_secondList(yarp::os::idl::WireReader& reader)
yarp::os::idl::WireState _etype21;
reader.readListBegin(_etype21, _size18);
secondList.resize(_size18);
for (auto& _elem22 : secondList) {
if (!reader.readNested(_elem22)) {
for (size_t _i22 = 0; _i22 < _size18; ++_i22) {
if (!reader.readNested(secondList[_i22])) {
reader.fail();
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion example/idl/thrift/generated/src/PointWithQuality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ bool PointWithQuality::Editor::read(yarp::os::ConnectionReader& connection)
return true;
}
writer.writeListHeader(1);
writer.writeVocab(yarp::os::createVocab('o', 'k'));
writer.writeVocab32('o', 'k');
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion example/os/browse_bottle/browse_bottle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void showBottle(Bottle& anUnknownBottle, int indentation = 0)
printf("binary blob of length %zd\n", element.asBlobLength());
break;
case BOTTLE_TAG_VOCAB32:
printf("vocab [%s]\n", yarp::os::Vocab::decode(element.asVocab()).c_str());
printf("vocab [%s]\n", yarp::os::Vocab32::decode(element.asVocab32()).c_str());
break;
default:
if (element.isList()) {
Expand Down
4 changes: 2 additions & 2 deletions example/os/database/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char* argv[])
tmp.add(cmd.get(1));
std::string key = tmp.toString();

switch (yarp::os::Vocab::encode(cmd.get(0).toString())) {
switch (cmd.get(0).asVocab32()) {
case VOCAB_SET:
state.put(key, cmd.get(2));
break;
Expand All @@ -72,7 +72,7 @@ int main(int argc, char* argv[])
break;
}
Value& v = state.find(key);
response.addVocab(v.isNull() ? VOCAB_NOT : VOCAB_IS);
response.addVocab32(v.isNull() ? VOCAB_NOT : VOCAB_IS);
response.add(cmd.get(1));
if (!v.isNull()) {
response.add(v);
Expand Down
20 changes: 10 additions & 10 deletions example/os/queue_manager/queue_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class QueueManager : public DeviceResponder

void addQueue(Bottle& status)
{
status.add(Value::makeVocab("q"));
status.addVocab32('q');
for (const auto& entry : q) {
std::string name = entry.name;
status.addString(name.c_str());
Expand Down Expand Up @@ -116,31 +116,31 @@ class QueueManager : public DeviceResponder
yarp::os::Bottle& reply) override
{
mutex.lock();
switch (command.get(0).asVocab()) {
case yarp::os::createVocab('a', 'd', 'd'): {
switch (command.get(0).asVocab32()) {
case yarp::os::createVocab32('a', 'd', 'd'): {
std::string name = command.get(1).asString();
if (!name.empty()) {
removeName(name.c_str());
Entry entry;
entry.name = name;
q.push_back(entry);
reply.clear();
reply.add(Value::makeVocab("add"));
reply.addVocab32("add");
reply.addString(name.c_str());
addQueue(reply);
}
} break;
case yarp::os::createVocab('d', 'e', 'l'): {
case yarp::os::createVocab32('d', 'e', 'l'): {
if (command.get(1).isInt32()) {
int idx = command.get(1).asInt32();
bool acted = removeName(idx);
if (acted) {
reply.clear();
reply.add(Value::makeVocab("del"));
reply.addVocab32("del");
reply.addInt32(idx);
} else {
reply.clear();
reply.add(Value::makeVocab("no"));
reply.addVocab32("no");
reply.addInt32(idx);
}
addQueue(reply);
Expand All @@ -150,18 +150,18 @@ class QueueManager : public DeviceResponder
bool acted = removeName(name.c_str());
if (acted) {
reply.clear();
reply.add(Value::makeVocab("del"));
reply.addVocab32("del");
reply.addString(name.c_str());
} else {
reply.clear();
reply.add(Value::makeVocab("no"));
reply.addVocab32("no");
reply.addString(name.c_str());
}
addQueue(reply);
}
}
} break;
case yarp::os::createVocab('l', 'i', 's', 't'): {
case yarp::os::createVocab32('l', 'i', 's', 't'): {
reply.clear();
addQueue(reply);
} break;
Expand Down
8 changes: 4 additions & 4 deletions example/remote_check/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class FakeFrameGrabber : public Thread, PortReader {
Bottle cmd, response;
cmd.read(connection);
printf("command received: %s\n", cmd.toString().c_str());
int code = cmd.get(0).asVocab();
int code = cmd.get(0).asVocab32();
switch (code) {
case yarp::os::createVocab('s','e','t'):
case yarp::os::createVocab32('s','e','t'):
printf("set command received\n");
prop.put(cmd.get(1).asString().c_str(),cmd.get(2));
break;
case yarp::os::createVocab('g','e','t'):
case yarp::os::createVocab32('g','e','t'):
printf("get command received\n");
response.addVocab(yarp::os::createVocab('i','s'));
response.addVocab32('i','s');
response.add(cmd.get(1));
response.add(prop.find(cmd.get(1).asString().c_str()));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void CollatzClient::run()
while (!isStopping())
{
out.clear();
out.addVocab(COLLATZ_VOCAB_REQ_ITEM);
out.addVocab32(COLLATZ_VOCAB_REQ_ITEM);
out.addInt32(replyField);

fprintf(stdout,"Requiring item: %s\n",out.toString().c_str());
Expand All @@ -86,7 +86,7 @@ void CollatzClient::run()

if (in.size()>0)
{
if (in.get(0).asVocab()==COLLATZ_VOCAB_ITEM)
if (in.get(0).asVocab32()==COLLATZ_VOCAB_ITEM)
{
// process the reply
const unsigned int num=(unsigned int)in.get(1).asInt32();
Expand Down
4 changes: 2 additions & 2 deletions example/stressTests/testcase-client-server/common/vocabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include <yarp/os/Vocab.h>

#define COLLATZ_VOCAB_REQ_ITEM yarp::os::createVocab('r','e','q')
#define COLLATZ_VOCAB_ITEM yarp::os::createVocab('i','t','e','m')
#define COLLATZ_VOCAB_REQ_ITEM yarp::os::createVocab32('r','e','q')
#define COLLATZ_VOCAB_ITEM yarp::os::createVocab32('i','t','e','m')

#define COLLATZ_EMPTY_FIELD 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void CollatzServer::run()
{
// fprintf(stdout,"Request received\n");
#if 0
if (in.get(0).asVocab()==COLLATZ_VOCAB_REQ_ITEM)
if (in.get(0).asVocab32()==COLLATZ_VOCAB_REQ_ITEM)
{
unsigned int num=in.get(1).asInt32();

Expand All @@ -91,7 +91,7 @@ void CollatzServer::run()
//generateItem(num,thres);

out.clear();
out.addVocab(COLLATZ_VOCAB_ITEM);
out.addVocab32(COLLATZ_VOCAB_ITEM);
out.addInt32((int)num);
out.addInt32((int)thres);

Expand Down
22 changes: 18 additions & 4 deletions example/yarpros_examples/src/waggler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@

#include <ros/ros.h>
#include <yarpros_examples/VocabVocabDoubles.h>
#include <stdio.h>
#include <cstdio>
#include <cstdint>

// A few YARP defines
#define BOTTLE_TAG_INT32 1
#define BOTTLE_TAG_VOCAB32 (1+8)
#define BOTTLE_TAG_FLOAT64 (2+8)
#define BOTTLE_TAG_LIST 256
#define yarp::os::createVocab(a,b,c,d) ((((int)(d))<<24)+(((int)(c))<<16)+(((int)(b))<<8)+((int)(a)))
namespace yarp {
namespace conf {
using vocab32_t = std::int32_t;
} // namespace conf
namespace os {
constexpr yarp::conf::vocab32_t createVocab32(char a, char b = 0, char c = 0, char d = 0)
{
return (static_cast<yarp::conf::vocab32_t>(a)) +
(static_cast<yarp::conf::vocab32_t>(b) << 8) +
(static_cast<yarp::conf::vocab32_t>(c) << 16) +
(static_cast<yarp::conf::vocab32_t>(d) << 24);
}
} // namespace os
} // namespace yarp
// YARP defines over

int main(int argc, char** argv) {
Expand All @@ -38,9 +52,9 @@ int main(int argc, char** argv) {
msg.list_tag = BOTTLE_TAG_LIST;
msg.list_len = 3;
msg.vocab1_tag = BOTTLE_TAG_VOCAB32;
msg.vocab1_val = yarp::os::createVocab('s','e','t',0);
msg.vocab1_val = yarp::os::createVocab32('s','e','t',0);
msg.vocab2_tag = BOTTLE_TAG_VOCAB32;
msg.vocab2_val = yarp::os::createVocab('p','o','s','s');
msg.vocab2_val = yarp::os::createVocab32('p','o','s','s');
msg.setpoints_tag = BOTTLE_TAG_LIST+BOTTLE_TAG_FLOAT64;
msg.setpoints.resize(joint_count);
for (int i=0; i<joint_count; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/carriers/tcpros_carrier/yarpros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ string showFormat(Bottle& b, string root) {
char val_name[1000];
sprintf(tag_name,"%s%zu_tag", root.c_str(), i);
sprintf(val_name,"%s%zu", root.c_str(), i);
if (v.isVocab()) {
if (v.isVocab32()) {
if (!specialized) {
r += addPart("int32",tag_name,BOTTLE_TAG_VOCAB32,nullptr,
"BOTTLE_TAG_VOCAB32");
Expand Down Expand Up @@ -430,7 +430,7 @@ int main(int argc, char *argv[]) {
Bottle b;
p.read(b);
string r;
if (in&&b.get(0).asVocab()==yarp::os::createVocab('r','p','c')&&b.get(1).isList()) {
if (in&&b.get(0).asVocab32()==yarp::os::createVocab32('r','p','c')&&b.get(1).isList()) {

r = showFormat(*b.get(1).asList(),"v");
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/carriers/xmlrpc_carrier/XmlRpcCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void toXmlRpcValue(Value& vin, XmlRpcValue& vout)
vout = vin.asFloat64();
} else if (vin.isString()) {
vout = std::string(vin.asString());
} else if (vin.isVocab()) {
} else if (vin.isVocab32()) {
vout = std::string("[") + std::string(vin.toString()) + "]";
} else if (vin.isList()) {
Bottle *bot = vin.asList();
Expand Down
Loading