YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ISpeechTranscriptionMsgs.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 Compiler (0.14.1-yarped)
7//
8// This is an automatically generated file.
9// It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
10
12
14
15#include <algorithm>
16
17// set_language helper class declaration
20{
21public:
23 explicit ISpeechTranscriptionMsgs_set_language_helper(const std::string& language);
24 bool write(yarp::os::ConnectionWriter& connection) const override;
25 bool read(yarp::os::ConnectionReader& connection) override;
26
27 class Command :
29 {
30 public:
31 Command() = default;
32 explicit Command(const std::string& language);
33
34 ~Command() override = default;
35
36 bool write(yarp::os::ConnectionWriter& connection) const override;
37 bool read(yarp::os::ConnectionReader& connection) override;
38
39 bool write(const yarp::os::idl::WireWriter& writer) const override;
40 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
41 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
42
43 bool read(yarp::os::idl::WireReader& reader) override;
46
47 std::string language{};
48 };
49
50 class Reply :
52 {
53 public:
54 Reply() = default;
55 ~Reply() override = default;
56
57 bool write(yarp::os::ConnectionWriter& connection) const override;
58 bool read(yarp::os::ConnectionReader& connection) override;
59
60 bool write(const yarp::os::idl::WireWriter& writer) const override;
61 bool read(yarp::os::idl::WireReader& reader) override;
62
63 bool return_helper{false};
64 };
65
66 using funcptr_t = bool (*)(const std::string&);
68
71
72 static constexpr const char* s_tag{"set_language"};
73 static constexpr size_t s_tag_len{2};
74 static constexpr size_t s_cmd_len{3};
75 static constexpr size_t s_reply_len{1};
76 static constexpr const char* s_prototype{"bool ISpeechTranscriptionMsgs::set_language(const std::string& language)"};
77 static constexpr const char* s_help{""};
78};
79
80// get_language helper class declaration
83{
84public:
86 bool write(yarp::os::ConnectionWriter& connection) const override;
87 bool read(yarp::os::ConnectionReader& connection) override;
88
89 class Command :
91 {
92 public:
93 Command() = default;
94 ~Command() override = default;
95
96 bool write(yarp::os::ConnectionWriter& connection) const override;
97 bool read(yarp::os::ConnectionReader& connection) override;
98
99 bool write(const yarp::os::idl::WireWriter& writer) const override;
100 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
101 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
102
103 bool read(yarp::os::idl::WireReader& reader) override;
106 };
107
108 class Reply :
110 {
111 public:
112 Reply() = default;
113 ~Reply() override = default;
114
115 bool write(yarp::os::ConnectionWriter& connection) const override;
116 bool read(yarp::os::ConnectionReader& connection) override;
117
118 bool write(const yarp::os::idl::WireWriter& writer) const override;
119 bool read(yarp::os::idl::WireReader& reader) override;
120
122 };
123
126
129
130 static constexpr const char* s_tag{"get_language"};
131 static constexpr size_t s_tag_len{2};
132 static constexpr size_t s_cmd_len{2};
133 static constexpr size_t s_reply_len{2};
134 static constexpr const char* s_prototype{"return_get_language ISpeechTranscriptionMsgs::get_language()"};
135 static constexpr const char* s_help{""};
136};
137
138// transcribe helper class declaration
140 public yarp::os::Portable
141{
142public:
145 bool write(yarp::os::ConnectionWriter& connection) const override;
146 bool read(yarp::os::ConnectionReader& connection) override;
147
148 class Command :
150 {
151 public:
152 Command() = default;
153 explicit Command(const yarp::sig::Sound& sound);
154
155 ~Command() override = default;
156
157 bool write(yarp::os::ConnectionWriter& connection) const override;
158 bool read(yarp::os::ConnectionReader& connection) override;
159
160 bool write(const yarp::os::idl::WireWriter& writer) const override;
161 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
162 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
163
164 bool read(yarp::os::idl::WireReader& reader) override;
167
169 };
170
171 class Reply :
173 {
174 public:
175 Reply() = default;
176 ~Reply() override = default;
177
178 bool write(yarp::os::ConnectionWriter& connection) const override;
179 bool read(yarp::os::ConnectionReader& connection) override;
180
181 bool write(const yarp::os::idl::WireWriter& writer) const override;
182 bool read(yarp::os::idl::WireReader& reader) override;
183
185 };
186
189
192
193 static constexpr const char* s_tag{"transcribe"};
194 static constexpr size_t s_tag_len{1};
195 static constexpr size_t s_cmd_len{2};
196 static constexpr size_t s_reply_len{3};
197 static constexpr const char* s_prototype{"return_transcribe ISpeechTranscriptionMsgs::transcribe(const yarp::sig::Sound& sound)"};
198 static constexpr const char* s_help{""};
199};
200
201// set_language helper class implementation
206
208{
209 return cmd.write(connection);
210}
211
216
218 language{language}
219{
220}
221
223{
224 yarp::os::idl::WireWriter writer(connection);
225 if (!writer.writeListHeader(s_cmd_len)) {
226 return false;
227 }
228 return write(writer);
229}
230
232{
233 yarp::os::idl::WireReader reader(connection);
234 if (!reader.readListHeader()) {
235 reader.fail();
236 return false;
237 }
238 return read(reader);
239}
240
242{
243 if (!writeTag(writer)) {
244 return false;
245 }
246 if (!writeArgs(writer)) {
247 return false;
248 }
249 return true;
250}
251
253{
254 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
255 return false;
256 }
257 return true;
258}
259
261{
262 if (!writer.writeString(language)) {
263 return false;
264 }
265 return true;
266}
267
269{
270 if (!readTag(reader)) {
271 return false;
272 }
273 if (!readArgs(reader)) {
274 return false;
275 }
276 return true;
277}
278
280{
281 std::string tag = reader.readTag(s_tag_len);
282 if (reader.isError()) {
283 return false;
284 }
285 if (tag != s_tag) {
286 reader.fail();
287 return false;
288 }
289 return true;
290}
291
293{
294 if (reader.noMore()) {
295 reader.fail();
296 return false;
297 }
298 if (!reader.readString(language)) {
299 reader.fail();
300 return false;
301 }
302 if (!reader.noMore()) {
303 reader.fail();
304 return false;
305 }
306 return true;
307}
308
310{
311 yarp::os::idl::WireWriter writer(connection);
312 return write(writer);
313}
314
320
322{
323 if (!writer.isNull()) {
324 if (!writer.writeListHeader(s_reply_len)) {
325 return false;
326 }
327 if (!writer.writeBool(return_helper)) {
328 return false;
329 }
330 }
331 return true;
332}
333
335{
336 if (!reader.readListReturn()) {
337 return false;
338 }
339 if (reader.noMore()) {
340 reader.fail();
341 return false;
342 }
343 if (!reader.readBool(return_helper)) {
344 reader.fail();
345 return false;
346 }
347 return true;
348}
349
354
355// get_language helper class implementation
357{
358 return cmd.write(connection);
359}
360
365
367{
368 yarp::os::idl::WireWriter writer(connection);
369 if (!writer.writeListHeader(s_cmd_len)) {
370 return false;
371 }
372 return write(writer);
373}
374
376{
377 yarp::os::idl::WireReader reader(connection);
378 if (!reader.readListHeader()) {
379 reader.fail();
380 return false;
381 }
382 return read(reader);
383}
384
386{
387 if (!writeTag(writer)) {
388 return false;
389 }
390 if (!writeArgs(writer)) {
391 return false;
392 }
393 return true;
394}
395
397{
398 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
399 return false;
400 }
401 return true;
402}
403
405{
406 return true;
407}
408
410{
411 if (!readTag(reader)) {
412 return false;
413 }
414 if (!readArgs(reader)) {
415 return false;
416 }
417 return true;
418}
419
421{
422 std::string tag = reader.readTag(s_tag_len);
423 if (reader.isError()) {
424 return false;
425 }
426 if (tag != s_tag) {
427 reader.fail();
428 return false;
429 }
430 return true;
431}
432
434{
435 if (!reader.noMore()) {
436 reader.fail();
437 return false;
438 }
439 return true;
440}
441
443{
444 yarp::os::idl::WireWriter writer(connection);
445 return write(writer);
446}
447
453
455{
456 if (!writer.isNull()) {
457 if (!writer.writeListHeader(s_reply_len)) {
458 return false;
459 }
460 if (!writer.write(return_helper)) {
461 return false;
462 }
463 }
464 return true;
465}
466
468{
469 if (!reader.readListReturn()) {
470 return false;
471 }
472 if (reader.noMore()) {
473 reader.fail();
474 return false;
475 }
476 if (!reader.read(return_helper)) {
477 reader.fail();
478 return false;
479 }
480 return true;
481}
482
487
488// transcribe helper class implementation
493
495{
496 return cmd.write(connection);
497}
498
503
508
510{
511 yarp::os::idl::WireWriter writer(connection);
512 if (!writer.writeListHeader(s_cmd_len)) {
513 return false;
514 }
515 return write(writer);
516}
517
519{
520 yarp::os::idl::WireReader reader(connection);
521 if (!reader.readListHeader()) {
522 reader.fail();
523 return false;
524 }
525 return read(reader);
526}
527
529{
530 if (!writeTag(writer)) {
531 return false;
532 }
533 if (!writeArgs(writer)) {
534 return false;
535 }
536 return true;
537}
538
540{
541 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
542 return false;
543 }
544 return true;
545}
546
548{
549 if (!writer.writeNested(sound)) {
550 return false;
551 }
552 return true;
553}
554
556{
557 if (!readTag(reader)) {
558 return false;
559 }
560 if (!readArgs(reader)) {
561 return false;
562 }
563 return true;
564}
565
567{
568 std::string tag = reader.readTag(s_tag_len);
569 if (reader.isError()) {
570 return false;
571 }
572 if (tag != s_tag) {
573 reader.fail();
574 return false;
575 }
576 return true;
577}
578
580{
581 if (reader.noMore()) {
582 reader.fail();
583 return false;
584 }
585 if (!reader.readNested(sound)) {
586 reader.fail();
587 return false;
588 }
589 if (!reader.noMore()) {
590 reader.fail();
591 return false;
592 }
593 return true;
594}
595
597{
598 yarp::os::idl::WireWriter writer(connection);
599 return write(writer);
600}
601
603{
604 yarp::os::idl::WireReader reader(connection);
605 return read(reader);
606}
607
609{
610 if (!writer.isNull()) {
611 if (!writer.writeListHeader(s_reply_len)) {
612 return false;
613 }
614 if (!writer.write(return_helper)) {
615 return false;
616 }
617 }
618 return true;
619}
620
622{
623 if (!reader.readListReturn()) {
624 return false;
625 }
626 if (reader.noMore()) {
627 reader.fail();
628 return false;
629 }
630 if (!reader.read(return_helper)) {
631 reader.fail();
632 return false;
633 }
634 return true;
635}
636
641
642// Constructor
647
648bool ISpeechTranscriptionMsgs::set_language(const std::string& language)
649{
650 if (!yarp().canWrite()) {
652 }
654 bool ok = yarp().write(helper, helper);
655 return ok ? helper.reply.return_helper : bool{};
656}
657
659{
660 if (!yarp().canWrite()) {
662 }
664 bool ok = yarp().write(helper, helper);
665 return ok ? helper.reply.return_helper : return_get_language{};
666}
667
669{
670 if (!yarp().canWrite()) {
672 }
674 bool ok = yarp().write(helper, helper);
675 return ok ? helper.reply.return_helper : return_transcribe{};
676}
677
678// help method
679std::vector<std::string> ISpeechTranscriptionMsgs::help(const std::string& functionName)
680{
681 bool showAll = (functionName == "--all");
682 std::vector<std::string> helpString;
683 if (showAll) {
684 helpString.emplace_back("*** Available commands:");
688 helpString.emplace_back("help");
689 } else {
692 }
695 }
698 }
699 if (functionName == "help") {
700 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
701 helpString.emplace_back("Return list of available commands, or help message for a specific function");
702 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");
703 helpString.emplace_back("@return list of strings (one string per line)");
704 }
705 }
706 if (helpString.empty()) {
707 helpString.emplace_back("Command not found");
708 }
709 return helpString;
710}
711
712// read from ConnectionReader
714{
715 constexpr size_t max_tag_len = 2;
716 size_t tag_len = 1;
717
718 yarp::os::idl::WireReader reader(connection);
719 reader.expectAccept();
720 if (!reader.readListHeader()) {
721 reader.fail();
722 return false;
723 }
724
725 std::string tag = reader.readTag(1);
726 bool direct = (tag == "__direct__");
727 if (direct) {
728 tag = reader.readTag(1);
729 }
730 while (tag_len <= max_tag_len && !reader.isError()) {
733 if (!helper.cmd.readArgs(reader)) {
734 return false;
735 }
736
737 helper.call(this);
738
739 yarp::os::idl::WireWriter writer(reader);
740 if (!helper.reply.write(writer)) {
741 return false;
742 }
743 reader.accept();
744 return true;
745 }
748 if (!helper.cmd.readArgs(reader)) {
749 return false;
750 }
751
752 helper.call(this);
753
754 yarp::os::idl::WireWriter writer(reader);
755 if (!helper.reply.write(writer)) {
756 return false;
757 }
758 reader.accept();
759 return true;
760 }
763 if (!helper.cmd.readArgs(reader)) {
764 return false;
765 }
766
767 helper.call(this);
768
769 yarp::os::idl::WireWriter writer(reader);
770 if (!helper.reply.write(writer)) {
771 return false;
772 }
773 reader.accept();
774 return true;
775 }
776 if (tag == "help") {
777 std::string functionName;
778 if (!reader.readString(functionName)) {
779 functionName = "--all";
780 }
781 auto help_strings = help(functionName);
782 yarp::os::idl::WireWriter writer(reader);
783 if (!writer.isNull()) {
784 if (!writer.writeListHeader(2)) {
785 return false;
786 }
787 if (!writer.writeTag("many", 1, 0)) {
788 return false;
789 }
790 if (!writer.writeListBegin(0, help_strings.size())) {
791 return false;
792 }
793 for (const auto& help_string : help_strings) {
794 if (!writer.writeString(help_string)) {
795 return false;
796 }
797 }
798 if (!writer.writeListEnd()) {
799 return false;
800 }
801 }
802 reader.accept();
803 return true;
804 }
805 if (reader.noMore()) {
806 reader.fail();
807 return false;
808 }
809 std::string next_tag = reader.readTag(1);
810 if (next_tag.empty()) {
811 break;
812 }
813 tag.append("_").append(next_tag);
814 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
815 }
816 return false;
817}
#define yError(...)
Definition Log.h:361
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.
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
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 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 writeTag(const yarp::os::idl::WireWriter &writer) const
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 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.
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.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from 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 writeArgs(const yarp::os::idl::WireWriter &writer) const
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 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 write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
return_transcribe(*)(const yarp::sig::Sound &) funcptr_t
virtual return_transcribe transcribe(const yarp::sig::Sound &sound)
virtual bool set_language(const std::string &language)
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
virtual return_get_language get_language()
virtual std::vector< std::string > help(const std::string &functionName="--all")
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
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
IDL-friendly connection reader.
Definition WireReader.h:27
bool readNested(WirePortable &obj)
bool readString(std::string &str, bool *is_vocab=nullptr)
std::string readTag(size_t len=static_cast< size_t >(-1))
bool read(WirePortable &obj)
IDL-friendly connection writer.
Definition WireWriter.h:28
bool writeBool(bool x, bool skip_tag=false) const
bool write(const WirePortable &obj) const
bool writeListHeader(int len) const
bool writeTag(const char *tag, int split, int len) const
bool writeString(const std::string &str, bool skip_tag=false) const
bool writeNested(const WirePortable &obj) const
bool writeListBegin(int tag, size_t len) const
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition Sound.h:25
The main, catch-all namespace for YARP.
Definition dirs.h:16