Open Lighting Architecture: common/rpc/RpcServer.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
RpcServer.h
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * RpcServer.h
17 * A generic RPC server.
18 * Copyright (C) 2014 Simon Newton
19 */
20
21#ifndef COMMON_RPC_RPCSERVER_H_
22#define COMMON_RPC_RPCSERVER_H_
23
24#include <stdint.h>
25#include <ola/io/SelectServerInterface.h>
26#include <ola/network/TCPSocketFactory.h>
27
28#include <set>
29#include <memory>
30
31namespace ola {
32
33class ExportMap;
34
35namespace rpc {
36
48 class RpcServer {
49 public:
53 struct Options {
54 public:
60 uint16_t listen_port;
61
62 class ExportMap *export_map;
63
73 ola::network::TCPAcceptingSocket *listen_socket;
74
75 Options()
76 : listen_port(0),
77 export_map(NULL),
78 listen_socket(NULL) {
79 }
80 };
81
90 RpcServer(ola::io::SelectServerInterface *ss,
91 class RpcService *service,
92 class RpcSessionHandlerInterface *session_handler,
93 const Options &options);
94
95 ~RpcServer();
96
101 bool Init();
102
107 ola::network::GenericSocketAddress ListenAddress();
108
114 bool AddClient(ola::io::ConnectedDescriptor *descriptor);
115
116 private:
117 typedef std::set<ola::io::ConnectedDescriptor*> ClientDescriptors;
118
119 ola::io::SelectServerInterface *m_ss;
120 RpcService *m_service;
121 class RpcSessionHandlerInterface *m_session_handler;
122 const Options m_options;
123
124 ola::network::TCPSocketFactory m_tcp_socket_factory;
125 std::auto_ptr<ola::network::TCPAcceptingSocket> m_accepting_socket;
126 ClientDescriptors m_connected_sockets;
127
128 void NewTCPConnection(ola::network::TCPSocket *socket);
129 void ChannelClosed(ola::io::ConnectedDescriptor *socket,
130 class RpcSession *session);
131
132 static const char K_CLIENT_VAR[];
133 static const char K_RPC_PORT_VAR[];
134};
135} // namespace rpc
136} // namespace ola
137
138#endif // COMMON_RPC_RPCSERVER_H_
ola::ExportMap
A container for the exported variables.
Definition ExportMap.h:324
ola::io::ConnectedDescriptor
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
ola::io::SelectServerInterface
The interface for the SelectServer.
Definition SelectServerInterface.h:42
ola::network::GenericSocketAddress
a Generic Socket Address
Definition SocketAddress.h:166
ola::network::TCPAcceptingSocket
Definition TCPSocket.h:74
ola::network::TCPSocket
Definition TCPSocket.h:43
ola::rpc::RpcServer
An RPC server.
Definition RpcServer.h:48
ola::rpc::RpcServer::Init
bool Init()
Initialize the RpcServer.
Definition RpcServer.cpp:86
ola::rpc::RpcServer::AddClient
bool AddClient(ola::io::ConnectedDescriptor *descriptor)
Manually attach a new client on the given descriptor.
Definition RpcServer.cpp:128
ola::rpc::RpcServer::ListenAddress
ola::network::GenericSocketAddress ListenAddress()
Return the address this RpcServer is listening on.
Definition RpcServer.cpp:121
ola::rpc::RpcServer::RpcServer
RpcServer(ola::io::SelectServerInterface *ss, class RpcService *service, class RpcSessionHandlerInterface *session_handler, const Options &options)
Create a new RpcServer.
Definition RpcServer.cpp:53
ola::rpc::RpcService
Definition RpcService.h:35
ola::rpc::RpcSessionHandlerInterface
Used to receive notifications of RPC client session activity.
Definition RpcSessionHandler.h:36
ola::rpc::RpcSession
Represents the RPC session between a client and server.
Definition RpcSession.h:45
ola::rpc
The RPC (Remote Procedure Call) system.
Definition RpcChannel.cpp:41
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::rpc::RpcServer::Options::listen_port
uint16_t listen_port
The TCP port to listen on.
Definition RpcServer.h:60
ola::rpc::RpcServer::Options::export_map
class ExportMap * export_map
The export map to use for stats.
Definition RpcServer.h:62
ola::rpc::RpcServer::Options::listen_socket
ola::network::TCPAcceptingSocket * listen_socket
The listening TCP socket to wait for clients on.
Definition RpcServer.h:73