YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
yarpAudioPlayer_IDL.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6// Autogenerated by Thrift (based on compiler 0.14.1-yarped)
7// yarpidl_thrift version 2.0 - 11/11/2026
8// Protocol version: protocol_version=0, yarp_major=4, yarp_minor=0, yarp_patch=2
9// This is an automatically generated file.
10// It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
11
12#include <yarp/conf/version.h>
13#include <yarpAudioPlayer_IDL.h>
15#include <yarp/os/LogStream.h>
16
18
19#include <algorithm>
20
21namespace
22{
23 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "yarpAudioPlayer_IDL")
24}
25
26//yarpAudioPlayer_IDL_getRemoteProtocolVersion_helper declaration
37
39{
40 yarp::os::idl::WireWriter writer(connection);
41 if (!writer.writeListHeader(1)) {
42 return false;
43 }
44 if (!writer.writeString("getRemoteProtocolVersion")) {
45 return false;
46 }
47 return true;
48}
49
50bool yarpAudioPlayer_IDL_getRemoteProtocolVersion_helper ::read(yarp::os::ConnectionReader & connection)
51 {
52 yarp::os::idl::WireReader reader(connection);
53 if (!reader.readListHeader()) {
54 reader.fail();
55 return false;
56 }
57
58 if (!helper_proto.read(connection)) {
59 reader.fail();
60 return false;
61 }
62 return true;
63}
64
65//ProtocolVersion, client side
67 {
68 if(!yarp().canWrite()) {
69 yError(" Missing server method yarpAudioPlayer_IDL::getRemoteProtocolVersion");
70 }
72 bool ok = yarp().write(helper, helper);
73 if (ok) {
74 return helper.helper_proto;}
75 else {
77 return failureproto;}
78}
79
80//ProtocolVersion, client side
82 {
83 auto locproto = this->getLocalProtocolVersion();
84 auto remproto = this->getRemoteProtocolVersion();
85 if (remproto.protocol_version != locproto.protocol_version)
86 {
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();
90 return false;
91 }
92 return true;
93}
94
95//ProtocolVersion, server side
97{
99 //myproto.protocol_version using default value = 0
100 //to change this value add the following line to the .thrift file:
101 //const i16 protocol_version = <your_number_here>
102 myproto.protocol_version = 0;
106 return myproto;
107}
108
109// play helper class declaration
111 public yarp::os::Portable
112{
113public:
115 explicit yarpAudioPlayer_IDL_play_helper(const std::string& filename);
116 bool write(yarp::os::ConnectionWriter& connection) const override;
117 bool read(yarp::os::ConnectionReader& connection) override;
118
119 class Command :
121 {
122 public:
123 Command() = default;
124 explicit Command(const std::string& filename);
125
126 ~Command() override = default;
127
128 bool write(yarp::os::ConnectionWriter& connection) const override;
129 bool read(yarp::os::ConnectionReader& connection) override;
130
131 bool write(const yarp::os::idl::WireWriter& writer) const override;
132 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
133 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
134
135 bool read(yarp::os::idl::WireReader& reader) override;
138
139 std::string filename{};
140 };
141
142 class Reply :
144 {
145 public:
146 Reply() = default;
147 ~Reply() override = default;
148
149 bool write(yarp::os::ConnectionWriter& connection) const override;
150 bool read(yarp::os::ConnectionReader& connection) override;
151
152 bool write(const yarp::os::idl::WireWriter& writer) const override;
153 bool read(yarp::os::idl::WireReader& reader) override;
154
155 bool return_helper{false};
156 };
157
158 using funcptr_t = bool (*)(const std::string&);
159 void call(yarpAudioPlayer_IDL* ptr);
160
163
164 static constexpr const char* s_tag{"play"};
165 static constexpr size_t s_tag_len{1};
166 static constexpr size_t s_cmd_len{2};
167 static constexpr size_t s_reply_len{1};
168 static constexpr const char* s_prototype{"bool yarpAudioPlayer_IDL::play(const std::string& filename)"};
169 static constexpr const char* s_help{
170 "Play the given audio file\n"
171 "@return true/false on success/failure"
172 };
173};
174
175// test helper class declaration
177 public yarp::os::Portable
178{
179public:
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);
182 bool write(yarp::os::ConnectionWriter& connection) const override;
183 bool read(yarp::os::ConnectionReader& connection) override;
184
185 class Command :
187 {
188 public:
189 Command() = default;
190 Command(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);
191
192 ~Command() override = default;
193
194 bool write(yarp::os::ConnectionWriter& connection) const override;
195 bool read(yarp::os::ConnectionReader& connection) override;
196
197 bool write(const yarp::os::idl::WireWriter& writer) const override;
198 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
199 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
200
201 bool read(yarp::os::idl::WireReader& reader) override;
204
205 std::string type{"sine"};
206 double duration{0.000000};
207 double frequency{0.000000};
208 std::int16_t amplitude{30000};
209 std::int16_t sampling_rate{16000};
210 std::int16_t channels{1};
211 };
212
213 class Reply :
215 {
216 public:
217 Reply() = default;
218 ~Reply() override = default;
219
220 bool write(yarp::os::ConnectionWriter& connection) const override;
221 bool read(yarp::os::ConnectionReader& connection) override;
222
223 bool write(const yarp::os::idl::WireWriter& writer) const override;
224 bool read(yarp::os::idl::WireReader& reader) override;
225
226 bool return_helper{false};
227 };
228
229 using funcptr_t = bool (*)(const std::string&, const double, const double, const std::int16_t, const std::int16_t, const std::int16_t);
230 void call(yarpAudioPlayer_IDL* ptr);
231
234
235 static constexpr const char* s_tag{"test"};
236 static constexpr size_t s_tag_len{1};
237 static constexpr size_t s_cmd_len{7};
238 static constexpr size_t s_reply_len{1};
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)"};
240 static constexpr const char* s_help{
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"
249 };
250};
251
252// play helper class implementation
254 cmd{filename}
255{
256}
257
259{
260 return cmd.write(connection);
261}
262
264{
265 return reply.read(connection);
266}
267
269 filename{filename}
270{
271}
272
274{
275 yarp::os::idl::WireWriter writer(connection);
276 if (!writer.writeListHeader(s_cmd_len)) {
277 return false;
278 }
279 return write(writer);
280}
281
283{
284 yarp::os::idl::WireReader reader(connection);
285 if (!reader.readListHeader()) {
286 reader.fail();
287 return false;
288 }
289 return read(reader);
290}
291
293{
294 if (!writeTag(writer)) {
295 return false;
296 }
297 if (!writeArgs(writer)) {
298 return false;
299 }
300 return true;
301}
302
304{
305 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
306 return false;
307 }
308 return true;
309}
310
312{
313 if (!writer.writeString(filename)) {
314 return false;
315 }
316 return true;
317}
318
320{
321 if (!readTag(reader)) {
322 return false;
323 }
324 if (!readArgs(reader)) {
325 return false;
326 }
327 return true;
328}
329
331{
332 std::string tag = reader.readTag(s_tag_len);
333 if (reader.isError()) {
334 return false;
335 }
336 if (tag != s_tag) {
337 reader.fail();
338 return false;
339 }
340 return true;
341}
342
344{
345 if (reader.noMore()) {
346 reader.fail();
347 return false;
348 }
349 if (!reader.readString(filename)) {
350 reader.fail();
351 return false;
352 }
353 if (!reader.noMore()) {
354 reader.fail();
355 return false;
356 }
357 return true;
358}
359
361{
362 yarp::os::idl::WireWriter writer(connection);
363 return write(writer);
364}
365
367{
368 yarp::os::idl::WireReader reader(connection);
369 return read(reader);
370}
371
373{
374 if (!writer.isNull()) {
375 if (!writer.writeListHeader(s_reply_len)) {
376 return false;
377 }
378 if (!writer.writeBool(return_helper)) {
379 return false;
380 }
381 }
382 return true;
383}
384
386{
387 if (!reader.readListReturn()) {
388 return false;
389 }
390 if (reader.noMore()) {
391 reader.fail();
392 return false;
393 }
394 if (!reader.readBool(return_helper)) {
395 reader.fail();
396 return false;
397 }
398 return true;
399}
400
405
406// test helper class implementation
407yarpAudioPlayer_IDL_test_helper::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) :
408 cmd{type, duration, frequency, amplitude, sampling_rate, channels}
409{
410}
411
413{
414 return cmd.write(connection);
415}
416
418{
419 return reply.read(connection);
420}
421
422yarpAudioPlayer_IDL_test_helper::Command::Command(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) :
423 type{type},
424 duration{duration},
425 frequency{frequency},
426 amplitude{amplitude},
427 sampling_rate{sampling_rate},
428 channels{channels}
429{
430}
431
433{
434 yarp::os::idl::WireWriter writer(connection);
435 if (!writer.writeListHeader(s_cmd_len)) {
436 return false;
437 }
438 return write(writer);
439}
440
442{
443 yarp::os::idl::WireReader reader(connection);
444 if (!reader.readListHeader()) {
445 reader.fail();
446 return false;
447 }
448 return read(reader);
449}
450
452{
453 if (!writeTag(writer)) {
454 return false;
455 }
456 if (!writeArgs(writer)) {
457 return false;
458 }
459 return true;
460}
461
463{
464 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
465 return false;
466 }
467 return true;
468}
469
471{
472 if (!writer.writeString(type)) {
473 return false;
474 }
475 if (!writer.writeFloat64(duration)) {
476 return false;
477 }
478 if (!writer.writeFloat64(frequency)) {
479 return false;
480 }
481 if (!writer.writeI16(amplitude)) {
482 return false;
483 }
484 if (!writer.writeI16(sampling_rate)) {
485 return false;
486 }
487 if (!writer.writeI16(channels)) {
488 return false;
489 }
490 return true;
491}
492
494{
495 if (!readTag(reader)) {
496 return false;
497 }
498 if (!readArgs(reader)) {
499 return false;
500 }
501 return true;
502}
503
505{
506 std::string tag = reader.readTag(s_tag_len);
507 if (reader.isError()) {
508 return false;
509 }
510 if (tag != s_tag) {
511 reader.fail();
512 return false;
513 }
514 return true;
515}
516
518{
519 if (!reader.readString(type)) {
520 type = "sine";
521 }
522 if (!reader.readFloat64(duration)) {
523 duration = 1;
524 }
525 if (!reader.readFloat64(frequency)) {
526 frequency = 440;
527 }
528 if (!reader.readI16(amplitude)) {
529 amplitude = 30000;
530 }
531 if (!reader.readI16(sampling_rate)) {
532 sampling_rate = 16000;
533 }
534 if (!reader.readI16(channels)) {
535 channels = 1;
536 }
537 if (!reader.noMore()) {
538 reader.fail();
539 return false;
540 }
541 return true;
542}
543
545{
546 yarp::os::idl::WireWriter writer(connection);
547 return write(writer);
548}
549
551{
552 yarp::os::idl::WireReader reader(connection);
553 return read(reader);
554}
555
557{
558 if (!writer.isNull()) {
559 if (!writer.writeListHeader(s_reply_len)) {
560 return false;
561 }
562 if (!writer.writeBool(return_helper)) {
563 return false;
564 }
565 }
566 return true;
567}
568
570{
571 if (!reader.readListReturn()) {
572 return false;
573 }
574 if (reader.noMore()) {
575 reader.fail();
576 return false;
577 }
578 if (!reader.readBool(return_helper)) {
579 reader.fail();
580 return false;
581 }
582 return true;
583}
584
589
590// Constructor
592{
593 yarp().setOwner(*this);
594}
595
596bool yarpAudioPlayer_IDL::play(const std::string& filename)
597{
598 if (!yarp().canWrite()) {
599 yError("Missing server method '%s'?", yarpAudioPlayer_IDL_play_helper::s_prototype);
600 }
601 yarpAudioPlayer_IDL_play_helper helper{filename};
602 bool ok = yarp().write(helper, helper);
603 return ok ? helper.reply.return_helper : bool{};
604}
605
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)
607{
608 if (!yarp().canWrite()) {
609 yError("Missing server method '%s'?", yarpAudioPlayer_IDL_test_helper::s_prototype);
610 }
611 yarpAudioPlayer_IDL_test_helper helper{type, duration, frequency, amplitude, sampling_rate, channels};
612 bool ok = yarp().write(helper, helper);
613 return ok ? helper.reply.return_helper : bool{};
614}
615
616// help method
617std::vector<std::string> yarpAudioPlayer_IDL::help(const std::string& functionName)
618{
619 bool showAll = (functionName == "--all");
620 std::vector<std::string> helpString;
621 if (showAll) {
622 helpString.emplace_back("*** Available commands:");
623 helpString.emplace_back(yarpAudioPlayer_IDL_play_helper::s_tag);
624 helpString.emplace_back(yarpAudioPlayer_IDL_test_helper::s_tag);
625 helpString.emplace_back("help");
626 } else {
627 if (functionName == yarpAudioPlayer_IDL_play_helper::s_tag) {
628 helpString.emplace_back(yarpAudioPlayer_IDL_play_helper::s_prototype);
629 helpString.emplace_back(yarpAudioPlayer_IDL_play_helper::s_help);
630 }
631 if (functionName == yarpAudioPlayer_IDL_test_helper::s_tag) {
632 helpString.emplace_back(yarpAudioPlayer_IDL_test_helper::s_prototype);
633 helpString.emplace_back(yarpAudioPlayer_IDL_test_helper::s_help);
634 }
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)");
640 }
641 }
642 if (helpString.empty()) {
643 helpString.emplace_back("Command not found");
644 }
645 return helpString;
646}
647
648// read from ConnectionReader
650{
651 constexpr size_t max_tag_len = 1;
652 size_t tag_len = 1;
653
654 yarp::os::idl::WireReader reader(connection);
655 reader.expectAccept();
656 if (!reader.readListHeader()) {
657 reader.fail();
658 return false;
659 }
660
661 std::string tag = reader.readTag(1);
662 bool direct = (tag == "__direct__");
663 if (direct) {
664 tag = reader.readTag(1);
665 }
666 while (tag_len <= max_tag_len && !reader.isError()) {
667 if(tag == "getRemoteProtocolVersion") {
668 if (!reader.noMore()) {
669 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
670 reader.fail();
671 return false;
672 }
673
674 auto proto = getLocalProtocolVersion();
675
676 yarp::os::idl::WireWriter writer(reader);
677 if (!writer.writeListHeader(1)) {
678 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
679 return false;}
680 if (!writer.write(proto)) {
681 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
682 return false;
683 }
684 reader.accept();
685 return true;
686 }
689 if (!helper.cmd.readArgs(reader)) {
690 return false;
691 }
692
693 helper.call(this);
694
695 yarp::os::idl::WireWriter writer(reader);
696 if (!helper.reply.write(writer)) {
697 return false;
698 }
699 reader.accept();
700 return true;
701 }
704 if (!helper.cmd.readArgs(reader)) {
705 return false;
706 }
707
708 helper.call(this);
709
710 yarp::os::idl::WireWriter writer(reader);
711 if (!helper.reply.write(writer)) {
712 return false;
713 }
714 reader.accept();
715 return true;
716 }
717 if (tag == "help") {
718 std::string functionName;
719 if (!reader.readString(functionName)) {
720 functionName = "--all";
721 }
722 auto help_strings = help(functionName);
723 yarp::os::idl::WireWriter writer(reader);
724 if (!writer.isNull()) {
725 if (!writer.writeListHeader(2)) {
726 return false;
727 }
728 if (!writer.writeTag("many", 1, 0)) {
729 return false;
730 }
731 if (!writer.writeListBegin(0, help_strings.size())) {
732 return false;
733 }
734 for (const auto& help_string : help_strings) {
735 if (!writer.writeString(help_string)) {
736 return false;
737 }
738 }
739 if (!writer.writeListEnd()) {
740 return false;
741 }
742 }
743 reader.accept();
744 return true;
745 }
746 if (reader.noMore()) {
747 reader.fail();
748 return false;
749 }
750 std::string next_tag = reader.readTag(1);
751 if (next_tag.empty()) {
752 break;
753 }
754 tag.append("_").append(next_tag);
755 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
756 }
757 return false;
758}
#define yError(...)
Definition Log.h:361
#define __YFUNCTION__
Definition Log.h:24
#define yWarning(...)
Definition Log.h:340
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
yarp::os::ApplicationNetworkProtocolVersion helper_proto
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.
bool readTag(yarp::os::idl::WireReader &reader)
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 const char * s_tag
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.
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 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.
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
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.
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.
Definition Portable.h:25
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
IDL-friendly connection reader.
Definition WireReader.h:27
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.
Definition WireWriter.h:28
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 writeListBegin(int tag, size_t len) const
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
The main, catch-all namespace for YARP.
Definition dirs.h:16
#define YARP_VERSION_PATCH
Definition version.h:12
#define YARP_VERSION_MAJOR
Definition version.h:10
#define YARP_VERSION_MINOR
Definition version.h:11