YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ChatBotRPC_CallbackHelper.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(CHATBOTRPC_HELPER, "yarp.devices.chatBot_nws_yarp.ChatBotRPC_CallbackHelper")
14}
15
17{
18 if (iChat ==nullptr || p==nullptr)
19 {
20 yCError(CHATBOTRPC_HELPER) << "Could not get IChatBot interface/output port";
21 return false;
22 }
24 m_outPort = p;
25
26 return true;
27}
28
30{
31 if (m_iChatBot)
32 {
33 std::string response;
34 bool ok = m_iChatBot->interact(b.get(0).asString(), response);
35
36 yCWarning(CHATBOTRPC_HELPER) << "Sent:" << b.get(0).asString() << "Got" << response;
37
39 toSend.addString(response);
40 if (!ok)
41 {
42 yCError(CHATBOTRPC_HELPER) << "Problems during interaction with the chatBot";
43 }
44 else
45 {
47 {
49 }
50 }
51 }
52 else
53 {
54 yCError(CHATBOTRPC_HELPER)<< "IChatBot interface was not set";
55 }
56}
yarp::dev::IChatBot * m_iChatBot
bool setCommunications(yarp::dev::IChatBot *iser, yarp::os::Port *port)
void onRead(yarp::os::Bottle &b) override
IChatBot interface.
Definition IChatBot.h:26
virtual yarp::dev::ReturnValue interact(const std::string &messageIn, std::string &messageOut)=0
Sends a message to the chatbot.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
A mini-server for performing network communication in the background.
A mini-server for network communication.
Definition Port.h:46
int getOutputCount() override
Determine how many output connections this port has.
Definition Port.cpp:567
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition Port.cpp:436
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
#define yCError(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)