44 if (!writer.
writeString(
"getRemoteProtocolVersion")) {
58 if (!helper_proto.read(connection)) {
68 if(!
yarp().canWrite()) {
69 yError(
" Missing server method yarpAudioPlayer_IDL::getRemoteProtocolVersion");
74 return helper.helper_proto;}
85 if (remproto.protocol_version != locproto.protocol_version)
87 yCError(SERVICE_LOG_COMPONENT) <<
"Invalid communication protocol.";
88 yCError(SERVICE_LOG_COMPONENT) <<
"Local Protocol Version: " << locproto.toString();
89 yCError(SERVICE_LOG_COMPONENT) <<
"Remote Protocol Version: " << remproto.toString();
164 static constexpr const char*
s_tag{
"play"};
168 static constexpr const char*
s_prototype{
"bool yarpAudioPlayer_IDL::play(const std::string& filename)"};
170 "Play the given audio file\n"
171 "@return true/false on success/failure"
181 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);
229 using funcptr_t = bool (*)(
const std::string&,
const double,
const double,
const std::int16_t,
const std::int16_t,
const std::int16_t);
235 static constexpr const char*
s_tag{
"test"};
239 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)"};
241 "Generate and send a test sound\n"
242 "@param type can be \"sine\" , \"sawtooth\" , \"squarewave\"\n"
243 "@param duration the duration of the sound in seconds\n"
244 "@param frequency the signal in hertz\n"
245 "@param amplitude the amplitude of the signal (16 bit)\n"
246 "@param channels number of channels\n"
247 "@param sampling_rate signal sampling rate (samples/s)\n"
248 "@return true/false on success/failure"
279 return write(writer);
294 if (!writeTag(writer)) {
297 if (!writeArgs(writer)) {
321 if (!readTag(reader)) {
324 if (!readArgs(reader)) {
363 return write(writer);
394 if (!reader.
readBool(return_helper)) {
408 cmd{type, duration, frequency, amplitude, sampling_rate, channels}
425 frequency{frequency},
426 amplitude{amplitude},
427 sampling_rate{sampling_rate},
438 return write(writer);
453 if (!writeTag(writer)) {
456 if (!writeArgs(writer)) {
484 if (!writer.
writeI16(sampling_rate)) {
495 if (!readTag(reader)) {
498 if (!readArgs(reader)) {
528 if (!reader.
readI16(amplitude)) {
531 if (!reader.
readI16(sampling_rate)) {
532 sampling_rate = 16000;
534 if (!reader.
readI16(channels)) {
547 return write(writer);
578 if (!reader.
readBool(return_helper)) {
593 yarp().setOwner(*
this);
598 if (!
yarp().canWrite()) {
602 bool ok =
yarp().write(helper, helper);
603 return ok ? helper.reply.return_helper :
bool{};
606bool 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)
608 if (!
yarp().canWrite()) {
612 bool ok =
yarp().write(helper, helper);
613 return ok ? helper.reply.return_helper :
bool{};
619 bool showAll = (functionName ==
"--all");
620 std::vector<std::string> helpString;
622 helpString.emplace_back(
"*** Available commands:");
625 helpString.emplace_back(
"help");
635 if (functionName ==
"help") {
636 helpString.emplace_back(
"std::vector<std::string> help(const std::string& functionName = \"--all\")");
637 helpString.emplace_back(
"Return list of available commands, or help message for a specific function");
638 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");
639 helpString.emplace_back(
"@return list of strings (one string per line)");
642 if (helpString.empty()) {
643 helpString.emplace_back(
"Command not found");
651 constexpr size_t max_tag_len = 1;
661 std::string tag = reader.
readTag(1);
662 bool direct = (tag ==
"__direct__");
666 while (tag_len <= max_tag_len && !reader.
isError()) {
667 if(tag ==
"getRemoteProtocolVersion") {
674 auto proto = getLocalProtocolVersion();
680 if (!writer.
write(proto)) {
718 std::string functionName;
720 functionName =
"--all";
722 auto help_strings = help(functionName);
728 if (!writer.
writeTag(
"many", 1, 0)) {
734 for (
const auto& help_string : help_strings) {
750 std::string next_tag = reader.
readTag(1);
751 if (next_tag.empty()) {
754 tag.append(
"_").append(next_tag);
755 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