YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ChatBot_nwc_yarp.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "ChatBot_nwc_yarp.h"
7#include <yarp/os/Log.h>
9#include <yarp/os/LogStream.h>
10
11namespace
12{
13 YARP_LOG_COMPONENT(CHATBOT_NWC_YARP, "yarp.device.chatBot_nwc_yarp")
14}
15
16using namespace yarp::dev;
17
19{
20 if (!parseParams(config)) { return false; }
21
23 {
24 yCError(CHATBOT_NWC_YARP) << "Cannot open rpc port, check network";
25
26 return false;
27 }
28
29 bool ok = false;
30
32
33 if (!ok)
34 {
35 yCError(CHATBOT_NWC_YARP) << "open() error could not connect to" << m_remote;
36 return false;
37 }
38
40 {
41 yCError(CHATBOT_NWC_YARP) << "Cannot attach the m_thriftClientPort port as client";
42 return false;
43 }
44
45 yCDebug(CHATBOT_NWC_YARP) << "Opening of nwc successful";
46 return true;
47}
48
50{
52 return true;
53}
54
55ReturnValue ChatBot_nwc_yarp::interact(const std::string& messageIn, std::string& messageOut)
56{
57 return_interact output = m_thriftClient.interactRPC(messageIn);
58 if(!output.result)
59 {
60 yCError(CHATBOT_NWC_YARP) << "Could not interact with the chatbot";
61 return output.result;
62 }
63
64 messageOut = output.messageOut;
65 return ReturnValue_ok;
66}
67
68ReturnValue ChatBot_nwc_yarp::setLanguage(const std::string& language)
69{
70 auto ret = m_thriftClient.setLanguageRPC(language);
71 if(!ret)
72 {
73 yCError(CHATBOT_NWC_YARP) << "Could not set the chatbot language to" << language;
74 return ret;
75 }
76 return ReturnValue_ok;
77}
78
80{
81 auto output = m_thriftClient.getLanguageRPC();
82 if(!output.result)
83 {
84 yCError(CHATBOT_NWC_YARP) << "Could not retrieve the currently set language";
85 return output.result;
86 }
87 language = output.language;
88 return ReturnValue_ok;
89}
90
92{
93 auto output = m_thriftClient.getStatusRPC();
94 if(!output.result)
95 {
96 yCError(CHATBOT_NWC_YARP) << "Could not retrieve the current bot status";
97 return output.result;
98 }
99 status = output.status;
100 return ReturnValue_ok;
101}
102
104{
105 auto output = m_thriftClient.resetBotRPC();
106 if(!output)
107 {
108 yCError(CHATBOT_NWC_YARP) << "Could not reset the chatbot";
109 return output;
110 }
111 return ReturnValue_ok;
112}
bool ret
#define ReturnValue_ok
Definition ReturnValue.h:77
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue setLanguage(const std::string &language) override
Sets the chat bot language.
yarp::dev::ReturnValue getStatus(std::string &status) override
Gets the current status of the bot.
yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current chatbot language.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
IChatBotMsgs m_thriftClient
yarp::dev::ReturnValue interact(const std::string &messageIn, std::string &messageOut) override
Sends a message to the chatbot.
yarp::dev::ReturnValue resetBot() override
Resets the chatbot.
bool close() override
Close the DeviceDriver.
yarp::os::Port m_thriftClientPort
virtual yarp::dev::ReturnValue resetBotRPC()
virtual yarp::dev::ReturnValue setLanguageRPC(const std::string &language)
virtual return_getStatus getStatusRPC()
virtual return_interact interactRPC(const std::string &messageIn)
virtual return_getLanguage getLanguageRPC()
yarp::dev::ReturnValue result
yarp::dev::ReturnValue result
std::string messageOut
yarp::dev::ReturnValue result
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:682
void close() override
Stop port activity.
Definition Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A base class for nested structures that can be searched.
Definition Searchable.h:31
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.