diff --git a/doc/release/master.md b/doc/release/master.md index ebf9850dc11..7e6da714903 100644 --- a/doc/release/master.md +++ b/doc/release/master.md @@ -35,3 +35,12 @@ New Features * added new datatype `yarp::sig::LayeredImage` * added `yarp::sig::utils::sum()` to transform `yarp::sig::LayeredImage` to `yarp::sig::Image` + +#### `libYARP_dev` + +* added new class `yarp::dev::ReturnValue` +* modified interfaces `yarp::dev::ISpeechSynthesizer`,`yarp::dev::ISpeechTranscription` to use the new class ReturnValue. + +#### `devices` + +* modified devices implementing `yarp::dev::ISpeechSynthesizer`,`yarp::dev::ISpeechTranscription` to use the new class ReturnValue. diff --git a/src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.cpp b/src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.cpp index 015467b2a83..6470545660f 100644 --- a/src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.cpp +++ b/src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.cpp @@ -40,67 +40,67 @@ bool FakeSpeechSynthesizer::close() return true; } -bool FakeSpeechSynthesizer::setLanguage(const std::string& language) +ReturnValue FakeSpeechSynthesizer::setLanguage(const std::string& language) { m_language=language; yCInfo(FAKE_SPEECHSYN) << "Language set to" << language; - return true; + return ReturnValue_ok; } -bool FakeSpeechSynthesizer::getLanguage(std::string& language) +ReturnValue FakeSpeechSynthesizer::getLanguage(std::string& language) { language = m_language; - return true; + return ReturnValue_ok; } -bool FakeSpeechSynthesizer::setVoice(const std::string& voice) +ReturnValue FakeSpeechSynthesizer::setVoice(const std::string& voice) { m_voice = voice; yCInfo(FAKE_SPEECHSYN) << "Voice set to" << voice; - return true; + return ReturnValue_ok; } -bool FakeSpeechSynthesizer::getVoice(std::string& voice) +ReturnValue FakeSpeechSynthesizer::getVoice(std::string& voice) { voice = m_voice; - return true; + return ReturnValue_ok; } -bool FakeSpeechSynthesizer::setSpeed(const double speed) +ReturnValue FakeSpeechSynthesizer::setSpeed(const double speed) { m_speed = speed; yCInfo(FAKE_SPEECHSYN) << "Speed set to" << speed; - return true; + return ReturnValue_ok; } -bool FakeSpeechSynthesizer::getSpeed(double& speed) +ReturnValue FakeSpeechSynthesizer::getSpeed(double& speed) { speed = m_speed; - return true; + return ReturnValue_ok; } -bool FakeSpeechSynthesizer::setPitch(const double pitch) +ReturnValue FakeSpeechSynthesizer::setPitch(const double pitch) { m_pitch = pitch; yCInfo(FAKE_SPEECHSYN) << "Pitch set to" << pitch; - return true; + return ReturnValue_ok; } -bool FakeSpeechSynthesizer::getPitch(double& pitch) +ReturnValue FakeSpeechSynthesizer::getPitch(double& pitch) { pitch = m_pitch; - return true; + return ReturnValue_ok; } -bool FakeSpeechSynthesizer::synthesize(const std::string& text, yarp::sig::Sound& sound) +ReturnValue FakeSpeechSynthesizer::synthesize(const std::string& text, yarp::sig::Sound& sound) { if (text == "") { yCError(FAKE_SPEECHSYN) << "Text is empty"; - return false; + return ReturnValue::return_code::return_value_error_method_failed; } sound.resize(100,2); - return true; + return ReturnValue_ok; } diff --git a/src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.h b/src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.h index c834c175526..e62c9611c62 100644 --- a/src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.h +++ b/src/devices/fake/fakeSpeechSynthesizer/FakeSpeechSynthesizer.h @@ -41,15 +41,15 @@ class FakeSpeechSynthesizer : bool open(yarp::os::Searchable& config) override; bool close() override; - virtual bool setLanguage(const std::string& language) override; - virtual bool getLanguage(std::string& language) override; - virtual bool setVoice(const std::string& voice) override; - virtual bool getVoice(std::string& voice) override; - virtual bool setSpeed(const double speed) override; - virtual bool getSpeed(double& voice) override; - virtual bool setPitch(const double pitch) override; - virtual bool getPitch(double& voice) override; - virtual bool synthesize(const std::string& text, yarp::sig::Sound& sound) override; + virtual yarp::dev::ReturnValue setLanguage(const std::string& language) override; + virtual yarp::dev::ReturnValue getLanguage(std::string& language) override; + virtual yarp::dev::ReturnValue setVoice(const std::string& voice) override; + virtual yarp::dev::ReturnValue getVoice(std::string& voice) override; + virtual yarp::dev::ReturnValue setSpeed(const double speed) override; + virtual yarp::dev::ReturnValue getSpeed(double& voice) override; + virtual yarp::dev::ReturnValue setPitch(const double pitch) override; + virtual yarp::dev::ReturnValue getPitch(double& voice) override; + virtual yarp::dev::ReturnValue synthesize(const std::string& text, yarp::sig::Sound& sound) override; }; #endif diff --git a/src/devices/fake/fakeSpeechTranscription/FakeSpeechTranscription.cpp b/src/devices/fake/fakeSpeechTranscription/FakeSpeechTranscription.cpp index c4ad43b87ba..b207d264fef 100644 --- a/src/devices/fake/fakeSpeechTranscription/FakeSpeechTranscription.cpp +++ b/src/devices/fake/fakeSpeechTranscription/FakeSpeechTranscription.cpp @@ -40,20 +40,20 @@ bool FakeSpeechTranscription::close() return true; } -bool FakeSpeechTranscription::setLanguage(const std::string& language) +yarp::dev::ReturnValue FakeSpeechTranscription::setLanguage(const std::string& language) { m_language=language; yCInfo(FAKE_SPEECHTR) << "Language set to" << language; - return true; + return ReturnValue_ok; } -bool FakeSpeechTranscription::getLanguage(std::string& language) +yarp::dev::ReturnValue FakeSpeechTranscription::getLanguage(std::string& language) { language = m_language; - return true; + return ReturnValue_ok; } -bool FakeSpeechTranscription::transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) +yarp::dev::ReturnValue FakeSpeechTranscription::transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) { if (sound.getSamples() == 0 || sound.getChannels() == 0) @@ -61,10 +61,10 @@ bool FakeSpeechTranscription::transcribe(const yarp::sig::Sound& sound, std::str yCError(FAKE_SPEECHTR) << "Invalid Sound sample received"; transcription = ""; score = 0.0; - return false; + return ReturnValue::return_code::return_value_error_method_failed; } transcription = "hello world"; score = 1.0; - return true; + return ReturnValue_ok; } diff --git a/src/devices/fake/fakeSpeechTranscription/FakeSpeechTranscription.h b/src/devices/fake/fakeSpeechTranscription/FakeSpeechTranscription.h index 561fcd4400f..1d30a24ee87 100644 --- a/src/devices/fake/fakeSpeechTranscription/FakeSpeechTranscription.h +++ b/src/devices/fake/fakeSpeechTranscription/FakeSpeechTranscription.h @@ -41,9 +41,9 @@ class FakeSpeechTranscription : bool open(yarp::os::Searchable& config) override; bool close() override; - virtual bool setLanguage(const std::string& language) override; - virtual bool getLanguage(std::string& language) override; - virtual bool transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) override; + virtual yarp::dev::ReturnValue setLanguage(const std::string& language) override; + virtual yarp::dev::ReturnValue getLanguage(std::string& language) override; + virtual yarp::dev::ReturnValue transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) override; }; #endif diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/ISpeechSynthesizerMsgs.thrift b/src/devices/messages/ISpeechSynthesizerMsgs/ISpeechSynthesizerMsgs.thrift index f075a65470d..b293f3e9a10 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/ISpeechSynthesizerMsgs.thrift +++ b/src/devices/messages/ISpeechSynthesizerMsgs/ISpeechSynthesizerMsgs.thrift @@ -9,40 +9,62 @@ struct yarp_sig_Sound { yarp.includefile = "yarp/sig/Sound.h" ) +struct yReturnValue { +} ( + yarp.name = "yarp::dev::ReturnValue" + yarp.includefile = "yarp/dev/ReturnValue.h" +) + +struct return_set_language { + 1: yReturnValue ret; +} + +struct return_set_voice { + 1: yReturnValue ret; +} + +struct return_set_speed { + 1: yReturnValue ret; +} + +struct return_set_pitch { + 1: yReturnValue ret; +} + struct return_get_language { - 1: bool ret = false; + 1: yReturnValue ret; 2: string language; } struct return_get_voice { - 1: bool ret = false; + 1: yReturnValue ret; 2: string voice; } struct return_get_speed { - 1: bool ret = false; + 1: yReturnValue ret; 2: double speed; } struct return_get_pitch { - 1: bool ret = false; + 1: yReturnValue ret; 2: double pitch; } struct return_synthesize { - 1: bool ret = false; + 1: yReturnValue ret; 2: yarp_sig_Sound sound; } service ISpeechSynthesizerMsgs { - bool set_language (1:string language); + return_set_language set_language (1:string language); return_get_language get_language (); - bool set_voice (1:string language); + return_set_voice set_voice (1:string language); return_get_voice get_voice (); - bool set_speed (1:double speed); + return_set_speed set_speed (1:double speed); return_get_speed get_speed (); - bool set_pitch (1:double pitch); + return_set_pitch set_pitch (1:double pitch); return_get_pitch get_pitch (); return_synthesize synthesize (1:string text); } diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs.cpp index 609195838fd..2c2e3f80e84 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs.cpp +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs.cpp @@ -60,10 +60,10 @@ class ISpeechSynthesizerMsgs_set_language_helper : bool write(const yarp::os::idl::WireWriter& writer) const override; bool read(yarp::os::idl::WireReader& reader) override; - bool return_helper{false}; + return_set_language return_helper{}; }; - using funcptr_t = bool (*)(const std::string&); + using funcptr_t = return_set_language (*)(const std::string&); void call(ISpeechSynthesizerMsgs* ptr); Command cmd; @@ -73,7 +73,7 @@ class ISpeechSynthesizerMsgs_set_language_helper : static constexpr size_t s_tag_len{2}; static constexpr size_t s_cmd_len{3}; static constexpr size_t s_reply_len{1}; - static constexpr const char* s_prototype{"bool ISpeechSynthesizerMsgs::set_language(const std::string& language)"}; + static constexpr const char* s_prototype{"return_set_language ISpeechSynthesizerMsgs::set_language(const std::string& language)"}; static constexpr const char* s_help{""}; }; @@ -181,10 +181,10 @@ class ISpeechSynthesizerMsgs_set_voice_helper : bool write(const yarp::os::idl::WireWriter& writer) const override; bool read(yarp::os::idl::WireReader& reader) override; - bool return_helper{false}; + return_set_voice return_helper{}; }; - using funcptr_t = bool (*)(const std::string&); + using funcptr_t = return_set_voice (*)(const std::string&); void call(ISpeechSynthesizerMsgs* ptr); Command cmd; @@ -194,7 +194,7 @@ class ISpeechSynthesizerMsgs_set_voice_helper : static constexpr size_t s_tag_len{2}; static constexpr size_t s_cmd_len{3}; static constexpr size_t s_reply_len{1}; - static constexpr const char* s_prototype{"bool ISpeechSynthesizerMsgs::set_voice(const std::string& language)"}; + static constexpr const char* s_prototype{"return_set_voice ISpeechSynthesizerMsgs::set_voice(const std::string& language)"}; static constexpr const char* s_help{""}; }; @@ -302,10 +302,10 @@ class ISpeechSynthesizerMsgs_set_speed_helper : bool write(const yarp::os::idl::WireWriter& writer) const override; bool read(yarp::os::idl::WireReader& reader) override; - bool return_helper{false}; + return_set_speed return_helper{}; }; - using funcptr_t = bool (*)(const double); + using funcptr_t = return_set_speed (*)(const double); void call(ISpeechSynthesizerMsgs* ptr); Command cmd; @@ -315,7 +315,7 @@ class ISpeechSynthesizerMsgs_set_speed_helper : static constexpr size_t s_tag_len{2}; static constexpr size_t s_cmd_len{3}; static constexpr size_t s_reply_len{1}; - static constexpr const char* s_prototype{"bool ISpeechSynthesizerMsgs::set_speed(const double speed)"}; + static constexpr const char* s_prototype{"return_set_speed ISpeechSynthesizerMsgs::set_speed(const double speed)"}; static constexpr const char* s_help{""}; }; @@ -423,10 +423,10 @@ class ISpeechSynthesizerMsgs_set_pitch_helper : bool write(const yarp::os::idl::WireWriter& writer) const override; bool read(yarp::os::idl::WireReader& reader) override; - bool return_helper{false}; + return_set_pitch return_helper{}; }; - using funcptr_t = bool (*)(const double); + using funcptr_t = return_set_pitch (*)(const double); void call(ISpeechSynthesizerMsgs* ptr); Command cmd; @@ -436,7 +436,7 @@ class ISpeechSynthesizerMsgs_set_pitch_helper : static constexpr size_t s_tag_len{2}; static constexpr size_t s_cmd_len{3}; static constexpr size_t s_reply_len{1}; - static constexpr const char* s_prototype{"bool ISpeechSynthesizerMsgs::set_pitch(const double pitch)"}; + static constexpr const char* s_prototype{"return_set_pitch ISpeechSynthesizerMsgs::set_pitch(const double pitch)"}; static constexpr const char* s_help{""}; }; @@ -687,7 +687,7 @@ bool ISpeechSynthesizerMsgs_set_language_helper::Reply::write(const yarp::os::id if (!writer.writeListHeader(s_reply_len)) { return false; } - if (!writer.writeBool(return_helper)) { + if (!writer.write(return_helper)) { return false; } } @@ -703,7 +703,7 @@ bool ISpeechSynthesizerMsgs_set_language_helper::Reply::read(yarp::os::idl::Wire reader.fail(); return false; } - if (!reader.readBool(return_helper)) { + if (!reader.read(return_helper)) { reader.fail(); return false; } @@ -974,7 +974,7 @@ bool ISpeechSynthesizerMsgs_set_voice_helper::Reply::write(const yarp::os::idl:: if (!writer.writeListHeader(s_reply_len)) { return false; } - if (!writer.writeBool(return_helper)) { + if (!writer.write(return_helper)) { return false; } } @@ -990,7 +990,7 @@ bool ISpeechSynthesizerMsgs_set_voice_helper::Reply::read(yarp::os::idl::WireRea reader.fail(); return false; } - if (!reader.readBool(return_helper)) { + if (!reader.read(return_helper)) { reader.fail(); return false; } @@ -1261,7 +1261,7 @@ bool ISpeechSynthesizerMsgs_set_speed_helper::Reply::write(const yarp::os::idl:: if (!writer.writeListHeader(s_reply_len)) { return false; } - if (!writer.writeBool(return_helper)) { + if (!writer.write(return_helper)) { return false; } } @@ -1277,7 +1277,7 @@ bool ISpeechSynthesizerMsgs_set_speed_helper::Reply::read(yarp::os::idl::WireRea reader.fail(); return false; } - if (!reader.readBool(return_helper)) { + if (!reader.read(return_helper)) { reader.fail(); return false; } @@ -1548,7 +1548,7 @@ bool ISpeechSynthesizerMsgs_set_pitch_helper::Reply::write(const yarp::os::idl:: if (!writer.writeListHeader(s_reply_len)) { return false; } - if (!writer.writeBool(return_helper)) { + if (!writer.write(return_helper)) { return false; } } @@ -1564,7 +1564,7 @@ bool ISpeechSynthesizerMsgs_set_pitch_helper::Reply::read(yarp::os::idl::WireRea reader.fail(); return false; } - if (!reader.readBool(return_helper)) { + if (!reader.read(return_helper)) { reader.fail(); return false; } @@ -1869,14 +1869,14 @@ ISpeechSynthesizerMsgs::ISpeechSynthesizerMsgs() yarp().setOwner(*this); } -bool ISpeechSynthesizerMsgs::set_language(const std::string& language) +return_set_language ISpeechSynthesizerMsgs::set_language(const std::string& language) { if (!yarp().canWrite()) { yError("Missing server method '%s'?", ISpeechSynthesizerMsgs_set_language_helper::s_prototype); } ISpeechSynthesizerMsgs_set_language_helper helper{language}; bool ok = yarp().write(helper, helper); - return ok ? helper.reply.return_helper : bool{}; + return ok ? helper.reply.return_helper : return_set_language{}; } return_get_language ISpeechSynthesizerMsgs::get_language() @@ -1889,14 +1889,14 @@ return_get_language ISpeechSynthesizerMsgs::get_language() return ok ? helper.reply.return_helper : return_get_language{}; } -bool ISpeechSynthesizerMsgs::set_voice(const std::string& language) +return_set_voice ISpeechSynthesizerMsgs::set_voice(const std::string& language) { if (!yarp().canWrite()) { yError("Missing server method '%s'?", ISpeechSynthesizerMsgs_set_voice_helper::s_prototype); } ISpeechSynthesizerMsgs_set_voice_helper helper{language}; bool ok = yarp().write(helper, helper); - return ok ? helper.reply.return_helper : bool{}; + return ok ? helper.reply.return_helper : return_set_voice{}; } return_get_voice ISpeechSynthesizerMsgs::get_voice() @@ -1909,14 +1909,14 @@ return_get_voice ISpeechSynthesizerMsgs::get_voice() return ok ? helper.reply.return_helper : return_get_voice{}; } -bool ISpeechSynthesizerMsgs::set_speed(const double speed) +return_set_speed ISpeechSynthesizerMsgs::set_speed(const double speed) { if (!yarp().canWrite()) { yError("Missing server method '%s'?", ISpeechSynthesizerMsgs_set_speed_helper::s_prototype); } ISpeechSynthesizerMsgs_set_speed_helper helper{speed}; bool ok = yarp().write(helper, helper); - return ok ? helper.reply.return_helper : bool{}; + return ok ? helper.reply.return_helper : return_set_speed{}; } return_get_speed ISpeechSynthesizerMsgs::get_speed() @@ -1929,14 +1929,14 @@ return_get_speed ISpeechSynthesizerMsgs::get_speed() return ok ? helper.reply.return_helper : return_get_speed{}; } -bool ISpeechSynthesizerMsgs::set_pitch(const double pitch) +return_set_pitch ISpeechSynthesizerMsgs::set_pitch(const double pitch) { if (!yarp().canWrite()) { yError("Missing server method '%s'?", ISpeechSynthesizerMsgs_set_pitch_helper::s_prototype); } ISpeechSynthesizerMsgs_set_pitch_helper helper{pitch}; bool ok = yarp().write(helper, helper); - return ok ? helper.reply.return_helper : bool{}; + return ok ? helper.reply.return_helper : return_set_pitch{}; } return_get_pitch ISpeechSynthesizerMsgs::get_pitch() diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs.h index 1c618910b19..8260130a5d9 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs.h +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs.h @@ -17,6 +17,10 @@ #include #include #include +#include +#include +#include +#include #include class ISpeechSynthesizerMsgs : @@ -26,19 +30,19 @@ class ISpeechSynthesizerMsgs : // Constructor ISpeechSynthesizerMsgs(); - virtual bool set_language(const std::string& language); + virtual return_set_language set_language(const std::string& language); virtual return_get_language get_language(); - virtual bool set_voice(const std::string& language); + virtual return_set_voice set_voice(const std::string& language); virtual return_get_voice get_voice(); - virtual bool set_speed(const double speed); + virtual return_set_speed set_speed(const double speed); virtual return_get_speed get_speed(); - virtual bool set_pitch(const double pitch); + virtual return_set_pitch set_pitch(const double pitch); virtual return_get_pitch get_pitch(); diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs_index.txt b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs_index.txt index 0af6262894f..a4f8c3edb68 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs_index.txt +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/ISpeechSynthesizerMsgs_index.txt @@ -1,3 +1,11 @@ +return_set_language.h +return_set_language.cpp +return_set_voice.h +return_set_voice.cpp +return_set_speed.h +return_set_speed.cpp +return_set_pitch.h +return_set_pitch.cpp return_get_language.h return_get_language.cpp return_get_voice.h diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_language.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_language.cpp index bbd24b51014..3b4eb88c496 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_language.cpp +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_language.cpp @@ -11,7 +11,7 @@ #include // Constructor with field values -return_get_language::return_get_language(const bool ret, +return_get_language::return_get_language(const yarp::dev::ReturnValue& ret, const std::string& language) : WirePortable(), ret(ret), @@ -22,7 +22,7 @@ return_get_language::return_get_language(const bool ret, // Read structure on a Wire bool return_get_language::read(yarp::os::idl::WireReader& reader) { - if (!read_ret(reader)) { + if (!nested_read_ret(reader)) { return false; } if (!read_language(reader)) { @@ -50,7 +50,7 @@ bool return_get_language::read(yarp::os::ConnectionReader& connection) // Write structure on a Wire bool return_get_language::write(const yarp::os::idl::WireWriter& writer) const { - if (!write_ret(writer)) { + if (!nested_write_ret(writer)) { return false; } if (!write_language(writer)) { @@ -88,8 +88,13 @@ std::string return_get_language::toString() const // read ret field bool return_get_language::read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; } return true; } @@ -97,7 +102,7 @@ bool return_get_language::read_ret(yarp::os::idl::WireReader& reader) // write ret field bool return_get_language::write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.write(ret)) { return false; } return true; @@ -106,8 +111,13 @@ bool return_get_language::write_ret(const yarp::os::idl::WireWriter& writer) con // read (nested) ret field bool return_get_language::nested_read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; } return true; } @@ -115,7 +125,7 @@ bool return_get_language::nested_read_ret(yarp::os::idl::WireReader& reader) // write (nested) ret field bool return_get_language::nested_write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.writeNested(ret)) { return false; } return true; diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_language.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_language.h index a00bb6dbf65..1b01f23632f 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_language.h +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_language.h @@ -13,20 +13,21 @@ #include #include +#include class return_get_language : public yarp::os::idl::WirePortable { public: // Fields - bool ret{false}; + yarp::dev::ReturnValue ret{}; std::string language{}; // Default constructor return_get_language() = default; // Constructor with field values - return_get_language(const bool ret, + return_get_language(const yarp::dev::ReturnValue& ret, const std::string& language); // Read structure on a Wire diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_pitch.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_pitch.cpp index 5c98ae961ae..8ba937a34e8 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_pitch.cpp +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_pitch.cpp @@ -11,7 +11,7 @@ #include // Constructor with field values -return_get_pitch::return_get_pitch(const bool ret, +return_get_pitch::return_get_pitch(const yarp::dev::ReturnValue& ret, const double pitch) : WirePortable(), ret(ret), @@ -22,7 +22,7 @@ return_get_pitch::return_get_pitch(const bool ret, // Read structure on a Wire bool return_get_pitch::read(yarp::os::idl::WireReader& reader) { - if (!read_ret(reader)) { + if (!nested_read_ret(reader)) { return false; } if (!read_pitch(reader)) { @@ -50,7 +50,7 @@ bool return_get_pitch::read(yarp::os::ConnectionReader& connection) // Write structure on a Wire bool return_get_pitch::write(const yarp::os::idl::WireWriter& writer) const { - if (!write_ret(writer)) { + if (!nested_write_ret(writer)) { return false; } if (!write_pitch(writer)) { @@ -88,8 +88,13 @@ std::string return_get_pitch::toString() const // read ret field bool return_get_pitch::read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; } return true; } @@ -97,7 +102,7 @@ bool return_get_pitch::read_ret(yarp::os::idl::WireReader& reader) // write ret field bool return_get_pitch::write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.write(ret)) { return false; } return true; @@ -106,8 +111,13 @@ bool return_get_pitch::write_ret(const yarp::os::idl::WireWriter& writer) const // read (nested) ret field bool return_get_pitch::nested_read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; } return true; } @@ -115,7 +125,7 @@ bool return_get_pitch::nested_read_ret(yarp::os::idl::WireReader& reader) // write (nested) ret field bool return_get_pitch::nested_write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.writeNested(ret)) { return false; } return true; diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_pitch.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_pitch.h index 6f552abca34..854bba82b10 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_pitch.h +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_pitch.h @@ -13,20 +13,21 @@ #include #include +#include class return_get_pitch : public yarp::os::idl::WirePortable { public: // Fields - bool ret{false}; + yarp::dev::ReturnValue ret{}; double pitch{0.0}; // Default constructor return_get_pitch() = default; // Constructor with field values - return_get_pitch(const bool ret, + return_get_pitch(const yarp::dev::ReturnValue& ret, const double pitch); // Read structure on a Wire diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_speed.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_speed.cpp index b725e25beed..deaef872d74 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_speed.cpp +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_speed.cpp @@ -11,7 +11,7 @@ #include // Constructor with field values -return_get_speed::return_get_speed(const bool ret, +return_get_speed::return_get_speed(const yarp::dev::ReturnValue& ret, const double speed) : WirePortable(), ret(ret), @@ -22,7 +22,7 @@ return_get_speed::return_get_speed(const bool ret, // Read structure on a Wire bool return_get_speed::read(yarp::os::idl::WireReader& reader) { - if (!read_ret(reader)) { + if (!nested_read_ret(reader)) { return false; } if (!read_speed(reader)) { @@ -50,7 +50,7 @@ bool return_get_speed::read(yarp::os::ConnectionReader& connection) // Write structure on a Wire bool return_get_speed::write(const yarp::os::idl::WireWriter& writer) const { - if (!write_ret(writer)) { + if (!nested_write_ret(writer)) { return false; } if (!write_speed(writer)) { @@ -88,8 +88,13 @@ std::string return_get_speed::toString() const // read ret field bool return_get_speed::read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; } return true; } @@ -97,7 +102,7 @@ bool return_get_speed::read_ret(yarp::os::idl::WireReader& reader) // write ret field bool return_get_speed::write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.write(ret)) { return false; } return true; @@ -106,8 +111,13 @@ bool return_get_speed::write_ret(const yarp::os::idl::WireWriter& writer) const // read (nested) ret field bool return_get_speed::nested_read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; } return true; } @@ -115,7 +125,7 @@ bool return_get_speed::nested_read_ret(yarp::os::idl::WireReader& reader) // write (nested) ret field bool return_get_speed::nested_write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.writeNested(ret)) { return false; } return true; diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_speed.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_speed.h index 71c8e268f82..ede67c3fe43 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_speed.h +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_speed.h @@ -13,20 +13,21 @@ #include #include +#include class return_get_speed : public yarp::os::idl::WirePortable { public: // Fields - bool ret{false}; + yarp::dev::ReturnValue ret{}; double speed{0.0}; // Default constructor return_get_speed() = default; // Constructor with field values - return_get_speed(const bool ret, + return_get_speed(const yarp::dev::ReturnValue& ret, const double speed); // Read structure on a Wire diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_voice.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_voice.cpp index 4b4323b515a..f334b48ca98 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_voice.cpp +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_voice.cpp @@ -11,7 +11,7 @@ #include // Constructor with field values -return_get_voice::return_get_voice(const bool ret, +return_get_voice::return_get_voice(const yarp::dev::ReturnValue& ret, const std::string& voice) : WirePortable(), ret(ret), @@ -22,7 +22,7 @@ return_get_voice::return_get_voice(const bool ret, // Read structure on a Wire bool return_get_voice::read(yarp::os::idl::WireReader& reader) { - if (!read_ret(reader)) { + if (!nested_read_ret(reader)) { return false; } if (!read_voice(reader)) { @@ -50,7 +50,7 @@ bool return_get_voice::read(yarp::os::ConnectionReader& connection) // Write structure on a Wire bool return_get_voice::write(const yarp::os::idl::WireWriter& writer) const { - if (!write_ret(writer)) { + if (!nested_write_ret(writer)) { return false; } if (!write_voice(writer)) { @@ -88,8 +88,13 @@ std::string return_get_voice::toString() const // read ret field bool return_get_voice::read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; } return true; } @@ -97,7 +102,7 @@ bool return_get_voice::read_ret(yarp::os::idl::WireReader& reader) // write ret field bool return_get_voice::write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.write(ret)) { return false; } return true; @@ -106,8 +111,13 @@ bool return_get_voice::write_ret(const yarp::os::idl::WireWriter& writer) const // read (nested) ret field bool return_get_voice::nested_read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; } return true; } @@ -115,7 +125,7 @@ bool return_get_voice::nested_read_ret(yarp::os::idl::WireReader& reader) // write (nested) ret field bool return_get_voice::nested_write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.writeNested(ret)) { return false; } return true; diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_voice.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_voice.h index fb9ab5f7e43..10e10d795f0 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_voice.h +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_get_voice.h @@ -13,20 +13,21 @@ #include #include +#include class return_get_voice : public yarp::os::idl::WirePortable { public: // Fields - bool ret{false}; + yarp::dev::ReturnValue ret{}; std::string voice{}; // Default constructor return_get_voice() = default; // Constructor with field values - return_get_voice(const bool ret, + return_get_voice(const yarp::dev::ReturnValue& ret, const std::string& voice); // Read structure on a Wire diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_language.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_language.cpp new file mode 100644 index 00000000000..aa50982c0f2 --- /dev/null +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_language.cpp @@ -0,0 +1,124 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#include + +// Constructor with field values +return_set_language::return_set_language(const yarp::dev::ReturnValue& ret) : + WirePortable(), + ret(ret) +{ +} + +// Read structure on a Wire +bool return_set_language::read(yarp::os::idl::WireReader& reader) +{ + if (!nested_read_ret(reader)) { + return false; + } + if (reader.isError()) { + return false; + } + return true; +} + +// Read structure on a Connection +bool return_set_language::read(yarp::os::ConnectionReader& connection) +{ + yarp::os::idl::WireReader reader(connection); + if (!reader.readListHeader(1)) { + return false; + } + if (!read(reader)) { + return false; + } + return true; +} + +// Write structure on a Wire +bool return_set_language::write(const yarp::os::idl::WireWriter& writer) const +{ + if (!nested_write_ret(writer)) { + return false; + } + if (writer.isError()) { + return false; + } + return true; +} + +// Write structure on a Connection +bool return_set_language::write(yarp::os::ConnectionWriter& connection) const +{ + yarp::os::idl::WireWriter writer(connection); + if (!writer.writeListHeader(1)) { + return false; + } + if (!write(writer)) { + return false; + } + return true; +} + +// Convert to a printable string +std::string return_set_language::toString() const +{ + yarp::os::Bottle b; + if (!yarp::os::Portable::copyPortable(*this, b)) { + return {}; + } + return b.toString(); +} + +// read ret field +bool return_set_language::read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write ret field +bool return_set_language::write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.write(ret)) { + return false; + } + return true; +} + +// read (nested) ret field +bool return_set_language::nested_read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write (nested) ret field +bool return_set_language::nested_write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.writeNested(ret)) { + return false; + } + return true; +} diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_language.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_language.h new file mode 100644 index 00000000000..a21a3b42bbd --- /dev/null +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_language.h @@ -0,0 +1,57 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#ifndef YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_LANGUAGE_H +#define YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_LANGUAGE_H + +#include +#include +#include + +class return_set_language : + public yarp::os::idl::WirePortable +{ +public: + // Fields + yarp::dev::ReturnValue ret{}; + + // Default constructor + return_set_language() = default; + + // Constructor with field values + return_set_language(const yarp::dev::ReturnValue& ret); + + // Read structure on a Wire + bool read(yarp::os::idl::WireReader& reader) override; + + // Read structure on a Connection + bool read(yarp::os::ConnectionReader& connection) override; + + // Write structure on a Wire + bool write(const yarp::os::idl::WireWriter& writer) const override; + + // Write structure on a Connection + bool write(yarp::os::ConnectionWriter& connection) const override; + + // Convert to a printable string + std::string toString() const; + + // If you want to serialize this class without nesting, use this helper + typedef yarp::os::idl::Unwrapped unwrapped; + +private: + // read/write ret field + bool read_ret(yarp::os::idl::WireReader& reader); + bool write_ret(const yarp::os::idl::WireWriter& writer) const; + bool nested_read_ret(yarp::os::idl::WireReader& reader); + bool nested_write_ret(const yarp::os::idl::WireWriter& writer) const; +}; + +#endif // YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_LANGUAGE_H diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_pitch.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_pitch.cpp new file mode 100644 index 00000000000..8a7cc907e5b --- /dev/null +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_pitch.cpp @@ -0,0 +1,124 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#include + +// Constructor with field values +return_set_pitch::return_set_pitch(const yarp::dev::ReturnValue& ret) : + WirePortable(), + ret(ret) +{ +} + +// Read structure on a Wire +bool return_set_pitch::read(yarp::os::idl::WireReader& reader) +{ + if (!nested_read_ret(reader)) { + return false; + } + if (reader.isError()) { + return false; + } + return true; +} + +// Read structure on a Connection +bool return_set_pitch::read(yarp::os::ConnectionReader& connection) +{ + yarp::os::idl::WireReader reader(connection); + if (!reader.readListHeader(1)) { + return false; + } + if (!read(reader)) { + return false; + } + return true; +} + +// Write structure on a Wire +bool return_set_pitch::write(const yarp::os::idl::WireWriter& writer) const +{ + if (!nested_write_ret(writer)) { + return false; + } + if (writer.isError()) { + return false; + } + return true; +} + +// Write structure on a Connection +bool return_set_pitch::write(yarp::os::ConnectionWriter& connection) const +{ + yarp::os::idl::WireWriter writer(connection); + if (!writer.writeListHeader(1)) { + return false; + } + if (!write(writer)) { + return false; + } + return true; +} + +// Convert to a printable string +std::string return_set_pitch::toString() const +{ + yarp::os::Bottle b; + if (!yarp::os::Portable::copyPortable(*this, b)) { + return {}; + } + return b.toString(); +} + +// read ret field +bool return_set_pitch::read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write ret field +bool return_set_pitch::write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.write(ret)) { + return false; + } + return true; +} + +// read (nested) ret field +bool return_set_pitch::nested_read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write (nested) ret field +bool return_set_pitch::nested_write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.writeNested(ret)) { + return false; + } + return true; +} diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_pitch.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_pitch.h new file mode 100644 index 00000000000..daaa70d957f --- /dev/null +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_pitch.h @@ -0,0 +1,57 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#ifndef YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_PITCH_H +#define YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_PITCH_H + +#include +#include +#include + +class return_set_pitch : + public yarp::os::idl::WirePortable +{ +public: + // Fields + yarp::dev::ReturnValue ret{}; + + // Default constructor + return_set_pitch() = default; + + // Constructor with field values + return_set_pitch(const yarp::dev::ReturnValue& ret); + + // Read structure on a Wire + bool read(yarp::os::idl::WireReader& reader) override; + + // Read structure on a Connection + bool read(yarp::os::ConnectionReader& connection) override; + + // Write structure on a Wire + bool write(const yarp::os::idl::WireWriter& writer) const override; + + // Write structure on a Connection + bool write(yarp::os::ConnectionWriter& connection) const override; + + // Convert to a printable string + std::string toString() const; + + // If you want to serialize this class without nesting, use this helper + typedef yarp::os::idl::Unwrapped unwrapped; + +private: + // read/write ret field + bool read_ret(yarp::os::idl::WireReader& reader); + bool write_ret(const yarp::os::idl::WireWriter& writer) const; + bool nested_read_ret(yarp::os::idl::WireReader& reader); + bool nested_write_ret(const yarp::os::idl::WireWriter& writer) const; +}; + +#endif // YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_PITCH_H diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_speed.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_speed.cpp new file mode 100644 index 00000000000..1aeb428273b --- /dev/null +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_speed.cpp @@ -0,0 +1,124 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#include + +// Constructor with field values +return_set_speed::return_set_speed(const yarp::dev::ReturnValue& ret) : + WirePortable(), + ret(ret) +{ +} + +// Read structure on a Wire +bool return_set_speed::read(yarp::os::idl::WireReader& reader) +{ + if (!nested_read_ret(reader)) { + return false; + } + if (reader.isError()) { + return false; + } + return true; +} + +// Read structure on a Connection +bool return_set_speed::read(yarp::os::ConnectionReader& connection) +{ + yarp::os::idl::WireReader reader(connection); + if (!reader.readListHeader(1)) { + return false; + } + if (!read(reader)) { + return false; + } + return true; +} + +// Write structure on a Wire +bool return_set_speed::write(const yarp::os::idl::WireWriter& writer) const +{ + if (!nested_write_ret(writer)) { + return false; + } + if (writer.isError()) { + return false; + } + return true; +} + +// Write structure on a Connection +bool return_set_speed::write(yarp::os::ConnectionWriter& connection) const +{ + yarp::os::idl::WireWriter writer(connection); + if (!writer.writeListHeader(1)) { + return false; + } + if (!write(writer)) { + return false; + } + return true; +} + +// Convert to a printable string +std::string return_set_speed::toString() const +{ + yarp::os::Bottle b; + if (!yarp::os::Portable::copyPortable(*this, b)) { + return {}; + } + return b.toString(); +} + +// read ret field +bool return_set_speed::read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write ret field +bool return_set_speed::write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.write(ret)) { + return false; + } + return true; +} + +// read (nested) ret field +bool return_set_speed::nested_read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write (nested) ret field +bool return_set_speed::nested_write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.writeNested(ret)) { + return false; + } + return true; +} diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_speed.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_speed.h new file mode 100644 index 00000000000..4c8bd38a092 --- /dev/null +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_speed.h @@ -0,0 +1,57 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#ifndef YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_SPEED_H +#define YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_SPEED_H + +#include +#include +#include + +class return_set_speed : + public yarp::os::idl::WirePortable +{ +public: + // Fields + yarp::dev::ReturnValue ret{}; + + // Default constructor + return_set_speed() = default; + + // Constructor with field values + return_set_speed(const yarp::dev::ReturnValue& ret); + + // Read structure on a Wire + bool read(yarp::os::idl::WireReader& reader) override; + + // Read structure on a Connection + bool read(yarp::os::ConnectionReader& connection) override; + + // Write structure on a Wire + bool write(const yarp::os::idl::WireWriter& writer) const override; + + // Write structure on a Connection + bool write(yarp::os::ConnectionWriter& connection) const override; + + // Convert to a printable string + std::string toString() const; + + // If you want to serialize this class without nesting, use this helper + typedef yarp::os::idl::Unwrapped unwrapped; + +private: + // read/write ret field + bool read_ret(yarp::os::idl::WireReader& reader); + bool write_ret(const yarp::os::idl::WireWriter& writer) const; + bool nested_read_ret(yarp::os::idl::WireReader& reader); + bool nested_write_ret(const yarp::os::idl::WireWriter& writer) const; +}; + +#endif // YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_SPEED_H diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_voice.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_voice.cpp new file mode 100644 index 00000000000..ca038465b9b --- /dev/null +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_voice.cpp @@ -0,0 +1,124 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#include + +// Constructor with field values +return_set_voice::return_set_voice(const yarp::dev::ReturnValue& ret) : + WirePortable(), + ret(ret) +{ +} + +// Read structure on a Wire +bool return_set_voice::read(yarp::os::idl::WireReader& reader) +{ + if (!nested_read_ret(reader)) { + return false; + } + if (reader.isError()) { + return false; + } + return true; +} + +// Read structure on a Connection +bool return_set_voice::read(yarp::os::ConnectionReader& connection) +{ + yarp::os::idl::WireReader reader(connection); + if (!reader.readListHeader(1)) { + return false; + } + if (!read(reader)) { + return false; + } + return true; +} + +// Write structure on a Wire +bool return_set_voice::write(const yarp::os::idl::WireWriter& writer) const +{ + if (!nested_write_ret(writer)) { + return false; + } + if (writer.isError()) { + return false; + } + return true; +} + +// Write structure on a Connection +bool return_set_voice::write(yarp::os::ConnectionWriter& connection) const +{ + yarp::os::idl::WireWriter writer(connection); + if (!writer.writeListHeader(1)) { + return false; + } + if (!write(writer)) { + return false; + } + return true; +} + +// Convert to a printable string +std::string return_set_voice::toString() const +{ + yarp::os::Bottle b; + if (!yarp::os::Portable::copyPortable(*this, b)) { + return {}; + } + return b.toString(); +} + +// read ret field +bool return_set_voice::read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write ret field +bool return_set_voice::write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.write(ret)) { + return false; + } + return true; +} + +// read (nested) ret field +bool return_set_voice::nested_read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write (nested) ret field +bool return_set_voice::nested_write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.writeNested(ret)) { + return false; + } + return true; +} diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_voice.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_voice.h new file mode 100644 index 00000000000..d994550f2c9 --- /dev/null +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_set_voice.h @@ -0,0 +1,57 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#ifndef YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_VOICE_H +#define YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_VOICE_H + +#include +#include +#include + +class return_set_voice : + public yarp::os::idl::WirePortable +{ +public: + // Fields + yarp::dev::ReturnValue ret{}; + + // Default constructor + return_set_voice() = default; + + // Constructor with field values + return_set_voice(const yarp::dev::ReturnValue& ret); + + // Read structure on a Wire + bool read(yarp::os::idl::WireReader& reader) override; + + // Read structure on a Connection + bool read(yarp::os::ConnectionReader& connection) override; + + // Write structure on a Wire + bool write(const yarp::os::idl::WireWriter& writer) const override; + + // Write structure on a Connection + bool write(yarp::os::ConnectionWriter& connection) const override; + + // Convert to a printable string + std::string toString() const; + + // If you want to serialize this class without nesting, use this helper + typedef yarp::os::idl::Unwrapped unwrapped; + +private: + // read/write ret field + bool read_ret(yarp::os::idl::WireReader& reader); + bool write_ret(const yarp::os::idl::WireWriter& writer) const; + bool nested_read_ret(yarp::os::idl::WireReader& reader); + bool nested_write_ret(const yarp::os::idl::WireWriter& writer) const; +}; + +#endif // YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_VOICE_H diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_synthesize.cpp b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_synthesize.cpp index b9989a09bf9..72b32b04b3f 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_synthesize.cpp +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_synthesize.cpp @@ -11,7 +11,7 @@ #include // Constructor with field values -return_synthesize::return_synthesize(const bool ret, +return_synthesize::return_synthesize(const yarp::dev::ReturnValue& ret, const yarp::sig::Sound& sound) : WirePortable(), ret(ret), @@ -22,7 +22,7 @@ return_synthesize::return_synthesize(const bool ret, // Read structure on a Wire bool return_synthesize::read(yarp::os::idl::WireReader& reader) { - if (!read_ret(reader)) { + if (!nested_read_ret(reader)) { return false; } if (!nested_read_sound(reader)) { @@ -50,7 +50,7 @@ bool return_synthesize::read(yarp::os::ConnectionReader& connection) // Write structure on a Wire bool return_synthesize::write(const yarp::os::idl::WireWriter& writer) const { - if (!write_ret(writer)) { + if (!nested_write_ret(writer)) { return false; } if (!nested_write_sound(writer)) { @@ -88,8 +88,13 @@ std::string return_synthesize::toString() const // read ret field bool return_synthesize::read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; } return true; } @@ -97,7 +102,7 @@ bool return_synthesize::read_ret(yarp::os::idl::WireReader& reader) // write ret field bool return_synthesize::write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.write(ret)) { return false; } return true; @@ -106,8 +111,13 @@ bool return_synthesize::write_ret(const yarp::os::idl::WireWriter& writer) const // read (nested) ret field bool return_synthesize::nested_read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; } return true; } @@ -115,7 +125,7 @@ bool return_synthesize::nested_read_ret(yarp::os::idl::WireReader& reader) // write (nested) ret field bool return_synthesize::nested_write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.writeNested(ret)) { return false; } return true; diff --git a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_synthesize.h b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_synthesize.h index 7c847a55b5e..a1e656b386d 100644 --- a/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_synthesize.h +++ b/src/devices/messages/ISpeechSynthesizerMsgs/idl_generated_code/return_synthesize.h @@ -13,6 +13,7 @@ #include #include +#include #include class return_synthesize : @@ -20,14 +21,14 @@ class return_synthesize : { public: // Fields - bool ret{false}; + yarp::dev::ReturnValue ret{}; yarp::sig::Sound sound{}; // Default constructor return_synthesize() = default; // Constructor with field values - return_synthesize(const bool ret, + return_synthesize(const yarp::dev::ReturnValue& ret, const yarp::sig::Sound& sound); // Read structure on a Wire diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/ISpeechTranscriptionMsgs.thrift b/src/devices/messages/ISpeechTranscriptionMsgs/ISpeechTranscriptionMsgs.thrift index 72b99202643..1abdc322e57 100644 --- a/src/devices/messages/ISpeechTranscriptionMsgs/ISpeechTranscriptionMsgs.thrift +++ b/src/devices/messages/ISpeechTranscriptionMsgs/ISpeechTranscriptionMsgs.thrift @@ -9,20 +9,30 @@ struct yarp_sig_Sound { yarp.includefile = "yarp/sig/Sound.h" ) +struct yReturnValue { +} ( + yarp.name = "yarp::dev::ReturnValue" + yarp.includefile = "yarp/dev/ReturnValue.h" +) + +struct return_set_language { + 1: yReturnValue ret; +} + struct return_get_language { - 1: bool ret = false; + 1: yReturnValue ret; 2: string language; } struct return_transcribe { - 1: bool ret = false; + 1: yReturnValue ret; 2: string transcription; 3: double score; } service ISpeechTranscriptionMsgs { - bool set_language (1:string language); + return_set_language set_language (1:string language); return_get_language get_language (); return_transcribe transcribe (1:yarp_sig_Sound sound); } diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs.cpp b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs.cpp index 96582feffc7..5ccb957245b 100644 --- a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs.cpp +++ b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs.cpp @@ -60,10 +60,10 @@ class ISpeechTranscriptionMsgs_set_language_helper : bool write(const yarp::os::idl::WireWriter& writer) const override; bool read(yarp::os::idl::WireReader& reader) override; - bool return_helper{false}; + return_set_language return_helper{}; }; - using funcptr_t = bool (*)(const std::string&); + using funcptr_t = return_set_language (*)(const std::string&); void call(ISpeechTranscriptionMsgs* ptr); Command cmd; @@ -73,7 +73,7 @@ class ISpeechTranscriptionMsgs_set_language_helper : static constexpr size_t s_tag_len{2}; static constexpr size_t s_cmd_len{3}; static constexpr size_t s_reply_len{1}; - static constexpr const char* s_prototype{"bool ISpeechTranscriptionMsgs::set_language(const std::string& language)"}; + static constexpr const char* s_prototype{"return_set_language ISpeechTranscriptionMsgs::set_language(const std::string& language)"}; static constexpr const char* s_help{""}; }; @@ -324,7 +324,7 @@ bool ISpeechTranscriptionMsgs_set_language_helper::Reply::write(const yarp::os:: if (!writer.writeListHeader(s_reply_len)) { return false; } - if (!writer.writeBool(return_helper)) { + if (!writer.write(return_helper)) { return false; } } @@ -340,7 +340,7 @@ bool ISpeechTranscriptionMsgs_set_language_helper::Reply::read(yarp::os::idl::Wi reader.fail(); return false; } - if (!reader.readBool(return_helper)) { + if (!reader.read(return_helper)) { reader.fail(); return false; } @@ -645,14 +645,14 @@ ISpeechTranscriptionMsgs::ISpeechTranscriptionMsgs() yarp().setOwner(*this); } -bool ISpeechTranscriptionMsgs::set_language(const std::string& language) +return_set_language ISpeechTranscriptionMsgs::set_language(const std::string& language) { if (!yarp().canWrite()) { yError("Missing server method '%s'?", ISpeechTranscriptionMsgs_set_language_helper::s_prototype); } ISpeechTranscriptionMsgs_set_language_helper helper{language}; bool ok = yarp().write(helper, helper); - return ok ? helper.reply.return_helper : bool{}; + return ok ? helper.reply.return_helper : return_set_language{}; } return_get_language ISpeechTranscriptionMsgs::get_language() diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs.h b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs.h index 354fe008a80..644699995cd 100644 --- a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs.h +++ b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -24,7 +25,7 @@ class ISpeechTranscriptionMsgs : // Constructor ISpeechTranscriptionMsgs(); - virtual bool set_language(const std::string& language); + virtual return_set_language set_language(const std::string& language); virtual return_get_language get_language(); diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs_index.txt b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs_index.txt index 42752861ef5..03ca53cbd1a 100644 --- a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs_index.txt +++ b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/ISpeechTranscriptionMsgs_index.txt @@ -1,3 +1,5 @@ +return_set_language.h +return_set_language.cpp return_get_language.h return_get_language.cpp return_transcribe.h diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_get_language.cpp b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_get_language.cpp index bbd24b51014..3b4eb88c496 100644 --- a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_get_language.cpp +++ b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_get_language.cpp @@ -11,7 +11,7 @@ #include // Constructor with field values -return_get_language::return_get_language(const bool ret, +return_get_language::return_get_language(const yarp::dev::ReturnValue& ret, const std::string& language) : WirePortable(), ret(ret), @@ -22,7 +22,7 @@ return_get_language::return_get_language(const bool ret, // Read structure on a Wire bool return_get_language::read(yarp::os::idl::WireReader& reader) { - if (!read_ret(reader)) { + if (!nested_read_ret(reader)) { return false; } if (!read_language(reader)) { @@ -50,7 +50,7 @@ bool return_get_language::read(yarp::os::ConnectionReader& connection) // Write structure on a Wire bool return_get_language::write(const yarp::os::idl::WireWriter& writer) const { - if (!write_ret(writer)) { + if (!nested_write_ret(writer)) { return false; } if (!write_language(writer)) { @@ -88,8 +88,13 @@ std::string return_get_language::toString() const // read ret field bool return_get_language::read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; } return true; } @@ -97,7 +102,7 @@ bool return_get_language::read_ret(yarp::os::idl::WireReader& reader) // write ret field bool return_get_language::write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.write(ret)) { return false; } return true; @@ -106,8 +111,13 @@ bool return_get_language::write_ret(const yarp::os::idl::WireWriter& writer) con // read (nested) ret field bool return_get_language::nested_read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; } return true; } @@ -115,7 +125,7 @@ bool return_get_language::nested_read_ret(yarp::os::idl::WireReader& reader) // write (nested) ret field bool return_get_language::nested_write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.writeNested(ret)) { return false; } return true; diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_get_language.h b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_get_language.h index a00bb6dbf65..1b01f23632f 100644 --- a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_get_language.h +++ b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_get_language.h @@ -13,20 +13,21 @@ #include #include +#include class return_get_language : public yarp::os::idl::WirePortable { public: // Fields - bool ret{false}; + yarp::dev::ReturnValue ret{}; std::string language{}; // Default constructor return_get_language() = default; // Constructor with field values - return_get_language(const bool ret, + return_get_language(const yarp::dev::ReturnValue& ret, const std::string& language); // Read structure on a Wire diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_set_language.cpp b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_set_language.cpp new file mode 100644 index 00000000000..aa50982c0f2 --- /dev/null +++ b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_set_language.cpp @@ -0,0 +1,124 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#include + +// Constructor with field values +return_set_language::return_set_language(const yarp::dev::ReturnValue& ret) : + WirePortable(), + ret(ret) +{ +} + +// Read structure on a Wire +bool return_set_language::read(yarp::os::idl::WireReader& reader) +{ + if (!nested_read_ret(reader)) { + return false; + } + if (reader.isError()) { + return false; + } + return true; +} + +// Read structure on a Connection +bool return_set_language::read(yarp::os::ConnectionReader& connection) +{ + yarp::os::idl::WireReader reader(connection); + if (!reader.readListHeader(1)) { + return false; + } + if (!read(reader)) { + return false; + } + return true; +} + +// Write structure on a Wire +bool return_set_language::write(const yarp::os::idl::WireWriter& writer) const +{ + if (!nested_write_ret(writer)) { + return false; + } + if (writer.isError()) { + return false; + } + return true; +} + +// Write structure on a Connection +bool return_set_language::write(yarp::os::ConnectionWriter& connection) const +{ + yarp::os::idl::WireWriter writer(connection); + if (!writer.writeListHeader(1)) { + return false; + } + if (!write(writer)) { + return false; + } + return true; +} + +// Convert to a printable string +std::string return_set_language::toString() const +{ + yarp::os::Bottle b; + if (!yarp::os::Portable::copyPortable(*this, b)) { + return {}; + } + return b.toString(); +} + +// read ret field +bool return_set_language::read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write ret field +bool return_set_language::write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.write(ret)) { + return false; + } + return true; +} + +// read (nested) ret field +bool return_set_language::nested_read_ret(yarp::os::idl::WireReader& reader) +{ + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; + } + return true; +} + +// write (nested) ret field +bool return_set_language::nested_write_ret(const yarp::os::idl::WireWriter& writer) const +{ + if (!writer.writeNested(ret)) { + return false; + } + return true; +} diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_set_language.h b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_set_language.h new file mode 100644 index 00000000000..a21a3b42bbd --- /dev/null +++ b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_set_language.h @@ -0,0 +1,57 @@ +/* + * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +// Autogenerated by Thrift Compiler (0.14.1-yarped) +// +// This is an automatically generated file. +// It could get re-generated if the ALLOW_IDL_GENERATION flag is on. + +#ifndef YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_LANGUAGE_H +#define YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_LANGUAGE_H + +#include +#include +#include + +class return_set_language : + public yarp::os::idl::WirePortable +{ +public: + // Fields + yarp::dev::ReturnValue ret{}; + + // Default constructor + return_set_language() = default; + + // Constructor with field values + return_set_language(const yarp::dev::ReturnValue& ret); + + // Read structure on a Wire + bool read(yarp::os::idl::WireReader& reader) override; + + // Read structure on a Connection + bool read(yarp::os::ConnectionReader& connection) override; + + // Write structure on a Wire + bool write(const yarp::os::idl::WireWriter& writer) const override; + + // Write structure on a Connection + bool write(yarp::os::ConnectionWriter& connection) const override; + + // Convert to a printable string + std::string toString() const; + + // If you want to serialize this class without nesting, use this helper + typedef yarp::os::idl::Unwrapped unwrapped; + +private: + // read/write ret field + bool read_ret(yarp::os::idl::WireReader& reader); + bool write_ret(const yarp::os::idl::WireWriter& writer) const; + bool nested_read_ret(yarp::os::idl::WireReader& reader); + bool nested_write_ret(const yarp::os::idl::WireWriter& writer) const; +}; + +#endif // YARP_THRIFT_GENERATOR_STRUCT_RETURN_SET_LANGUAGE_H diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_transcribe.cpp b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_transcribe.cpp index 8191864cb30..9eed578e8e3 100644 --- a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_transcribe.cpp +++ b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_transcribe.cpp @@ -11,7 +11,7 @@ #include // Constructor with field values -return_transcribe::return_transcribe(const bool ret, +return_transcribe::return_transcribe(const yarp::dev::ReturnValue& ret, const std::string& transcription, const double score) : WirePortable(), @@ -24,7 +24,7 @@ return_transcribe::return_transcribe(const bool ret, // Read structure on a Wire bool return_transcribe::read(yarp::os::idl::WireReader& reader) { - if (!read_ret(reader)) { + if (!nested_read_ret(reader)) { return false; } if (!read_transcription(reader)) { @@ -55,7 +55,7 @@ bool return_transcribe::read(yarp::os::ConnectionReader& connection) // Write structure on a Wire bool return_transcribe::write(const yarp::os::idl::WireWriter& writer) const { - if (!write_ret(writer)) { + if (!nested_write_ret(writer)) { return false; } if (!write_transcription(writer)) { @@ -96,8 +96,13 @@ std::string return_transcribe::toString() const // read ret field bool return_transcribe::read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.read(ret)) { + reader.fail(); + return false; } return true; } @@ -105,7 +110,7 @@ bool return_transcribe::read_ret(yarp::os::idl::WireReader& reader) // write ret field bool return_transcribe::write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.write(ret)) { return false; } return true; @@ -114,8 +119,13 @@ bool return_transcribe::write_ret(const yarp::os::idl::WireWriter& writer) const // read (nested) ret field bool return_transcribe::nested_read_ret(yarp::os::idl::WireReader& reader) { - if (!reader.readBool(ret)) { - ret = false; + if (reader.noMore()) { + reader.fail(); + return false; + } + if (!reader.readNested(ret)) { + reader.fail(); + return false; } return true; } @@ -123,7 +133,7 @@ bool return_transcribe::nested_read_ret(yarp::os::idl::WireReader& reader) // write (nested) ret field bool return_transcribe::nested_write_ret(const yarp::os::idl::WireWriter& writer) const { - if (!writer.writeBool(ret)) { + if (!writer.writeNested(ret)) { return false; } return true; diff --git a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_transcribe.h b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_transcribe.h index 21334abc0be..a95e079120c 100644 --- a/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_transcribe.h +++ b/src/devices/messages/ISpeechTranscriptionMsgs/idl_generated_code/return_transcribe.h @@ -13,13 +13,14 @@ #include #include +#include class return_transcribe : public yarp::os::idl::WirePortable { public: // Fields - bool ret{false}; + yarp::dev::ReturnValue ret{}; std::string transcription{}; double score{0.0}; @@ -27,7 +28,7 @@ class return_transcribe : return_transcribe() = default; // Constructor with field values - return_transcribe(const bool ret, + return_transcribe(const yarp::dev::ReturnValue& ret, const std::string& transcription, const double score); diff --git a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.cpp b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.cpp index e7b214a05cc..775aea174d9 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.cpp +++ b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.cpp @@ -13,6 +13,8 @@ namespace { YARP_LOG_COMPONENT(SPEECHSYNTH_NWC, "yarp.devices.speechSynthesizer_nwc_yarp") } +using namespace yarp::dev; + SpeechSynthesizer_nwc_yarp::~SpeechSynthesizer_nwc_yarp() { closeMain(); @@ -62,115 +64,119 @@ bool SpeechSynthesizer_nwc_yarp::closeMain() return true; } -bool SpeechSynthesizer_nwc_yarp::setLanguage(const std::string& language) +ReturnValue SpeechSynthesizer_nwc_yarp::setLanguage(const std::string& language) { - if(!m_thriftClient.set_language(language)) + auto result = m_thriftClient.set_language(language); + if(!result.ret) { yCError(SPEECHSYNTH_NWC) << "Error while setting language to" << language; - return false; + return result.ret; } - return true; + return result.ret; } -bool SpeechSynthesizer_nwc_yarp::getLanguage(std::string& language) +ReturnValue SpeechSynthesizer_nwc_yarp::getLanguage(std::string& language) { - return_get_language result = m_thriftClient.get_language(); + auto result = m_thriftClient.get_language(); if(!result.ret) { yCError(SPEECHSYNTH_NWC) << "Error while retrieving language"; - return false; + return result.ret; } language = result.language; - return true; + return result.ret; } -bool SpeechSynthesizer_nwc_yarp::setVoice(const std::string& voice_name) +ReturnValue SpeechSynthesizer_nwc_yarp::setVoice(const std::string& voice_name) { - if(!m_thriftClient.set_voice(voice_name)) + auto result = m_thriftClient.set_voice(voice_name); + if(!result.ret) { yCError(SPEECHSYNTH_NWC) << "Error while setting voice to" << voice_name; - return false; + return result.ret; } - return true; + return result.ret; } -bool SpeechSynthesizer_nwc_yarp::getVoice(std::string& voice_name) +ReturnValue SpeechSynthesizer_nwc_yarp::getVoice(std::string& voice_name) { - return_get_voice result = m_thriftClient.get_voice(); + auto result = m_thriftClient.get_voice(); if(!result.ret) { yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice name"; - return false; + return result.ret; } voice_name = result.voice; - return true; + return result.ret; } -bool SpeechSynthesizer_nwc_yarp::setSpeed(const double speed) +ReturnValue SpeechSynthesizer_nwc_yarp::setSpeed(const double speed) { - if(!m_thriftClient.set_speed(speed)) + auto result = m_thriftClient.set_speed(speed); + if(!result.ret) { yCError(SPEECHSYNTH_NWC) << "Error while setting voice speed to" << speed; - return false; + return result.ret; } - return true; + return result.ret; } -bool SpeechSynthesizer_nwc_yarp::getSpeed(double& speed) +ReturnValue SpeechSynthesizer_nwc_yarp::getSpeed(double& speed) { - return_get_speed result = m_thriftClient.get_speed(); + auto result = m_thriftClient.get_speed(); if(!result.ret) { yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice speed"; - return false; + return result.ret; } speed = result.speed; - return true; + return result.ret; } -bool SpeechSynthesizer_nwc_yarp::setPitch(const double pitch) +ReturnValue SpeechSynthesizer_nwc_yarp::setPitch(const double pitch) { - if(!m_thriftClient.set_pitch(pitch)) + auto result = m_thriftClient.set_pitch(pitch); + if(!result.ret) { yCError(SPEECHSYNTH_NWC) << "Error while setting voice pitch to" << pitch; - return false; + return result.ret; } - return true; + return result.ret; } -bool SpeechSynthesizer_nwc_yarp::getPitch(double& pitch) +ReturnValue SpeechSynthesizer_nwc_yarp::getPitch(double& pitch) { - return_get_pitch result = m_thriftClient.get_pitch(); + auto result = m_thriftClient.get_pitch(); if(!result.ret) { yCError(SPEECHSYNTH_NWC) << "Error while retrieving the voice pitch"; - return false; + return result.ret; } pitch = result.pitch; - return true; + return result.ret; } -bool SpeechSynthesizer_nwc_yarp::synthesize(const std::string& text, yarp::sig::Sound& sound) +ReturnValue SpeechSynthesizer_nwc_yarp::synthesize(const std::string& text, yarp::sig::Sound& sound) { - return_synthesize result = m_thriftClient.synthesize(text); + auto result = m_thriftClient.synthesize(text); if(!result.ret) { yCError(SPEECHSYNTH_NWC) << "Error while performing voice synthesis"; - return false; + return result.ret; } sound = result.sound; - return true; + return result.ret; } diff --git a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.h b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.h index eb1ec988548..4b1c6160a8f 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.h +++ b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "ISpeechSynthesizerMsgs.h" #include "SpeechSynthesizer_nwc_yarp_ParamsParser.h" @@ -56,15 +57,15 @@ class SpeechSynthesizer_nwc_yarp : bool close() override; // yarp::dev::ISpeechSynthesizer - bool setLanguage(const std::string& language="auto") override; - bool getLanguage(std::string& language) override; - bool setVoice(const std::string& voice_name = "auto") override; - bool getVoice(std::string& voice_name) override; - bool setSpeed(const double speed=0) override; - bool getSpeed(double& speed) override; - bool setPitch(const double pitch) override; - bool getPitch(double& pitch) override; - bool synthesize(const std::string& text, yarp::sig::Sound& sound) override; + yarp::dev::ReturnValue setLanguage(const std::string& language="auto") override; + yarp::dev::ReturnValue getLanguage(std::string& language) override; + yarp::dev::ReturnValue setVoice(const std::string& voice_name = "auto") override; + yarp::dev::ReturnValue getVoice(std::string& voice_name) override; + yarp::dev::ReturnValue setSpeed(const double speed=0) override; + yarp::dev::ReturnValue getSpeed(double& speed) override; + yarp::dev::ReturnValue setPitch(const double pitch) override; + yarp::dev::ReturnValue getPitch(double& pitch) override; + yarp::dev::ReturnValue synthesize(const std::string& text, yarp::sig::Sound& sound) override; // Parameters private: diff --git a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/tests/speechSynthesizer_nwc_yarp_test.cpp b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/tests/speechSynthesizer_nwc_yarp_test.cpp index 97c3ccdc7ee..98da3059991 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/tests/speechSynthesizer_nwc_yarp_test.cpp +++ b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/tests/speechSynthesizer_nwc_yarp_test.cpp @@ -72,6 +72,15 @@ TEST_CASE("dev::speechSynthesizer_nwc_yarp", "[yarp::dev]") double speed = 100; double speedReturned; + CHECK(iSpeech->setLanguage("ENG")); + std::string getLang; + CHECK(iSpeech->getLanguage(getLang)); + CHECK(getLang == "ENG"); + + yarp::sig::Sound ss2; + CHECK(!iSpeech->synthesize("",ss2)); + CHECK(ss2.getSamples() == 0); + CHECK(iSpeech->setVoice(voice)); CHECK(iSpeech->getVoice(voiceReturned)); CHECK(voice == voiceReturned); diff --git a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.cpp b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.cpp index f8be491cf63..8f5156e4cb3 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.cpp +++ b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.cpp @@ -113,15 +113,17 @@ bool SpeechSynthesizer_nws_yarp::read(yarp::os::ConnectionReader& connection) //-------------------------------------------------- // RPC methods -bool ISpeechSynthesizerMsgsd::set_language(const std::string& language) +return_set_language ISpeechSynthesizerMsgsd::set_language(const std::string& language) { std::lock_guard lg(m_mutex); + return_set_language ret; if (m_isptr) { return m_isptr->setLanguage(language); } yCError(SPEECHSYNTH_NWS, "ISpeechSynthesizer interface was not set"); - return false; + ret.ret = ReturnValue::return_code::return_value_error_generic; + return ret; } return_get_language ISpeechSynthesizerMsgsd::get_language() @@ -131,24 +133,26 @@ return_get_language ISpeechSynthesizerMsgsd::get_language() if (m_isptr) { std::string language; - bool b = m_isptr->getLanguage(language); + ReturnValue b = m_isptr->getLanguage(language); ret.ret = b; ret.language = language; return ret; } yCError(SPEECHSYNTH_NWS, "ISpeechSynthesizer interface was not set"); + ret.ret = ReturnValue::return_code::return_value_error_generic; return ret; } -bool ISpeechSynthesizerMsgsd::set_voice(const std::string& voice) +return_set_voice ISpeechSynthesizerMsgsd::set_voice(const std::string& voice) { std::lock_guard lg(m_mutex); + return_set_voice ret; if (m_isptr) { return m_isptr->setVoice(voice); } yCError(SPEECHSYNTH_NWS, "ISpeechSynthesizer interface was not set"); - return false; + return ret; } return_get_voice ISpeechSynthesizerMsgsd::get_voice() @@ -158,24 +162,27 @@ return_get_voice ISpeechSynthesizerMsgsd::get_voice() if (m_isptr) { std::string voice; - bool b = m_isptr->getVoice(voice); + ReturnValue b = m_isptr->getVoice(voice); ret.ret = b; ret.voice = voice; return ret; } yCError(SPEECHSYNTH_NWS, "ISpeechSynthesizer interface was not set"); + ret.ret = ReturnValue::return_code::return_value_error_generic; return ret; } -bool ISpeechSynthesizerMsgsd::set_pitch(double pitch) +return_set_pitch ISpeechSynthesizerMsgsd::set_pitch(double pitch) { std::lock_guard lg(m_mutex); + return_set_pitch ret; if (m_isptr) { return m_isptr->setPitch(pitch); } yCError(SPEECHSYNTH_NWS, "ISpeechSynthesizer interface was not set"); - return false; + ret.ret = ReturnValue::return_code::return_value_error_generic; + return ret; } return_get_pitch ISpeechSynthesizerMsgsd::get_pitch() @@ -185,7 +192,7 @@ return_get_pitch ISpeechSynthesizerMsgsd::get_pitch() if (m_isptr) { double pitch; - bool b = m_isptr->getPitch(pitch); + ReturnValue b = m_isptr->getPitch(pitch); ret.ret = b; ret.pitch = pitch; return ret; @@ -194,15 +201,17 @@ return_get_pitch ISpeechSynthesizerMsgsd::get_pitch() return ret; } -bool ISpeechSynthesizerMsgsd::set_speed(double speed) +return_set_speed ISpeechSynthesizerMsgsd::set_speed(double speed) { std::lock_guard lg(m_mutex); + return_set_speed ret; if (m_isptr) { return m_isptr->setSpeed(speed); } yCError(SPEECHSYNTH_NWS, "ISpeechSynthesizer interface was not set"); - return false; + ret.ret = ReturnValue::return_code::return_value_error_generic; + return ret; } return_get_speed ISpeechSynthesizerMsgsd::get_speed() @@ -212,12 +221,13 @@ return_get_speed ISpeechSynthesizerMsgsd::get_speed() if (m_isptr) { double speed; - bool b = m_isptr->getSpeed(speed); + ReturnValue b = m_isptr->getSpeed(speed); ret.ret = b; ret.speed = speed; return ret; } yCError(SPEECHSYNTH_NWS, "ISpeechSynthesizer interface was not set"); + ret.ret = ReturnValue::return_code::return_value_error_generic; return ret; } @@ -229,7 +239,7 @@ return_synthesize ISpeechSynthesizerMsgsd::synthesize(const std::string& text) { yarp::sig::Sound snd; double score; - bool b = m_isptr->synthesize(text, snd); + ReturnValue b = m_isptr->synthesize(text, snd); ret.ret = b; ret.sound = snd; @@ -241,6 +251,7 @@ return_synthesize ISpeechSynthesizerMsgsd::synthesize(const std::string& text) return ret; } yCError(SPEECHSYNTH_NWS, "ISpeechSynthesizer interface was not set"); + ret.ret = ReturnValue::return_code::return_value_error_generic; return ret; } diff --git a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.h b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.h index d78ddc1ac19..f4d5a879797 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.h +++ b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.h @@ -55,13 +55,13 @@ class ISpeechSynthesizerMsgsd : public ISpeechSynthesizerMsgs yarp::os::Port* m_output_port{ nullptr }; public: - virtual bool set_language(const std::string& language) override; + virtual return_set_language set_language(const std::string& language) override; virtual return_get_language get_language() override; - virtual bool set_voice(const std::string& language) override; + virtual return_set_voice set_voice(const std::string& language) override; virtual return_get_voice get_voice() override; - virtual bool set_speed(double speed) override; + virtual return_set_speed set_speed(double speed) override; virtual return_get_speed get_speed() override; - virtual bool set_pitch(double pitch) override; + virtual return_set_pitch set_pitch(double pitch) override; virtual return_get_pitch get_pitch() override; virtual return_synthesize synthesize(const std::string& text) override; diff --git a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.cpp b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.cpp index 218c23a54a5..8d1ed2fb667 100644 --- a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.cpp +++ b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.cpp @@ -62,32 +62,34 @@ bool SpeechTranscription_nwc_yarp::closeMain() return true; } -bool SpeechTranscription_nwc_yarp::setLanguage(const std::string& language) +yarp::dev::ReturnValue SpeechTranscription_nwc_yarp::setLanguage(const std::string& language) { - if(!m_thriftClient.set_language(language)) + return_set_language result = m_thriftClient.set_language(language); + if(!result.ret) { yCError(SPEECHTR_NWC) << "Error while setting language to" << language; - return false; } - - return true; + else + { + } + return result.ret; } -bool SpeechTranscription_nwc_yarp::getLanguage(std::string& language) +yarp::dev::ReturnValue SpeechTranscription_nwc_yarp::getLanguage(std::string& language) { return_get_language result = m_thriftClient.get_language(); if(!result.ret) { yCError(SPEECHTR_NWC) << "Error while retrieving language"; - return false; } - - language = result.language; - - return true; + else + { + language = result.language; + } + return result.ret; } -bool SpeechTranscription_nwc_yarp::transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) +yarp::dev::ReturnValue SpeechTranscription_nwc_yarp::transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) { YARP_UNUSED(sound); YARP_UNUSED(transcription); @@ -98,11 +100,11 @@ bool SpeechTranscription_nwc_yarp::transcribe(const yarp::sig::Sound& sound, std if(!result.ret) { yCError(SPEECHTR_NWC) << "Error while transcribing the audio signal"; - return false; } - - transcription = result.transcription; - score = result.score; - - return true; + else + { + transcription = result.transcription; + score = result.score; + } + return result.ret; } diff --git a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.h b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.h index b4150dd10a4..cbd4595443b 100644 --- a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.h +++ b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.h @@ -55,9 +55,9 @@ class SpeechTranscription_nwc_yarp : bool close() override; //yarp::dev::ISpeechTranscription - bool setLanguage(const std::string& language="auto") override; - bool getLanguage(std::string& language) override; - bool transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) override; + yarp::dev::ReturnValue setLanguage(const std::string& language="auto") override; + yarp::dev::ReturnValue getLanguage(std::string& language) override; + yarp::dev::ReturnValue transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) override; // Parameters private: diff --git a/src/devices/networkWrappers/speechTranscription_nwc_yarp/tests/speechTranscription_nwc_yarp_test.cpp b/src/devices/networkWrappers/speechTranscription_nwc_yarp/tests/speechTranscription_nwc_yarp_test.cpp index 1c5e5ba2224..cf26cef2a0f 100644 --- a/src/devices/networkWrappers/speechTranscription_nwc_yarp/tests/speechTranscription_nwc_yarp_test.cpp +++ b/src/devices/networkWrappers/speechTranscription_nwc_yarp/tests/speechTranscription_nwc_yarp_test.cpp @@ -70,6 +70,9 @@ TEST_CASE("dev::speechTranscription_nwc_yarp", "[yarp::dev]") CHECK(text == "hello world"); CHECK(score == 1); + yarp::sig::Sound s2; + CHECK(!iSpeech->transcribe(s2,text,score)); + //"Close all polydrivers and check" { CHECK(ddnwc.close()); diff --git a/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.cpp b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.cpp index 313c79f7696..baffea356e0 100644 --- a/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.cpp +++ b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.cpp @@ -113,15 +113,17 @@ bool SpeechTranscription_nws_yarp::read(yarp::os::ConnectionReader& connection) //-------------------------------------------------- // RPC methods -bool ISpeechTranscriptionMsgsd::set_language(const std::string& language) +return_set_language ISpeechTranscriptionMsgsd::set_language(const std::string& language) { std::lock_guard lg(m_mutex); + return_set_language ret; if (m_isptr) { return m_isptr->setLanguage(language); } yCError(SPEECHTR_NWS, "ISpeechTranscription interface was not set"); - return false; + ret.ret = ReturnValue::return_code::return_value_error_generic; + return ret; } return_get_language ISpeechTranscriptionMsgsd::get_language() @@ -131,12 +133,13 @@ return_get_language ISpeechTranscriptionMsgsd::get_language() if (m_isptr) { std::string language; - bool b = m_isptr->getLanguage(language); + ReturnValue b = m_isptr->getLanguage(language); ret.ret = b; ret.language = language; return ret; } yCError(SPEECHTR_NWS, "ISpeechTranscription interface was not set"); + ret.ret = ReturnValue::return_code::return_value_error_generic; return ret; } @@ -148,7 +151,7 @@ return_transcribe ISpeechTranscriptionMsgsd::transcribe(const yarp::sig::Sound& { std::string transcription; double score; - bool b = m_isptr->transcribe(sound, transcription, score); + ReturnValue b = m_isptr->transcribe(sound, transcription, score); ret.ret = b; ret.transcription = transcription; ret.score = score; @@ -164,6 +167,7 @@ return_transcribe ISpeechTranscriptionMsgsd::transcribe(const yarp::sig::Sound& return ret; } yCError(SPEECHTR_NWS, "ISpeechTranscription interface was not set"); + ret.ret = ReturnValue::return_code::return_value_error_generic; return ret; } diff --git a/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.h b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.h index 654c9b53f67..8829632d98f 100644 --- a/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.h +++ b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.h @@ -55,7 +55,7 @@ class ISpeechTranscriptionMsgsd : public ISpeechTranscriptionMsgs yarp::os::Port* m_output_port{ nullptr }; public: - virtual bool set_language(const std::string& language) override; + virtual return_set_language set_language(const std::string& language) override; virtual return_get_language get_language() override; virtual return_transcribe transcribe(const yarp::sig::Sound& sound) override; diff --git a/src/libYARP_dev/src/CMakeLists.txt b/src/libYARP_dev/src/CMakeLists.txt index 42c1a506f69..c7182131c76 100644 --- a/src/libYARP_dev/src/CMakeLists.txt +++ b/src/libYARP_dev/src/CMakeLists.txt @@ -114,6 +114,7 @@ set(YARP_dev_HDRS yarp/dev/PolyDriverDescriptor.h yarp/dev/PolyDriverList.h yarp/dev/RGBDSensorParamParser.h + yarp/dev/ReturnValue.h yarp/dev/ServiceInterfaces.h yarp/dev/WrapperMultiple.h yarp/dev/WrapperSingle.h @@ -222,6 +223,7 @@ set(YARP_dev_SRCS yarp/dev/PolyDriver.cpp yarp/dev/PolyDriverDescriptor.cpp yarp/dev/PolyDriverList.cpp + yarp/dev/ReturnValue.cpp yarp/dev/RGBDSensorParamParser.cpp yarp/dev/WrapperMultiple.cpp yarp/dev/WrapperSingle.cpp diff --git a/src/libYARP_dev/src/yarp/dev/ISpeechSynthesizer.h b/src/libYARP_dev/src/yarp/dev/ISpeechSynthesizer.h index 922ff66abff..7ecd28f2810 100644 --- a/src/libYARP_dev/src/yarp/dev/ISpeechSynthesizer.h +++ b/src/libYARP_dev/src/yarp/dev/ISpeechSynthesizer.h @@ -8,6 +8,7 @@ #include #include +#include namespace yarp::dev { @@ -26,56 +27,56 @@ class YARP_dev_API ISpeechSynthesizer * \param language a string (code) representing the speech language (e.g. ita, eng...). Default value is "auto". * \return true on success */ - virtual bool setLanguage(const std::string& language="auto") = 0; + virtual yarp::dev::ReturnValue setLanguage(const std::string& language="auto") = 0; /** * Gets the current language set for speech synthesis. * \param language the returned string (code) representing the speech language (e.g. ita, eng...). Default value is "auto". * \return true on success */ - virtual bool getLanguage(std::string& language) = 0; + virtual yarp::dev::ReturnValue getLanguage(std::string& language) = 0; /** * Sets the voice set for speech synthesis. * \param voice_name the name of of the voice (device dependent). * \return true on success */ - virtual bool setVoice(const std::string& voice_name = "auto") = 0; + virtual yarp::dev::ReturnValue setVoice(const std::string& voice_name = "auto") = 0; /** * Gets the current voice set for speech synthesis. * \param voice_name the currently used voice (device dependent). * \return true on success */ - virtual bool getVoice(std::string& voice_name) = 0; + virtual yarp::dev::ReturnValue getVoice(std::string& voice_name) = 0; /** * Sets the voice speed for speech synthesis. * \param speed the voice speed. * \return true on success */ - virtual bool setSpeed(const double speed=0) = 0; + virtual yarp::dev::ReturnValue setSpeed(const double speed=0) = 0; /** * Gets the current voice speed. * \param speed the current voice speed. * \return true on success */ - virtual bool getSpeed(double& speed) = 0; + virtual yarp::dev::ReturnValue getSpeed(double& speed) = 0; /** * Sets the pitch for speech synthesis. * \param pitch the voice pitch. * \return true on success */ - virtual bool setPitch(const double pitch) = 0; + virtual yarp::dev::ReturnValue setPitch(const double pitch) = 0; /** * Gets the current pitch set for speech synthesis. * \param pitch the current voice pitch. * \return true on success */ - virtual bool getPitch(double& voice) = 0; + virtual yarp::dev::ReturnValue getPitch(double& voice) = 0; /** * Performs the speech synthesis. @@ -83,7 +84,7 @@ class YARP_dev_API ISpeechSynthesizer * \param sound the synthesized audio stream * \return true on success */ - virtual bool synthesize(const std::string& text, yarp::sig::Sound& sound) = 0; + virtual yarp::dev::ReturnValue synthesize(const std::string& text, yarp::sig::Sound& sound) = 0; }; } // namespace yarp::dev diff --git a/src/libYARP_dev/src/yarp/dev/ISpeechTranscription.h b/src/libYARP_dev/src/yarp/dev/ISpeechTranscription.h index d68d0997c47..6f15abd7378 100644 --- a/src/libYARP_dev/src/yarp/dev/ISpeechTranscription.h +++ b/src/libYARP_dev/src/yarp/dev/ISpeechTranscription.h @@ -8,6 +8,7 @@ #include #include +#include namespace yarp::dev { @@ -26,14 +27,14 @@ class YARP_dev_API ISpeechTranscription * \param language a string (code) representing the speech language (e.g. ita, eng...). Default value is "auto". * \return true on success */ - virtual bool setLanguage(const std::string& language="auto") = 0; + virtual yarp::dev::ReturnValue setLanguage(const std::string& language="auto") = 0; /** * Gets the current language set for speech transcription. * \param language the returned string (code) representing the speech language (e.g. ita, eng...). Default value is "auto". * \return true on success */ - virtual bool getLanguage(std::string& language) = 0; + virtual yarp::dev::ReturnValue getLanguage(std::string& language) = 0; /** * Performs the speech transcription. @@ -42,7 +43,7 @@ class YARP_dev_API ISpeechTranscription * \param score the returned score/confidence value in the range (0-1.0). It may be not implemented. * \return true on success */ - virtual bool transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) = 0; + virtual yarp::dev::ReturnValue transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) = 0; }; } // namespace yarp::dev diff --git a/src/libYARP_dev/src/yarp/dev/ReturnValue.cpp b/src/libYARP_dev/src/yarp/dev/ReturnValue.cpp new file mode 100644 index 00000000000..19fc1a8638d --- /dev/null +++ b/src/libYARP_dev/src/yarp/dev/ReturnValue.cpp @@ -0,0 +1,137 @@ +/* + * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include + +using namespace yarp::dev; +using namespace yarp::os; + +ReturnValue::ReturnValue() +{ +} + +#ifndef DISABLE_BOOL_INPUT +ReturnValue::ReturnValue(const bool& val) +{ + if (val) + { + value_b = return_code::return_value_ok; + } + else + { + value_b = return_code::return_value_error_generic; + } +} +#endif + +ReturnValue& ReturnValue::operator && (const ReturnValue& other) +{ + // THIS IS THE IMPLEMENTATION RULE: + // OP1 OP2 RESULT + // 1) True True True + // 2) FalseType1 FalseType1 FalseType1 + // 3) FalseType1 FalseType2 FalseGeneric + // 4) True FalseType1 FalseGeneric + // 5) FalseType1 True FalseGeneric + + if (this->value_b == other.value_b) + { + //cases 1 and 2 + return *this; + } + + value_b = return_code::return_value_error_generic; + return *this; +} + +ReturnValue& ReturnValue::operator &= (const ReturnValue& other) +{ + // THIS IS THE IMPLEMENTATION RULE: + // OP1 OP2 RESULT + // 1) True True True + // 2) FalseType1 FalseType1 FalseType1 + // 3) FalseType1 FalseType2 FalseGeneric + // 4) True FalseType1 FalseGeneric + // 5) FalseType1 True FalseGeneric + + if (this->value_b == other.value_b) + { + //cases 1 and 2 + return *this; + } + + value_b = return_code::return_value_error_generic; + return *this; +} + +#ifndef DISABLE_BOOL_INPUT +ReturnValue& ReturnValue::operator=(const bool& bool_val) +{ + if (bool_val) + { + value_b = return_code::return_value_ok; + } + else + { + value_b = return_code::return_value_error_generic; + } + return *this; +} +#endif + +std::string ReturnValue::toString() +{ + switch (value_b) + { + case return_code::return_value_ok: + return std::string("ok"); + case return_code::return_value_uninitialized: + return std::string("return_value_uninitialized"); + case return_code::return_value_error_deprecated: + return std::string("return_value_error_deprecated"); + case return_code::return_value_error_generic: + return std::string("return_value_error_generic"); + case return_code::return_value_error_method_failed: + return std::string("return_value_error_method_fail"); + case return_code::return_value_error_not_implemented_by_device: + return std::string("return_value_error_not_implemented_by_device"); + case return_code::return_value_error_nws_nwc_communication_error: + return std::string("return_value_error_nws_nwc_communication_error"); + default: + return std::string("unknown"); + } +} + +ReturnValue::operator bool() const +{ + return value_b == return_code::return_value_ok; +} + +ReturnValue::ReturnValue(return_code code) +{ + value_b = code; +} + +bool ReturnValue::operator == (const return_code& code) const +{ + if (code == this->value_b) return true; + return false; +} + +bool ReturnValue::read(yarp::os::ConnectionReader& connection) +{ + connection.convertTextMode(); + this->value_b = (ReturnValue::return_code)(connection.expectInt64()); + return true; +} + +bool ReturnValue::write(yarp::os::ConnectionWriter& connection) const +{ + connection.convertTextMode(); + connection.appendInt64((int64_t)(this->value_b)); + return true; +} diff --git a/src/libYARP_dev/src/yarp/dev/ReturnValue.h b/src/libYARP_dev/src/yarp/dev/ReturnValue.h new file mode 100644 index 00000000000..3e4eba585a6 --- /dev/null +++ b/src/libYARP_dev/src/yarp/dev/ReturnValue.h @@ -0,0 +1,103 @@ +/* + * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ReturnValue_H +#define ReturnValue_H + +#include +#include +#include +#include +#include + +// The following macro is used for testing/development purposes only, but it must be generally not enabled. +// If enabled, a bool value cannot be automatically converted to ReturnValue +// In this way, the developer can check if some old devices/interfaces do unwanted automatic +// conversions and fix them. + #define DISABLE_BOOL_INPUT + +// The following macro is used for testing/development purposes only, but it must be generally not enabled. +// If enabled, a ReturnValue cannot be automatically converted to bool unless explicitly requested +// using the bool() operator. +// If enabled, it will break backward compatibility with user-application code. +// #define DISABLE_BOOL_OUTPUT + +namespace yarp::dev { + +class YARP_dev_API ReturnValue : public yarp::os::Portable +{ + public: + enum class YARP_dev_API return_code + { + return_value_ok = 0, /// Method was successfully executed + return_value_error_generic = 1, + return_value_error_not_implemented_by_device = 2, /// Method is not (yet) implemented + return_value_error_nws_nwc_communication_error = 3, /// Command answer lost during network transmission. Status unknown. + return_value_error_deprecated = 4, /// Method is deprecated + return_value_error_method_failed = 5, /// Method failed due to invalid internal status/invalid request + return_value_uninitialized = 100 /// Default value, should never be explicitly assigned + }; + + private: + return_code value_b = return_code::return_value_uninitialized; + + public: + ReturnValue(); + ~ReturnValue() = default; +#ifndef DISABLE_BOOL_INPUT + ReturnValue(const bool& val); +#endif + ReturnValue(return_code code); + ReturnValue(const ReturnValue& other) = default; + ReturnValue& operator && (const ReturnValue& other); + ReturnValue& operator &= (const ReturnValue& other); +#ifndef DISABLE_BOOL_INPUT + ReturnValue& operator=(const bool& bool_val); +#endif + bool operator == (const return_code& code) const; + std::string toString(); +#ifndef DISABLE_BOOL_OUTPUT + operator bool() const; +#else + explicit operator bool const(); +#endif + +public: + bool read(yarp::os::ConnectionReader& connection) override; + bool write(yarp::os::ConnectionWriter& connection) const override; +}; + +#define ReturnValue_ok ReturnValue(yarp::dev::ReturnValue::return_code::return_value_ok) + +#if __cplusplus >= 202002L +inline ReturnValue YARP_METHOD_NOT_YET_IMPLEMENTED(const std::source_location& location = std::source_location::current()) +{ + yError("Method %s not yet implemented\n", location.function_name()); + return ReturnValue(yarp::dev::ReturnValue::return_code::return_value_error_not_implemented_by_device); +} +inline ReturnValue YARP_METHOD_DEPRECATED(const std::source_location& location = std::source_location::current()) +{ + yError("Method %s has been deprecated\n", location.function_name()); + return ReturnValue(yarp::dev::ReturnValue::return_code::return_value_error_deprecated); +} +#else +inline ReturnValue yarp_method_not_implemented(const char* location) +{ + yError("Method %s not yet implemented\n", location); + return ReturnValue(yarp::dev::ReturnValue::return_code::return_value_error_not_implemented_by_device); +} +#define YARP_METHOD_NOT_YET_IMPLEMENTED() yarp_method_not_implemented(__func__) +inline ReturnValue yarp_method_deprecated(const char* location) +{ + yError("Method %s has been deprecated\n", location); + return ReturnValue(yarp::dev::ReturnValue::return_code::return_value_error_deprecated); +} +#define YARP_METHOD_DEPRECATED() yarp_method_deprecated(__func__) +#endif + + +} + +#endif // ReturnValue_H diff --git a/src/libYARP_dev/tests/CMakeLists.txt b/src/libYARP_dev/tests/CMakeLists.txt index c06251f2e6a..79305221db5 100644 --- a/src/libYARP_dev/tests/CMakeLists.txt +++ b/src/libYARP_dev/tests/CMakeLists.txt @@ -8,6 +8,7 @@ target_sources(harness_dev PRIVATE MapGrid2DTest.cpp PolyDriverTest.cpp + ReturnValueTest.cpp ) target_link_libraries(harness_dev diff --git a/src/libYARP_dev/tests/ReturnValueTest.cpp b/src/libYARP_dev/tests/ReturnValueTest.cpp new file mode 100644 index 00000000000..3441e352a40 --- /dev/null +++ b/src/libYARP_dev/tests/ReturnValueTest.cpp @@ -0,0 +1,209 @@ +/* + * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: BSD-3-Clause + */ + + +#include + +#include +#include + +using namespace yarp::dev; + +ReturnValue test_method1() +{ + return YARP_METHOD_NOT_YET_IMPLEMENTED(); +} + +ReturnValue test_method2() +{ + return YARP_METHOD_DEPRECATED(); +} + +TEST_CASE("dev::ReturnValue", "[yarp::dev]") +{ +#ifndef DISABLE_BOOL_INPUT + SECTION("test block 1") + { + ReturnValue val_f1(false); + ReturnValue val_f2(false); + + ReturnValue val_t1(true); + ReturnValue val_t2(true); + + CHECK(val_f1 == val_f2); + CHECK(val_t1 == val_t2); + CHECK(val_f1 != val_t1); + CHECK(val_t1); + CHECK(!val_f1); + + std::string sf = val_f1.toString(); + std::string st = val_t1.toString(); + } +#endif + + SECTION("test block 2") + { + ReturnValue val1; + CHECK(val1 == ReturnValue::return_code::return_value_uninitialized); + + std::string s; + val1 = ReturnValue::return_code::return_value_ok; + s = val1.toString(); + CHECK(val1); + CHECK(s!="unknown"); + + val1 = ReturnValue::return_code::return_value_error_generic; + s = val1.toString(); + CHECK(!val1); + CHECK(s != "unknown"); + + val1 = ReturnValue::return_code::return_value_error_method_failed; + s = val1.toString(); + CHECK(!val1); + CHECK(s != "unknown"); + + val1 = ReturnValue::return_code::return_value_error_not_implemented_by_device; + s = val1.toString(); + CHECK(!val1); + CHECK(s != "unknown"); + + val1 = ReturnValue::return_code::return_value_error_nws_nwc_communication_error; + s = val1.toString(); + CHECK(!val1); + CHECK(s != "unknown"); + + val1 = ReturnValue::return_code::return_value_uninitialized; + s = val1.toString(); + CHECK(!val1); + CHECK(s != "unknown"); + } + + SECTION("test block 3") + { + ReturnValue val1; + val1 = ReturnValue::return_code::return_value_ok; + ReturnValue val2(val1); + CHECK(val2); + CHECK(val2 == ReturnValue::return_code::return_value_ok); + + val1 = ReturnValue::return_code::return_value_error_method_failed; + ReturnValue val3 = val1; + CHECK(!val3); + CHECK(val3 == ReturnValue::return_code::return_value_error_method_failed); + } + +#ifndef DISABLE_BOOL_INPUT + SECTION("test block 4a") + { + ReturnValue val_f1(false); + ReturnValue val_t1(true); + bool bool_f1 = val_f1; + bool bool_t1 = val_t1; + CHECK (bool_f1 == false); + CHECK (bool_t1 == true); + } +#endif + + SECTION("test block 4b") + { + ReturnValue val_f2(ReturnValue::return_code::return_value_error_method_failed); + ReturnValue val_t2(ReturnValue::return_code::return_value_ok); + bool bool_f2 = val_f2; + bool bool_t2 = val_t2; + CHECK(bool_f2 == false); + CHECK(bool_t2 == true); + } + + SECTION("test block 5") + { + ReturnValue val_f(ReturnValue::return_code::return_value_error_method_failed); + ReturnValue val_t(ReturnValue::return_code::return_value_ok); + { + ReturnValue ret(ReturnValue::return_code::return_value_ok); + ret&= val_t; + CHECK(ret == ReturnValue::return_code::return_value_ok); + } + { + ReturnValue ret(ReturnValue::return_code::return_value_ok); + ret &= val_f; + CHECK(ret == ReturnValue::return_code::return_value_error_generic); + } + { + ReturnValue ret(ReturnValue::return_code::return_value_error_not_implemented_by_device); + ret &= val_t; + CHECK(ret == ReturnValue::return_code::return_value_error_generic); + } + { + ReturnValue ret(ReturnValue::return_code::return_value_error_not_implemented_by_device); + ret &= val_f; + CHECK(ret == ReturnValue::return_code::return_value_error_generic); + } + } + + SECTION("test block 5b") + { + ReturnValue val_f1(ReturnValue::return_code::return_value_error_method_failed); + ReturnValue val_f2(ReturnValue::return_code::return_value_error_not_implemented_by_device); + ReturnValue val_t(ReturnValue::return_code::return_value_ok); + { + ReturnValue ret; + ret = val_t && val_t; + CHECK(ret == ReturnValue::return_code::return_value_ok); + } + { + ReturnValue ret; + ret = val_f1 && val_f1; + CHECK(ret == ReturnValue::return_code::return_value_error_method_failed); + } + { + ReturnValue ret; + ret = val_f2 && val_f2; + CHECK(ret == ReturnValue::return_code::return_value_error_not_implemented_by_device); + } + { + ReturnValue ret(ReturnValue::return_code::return_value_ok); + ret &= val_f1 && val_f2; + CHECK(ret == ReturnValue::return_code::return_value_error_generic); + } + { + ReturnValue ret(ReturnValue::return_code::return_value_ok); + ret &= val_t && val_f1 ; + CHECK(ret == ReturnValue::return_code::return_value_error_generic); + } + { + ReturnValue ret(ReturnValue::return_code::return_value_ok); + ret &= val_f1 && val_f2; + CHECK(ret == ReturnValue::return_code::return_value_error_generic); + } + } + + SECTION("test block 6") + { + bool ok; + ReturnValue val_fi(ReturnValue::return_code::return_value_error_method_failed); + ReturnValue val_ti(ReturnValue::return_code::return_value_ok); + ReturnValue val_fo; + ReturnValue val_to; + + ok = yarp::os::Portable::copyPortable(val_fi,val_fo); + CHECK(ok); + CHECK(val_fi == val_fo); + + ok = yarp::os::Portable::copyPortable(val_ti, val_to); + CHECK(ok); + CHECK(val_ti == val_to); + } + + SECTION("test block 7") + { + auto ret1 = test_method1(); + CHECK(ret1 == ReturnValue::return_code::return_value_error_not_implemented_by_device); + CHECK(!(ret1 == ReturnValue::return_code::return_value_ok)); + + auto ret2 = test_method2(); + CHECK(ret2 == ReturnValue::return_code::return_value_error_deprecated); + CHECK(!(ret2 == ReturnValue::return_code::return_value_ok)); + } +}