YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ILLMMsgs.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
11#include <yarp/conf/version.h>
14#include <yarp/os/LogStream.h>
15
17
18#include <algorithm>
19
20namespace
21{
22 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "ILLMMsgs")
23}
24
25namespace yarp::dev::llm {
26
27//ILLMMsgs_getRemoteProtocolVersion_helper declaration
38
40{
41 yarp::os::idl::WireWriter writer(connection);
42 if (!writer.writeListHeader(1)) {
43 return false;
44 }
45 if (!writer.writeString("getRemoteProtocolVersion")) {
46 return false;
47 }
48 return true;
49}
50
51bool ILLMMsgs_getRemoteProtocolVersion_helper ::read(yarp::os::ConnectionReader & connection)
52 {
53 yarp::os::idl::WireReader reader(connection);
54 if (!reader.readListHeader()) {
55 reader.fail();
56 return false;
57 }
58
59 if (!helper_proto.read(connection)) {
60 reader.fail();
61 return false;
62 }
63 return true;
64}
65
66//ProtocolVersion, client side
68 {
69 if(!yarp().canWrite()) {
70 yError(" Missing server method ILLMMsgs::getRemoteProtocolVersion");
71 }
73 bool ok = yarp().write(helper, helper);
74 if (ok) {
75 return helper.helper_proto;}
76 else {
78 return failureproto;}
79}
80
81//ProtocolVersion, client side
83 {
84 auto locproto = this->getLocalProtocolVersion();
85 auto remproto = this->getRemoteProtocolVersion();
86 if (remproto.protocol_version != locproto.protocol_version)
87 {
88 yCError(SERVICE_LOG_COMPONENT) << "Invalid communication protocol.";
89 yCError(SERVICE_LOG_COMPONENT) << "Local Protocol Version: " << locproto.toString();
90 yCError(SERVICE_LOG_COMPONENT) << "Remote Protocol Version: " << remproto.toString();
91 return false;
92 }
93 return true;
94}
95
96//ProtocolVersion, server side
98{
100 //myproto.protocol_version using default value = 0
101 //to change this value add the following line to the .thrift file:
102 //const i16 protocol_version = <your_number_here>
103 myproto.protocol_version = 0;
107 return myproto;
108}
109
110// setPrompt helper class declaration
112 public yarp::os::Portable
113{
114public:
116 explicit ILLMMsgs_setPrompt_helper(const std::string& prompt);
117 bool write(yarp::os::ConnectionWriter& connection) const override;
118 bool read(yarp::os::ConnectionReader& connection) override;
119
120 class Command :
122 {
123 public:
124 Command() = default;
125 explicit Command(const std::string& prompt);
126
127 ~Command() override = default;
128
129 bool write(yarp::os::ConnectionWriter& connection) const override;
130 bool read(yarp::os::ConnectionReader& connection) override;
131
132 bool write(const yarp::os::idl::WireWriter& writer) const override;
133 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
134 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
135
136 bool read(yarp::os::idl::WireReader& reader) override;
139
140 std::string prompt{};
141 };
142
143 class Reply :
145 {
146 public:
147 Reply() = default;
148 ~Reply() override = default;
149
150 bool write(yarp::os::ConnectionWriter& connection) const override;
151 bool read(yarp::os::ConnectionReader& connection) override;
152
153 bool write(const yarp::os::idl::WireWriter& writer) const override;
154 bool read(yarp::os::idl::WireReader& reader) override;
155
157 };
158
159 using funcptr_t = yarp::dev::ReturnValue (*)(const std::string&);
160 void call(ILLMMsgs* ptr);
161
164
165 static constexpr const char* s_tag{"setPrompt"};
166 static constexpr size_t s_tag_len{1};
167 static constexpr size_t s_cmd_len{2};
168 static constexpr size_t s_reply_len{1};
169 static constexpr const char* s_prototype{"yarp::dev::ReturnValue ILLMMsgs::setPrompt(const std::string& prompt)"};
170 static constexpr const char* s_help{""};
171};
172
173// readPrompt helper class declaration
175 public yarp::os::Portable
176{
177public:
179 bool write(yarp::os::ConnectionWriter& connection) const override;
180 bool read(yarp::os::ConnectionReader& connection) override;
181
182 class Command :
184 {
185 public:
186 Command() = default;
187 ~Command() override = default;
188
189 bool write(yarp::os::ConnectionWriter& connection) const override;
190 bool read(yarp::os::ConnectionReader& connection) override;
191
192 bool write(const yarp::os::idl::WireWriter& writer) const override;
193 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
194 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
195
196 bool read(yarp::os::idl::WireReader& reader) override;
199 };
200
201 class Reply :
203 {
204 public:
205 Reply() = default;
206 ~Reply() override = default;
207
208 bool write(yarp::os::ConnectionWriter& connection) const override;
209 bool read(yarp::os::ConnectionReader& connection) override;
210
211 bool write(const yarp::os::idl::WireWriter& writer) const override;
212 bool read(yarp::os::idl::WireReader& reader) override;
213
215 };
216
218 void call(ILLMMsgs* ptr);
219
222
223 static constexpr const char* s_tag{"readPrompt"};
224 static constexpr size_t s_tag_len{1};
225 static constexpr size_t s_cmd_len{1};
226 static constexpr size_t s_reply_len{2};
227 static constexpr const char* s_prototype{"return_readPrompt ILLMMsgs::readPrompt()"};
228 static constexpr const char* s_help{""};
229};
230
231// ask helper class declaration
233 public yarp::os::Portable
234{
235public:
237 explicit ILLMMsgs_ask_helper(const std::string& question);
238 bool write(yarp::os::ConnectionWriter& connection) const override;
239 bool read(yarp::os::ConnectionReader& connection) override;
240
241 class Command :
243 {
244 public:
245 Command() = default;
246 explicit Command(const std::string& question);
247
248 ~Command() override = default;
249
250 bool write(yarp::os::ConnectionWriter& connection) const override;
251 bool read(yarp::os::ConnectionReader& connection) override;
252
253 bool write(const yarp::os::idl::WireWriter& writer) const override;
254 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
255 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
256
257 bool read(yarp::os::idl::WireReader& reader) override;
260
261 std::string question{};
262 };
263
264 class Reply :
266 {
267 public:
268 Reply() = default;
269 ~Reply() override = default;
270
271 bool write(yarp::os::ConnectionWriter& connection) const override;
272 bool read(yarp::os::ConnectionReader& connection) override;
273
274 bool write(const yarp::os::idl::WireWriter& writer) const override;
275 bool read(yarp::os::idl::WireReader& reader) override;
276
278 };
279
280 using funcptr_t = return_ask (*)(const std::string&);
281 void call(ILLMMsgs* ptr);
282
285
286 static constexpr const char* s_tag{"ask"};
287 static constexpr size_t s_tag_len{1};
288 static constexpr size_t s_cmd_len{2};
289 static constexpr size_t s_reply_len{2};
290 static constexpr const char* s_prototype{"return_ask ILLMMsgs::ask(const std::string& question)"};
291 static constexpr const char* s_help{""};
292};
293
294// getConversation helper class declaration
296 public yarp::os::Portable
297{
298public:
300 bool write(yarp::os::ConnectionWriter& connection) const override;
301 bool read(yarp::os::ConnectionReader& connection) override;
302
303 class Command :
305 {
306 public:
307 Command() = default;
308 ~Command() override = default;
309
310 bool write(yarp::os::ConnectionWriter& connection) const override;
311 bool read(yarp::os::ConnectionReader& connection) override;
312
313 bool write(const yarp::os::idl::WireWriter& writer) const override;
314 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
315 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
316
317 bool read(yarp::os::idl::WireReader& reader) override;
320 };
321
322 class Reply :
324 {
325 public:
326 Reply() = default;
327 ~Reply() override = default;
328
329 bool write(yarp::os::ConnectionWriter& connection) const override;
330 bool read(yarp::os::ConnectionReader& connection) override;
331
332 bool write(const yarp::os::idl::WireWriter& writer) const override;
333 bool read(yarp::os::idl::WireReader& reader) override;
334
336 };
337
339 void call(ILLMMsgs* ptr);
340
343
344 static constexpr const char* s_tag{"getConversation"};
345 static constexpr size_t s_tag_len{1};
346 static constexpr size_t s_cmd_len{1};
347 static constexpr size_t s_reply_len{2};
348 static constexpr const char* s_prototype{"return_getConversation ILLMMsgs::getConversation()"};
349 static constexpr const char* s_help{""};
350};
351
352// deleteConversation helper class declaration
354 public yarp::os::Portable
355{
356public:
358 bool write(yarp::os::ConnectionWriter& connection) const override;
359 bool read(yarp::os::ConnectionReader& connection) override;
360
361 class Command :
363 {
364 public:
365 Command() = default;
366 ~Command() override = default;
367
368 bool write(yarp::os::ConnectionWriter& connection) const override;
369 bool read(yarp::os::ConnectionReader& connection) override;
370
371 bool write(const yarp::os::idl::WireWriter& writer) const override;
372 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
373 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
374
375 bool read(yarp::os::idl::WireReader& reader) override;
378 };
379
380 class Reply :
382 {
383 public:
384 Reply() = default;
385 ~Reply() override = default;
386
387 bool write(yarp::os::ConnectionWriter& connection) const override;
388 bool read(yarp::os::ConnectionReader& connection) override;
389
390 bool write(const yarp::os::idl::WireWriter& writer) const override;
391 bool read(yarp::os::idl::WireReader& reader) override;
392
394 };
395
397 void call(ILLMMsgs* ptr);
398
401
402 static constexpr const char* s_tag{"deleteConversation"};
403 static constexpr size_t s_tag_len{1};
404 static constexpr size_t s_cmd_len{1};
405 static constexpr size_t s_reply_len{1};
406 static constexpr const char* s_prototype{"yarp::dev::ReturnValue ILLMMsgs::deleteConversation()"};
407 static constexpr const char* s_help{""};
408};
409
410// refreshConversation helper class declaration
412 public yarp::os::Portable
413{
414public:
416 bool write(yarp::os::ConnectionWriter& connection) const override;
417 bool read(yarp::os::ConnectionReader& connection) override;
418
419 class Command :
421 {
422 public:
423 Command() = default;
424 ~Command() override = default;
425
426 bool write(yarp::os::ConnectionWriter& connection) const override;
427 bool read(yarp::os::ConnectionReader& connection) override;
428
429 bool write(const yarp::os::idl::WireWriter& writer) const override;
430 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
431 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
432
433 bool read(yarp::os::idl::WireReader& reader) override;
436 };
437
438 class Reply :
440 {
441 public:
442 Reply() = default;
443 ~Reply() override = default;
444
445 bool write(yarp::os::ConnectionWriter& connection) const override;
446 bool read(yarp::os::ConnectionReader& connection) override;
447
448 bool write(const yarp::os::idl::WireWriter& writer) const override;
449 bool read(yarp::os::idl::WireReader& reader) override;
450
452 };
453
455 void call(ILLMMsgs* ptr);
456
459
460 static constexpr const char* s_tag{"refreshConversation"};
461 static constexpr size_t s_tag_len{1};
462 static constexpr size_t s_cmd_len{1};
463 static constexpr size_t s_reply_len{1};
464 static constexpr const char* s_prototype{"yarp::dev::ReturnValue ILLMMsgs::refreshConversation()"};
465 static constexpr const char* s_help{""};
466};
467
468// setPrompt helper class implementation
470 cmd{prompt}
471{
472}
473
475{
476 return cmd.write(connection);
477}
478
480{
481 return reply.read(connection);
482}
483
485 prompt{prompt}
486{
487}
488
490{
491 yarp::os::idl::WireWriter writer(connection);
492 if (!writer.writeListHeader(s_cmd_len)) {
493 return false;
494 }
495 return write(writer);
496}
497
499{
500 yarp::os::idl::WireReader reader(connection);
501 if (!reader.readListHeader()) {
502 reader.fail();
503 return false;
504 }
505 return read(reader);
506}
507
509{
510 if (!writeTag(writer)) {
511 return false;
512 }
513 if (!writeArgs(writer)) {
514 return false;
515 }
516 return true;
517}
518
520{
521 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
522 return false;
523 }
524 return true;
525}
526
528{
529 if (!writer.writeString(prompt)) {
530 return false;
531 }
532 return true;
533}
534
536{
537 if (!readTag(reader)) {
538 return false;
539 }
540 if (!readArgs(reader)) {
541 return false;
542 }
543 return true;
544}
545
547{
548 std::string tag = reader.readTag(s_tag_len);
549 if (reader.isError()) {
550 return false;
551 }
552 if (tag != s_tag) {
553 reader.fail();
554 return false;
555 }
556 return true;
557}
558
560{
561 if (reader.noMore()) {
562 reader.fail();
563 return false;
564 }
565 if (!reader.readString(prompt)) {
566 reader.fail();
567 return false;
568 }
569 if (!reader.noMore()) {
570 reader.fail();
571 return false;
572 }
573 return true;
574}
575
577{
578 yarp::os::idl::WireWriter writer(connection);
579 return write(writer);
580}
581
583{
584 yarp::os::idl::WireReader reader(connection);
585 return read(reader);
586}
587
589{
590 if (!writer.isNull()) {
591 if (!writer.write(return_helper)) {
592 return false;
593 }
594 }
595 return true;
596}
597
599{
600 if (reader.noMore()) {
601 reader.fail();
602 return false;
603 }
604 if (!reader.read(return_helper)) {
605 reader.fail();
606 return false;
607 }
608 return true;
609}
610
615
616// readPrompt helper class implementation
618{
619 return cmd.write(connection);
620}
621
623{
624 return reply.read(connection);
625}
626
628{
629 yarp::os::idl::WireWriter writer(connection);
630 if (!writer.writeListHeader(s_cmd_len)) {
631 return false;
632 }
633 return write(writer);
634}
635
637{
638 yarp::os::idl::WireReader reader(connection);
639 if (!reader.readListHeader()) {
640 reader.fail();
641 return false;
642 }
643 return read(reader);
644}
645
647{
648 if (!writeTag(writer)) {
649 return false;
650 }
651 if (!writeArgs(writer)) {
652 return false;
653 }
654 return true;
655}
656
658{
659 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
660 return false;
661 }
662 return true;
663}
664
666{
667 return true;
668}
669
671{
672 if (!readTag(reader)) {
673 return false;
674 }
675 if (!readArgs(reader)) {
676 return false;
677 }
678 return true;
679}
680
682{
683 std::string tag = reader.readTag(s_tag_len);
684 if (reader.isError()) {
685 return false;
686 }
687 if (tag != s_tag) {
688 reader.fail();
689 return false;
690 }
691 return true;
692}
693
695{
696 if (!reader.noMore()) {
697 reader.fail();
698 return false;
699 }
700 return true;
701}
702
704{
705 yarp::os::idl::WireWriter writer(connection);
706 return write(writer);
707}
708
710{
711 yarp::os::idl::WireReader reader(connection);
712 return read(reader);
713}
714
716{
717 if (!writer.isNull()) {
718 if (!writer.writeListHeader(s_reply_len)) {
719 return false;
720 }
721 if (!writer.write(return_helper)) {
722 return false;
723 }
724 }
725 return true;
726}
727
729{
730 if (!reader.readListReturn()) {
731 return false;
732 }
733 if (reader.noMore()) {
734 reader.fail();
735 return false;
736 }
737 if (!reader.read(return_helper)) {
738 reader.fail();
739 return false;
740 }
741 return true;
742}
743
748
749// ask helper class implementation
750ILLMMsgs_ask_helper::ILLMMsgs_ask_helper(const std::string& question) :
751 cmd{question}
752{
753}
754
756{
757 return cmd.write(connection);
758}
759
761{
762 return reply.read(connection);
763}
764
765ILLMMsgs_ask_helper::Command::Command(const std::string& question) :
766 question{question}
767{
768}
769
771{
772 yarp::os::idl::WireWriter writer(connection);
773 if (!writer.writeListHeader(s_cmd_len)) {
774 return false;
775 }
776 return write(writer);
777}
778
780{
781 yarp::os::idl::WireReader reader(connection);
782 if (!reader.readListHeader()) {
783 reader.fail();
784 return false;
785 }
786 return read(reader);
787}
788
790{
791 if (!writeTag(writer)) {
792 return false;
793 }
794 if (!writeArgs(writer)) {
795 return false;
796 }
797 return true;
798}
799
801{
802 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
803 return false;
804 }
805 return true;
806}
807
809{
810 if (!writer.writeString(question)) {
811 return false;
812 }
813 return true;
814}
815
817{
818 if (!readTag(reader)) {
819 return false;
820 }
821 if (!readArgs(reader)) {
822 return false;
823 }
824 return true;
825}
826
828{
829 std::string tag = reader.readTag(s_tag_len);
830 if (reader.isError()) {
831 return false;
832 }
833 if (tag != s_tag) {
834 reader.fail();
835 return false;
836 }
837 return true;
838}
839
841{
842 if (reader.noMore()) {
843 reader.fail();
844 return false;
845 }
846 if (!reader.readString(question)) {
847 reader.fail();
848 return false;
849 }
850 if (!reader.noMore()) {
851 reader.fail();
852 return false;
853 }
854 return true;
855}
856
858{
859 yarp::os::idl::WireWriter writer(connection);
860 return write(writer);
861}
862
864{
865 yarp::os::idl::WireReader reader(connection);
866 return read(reader);
867}
868
870{
871 if (!writer.isNull()) {
872 if (!writer.writeListHeader(s_reply_len)) {
873 return false;
874 }
875 if (!writer.write(return_helper)) {
876 return false;
877 }
878 }
879 return true;
880}
881
883{
884 if (!reader.readListReturn()) {
885 return false;
886 }
887 if (reader.noMore()) {
888 reader.fail();
889 return false;
890 }
891 if (!reader.read(return_helper)) {
892 reader.fail();
893 return false;
894 }
895 return true;
896}
897
902
903// getConversation helper class implementation
905{
906 return cmd.write(connection);
907}
908
910{
911 return reply.read(connection);
912}
913
915{
916 yarp::os::idl::WireWriter writer(connection);
917 if (!writer.writeListHeader(s_cmd_len)) {
918 return false;
919 }
920 return write(writer);
921}
922
924{
925 yarp::os::idl::WireReader reader(connection);
926 if (!reader.readListHeader()) {
927 reader.fail();
928 return false;
929 }
930 return read(reader);
931}
932
934{
935 if (!writeTag(writer)) {
936 return false;
937 }
938 if (!writeArgs(writer)) {
939 return false;
940 }
941 return true;
942}
943
945{
946 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
947 return false;
948 }
949 return true;
950}
951
953{
954 return true;
955}
956
958{
959 if (!readTag(reader)) {
960 return false;
961 }
962 if (!readArgs(reader)) {
963 return false;
964 }
965 return true;
966}
967
969{
970 std::string tag = reader.readTag(s_tag_len);
971 if (reader.isError()) {
972 return false;
973 }
974 if (tag != s_tag) {
975 reader.fail();
976 return false;
977 }
978 return true;
979}
980
982{
983 if (!reader.noMore()) {
984 reader.fail();
985 return false;
986 }
987 return true;
988}
989
991{
992 yarp::os::idl::WireWriter writer(connection);
993 return write(writer);
994}
995
997{
998 yarp::os::idl::WireReader reader(connection);
999 return read(reader);
1000}
1001
1003{
1004 if (!writer.isNull()) {
1005 if (!writer.writeListHeader(s_reply_len)) {
1006 return false;
1007 }
1008 if (!writer.write(return_helper)) {
1009 return false;
1010 }
1011 }
1012 return true;
1013}
1014
1016{
1017 if (!reader.readListReturn()) {
1018 return false;
1019 }
1020 if (reader.noMore()) {
1021 reader.fail();
1022 return false;
1023 }
1024 if (!reader.read(return_helper)) {
1025 reader.fail();
1026 return false;
1027 }
1028 return true;
1029}
1030
1035
1036// deleteConversation helper class implementation
1038{
1039 return cmd.write(connection);
1040}
1041
1043{
1044 return reply.read(connection);
1045}
1046
1048{
1049 yarp::os::idl::WireWriter writer(connection);
1050 if (!writer.writeListHeader(s_cmd_len)) {
1051 return false;
1052 }
1053 return write(writer);
1054}
1055
1057{
1058 yarp::os::idl::WireReader reader(connection);
1059 if (!reader.readListHeader()) {
1060 reader.fail();
1061 return false;
1062 }
1063 return read(reader);
1064}
1065
1067{
1068 if (!writeTag(writer)) {
1069 return false;
1070 }
1071 if (!writeArgs(writer)) {
1072 return false;
1073 }
1074 return true;
1075}
1076
1078{
1079 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
1080 return false;
1081 }
1082 return true;
1083}
1084
1086{
1087 return true;
1088}
1089
1091{
1092 if (!readTag(reader)) {
1093 return false;
1094 }
1095 if (!readArgs(reader)) {
1096 return false;
1097 }
1098 return true;
1099}
1100
1102{
1103 std::string tag = reader.readTag(s_tag_len);
1104 if (reader.isError()) {
1105 return false;
1106 }
1107 if (tag != s_tag) {
1108 reader.fail();
1109 return false;
1110 }
1111 return true;
1112}
1113
1115{
1116 if (!reader.noMore()) {
1117 reader.fail();
1118 return false;
1119 }
1120 return true;
1121}
1122
1124{
1125 yarp::os::idl::WireWriter writer(connection);
1126 return write(writer);
1127}
1128
1130{
1131 yarp::os::idl::WireReader reader(connection);
1132 return read(reader);
1133}
1134
1136{
1137 if (!writer.isNull()) {
1138 if (!writer.write(return_helper)) {
1139 return false;
1140 }
1141 }
1142 return true;
1143}
1144
1146{
1147 if (reader.noMore()) {
1148 reader.fail();
1149 return false;
1150 }
1151 if (!reader.read(return_helper)) {
1152 reader.fail();
1153 return false;
1154 }
1155 return true;
1156}
1157
1162
1163// refreshConversation helper class implementation
1165{
1166 return cmd.write(connection);
1167}
1168
1170{
1171 return reply.read(connection);
1172}
1173
1175{
1176 yarp::os::idl::WireWriter writer(connection);
1177 if (!writer.writeListHeader(s_cmd_len)) {
1178 return false;
1179 }
1180 return write(writer);
1181}
1182
1184{
1185 yarp::os::idl::WireReader reader(connection);
1186 if (!reader.readListHeader()) {
1187 reader.fail();
1188 return false;
1189 }
1190 return read(reader);
1191}
1192
1194{
1195 if (!writeTag(writer)) {
1196 return false;
1197 }
1198 if (!writeArgs(writer)) {
1199 return false;
1200 }
1201 return true;
1202}
1203
1205{
1206 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
1207 return false;
1208 }
1209 return true;
1210}
1211
1213{
1214 return true;
1215}
1216
1218{
1219 if (!readTag(reader)) {
1220 return false;
1221 }
1222 if (!readArgs(reader)) {
1223 return false;
1224 }
1225 return true;
1226}
1227
1229{
1230 std::string tag = reader.readTag(s_tag_len);
1231 if (reader.isError()) {
1232 return false;
1233 }
1234 if (tag != s_tag) {
1235 reader.fail();
1236 return false;
1237 }
1238 return true;
1239}
1240
1242{
1243 if (!reader.noMore()) {
1244 reader.fail();
1245 return false;
1246 }
1247 return true;
1248}
1249
1251{
1252 yarp::os::idl::WireWriter writer(connection);
1253 return write(writer);
1254}
1255
1257{
1258 yarp::os::idl::WireReader reader(connection);
1259 return read(reader);
1260}
1261
1263{
1264 if (!writer.isNull()) {
1265 if (!writer.write(return_helper)) {
1266 return false;
1267 }
1268 }
1269 return true;
1270}
1271
1273{
1274 if (reader.noMore()) {
1275 reader.fail();
1276 return false;
1277 }
1278 if (!reader.read(return_helper)) {
1279 reader.fail();
1280 return false;
1281 }
1282 return true;
1283}
1284
1289
1290// Constructor
1292{
1293 yarp().setOwner(*this);
1294}
1295
1297{
1298 if (!yarp().canWrite()) {
1299 yError("Missing server method '%s'?", ILLMMsgs_setPrompt_helper::s_prototype);
1300 }
1301 ILLMMsgs_setPrompt_helper helper{prompt};
1302 bool ok = yarp().write(helper, helper);
1303 return ok ? helper.reply.return_helper : yarp::dev::ReturnValue{};
1304}
1305
1307{
1308 if (!yarp().canWrite()) {
1309 yError("Missing server method '%s'?", ILLMMsgs_readPrompt_helper::s_prototype);
1310 }
1312 bool ok = yarp().write(helper, helper);
1313 return ok ? helper.reply.return_helper : return_readPrompt{};
1314}
1315
1316return_ask ILLMMsgs::ask(const std::string& question)
1317{
1318 if (!yarp().canWrite()) {
1319 yError("Missing server method '%s'?", ILLMMsgs_ask_helper::s_prototype);
1320 }
1321 ILLMMsgs_ask_helper helper{question};
1322 bool ok = yarp().write(helper, helper);
1323 return ok ? helper.reply.return_helper : return_ask{};
1324}
1325
1327{
1328 if (!yarp().canWrite()) {
1329 yError("Missing server method '%s'?", ILLMMsgs_getConversation_helper::s_prototype);
1330 }
1332 bool ok = yarp().write(helper, helper);
1333 return ok ? helper.reply.return_helper : return_getConversation{};
1334}
1335
1337{
1338 if (!yarp().canWrite()) {
1339 yError("Missing server method '%s'?", ILLMMsgs_deleteConversation_helper::s_prototype);
1340 }
1342 bool ok = yarp().write(helper, helper);
1343 return ok ? helper.reply.return_helper : yarp::dev::ReturnValue{};
1344}
1345
1347{
1348 if (!yarp().canWrite()) {
1349 yError("Missing server method '%s'?", ILLMMsgs_refreshConversation_helper::s_prototype);
1350 }
1352 bool ok = yarp().write(helper, helper);
1353 return ok ? helper.reply.return_helper : yarp::dev::ReturnValue{};
1354}
1355
1356// help method
1357std::vector<std::string> ILLMMsgs::help(const std::string& functionName)
1358{
1359 bool showAll = (functionName == "--all");
1360 std::vector<std::string> helpString;
1361 if (showAll) {
1362 helpString.emplace_back("*** Available commands:");
1363 helpString.emplace_back(ILLMMsgs_setPrompt_helper::s_tag);
1364 helpString.emplace_back(ILLMMsgs_readPrompt_helper::s_tag);
1365 helpString.emplace_back(ILLMMsgs_ask_helper::s_tag);
1366 helpString.emplace_back(ILLMMsgs_getConversation_helper::s_tag);
1367 helpString.emplace_back(ILLMMsgs_deleteConversation_helper::s_tag);
1368 helpString.emplace_back(ILLMMsgs_refreshConversation_helper::s_tag);
1369 helpString.emplace_back("help");
1370 } else {
1371 if (functionName == ILLMMsgs_setPrompt_helper::s_tag) {
1372 helpString.emplace_back(ILLMMsgs_setPrompt_helper::s_prototype);
1373 }
1374 if (functionName == ILLMMsgs_readPrompt_helper::s_tag) {
1375 helpString.emplace_back(ILLMMsgs_readPrompt_helper::s_prototype);
1376 }
1377 if (functionName == ILLMMsgs_ask_helper::s_tag) {
1378 helpString.emplace_back(ILLMMsgs_ask_helper::s_prototype);
1379 }
1380 if (functionName == ILLMMsgs_getConversation_helper::s_tag) {
1381 helpString.emplace_back(ILLMMsgs_getConversation_helper::s_prototype);
1382 }
1383 if (functionName == ILLMMsgs_deleteConversation_helper::s_tag) {
1384 helpString.emplace_back(ILLMMsgs_deleteConversation_helper::s_prototype);
1385 }
1386 if (functionName == ILLMMsgs_refreshConversation_helper::s_tag) {
1387 helpString.emplace_back(ILLMMsgs_refreshConversation_helper::s_prototype);
1388 }
1389 if (functionName == "help") {
1390 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
1391 helpString.emplace_back("Return list of available commands, or help message for a specific function");
1392 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");
1393 helpString.emplace_back("@return list of strings (one string per line)");
1394 }
1395 }
1396 if (helpString.empty()) {
1397 helpString.emplace_back("Command not found");
1398 }
1399 return helpString;
1400}
1401
1402// read from ConnectionReader
1404{
1405 constexpr size_t max_tag_len = 1;
1406 size_t tag_len = 1;
1407
1408 yarp::os::idl::WireReader reader(connection);
1409 reader.expectAccept();
1410 if (!reader.readListHeader()) {
1411 reader.fail();
1412 return false;
1413 }
1414
1415 std::string tag = reader.readTag(1);
1416 bool direct = (tag == "__direct__");
1417 if (direct) {
1418 tag = reader.readTag(1);
1419 }
1420 while (tag_len <= max_tag_len && !reader.isError()) {
1421 if(tag == "getRemoteProtocolVersion") {
1422 if (!reader.noMore()) {
1423 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
1424 reader.fail();
1425 return false;
1426 }
1427
1428 auto proto = getLocalProtocolVersion();
1429
1430 yarp::os::idl::WireWriter writer(reader);
1431 if (!writer.writeListHeader(1)) {
1432 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
1433 return false;}
1434 if (!writer.write(proto)) {
1435 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
1436 return false;
1437 }
1438 reader.accept();
1439 return true;
1440 }
1443 if (!helper.cmd.readArgs(reader)) {
1444 return false;
1445 }
1446
1447 helper.call(this);
1448
1449 yarp::os::idl::WireWriter writer(reader);
1450 if (!helper.reply.write(writer)) {
1451 return false;
1452 }
1453 reader.accept();
1454 return true;
1455 }
1458 if (!helper.cmd.readArgs(reader)) {
1459 return false;
1460 }
1461
1462 helper.call(this);
1463
1464 yarp::os::idl::WireWriter writer(reader);
1465 if (!helper.reply.write(writer)) {
1466 return false;
1467 }
1468 reader.accept();
1469 return true;
1470 }
1471 if (tag == ILLMMsgs_ask_helper::s_tag) {
1472 ILLMMsgs_ask_helper helper;
1473 if (!helper.cmd.readArgs(reader)) {
1474 return false;
1475 }
1476
1477 helper.call(this);
1478
1479 yarp::os::idl::WireWriter writer(reader);
1480 if (!helper.reply.write(writer)) {
1481 return false;
1482 }
1483 reader.accept();
1484 return true;
1485 }
1488 if (!helper.cmd.readArgs(reader)) {
1489 return false;
1490 }
1491
1492 helper.call(this);
1493
1494 yarp::os::idl::WireWriter writer(reader);
1495 if (!helper.reply.write(writer)) {
1496 return false;
1497 }
1498 reader.accept();
1499 return true;
1500 }
1503 if (!helper.cmd.readArgs(reader)) {
1504 return false;
1505 }
1506
1507 helper.call(this);
1508
1509 yarp::os::idl::WireWriter writer(reader);
1510 if (!helper.reply.write(writer)) {
1511 return false;
1512 }
1513 reader.accept();
1514 return true;
1515 }
1518 if (!helper.cmd.readArgs(reader)) {
1519 return false;
1520 }
1521
1522 helper.call(this);
1523
1524 yarp::os::idl::WireWriter writer(reader);
1525 if (!helper.reply.write(writer)) {
1526 return false;
1527 }
1528 reader.accept();
1529 return true;
1530 }
1531 if (tag == "help") {
1532 std::string functionName;
1533 if (!reader.readString(functionName)) {
1534 functionName = "--all";
1535 }
1536 auto help_strings = help(functionName);
1537 yarp::os::idl::WireWriter writer(reader);
1538 if (!writer.isNull()) {
1539 if (!writer.writeListHeader(2)) {
1540 return false;
1541 }
1542 if (!writer.writeTag("many", 1, 0)) {
1543 return false;
1544 }
1545 if (!writer.writeListBegin(0, help_strings.size())) {
1546 return false;
1547 }
1548 for (const auto& help_string : help_strings) {
1549 if (!writer.writeString(help_string)) {
1550 return false;
1551 }
1552 }
1553 if (!writer.writeListEnd()) {
1554 return false;
1555 }
1556 }
1557 reader.accept();
1558 return true;
1559 }
1560 if (reader.noMore()) {
1561 reader.fail();
1562 return false;
1563 }
1564 std::string next_tag = reader.readTag(1);
1565 if (next_tag.empty()) {
1566 break;
1567 }
1568 tag.append("_").append(next_tag);
1569 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
1570 }
1571 return false;
1572}
1573
1574} // namespace yarp::dev::llm
#define yError(...)
Definition Log.h:361
#define __YFUNCTION__
Definition Log.h:24
#define yWarning(...)
Definition Log.h:340
bool readArgs(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:840
bool writeTag(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:800
bool readTag(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:827
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:779
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:808
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:770
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:863
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:857
static constexpr size_t s_cmd_len
Definition ILLMMsgs.cpp:288
static constexpr const char * s_help
Definition ILLMMsgs.cpp:291
static constexpr size_t s_reply_len
Definition ILLMMsgs.cpp:289
return_ask(*)(const std::string &) funcptr_t
Definition ILLMMsgs.cpp:280
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:760
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:755
static constexpr const char * s_tag
Definition ILLMMsgs.cpp:286
static constexpr size_t s_tag_len
Definition ILLMMsgs.cpp:287
static constexpr const char * s_prototype
Definition ILLMMsgs.cpp:290
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool readTag(yarp::os::idl::WireReader &reader)
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 readArgs(yarp::os::idl::WireReader &reader)
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 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.
Definition ILLMMsgs.cpp:914
bool writeTag(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:944
bool readTag(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:968
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:952
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:923
bool readArgs(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:981
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:996
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:990
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:909
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:904
static constexpr const char * s_prototype
Definition ILLMMsgs.cpp:348
yarp::os::ApplicationNetworkProtocolVersion helper_proto
Definition ILLMMsgs.cpp:36
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:39
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:51
bool readArgs(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:694
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:665
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:636
bool writeTag(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:657
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:627
bool readTag(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:681
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:709
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:703
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:622
static constexpr const char * s_prototype
Definition ILLMMsgs.cpp:227
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:617
static constexpr const char * s_tag
Definition ILLMMsgs.cpp:223
static constexpr const char * s_help
Definition ILLMMsgs.cpp:228
bool readTag(yarp::os::idl::WireReader &reader)
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 readArgs(yarp::os::idl::WireReader &reader)
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 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.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool writeTag(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:519
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:498
bool readTag(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:546
bool readArgs(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:559
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:489
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:527
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:582
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:576
static constexpr const char * s_prototype
Definition ILLMMsgs.cpp:169
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:479
yarp::dev::ReturnValue(*)(const std::string &) funcptr_t
Definition ILLMMsgs.cpp:159
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:474
static constexpr const char * s_help
Definition ILLMMsgs.cpp:170
static constexpr const char * s_tag
Definition ILLMMsgs.cpp:165
virtual yarp::dev::ReturnValue refreshConversation()
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
Definition ILLMMsgs.cpp:97
virtual yarp::dev::ReturnValue deleteConversation()
virtual std::vector< std::string > help(const std::string &functionName="--all")
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
virtual bool checkProtocolVersion()
Definition ILLMMsgs.cpp:82
virtual return_ask ask(const std::string &question)
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
Definition ILLMMsgs.cpp:67
virtual yarp::dev::ReturnValue setPrompt(const std::string &prompt)
virtual return_readPrompt readPrompt()
virtual return_getConversation getConversation()
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)
std::string readTag(size_t len=static_cast< size_t >(-1))
bool read(WirePortable &obj)
IDL-friendly connection writer.
Definition WireWriter.h:28
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 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