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 //Check the protocol version
46 if (!m_thriftClient.checkProtocolVersion()) { return false; }
47
48 yCInfo(CHATBOT_NWC_YARP) << "Opening of NWC successful";
49 return true;
50}
51
53{
55 return true;
56}
57
58ReturnValue ChatBot_nwc_yarp::interact(const std::string& messageIn, std::string& messageOut)
59{
60 return_interact output = m_thriftClient.interactRPC(messageIn);
61 if(!output.result)
62 {
63 yCError(CHATBOT_NWC_YARP) << "Could not interact with the chatbot";
64 return output.result;
65 }
66
67 messageOut = output.messageOut;
68 return ReturnValue_ok;
69}
70
71ReturnValue ChatBot_nwc_yarp::setLanguage(const std::string& language)
72{
73 auto ret = m_thriftClient.setLanguageRPC(language);
74 if(!ret)
75 {
76 yCError(CHATBOT_NWC_YARP) << "Could not set the chatbot language to" << language;
77 return ret;
78 }
79 return ReturnValue_ok;
80}
81
83{
84 auto output = m_thriftClient.getLanguageRPC();
85 if(!output.result)
86 {
87 yCError(CHATBOT_NWC_YARP) << "Could not retrieve the currently set language";
88 return output.result;
89 }
90 language = output.language;
91 return ReturnValue_ok;
92}
93
95{
96 auto output = m_thriftClient.getStatusRPC();
97 if(!output.result)
98 {
99 yCError(CHATBOT_NWC_YARP) << "Could not retrieve the current bot status";
100 return output.result;
101 }
102 status = output.status;
103 return ReturnValue_ok;
104}
105
107{
108 auto output = m_thriftClient.resetBotRPC();
109 if(!output)
110 {
111 yCError(CHATBOT_NWC_YARP) << "Could not reset the chatbot";
112 return output;
113 }
114 return ReturnValue_ok;
115}
bool ret
#define ReturnValue_ok
Definition ReturnValue.h:80
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 bool checkProtocolVersion()
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:330
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 yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.