43 if (!writer.
writeString(
"getRemoteProtocolVersion")) {
57 if (!helper_proto.read(connection)) {
67 if(!
yarp().canWrite()) {
68 yError(
" Missing server method yarpAudioPlayer_IDL::getRemoteProtocolVersion");
73 return helper.helper_proto;}
84 if (remproto.protocol_version != locproto.protocol_version)
86 yCError(SERVICE_LOG_COMPONENT) <<
"Invalid communication protocol.";
87 yCError(SERVICE_LOG_COMPONENT) <<
"Local Protocol Version: " << locproto.toString();
88 yCError(SERVICE_LOG_COMPONENT) <<
"Remote Protocol Version: " << remproto.toString();
163 static constexpr const char*
s_tag{
"play"};
167 static constexpr const char*
s_prototype{
"bool yarpAudioPlayer_IDL::play(const std::string& filename)"};
169 "Play the given audio file\n"
170 "@return true/false on success/failure"
180 yarpAudioPlayer_IDL_test_helper(
const std::string& type,
const double duration,
const double frequency,
const std::int16_t amplitude,
const std::int16_t sampling_rate,
const std::int16_t channels);
228 using funcptr_t = bool (*)(
const std::string&,
const double,
const double,
const std::int16_t,
const std::int16_t,
const std::int16_t);
234 static constexpr const char*
s_tag{
"test"};
238 static constexpr const char*
s_prototype{
"bool yarpAudioPlayer_IDL::test(const std::string& type, const double duration, const double frequency, const std::int16_t amplitude, const std::int16_t sampling_rate, const std::int16_t channels)"};
240 "Generate and send a test sound\n"
241 "@param type can be \"sine\" , \"sawtooth\" , \"squarewave\"\n"
242 "@param duration the duration of the sound in seconds\n"
243 "@param frequency the signal in hertz\n"
244 "@param amplitude the amplitude of the signal (16 bit)\n"
245 "@param channels number of channels\n"
246 "@param sampling_rate signal sampling rate (samples/s)\n"
247 "@return true/false on success/failure"
278 return write(writer);
293 if (!writeTag(writer)) {
296 if (!writeArgs(writer)) {
320 if (!readTag(reader)) {
323 if (!readArgs(reader)) {
362 return write(writer);
393 if (!reader.
readBool(return_helper)) {
407 cmd{type, duration, frequency, amplitude, sampling_rate, channels}
424 frequency{frequency},
425 amplitude{amplitude},
426 sampling_rate{sampling_rate},
437 return write(writer);
452 if (!writeTag(writer)) {
455 if (!writeArgs(writer)) {
483 if (!writer.
writeI16(sampling_rate)) {
494 if (!readTag(reader)) {
497 if (!readArgs(reader)) {
527 if (!reader.
readI16(amplitude)) {
530 if (!reader.
readI16(sampling_rate)) {
531 sampling_rate = 16000;
533 if (!reader.
readI16(channels)) {
546 return write(writer);
577 if (!reader.
readBool(return_helper)) {
592 yarp().setOwner(*
this);
597 if (!
yarp().canWrite()) {
601 bool ok =
yarp().write(helper, helper);
602 return ok ? helper.reply.return_helper :
bool{};
605bool yarpAudioPlayer_IDL::test(
const std::string& type,
const double duration,
const double frequency,
const std::int16_t amplitude,
const std::int16_t sampling_rate,
const std::int16_t channels)
607 if (!
yarp().canWrite()) {
611 bool ok =
yarp().write(helper, helper);
612 return ok ? helper.reply.return_helper :
bool{};
618 bool showAll = (functionName ==
"--all");
619 std::vector<std::string> helpString;
621 helpString.emplace_back(
"*** Available commands:");
624 helpString.emplace_back(
"help");
634 if (functionName ==
"help") {
635 helpString.emplace_back(
"std::vector<std::string> help(const std::string& functionName = \"--all\")");
636 helpString.emplace_back(
"Return list of available commands, or help message for a specific function");
637 helpString.emplace_back(
"@param functionName name of command for which to get a detailed description. If none or '--all' is provided, print list of available commands");
638 helpString.emplace_back(
"@return list of strings (one string per line)");
641 if (helpString.empty()) {
642 helpString.emplace_back(
"Command not found");
650 constexpr size_t max_tag_len = 1;
660 std::string tag = reader.
readTag(1);
661 bool direct = (tag ==
"__direct__");
665 while (tag_len <= max_tag_len && !reader.
isError()) {
666 if(tag ==
"getRemoteProtocolVersion") {
673 auto proto = getLocalProtocolVersion();
679 if (!writer.
write(proto)) {
717 std::string functionName;
719 functionName =
"--all";
721 auto help_strings = help(functionName);
727 if (!writer.
writeTag(
"many", 1, 0)) {
733 for (
const auto& help_string : help_strings) {
749 std::string next_tag = reader.
readTag(1);
750 if (next_tag.empty()) {
753 tag.append(
"_").append(next_tag);
754 tag_len = std::count(tag.begin(), tag.end(),
'_') + 1;
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
yarp::os::ApplicationNetworkProtocolVersion helper_proto
yarpAudioPlayer_IDL_getRemoteProtocolVersion_helper()=default
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool readArgs(yarp::os::idl::WireReader &reader)
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool writeTag(const yarp::os::idl::WireWriter &writer) const
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
~Command() override=default
bool readTag(yarp::os::idl::WireReader &reader)
~Reply() override=default
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static constexpr const char * s_help
void call(yarpAudioPlayer_IDL *ptr)
static constexpr const char * s_prototype
static constexpr size_t s_tag_len
static constexpr size_t s_cmd_len
static constexpr const char * s_tag
yarpAudioPlayer_IDL_play_helper()=default
static constexpr size_t s_reply_len
bool(*)(const std::string &) funcptr_t
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool readTag(yarp::os::idl::WireReader &reader)
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
std::int16_t sampling_rate
bool readArgs(yarp::os::idl::WireReader &reader)
~Command() override=default
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool writeTag(const yarp::os::idl::WireWriter &writer) const
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
~Reply() override=default
yarpAudioPlayer_IDL_test_helper()=default
static constexpr const char * s_help
bool(*)(const std::string &, const double, const double, const std::int16_t, const std::int16_t, const std::int16_t) funcptr_t
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
static constexpr const char * s_tag
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static constexpr const char * s_prototype
static constexpr size_t s_cmd_len
static constexpr size_t s_reply_len
static constexpr size_t s_tag_len
void call(yarpAudioPlayer_IDL *ptr)
yarpAudioPlayer_IDL Interface.
virtual std::vector< std::string > help(const std::string &functionName="--all")
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
virtual bool test(const std::string &type="sine", const double duration=1, const double frequency=440, const std::int16_t amplitude=30000, const std::int16_t sampling_rate=16000, const std::int16_t channels=1)
Generate and send a test sound.
virtual bool checkProtocolVersion()
virtual bool play(const std::string &filename)
Play the given audio file.
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
short int protocol_version
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
bool write(PortWriter &writer)
Write a message to the associated port or reader.
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
IDL-friendly connection reader.
bool readString(std::string &str, bool *is_vocab=nullptr)
bool readI16(std::int16_t &x)
std::string readTag(size_t len=static_cast< size_t >(-1))
bool readFloat64(yarp::conf::float64_t &x)
IDL-friendly connection writer.
bool writeBool(bool x, bool skip_tag=false) const
bool write(const WirePortable &obj) const
bool writeI16(std::int16_t x, bool skip_tag=false) const
bool writeListHeader(int len) const
bool writeTag(const char *tag, int split, int len) const
bool writeFloat64(yarp::conf::float64_t x, bool skip_tag=false) const
bool writeString(const std::string &str, bool skip_tag=false) const
bool writeListEnd() const
bool writeListBegin(int tag, size_t len) const
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
The main, catch-all namespace for YARP.
#define YARP_VERSION_PATCH
#define YARP_VERSION_MAJOR
#define YARP_VERSION_MINOR