YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ChatBot_nws_yarp.h
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#ifndef YARP_DEV_CHATBOT_NWS_YARP_H
7#define YARP_DEV_CHATBOT_NWS_YARP_H
8
9#include <cstdio>
10#include <cstdlib>
11#include <mutex>
12#include <memory>
13
15#include <yarp/dev/PolyDriver.h>
16#include <yarp/dev/IChatBot.h>
17#include <yarp/os/Time.h>
18#include <yarp/os/Network.h>
19#include <yarp/os/Vocab.h>
20#include <yarp/os/Bottle.h>
21#include <yarp/os/RpcServer.h>
23#include "IChatBotMsgs.h"
25
26using namespace yarp::os;
27using namespace yarp::dev;
28
29// Callback implementation after buffered input.
31{
32protected:
35
36public:
37 virtual ~ChatBotRPC_CallbackHelper() override {};
38
40
42 void onRead(yarp::os::Bottle& b) override;
43};
44
45// rpc commands
47{
48private:
49 std::mutex m_mutex;
50 yarp::dev::IChatBot* m_iChatBot{nullptr};
51
52public:
53 return_interact interactRPC(const std::string& messageIn) override;
54 ReturnValue setLanguageRPC(const std::string& language) override;
57 ReturnValue resetBotRPC() override;
58
59public:
61 std::mutex* getMutex() { return &m_mutex; }
62};
63
64
84{
85private:
86 yarp::dev::IChatBot* m_iChatBot{ nullptr };
87 yarp::os::Port m_inputPort;
88 yarp::os::Port m_outputPort;
89 yarp::os::RpcServer m_thriftServerPort;
90 IChatBotMsgsImpl m_msgsImpl;
91
93 std::unique_ptr<ChatBotRPC_CallbackHelper> m_cbkHelper;
94
95 // yarp::dev::IWrapper
96 bool attach(yarp::dev::PolyDriver* deviceToAttach) override;
97 bool detach() override;
98
99private:
100 bool closeMain();
101
102public:
103 ChatBot_nws_yarp() = default;
108 virtual ~ChatBot_nws_yarp() override;
109
110 bool open(yarp::os::Searchable& config) override;
111 bool close() override;
113};
114
115#endif // YARP_DEV_CHATBOT_NWS_YARP_H
yarp::dev::IChatBot * m_iChatBot
virtual ~ChatBotRPC_CallbackHelper() override
bool setCommunications(yarp::dev::IChatBot *iser, yarp::os::Port *port)
void onRead(yarp::os::Bottle &b) override
This class is the parameters parser for class ChatBot_nws_yarp.
ChatBot_nws_yarp: A wrapper for a plugin able to interact with a chatbot or implementing one.
ChatBot_nws_yarp & operator=(ChatBot_nws_yarp &&)=delete
ChatBot_nws_yarp(const ChatBot_nws_yarp &)=delete
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
ChatBot_nws_yarp(ChatBot_nws_yarp &&)=delete
virtual ~ChatBot_nws_yarp() override
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
ChatBot_nws_yarp()=default
bool close() override
Close the DeviceDriver.
ChatBot_nws_yarp & operator=(const ChatBot_nws_yarp &)=delete
std::mutex * getMutex()
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
Interface implemented by all device drivers.
IChatBot interface.
Definition IChatBot.h:26
A container for a device driver.
Definition PolyDriver.h:23
Helper interface for an object that can wrap/or "attach" to a single other device.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
A mini-server for network communication.
Definition Port.h:46
A port that is specialized as an RPC server.
Definition RpcServer.h:23
A base class for nested structures that can be searched.
Definition Searchable.h:31
A callback for typed data from a port.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.