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
17{
18 if(!iChatBot)
19 {
20 yCError(ICHATBOTMSGSIMPL) << "Invalid pointer to IChatBot device";
21 return false;
22 }
23
24 m_iChatBot = iChatBot;
25
26 return true;
27}
28
30{
31 std::lock_guard <std::mutex> lg(m_mutex);
32 return_interact response;
33 std::string messageOut;
34
35 if(!m_iChatBot->interact(messageIn,messageOut))
36 {
37 yCError(ICHATBOTMSGSIMPL) << "An error occurred while interacting with the chatBot";
38 response.result = false;
39 return response;
40 }
41
42 response.messageOut = messageOut;
43 response.result = true;
44 return response;
45}
46
47bool IChatBotMsgsImpl::setLanguageRPC(const std::string& language)
48{
49 std::lock_guard <std::mutex> lg(m_mutex);
50 if(!m_iChatBot->setLanguage(language))
51 {
52 yCError(ICHATBOTMSGSIMPL) << "Could not set bot language to" << language;
53 return false;
54 }
55
56 return true;
57}
58
60{
61 std::lock_guard <std::mutex> lg(m_mutex);
62 return_getLanguage response;
63 std::string language;
64 if(!m_iChatBot->getLanguage(language))
65 {
66 yCError(ICHATBOTMSGSIMPL) << "Could not retrieve the chatbot language";
67 response.result = false;
68 return response;
69 }
70
71 response.result = true;
72 response.language = language;
73
74 return response;
75}
76
78{
79 std::lock_guard <std::mutex> lg(m_mutex);
80 return_getStatus response;
81 std::string status;
82 if(!m_iChatBot->getStatus(status))
83 {
84 yCError(ICHATBOTMSGSIMPL) << "Could not retrieve the chatbot status";
85 response.result = false;
86 return response;
87 }
88
89 response.result = true;
90 response.status = status;
91
92 return response;
93}
94
96{
97 std::lock_guard <std::mutex> lg(m_mutex);
98 if(!m_iChatBot->resetBot())
99 {
100 yCError(ICHATBOTMSGSIMPL) << "Could not reset the bot";
101
102 return false;
103 }
104
105 return true;
106}
bool setLanguageRPC(const std::string &language) override
return_interact interactRPC(const std::string &messageIn) override
bool setInterfaces(yarp::dev::IChatBot *iChatBot)
bool resetBotRPC() override
return_getStatus getStatusRPC() override
return_getLanguage getLanguageRPC() override
std::string messageOut
IChatBot interface.
Definition IChatBot.h:25
virtual bool getStatus(std::string &status)=0
Gets the current status of the bot.
virtual bool resetBot()=0
Resets the chatbot.
virtual bool setLanguage(const std::string &language="auto")=0
Sets the chat bot language.
virtual bool getLanguage(std::string &language)=0
Gets the current chatbot language.
virtual bool interact(const std::string &messageIn, std::string &messageOut)=0
Sends a message to the chatbot.
A mini-server for performing network communication in the background.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)