YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IChatBotMsgsImpl.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_nws_yarp.h"
7
9#include <yarp/os/LogStream.h>
10#include <yarp/os/Os.h>
11
12namespace {
13YARP_LOG_COMPONENT(ICHATBOTMSGSIMPL, "yarp.devices.chatBot_nws_yarp.ChatBotRPC_CallbackHelper")
14}
15
16using namespace yarp::dev;
17
19{
20 if(!iChatBot)
21 {
22 yCError(ICHATBOTMSGSIMPL) << "Invalid pointer to IChatBot device";
23 return false;
24 }
25
26 m_iChatBot = iChatBot;
27
28 return true;
29}
30
32{
33 std::lock_guard <std::mutex> lg(m_mutex);
34 return_interact response;
35 std::string messageOut;
36
37 auto ret = m_iChatBot->interact(messageIn, messageOut);
38 if(!ret)
39 {
40 yCError(ICHATBOTMSGSIMPL) << "An error occurred while interacting with the chatBot";
41 response.result = ret;
42 return response;
43 }
44
45 response.result = ret;
46 response.messageOut = messageOut;
47 return response;
48}
49
51{
52 std::lock_guard <std::mutex> lg(m_mutex);
53
54 auto ret = m_iChatBot->setLanguage(language);
55 if(!ret)
56 {
57 yCError(ICHATBOTMSGSIMPL) << "Could not set bot language to" << language;
58 return ret;
59 }
60
61 return ReturnValue_ok;
62}
63
65{
66 std::lock_guard <std::mutex> lg(m_mutex);
67 return_getLanguage response;
68 std::string language;
69
70 auto ret = m_iChatBot->getLanguage(language);
71 if(!ret)
72 {
73 yCError(ICHATBOTMSGSIMPL) << "Could not retrieve the chatbot language";
74 response.result = ret;
75 return response;
76 }
77
78 response.result = ret;
79 response.language = language;
80
81 return response;
82}
83
85{
86 std::lock_guard <std::mutex> lg(m_mutex);
87 return_getStatus response;
88 std::string status;
89
90 auto ret = m_iChatBot->getStatus(status);
91 if(!ret)
92 {
93 yCError(ICHATBOTMSGSIMPL) << "Could not retrieve the chatbot status";
94 response.result = ret;
95 return response;
96 }
97
98 response.result = ret;
99 response.status = status;
100
101 return response;
102}
103
105{
106 std::lock_guard <std::mutex> lg(m_mutex);
107
108 auto ret = m_iChatBot->resetBot();
109 if(!ret)
110 {
111 yCError(ICHATBOTMSGSIMPL) << "Could not reset the bot";
112 return ret;
113 }
114
115 return ReturnValue_ok;
116}
bool ret
#define ReturnValue_ok
Definition ReturnValue.h:77
return_interact interactRPC(const std::string &messageIn) override
ReturnValue resetBotRPC() override
bool setInterfaces(yarp::dev::IChatBot *iChatBot)
return_getStatus getStatusRPC() override
return_getLanguage getLanguageRPC() override
ReturnValue setLanguageRPC(const std::string &language) override
yarp::dev::ReturnValue result
yarp::dev::ReturnValue result
std::string messageOut
yarp::dev::ReturnValue result
IChatBot interface.
Definition IChatBot.h:26
virtual yarp::dev::ReturnValue resetBot()=0
Resets the chatbot.
virtual yarp::dev::ReturnValue setLanguage(const std::string &language="auto")=0
Sets the chat bot language.
virtual yarp::dev::ReturnValue interact(const std::string &messageIn, std::string &messageOut)=0
Sends a message to the chatbot.
virtual yarp::dev::ReturnValue getLanguage(std::string &language)=0
Gets the current chatbot language.
virtual yarp::dev::ReturnValue getStatus(std::string &status)=0
Gets the current status of the bot.
A mini-server for performing network communication in the background.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.