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
12
14
15#include <algorithm>
16
17namespace yarp::dev::llm {
18
19// setPrompt helper class declaration
22{
23public:
25 explicit ILLMMsgs_setPrompt_helper(const std::string& prompt);
26 bool write(yarp::os::ConnectionWriter& connection) const override;
27 bool read(yarp::os::ConnectionReader& connection) override;
28
29 class Command :
31 {
32 public:
33 Command() = default;
34 explicit Command(const std::string& prompt);
35
36 ~Command() override = default;
37
38 bool write(yarp::os::ConnectionWriter& connection) const override;
39 bool read(yarp::os::ConnectionReader& connection) override;
40
41 bool write(const yarp::os::idl::WireWriter& writer) const override;
42 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
43 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
44
45 bool read(yarp::os::idl::WireReader& reader) override;
48
49 std::string prompt{};
50 };
51
52 class Reply :
54 {
55 public:
56 Reply() = default;
57 ~Reply() override = default;
58
59 bool write(yarp::os::ConnectionWriter& connection) const override;
60 bool read(yarp::os::ConnectionReader& connection) override;
61
62 bool write(const yarp::os::idl::WireWriter& writer) const override;
63 bool read(yarp::os::idl::WireReader& reader) override;
64
65 bool return_helper{false};
66 };
67
68 using funcptr_t = bool (*)(const std::string&);
69 void call(ILLMMsgs* ptr);
70
73
74 static constexpr const char* s_tag{"setPrompt"};
75 static constexpr size_t s_tag_len{1};
76 static constexpr size_t s_cmd_len{2};
77 static constexpr size_t s_reply_len{1};
78 static constexpr const char* s_prototype{"bool ILLMMsgs::setPrompt(const std::string& prompt)"};
79 static constexpr const char* s_help{""};
80};
81
82// readPrompt helper class declaration
85{
86public:
88 bool write(yarp::os::ConnectionWriter& connection) const override;
89 bool read(yarp::os::ConnectionReader& connection) override;
90
91 class Command :
93 {
94 public:
95 Command() = default;
96 ~Command() override = default;
97
98 bool write(yarp::os::ConnectionWriter& connection) const override;
99 bool read(yarp::os::ConnectionReader& connection) override;
100
101 bool write(const yarp::os::idl::WireWriter& writer) const override;
102 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
103 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
104
105 bool read(yarp::os::idl::WireReader& reader) override;
108 };
109
110 class Reply :
112 {
113 public:
114 Reply() = default;
115 ~Reply() override = default;
116
117 bool write(yarp::os::ConnectionWriter& connection) const override;
118 bool read(yarp::os::ConnectionReader& connection) override;
119
120 bool write(const yarp::os::idl::WireWriter& writer) const override;
121 bool read(yarp::os::idl::WireReader& reader) override;
122
124 };
125
127 void call(ILLMMsgs* ptr);
128
131
132 static constexpr const char* s_tag{"readPrompt"};
133 static constexpr size_t s_tag_len{1};
134 static constexpr size_t s_cmd_len{1};
135 static constexpr size_t s_reply_len{2};
136 static constexpr const char* s_prototype{"return_readPrompt ILLMMsgs::readPrompt()"};
137 static constexpr const char* s_help{""};
138};
139
140// ask helper class declaration
142 public yarp::os::Portable
143{
144public:
146 explicit ILLMMsgs_ask_helper(const std::string& question);
147 bool write(yarp::os::ConnectionWriter& connection) const override;
148 bool read(yarp::os::ConnectionReader& connection) override;
149
150 class Command :
152 {
153 public:
154 Command() = default;
155 explicit Command(const std::string& question);
156
157 ~Command() override = default;
158
159 bool write(yarp::os::ConnectionWriter& connection) const override;
160 bool read(yarp::os::ConnectionReader& connection) override;
161
162 bool write(const yarp::os::idl::WireWriter& writer) const override;
163 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
164 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
165
166 bool read(yarp::os::idl::WireReader& reader) override;
169
170 std::string question{};
171 };
172
173 class Reply :
175 {
176 public:
177 Reply() = default;
178 ~Reply() override = default;
179
180 bool write(yarp::os::ConnectionWriter& connection) const override;
181 bool read(yarp::os::ConnectionReader& connection) override;
182
183 bool write(const yarp::os::idl::WireWriter& writer) const override;
184 bool read(yarp::os::idl::WireReader& reader) override;
185
187 };
188
189 using funcptr_t = return_ask (*)(const std::string&);
190 void call(ILLMMsgs* ptr);
191
194
195 static constexpr const char* s_tag{"ask"};
196 static constexpr size_t s_tag_len{1};
197 static constexpr size_t s_cmd_len{2};
198 static constexpr size_t s_reply_len{2};
199 static constexpr const char* s_prototype{"return_ask ILLMMsgs::ask(const std::string& question)"};
200 static constexpr const char* s_help{""};
201};
202
203// getConversation helper class declaration
205 public yarp::os::Portable
206{
207public:
209 bool write(yarp::os::ConnectionWriter& connection) const override;
210 bool read(yarp::os::ConnectionReader& connection) override;
211
212 class Command :
214 {
215 public:
216 Command() = default;
217 ~Command() override = default;
218
219 bool write(yarp::os::ConnectionWriter& connection) const override;
220 bool read(yarp::os::ConnectionReader& connection) override;
221
222 bool write(const yarp::os::idl::WireWriter& writer) const override;
223 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
224 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
225
226 bool read(yarp::os::idl::WireReader& reader) override;
229 };
230
231 class Reply :
233 {
234 public:
235 Reply() = default;
236 ~Reply() override = default;
237
238 bool write(yarp::os::ConnectionWriter& connection) const override;
239 bool read(yarp::os::ConnectionReader& connection) override;
240
241 bool write(const yarp::os::idl::WireWriter& writer) const override;
242 bool read(yarp::os::idl::WireReader& reader) override;
243
245 };
246
248 void call(ILLMMsgs* ptr);
249
252
253 static constexpr const char* s_tag{"getConversation"};
254 static constexpr size_t s_tag_len{1};
255 static constexpr size_t s_cmd_len{1};
256 static constexpr size_t s_reply_len{2};
257 static constexpr const char* s_prototype{"return_getConversation ILLMMsgs::getConversation()"};
258 static constexpr const char* s_help{""};
259};
260
261// deleteConversation helper class declaration
263 public yarp::os::Portable
264{
265public:
267 bool write(yarp::os::ConnectionWriter& connection) const override;
268 bool read(yarp::os::ConnectionReader& connection) override;
269
270 class Command :
272 {
273 public:
274 Command() = default;
275 ~Command() override = default;
276
277 bool write(yarp::os::ConnectionWriter& connection) const override;
278 bool read(yarp::os::ConnectionReader& connection) override;
279
280 bool write(const yarp::os::idl::WireWriter& writer) const override;
281 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
282 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
283
284 bool read(yarp::os::idl::WireReader& reader) override;
287 };
288
289 class Reply :
291 {
292 public:
293 Reply() = default;
294 ~Reply() override = default;
295
296 bool write(yarp::os::ConnectionWriter& connection) const override;
297 bool read(yarp::os::ConnectionReader& connection) override;
298
299 bool write(const yarp::os::idl::WireWriter& writer) const override;
300 bool read(yarp::os::idl::WireReader& reader) override;
301
302 bool return_helper{false};
303 };
304
305 using funcptr_t = bool (*)();
306 void call(ILLMMsgs* ptr);
307
310
311 static constexpr const char* s_tag{"deleteConversation"};
312 static constexpr size_t s_tag_len{1};
313 static constexpr size_t s_cmd_len{1};
314 static constexpr size_t s_reply_len{1};
315 static constexpr const char* s_prototype{"bool ILLMMsgs::deleteConversation()"};
316 static constexpr const char* s_help{""};
317};
318
319// refreshConversation helper class declaration
321 public yarp::os::Portable
322{
323public:
325 bool write(yarp::os::ConnectionWriter& connection) const override;
326 bool read(yarp::os::ConnectionReader& connection) override;
327
328 class Command :
330 {
331 public:
332 Command() = default;
333 ~Command() override = default;
334
335 bool write(yarp::os::ConnectionWriter& connection) const override;
336 bool read(yarp::os::ConnectionReader& connection) override;
337
338 bool write(const yarp::os::idl::WireWriter& writer) const override;
339 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
340 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
341
342 bool read(yarp::os::idl::WireReader& reader) override;
345 };
346
347 class Reply :
349 {
350 public:
351 Reply() = default;
352 ~Reply() override = default;
353
354 bool write(yarp::os::ConnectionWriter& connection) const override;
355 bool read(yarp::os::ConnectionReader& connection) override;
356
357 bool write(const yarp::os::idl::WireWriter& writer) const override;
358 bool read(yarp::os::idl::WireReader& reader) override;
359
360 bool return_helper{false};
361 };
362
363 using funcptr_t = bool (*)();
364 void call(ILLMMsgs* ptr);
365
368
369 static constexpr const char* s_tag{"refreshConversation"};
370 static constexpr size_t s_tag_len{1};
371 static constexpr size_t s_cmd_len{1};
372 static constexpr size_t s_reply_len{1};
373 static constexpr const char* s_prototype{"bool ILLMMsgs::refreshConversation()"};
374 static constexpr const char* s_help{""};
375};
376
377// setPrompt helper class implementation
379 cmd{prompt}
380{
381}
382
384{
385 return cmd.write(connection);
386}
387
389{
390 return reply.read(connection);
391}
392
394 prompt{prompt}
395{
396}
397
399{
400 yarp::os::idl::WireWriter writer(connection);
401 if (!writer.writeListHeader(s_cmd_len)) {
402 return false;
403 }
404 return write(writer);
405}
406
408{
409 yarp::os::idl::WireReader reader(connection);
410 if (!reader.readListHeader()) {
411 reader.fail();
412 return false;
413 }
414 return read(reader);
415}
416
418{
419 if (!writeTag(writer)) {
420 return false;
421 }
422 if (!writeArgs(writer)) {
423 return false;
424 }
425 return true;
426}
427
429{
430 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
431 return false;
432 }
433 return true;
434}
435
437{
438 if (!writer.writeString(prompt)) {
439 return false;
440 }
441 return true;
442}
443
445{
446 if (!readTag(reader)) {
447 return false;
448 }
449 if (!readArgs(reader)) {
450 return false;
451 }
452 return true;
453}
454
456{
457 std::string tag = reader.readTag(s_tag_len);
458 if (reader.isError()) {
459 return false;
460 }
461 if (tag != s_tag) {
462 reader.fail();
463 return false;
464 }
465 return true;
466}
467
469{
470 if (reader.noMore()) {
471 reader.fail();
472 return false;
473 }
474 if (!reader.readString(prompt)) {
475 reader.fail();
476 return false;
477 }
478 if (!reader.noMore()) {
479 reader.fail();
480 return false;
481 }
482 return true;
483}
484
486{
487 yarp::os::idl::WireWriter writer(connection);
488 return write(writer);
489}
490
492{
493 yarp::os::idl::WireReader reader(connection);
494 return read(reader);
495}
496
498{
499 if (!writer.isNull()) {
500 if (!writer.writeListHeader(s_reply_len)) {
501 return false;
502 }
503 if (!writer.writeBool(return_helper)) {
504 return false;
505 }
506 }
507 return true;
508}
509
511{
512 if (!reader.readListReturn()) {
513 return false;
514 }
515 if (reader.noMore()) {
516 reader.fail();
517 return false;
518 }
519 if (!reader.readBool(return_helper)) {
520 reader.fail();
521 return false;
522 }
523 return true;
524}
525
530
531// readPrompt helper class implementation
533{
534 return cmd.write(connection);
535}
536
538{
539 return reply.read(connection);
540}
541
543{
544 yarp::os::idl::WireWriter writer(connection);
545 if (!writer.writeListHeader(s_cmd_len)) {
546 return false;
547 }
548 return write(writer);
549}
550
552{
553 yarp::os::idl::WireReader reader(connection);
554 if (!reader.readListHeader()) {
555 reader.fail();
556 return false;
557 }
558 return read(reader);
559}
560
562{
563 if (!writeTag(writer)) {
564 return false;
565 }
566 if (!writeArgs(writer)) {
567 return false;
568 }
569 return true;
570}
571
573{
574 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
575 return false;
576 }
577 return true;
578}
579
581{
582 return true;
583}
584
586{
587 if (!readTag(reader)) {
588 return false;
589 }
590 if (!readArgs(reader)) {
591 return false;
592 }
593 return true;
594}
595
597{
598 std::string tag = reader.readTag(s_tag_len);
599 if (reader.isError()) {
600 return false;
601 }
602 if (tag != s_tag) {
603 reader.fail();
604 return false;
605 }
606 return true;
607}
608
610{
611 if (!reader.noMore()) {
612 reader.fail();
613 return false;
614 }
615 return true;
616}
617
619{
620 yarp::os::idl::WireWriter writer(connection);
621 return write(writer);
622}
623
625{
626 yarp::os::idl::WireReader reader(connection);
627 return read(reader);
628}
629
631{
632 if (!writer.isNull()) {
633 if (!writer.writeListHeader(s_reply_len)) {
634 return false;
635 }
636 if (!writer.write(return_helper)) {
637 return false;
638 }
639 }
640 return true;
641}
642
644{
645 if (!reader.readListReturn()) {
646 return false;
647 }
648 if (reader.noMore()) {
649 reader.fail();
650 return false;
651 }
652 if (!reader.read(return_helper)) {
653 reader.fail();
654 return false;
655 }
656 return true;
657}
658
663
664// ask helper class implementation
665ILLMMsgs_ask_helper::ILLMMsgs_ask_helper(const std::string& question) :
666 cmd{question}
667{
668}
669
671{
672 return cmd.write(connection);
673}
674
676{
677 return reply.read(connection);
678}
679
680ILLMMsgs_ask_helper::Command::Command(const std::string& question) :
681 question{question}
682{
683}
684
686{
687 yarp::os::idl::WireWriter writer(connection);
688 if (!writer.writeListHeader(s_cmd_len)) {
689 return false;
690 }
691 return write(writer);
692}
693
695{
696 yarp::os::idl::WireReader reader(connection);
697 if (!reader.readListHeader()) {
698 reader.fail();
699 return false;
700 }
701 return read(reader);
702}
703
705{
706 if (!writeTag(writer)) {
707 return false;
708 }
709 if (!writeArgs(writer)) {
710 return false;
711 }
712 return true;
713}
714
716{
717 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
718 return false;
719 }
720 return true;
721}
722
724{
725 if (!writer.writeString(question)) {
726 return false;
727 }
728 return true;
729}
730
732{
733 if (!readTag(reader)) {
734 return false;
735 }
736 if (!readArgs(reader)) {
737 return false;
738 }
739 return true;
740}
741
743{
744 std::string tag = reader.readTag(s_tag_len);
745 if (reader.isError()) {
746 return false;
747 }
748 if (tag != s_tag) {
749 reader.fail();
750 return false;
751 }
752 return true;
753}
754
756{
757 if (reader.noMore()) {
758 reader.fail();
759 return false;
760 }
761 if (!reader.readString(question)) {
762 reader.fail();
763 return false;
764 }
765 if (!reader.noMore()) {
766 reader.fail();
767 return false;
768 }
769 return true;
770}
771
773{
774 yarp::os::idl::WireWriter writer(connection);
775 return write(writer);
776}
777
779{
780 yarp::os::idl::WireReader reader(connection);
781 return read(reader);
782}
783
785{
786 if (!writer.isNull()) {
787 if (!writer.writeListHeader(s_reply_len)) {
788 return false;
789 }
790 if (!writer.write(return_helper)) {
791 return false;
792 }
793 }
794 return true;
795}
796
798{
799 if (!reader.readListReturn()) {
800 return false;
801 }
802 if (reader.noMore()) {
803 reader.fail();
804 return false;
805 }
806 if (!reader.read(return_helper)) {
807 reader.fail();
808 return false;
809 }
810 return true;
811}
812
817
818// getConversation helper class implementation
820{
821 return cmd.write(connection);
822}
823
825{
826 return reply.read(connection);
827}
828
830{
831 yarp::os::idl::WireWriter writer(connection);
832 if (!writer.writeListHeader(s_cmd_len)) {
833 return false;
834 }
835 return write(writer);
836}
837
839{
840 yarp::os::idl::WireReader reader(connection);
841 if (!reader.readListHeader()) {
842 reader.fail();
843 return false;
844 }
845 return read(reader);
846}
847
849{
850 if (!writeTag(writer)) {
851 return false;
852 }
853 if (!writeArgs(writer)) {
854 return false;
855 }
856 return true;
857}
858
860{
861 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
862 return false;
863 }
864 return true;
865}
866
868{
869 return true;
870}
871
873{
874 if (!readTag(reader)) {
875 return false;
876 }
877 if (!readArgs(reader)) {
878 return false;
879 }
880 return true;
881}
882
884{
885 std::string tag = reader.readTag(s_tag_len);
886 if (reader.isError()) {
887 return false;
888 }
889 if (tag != s_tag) {
890 reader.fail();
891 return false;
892 }
893 return true;
894}
895
897{
898 if (!reader.noMore()) {
899 reader.fail();
900 return false;
901 }
902 return true;
903}
904
906{
907 yarp::os::idl::WireWriter writer(connection);
908 return write(writer);
909}
910
912{
913 yarp::os::idl::WireReader reader(connection);
914 return read(reader);
915}
916
918{
919 if (!writer.isNull()) {
920 if (!writer.writeListHeader(s_reply_len)) {
921 return false;
922 }
923 if (!writer.write(return_helper)) {
924 return false;
925 }
926 }
927 return true;
928}
929
931{
932 if (!reader.readListReturn()) {
933 return false;
934 }
935 if (reader.noMore()) {
936 reader.fail();
937 return false;
938 }
939 if (!reader.read(return_helper)) {
940 reader.fail();
941 return false;
942 }
943 return true;
944}
945
950
951// deleteConversation helper class implementation
953{
954 return cmd.write(connection);
955}
956
958{
959 return reply.read(connection);
960}
961
963{
964 yarp::os::idl::WireWriter writer(connection);
965 if (!writer.writeListHeader(s_cmd_len)) {
966 return false;
967 }
968 return write(writer);
969}
970
972{
973 yarp::os::idl::WireReader reader(connection);
974 if (!reader.readListHeader()) {
975 reader.fail();
976 return false;
977 }
978 return read(reader);
979}
980
982{
983 if (!writeTag(writer)) {
984 return false;
985 }
986 if (!writeArgs(writer)) {
987 return false;
988 }
989 return true;
990}
991
993{
994 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
995 return false;
996 }
997 return true;
998}
999
1001{
1002 return true;
1003}
1004
1006{
1007 if (!readTag(reader)) {
1008 return false;
1009 }
1010 if (!readArgs(reader)) {
1011 return false;
1012 }
1013 return true;
1014}
1015
1017{
1018 std::string tag = reader.readTag(s_tag_len);
1019 if (reader.isError()) {
1020 return false;
1021 }
1022 if (tag != s_tag) {
1023 reader.fail();
1024 return false;
1025 }
1026 return true;
1027}
1028
1030{
1031 if (!reader.noMore()) {
1032 reader.fail();
1033 return false;
1034 }
1035 return true;
1036}
1037
1039{
1040 yarp::os::idl::WireWriter writer(connection);
1041 return write(writer);
1042}
1043
1045{
1046 yarp::os::idl::WireReader reader(connection);
1047 return read(reader);
1048}
1049
1051{
1052 if (!writer.isNull()) {
1053 if (!writer.writeListHeader(s_reply_len)) {
1054 return false;
1055 }
1056 if (!writer.writeBool(return_helper)) {
1057 return false;
1058 }
1059 }
1060 return true;
1061}
1062
1064{
1065 if (!reader.readListReturn()) {
1066 return false;
1067 }
1068 if (reader.noMore()) {
1069 reader.fail();
1070 return false;
1071 }
1072 if (!reader.readBool(return_helper)) {
1073 reader.fail();
1074 return false;
1075 }
1076 return true;
1077}
1078
1083
1084// refreshConversation helper class implementation
1086{
1087 return cmd.write(connection);
1088}
1089
1091{
1092 return reply.read(connection);
1093}
1094
1096{
1097 yarp::os::idl::WireWriter writer(connection);
1098 if (!writer.writeListHeader(s_cmd_len)) {
1099 return false;
1100 }
1101 return write(writer);
1102}
1103
1105{
1106 yarp::os::idl::WireReader reader(connection);
1107 if (!reader.readListHeader()) {
1108 reader.fail();
1109 return false;
1110 }
1111 return read(reader);
1112}
1113
1115{
1116 if (!writeTag(writer)) {
1117 return false;
1118 }
1119 if (!writeArgs(writer)) {
1120 return false;
1121 }
1122 return true;
1123}
1124
1126{
1127 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
1128 return false;
1129 }
1130 return true;
1131}
1132
1134{
1135 return true;
1136}
1137
1139{
1140 if (!readTag(reader)) {
1141 return false;
1142 }
1143 if (!readArgs(reader)) {
1144 return false;
1145 }
1146 return true;
1147}
1148
1150{
1151 std::string tag = reader.readTag(s_tag_len);
1152 if (reader.isError()) {
1153 return false;
1154 }
1155 if (tag != s_tag) {
1156 reader.fail();
1157 return false;
1158 }
1159 return true;
1160}
1161
1163{
1164 if (!reader.noMore()) {
1165 reader.fail();
1166 return false;
1167 }
1168 return true;
1169}
1170
1172{
1173 yarp::os::idl::WireWriter writer(connection);
1174 return write(writer);
1175}
1176
1178{
1179 yarp::os::idl::WireReader reader(connection);
1180 return read(reader);
1181}
1182
1184{
1185 if (!writer.isNull()) {
1186 if (!writer.writeListHeader(s_reply_len)) {
1187 return false;
1188 }
1189 if (!writer.writeBool(return_helper)) {
1190 return false;
1191 }
1192 }
1193 return true;
1194}
1195
1197{
1198 if (!reader.readListReturn()) {
1199 return false;
1200 }
1201 if (reader.noMore()) {
1202 reader.fail();
1203 return false;
1204 }
1205 if (!reader.readBool(return_helper)) {
1206 reader.fail();
1207 return false;
1208 }
1209 return true;
1210}
1211
1216
1217// Constructor
1219{
1220 yarp().setOwner(*this);
1221}
1222
1223bool ILLMMsgs::setPrompt(const std::string& prompt)
1224{
1225 if (!yarp().canWrite()) {
1226 yError("Missing server method '%s'?", ILLMMsgs_setPrompt_helper::s_prototype);
1227 }
1228 ILLMMsgs_setPrompt_helper helper{prompt};
1229 bool ok = yarp().write(helper, helper);
1230 return ok ? helper.reply.return_helper : bool{};
1231}
1232
1234{
1235 if (!yarp().canWrite()) {
1236 yError("Missing server method '%s'?", ILLMMsgs_readPrompt_helper::s_prototype);
1237 }
1239 bool ok = yarp().write(helper, helper);
1240 return ok ? helper.reply.return_helper : return_readPrompt{};
1241}
1242
1243return_ask ILLMMsgs::ask(const std::string& question)
1244{
1245 if (!yarp().canWrite()) {
1246 yError("Missing server method '%s'?", ILLMMsgs_ask_helper::s_prototype);
1247 }
1248 ILLMMsgs_ask_helper helper{question};
1249 bool ok = yarp().write(helper, helper);
1250 return ok ? helper.reply.return_helper : return_ask{};
1251}
1252
1254{
1255 if (!yarp().canWrite()) {
1256 yError("Missing server method '%s'?", ILLMMsgs_getConversation_helper::s_prototype);
1257 }
1259 bool ok = yarp().write(helper, helper);
1260 return ok ? helper.reply.return_helper : return_getConversation{};
1261}
1262
1264{
1265 if (!yarp().canWrite()) {
1266 yError("Missing server method '%s'?", ILLMMsgs_deleteConversation_helper::s_prototype);
1267 }
1269 bool ok = yarp().write(helper, helper);
1270 return ok ? helper.reply.return_helper : bool{};
1271}
1272
1274{
1275 if (!yarp().canWrite()) {
1276 yError("Missing server method '%s'?", ILLMMsgs_refreshConversation_helper::s_prototype);
1277 }
1279 bool ok = yarp().write(helper, helper);
1280 return ok ? helper.reply.return_helper : bool{};
1281}
1282
1283// help method
1284std::vector<std::string> ILLMMsgs::help(const std::string& functionName)
1285{
1286 bool showAll = (functionName == "--all");
1287 std::vector<std::string> helpString;
1288 if (showAll) {
1289 helpString.emplace_back("*** Available commands:");
1290 helpString.emplace_back(ILLMMsgs_setPrompt_helper::s_tag);
1291 helpString.emplace_back(ILLMMsgs_readPrompt_helper::s_tag);
1292 helpString.emplace_back(ILLMMsgs_ask_helper::s_tag);
1293 helpString.emplace_back(ILLMMsgs_getConversation_helper::s_tag);
1294 helpString.emplace_back(ILLMMsgs_deleteConversation_helper::s_tag);
1295 helpString.emplace_back(ILLMMsgs_refreshConversation_helper::s_tag);
1296 helpString.emplace_back("help");
1297 } else {
1298 if (functionName == ILLMMsgs_setPrompt_helper::s_tag) {
1299 helpString.emplace_back(ILLMMsgs_setPrompt_helper::s_prototype);
1300 }
1301 if (functionName == ILLMMsgs_readPrompt_helper::s_tag) {
1302 helpString.emplace_back(ILLMMsgs_readPrompt_helper::s_prototype);
1303 }
1304 if (functionName == ILLMMsgs_ask_helper::s_tag) {
1305 helpString.emplace_back(ILLMMsgs_ask_helper::s_prototype);
1306 }
1307 if (functionName == ILLMMsgs_getConversation_helper::s_tag) {
1308 helpString.emplace_back(ILLMMsgs_getConversation_helper::s_prototype);
1309 }
1310 if (functionName == ILLMMsgs_deleteConversation_helper::s_tag) {
1311 helpString.emplace_back(ILLMMsgs_deleteConversation_helper::s_prototype);
1312 }
1313 if (functionName == ILLMMsgs_refreshConversation_helper::s_tag) {
1314 helpString.emplace_back(ILLMMsgs_refreshConversation_helper::s_prototype);
1315 }
1316 if (functionName == "help") {
1317 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
1318 helpString.emplace_back("Return list of available commands, or help message for a specific function");
1319 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");
1320 helpString.emplace_back("@return list of strings (one string per line)");
1321 }
1322 }
1323 if (helpString.empty()) {
1324 helpString.emplace_back("Command not found");
1325 }
1326 return helpString;
1327}
1328
1329// read from ConnectionReader
1331{
1332 constexpr size_t max_tag_len = 1;
1333 size_t tag_len = 1;
1334
1335 yarp::os::idl::WireReader reader(connection);
1336 reader.expectAccept();
1337 if (!reader.readListHeader()) {
1338 reader.fail();
1339 return false;
1340 }
1341
1342 std::string tag = reader.readTag(1);
1343 bool direct = (tag == "__direct__");
1344 if (direct) {
1345 tag = reader.readTag(1);
1346 }
1347 while (tag_len <= max_tag_len && !reader.isError()) {
1350 if (!helper.cmd.readArgs(reader)) {
1351 return false;
1352 }
1353
1354 helper.call(this);
1355
1356 yarp::os::idl::WireWriter writer(reader);
1357 if (!helper.reply.write(writer)) {
1358 return false;
1359 }
1360 reader.accept();
1361 return true;
1362 }
1365 if (!helper.cmd.readArgs(reader)) {
1366 return false;
1367 }
1368
1369 helper.call(this);
1370
1371 yarp::os::idl::WireWriter writer(reader);
1372 if (!helper.reply.write(writer)) {
1373 return false;
1374 }
1375 reader.accept();
1376 return true;
1377 }
1378 if (tag == ILLMMsgs_ask_helper::s_tag) {
1379 ILLMMsgs_ask_helper helper;
1380 if (!helper.cmd.readArgs(reader)) {
1381 return false;
1382 }
1383
1384 helper.call(this);
1385
1386 yarp::os::idl::WireWriter writer(reader);
1387 if (!helper.reply.write(writer)) {
1388 return false;
1389 }
1390 reader.accept();
1391 return true;
1392 }
1395 if (!helper.cmd.readArgs(reader)) {
1396 return false;
1397 }
1398
1399 helper.call(this);
1400
1401 yarp::os::idl::WireWriter writer(reader);
1402 if (!helper.reply.write(writer)) {
1403 return false;
1404 }
1405 reader.accept();
1406 return true;
1407 }
1410 if (!helper.cmd.readArgs(reader)) {
1411 return false;
1412 }
1413
1414 helper.call(this);
1415
1416 yarp::os::idl::WireWriter writer(reader);
1417 if (!helper.reply.write(writer)) {
1418 return false;
1419 }
1420 reader.accept();
1421 return true;
1422 }
1425 if (!helper.cmd.readArgs(reader)) {
1426 return false;
1427 }
1428
1429 helper.call(this);
1430
1431 yarp::os::idl::WireWriter writer(reader);
1432 if (!helper.reply.write(writer)) {
1433 return false;
1434 }
1435 reader.accept();
1436 return true;
1437 }
1438 if (tag == "help") {
1439 std::string functionName;
1440 if (!reader.readString(functionName)) {
1441 functionName = "--all";
1442 }
1443 auto help_strings = help(functionName);
1444 yarp::os::idl::WireWriter writer(reader);
1445 if (!writer.isNull()) {
1446 if (!writer.writeListHeader(2)) {
1447 return false;
1448 }
1449 if (!writer.writeTag("many", 1, 0)) {
1450 return false;
1451 }
1452 if (!writer.writeListBegin(0, help_strings.size())) {
1453 return false;
1454 }
1455 for (const auto& help_string : help_strings) {
1456 if (!writer.writeString(help_string)) {
1457 return false;
1458 }
1459 }
1460 if (!writer.writeListEnd()) {
1461 return false;
1462 }
1463 }
1464 reader.accept();
1465 return true;
1466 }
1467 if (reader.noMore()) {
1468 reader.fail();
1469 return false;
1470 }
1471 std::string next_tag = reader.readTag(1);
1472 if (next_tag.empty()) {
1473 break;
1474 }
1475 tag.append("_").append(next_tag);
1476 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
1477 }
1478 return false;
1479}
1480
1481} // namespace yarp::dev::llm
#define yError(...)
Definition Log.h:361
bool readArgs(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:755
bool writeTag(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:715
bool readTag(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:742
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:694
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:723
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:685
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:778
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:772
static constexpr size_t s_cmd_len
Definition ILLMMsgs.cpp:197
static constexpr const char * s_help
Definition ILLMMsgs.cpp:200
static constexpr size_t s_reply_len
Definition ILLMMsgs.cpp:198
return_ask(*)(const std::string &) funcptr_t
Definition ILLMMsgs.cpp:189
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:675
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:670
static constexpr const char * s_tag
Definition ILLMMsgs.cpp:195
static constexpr size_t s_tag_len
Definition ILLMMsgs.cpp:196
static constexpr const char * s_prototype
Definition ILLMMsgs.cpp:199
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:971
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
Definition ILLMMsgs.cpp:992
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:962
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.
Definition ILLMMsgs.cpp:952
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:957
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:829
bool writeTag(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:859
bool readTag(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:883
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:867
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:838
bool readArgs(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:896
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:911
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:905
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:824
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:819
static constexpr const char * s_prototype
Definition ILLMMsgs.cpp:257
bool readArgs(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:609
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:580
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:551
bool writeTag(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:572
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:542
bool readTag(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:596
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:624
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:618
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:537
static constexpr const char * s_prototype
Definition ILLMMsgs.cpp:136
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:532
static constexpr const char * s_tag
Definition ILLMMsgs.cpp:132
static constexpr const char * s_help
Definition ILLMMsgs.cpp:137
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:428
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:407
bool readTag(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:455
bool readArgs(yarp::os::idl::WireReader &reader)
Definition ILLMMsgs.cpp:468
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:398
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
Definition ILLMMsgs.cpp:436
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:491
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:485
static constexpr const char * s_prototype
Definition ILLMMsgs.cpp:78
static constexpr size_t s_reply_len
Definition ILLMMsgs.cpp:77
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition ILLMMsgs.cpp:388
bool(*)(const std::string &) funcptr_t
Definition ILLMMsgs.cpp:68
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition ILLMMsgs.cpp:383
static constexpr const char * s_help
Definition ILLMMsgs.cpp:79
static constexpr const char * s_tag
Definition ILLMMsgs.cpp:74
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 setPrompt(const std::string &prompt)
virtual return_ask ask(const std::string &question)
virtual bool refreshConversation()
virtual return_readPrompt readPrompt()
virtual bool deleteConversation()
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
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 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 writeListBegin(int tag, size_t len) const
The main, catch-all namespace for YARP.
Definition dirs.h:16