Fawkes API Fawkes Development Version
server_thread.h
1
2/***************************************************************************
3 * server_thread.h - Thread to manage Fawkes network clients
4 *
5 * Created: Sun Nov 19 14:27:31 2006
6 * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#ifndef _NETCOMM_FAWKES_SERVER_THREAD_H_
25#define _NETCOMM_FAWKES_SERVER_THREAD_H_
26
27#include <core/threading/thread.h>
28#include <core/utils/lock_map.h>
29#include <netcomm/fawkes/hub.h>
30#include <netcomm/utils/incoming_connection_handler.h>
31
32#include <string>
33#include <vector>
34
35namespace fawkes {
36
37class ThreadCollector;
38class Mutex;
39class FawkesNetworkServerClientThread;
40class NetworkAcceptorThread;
41class FawkesNetworkHandler;
42class FawkesNetworkMessage;
43class FawkesNetworkMessageQueue;
44class FawkesNetworkMessageContent;
45
47 public FawkesNetworkHub,
49{
50public:
51 FawkesNetworkServerThread(bool enable_ipv4,
52 bool enable_ipv6,
53 const std::string &listen_ipv4,
54 const std::string &listen_ipv6,
55 unsigned int fawkes_port,
56 ThreadCollector * thread_collector = 0);
58
59 virtual void loop();
60
61 virtual void add_handler(FawkesNetworkHandler *handler);
62 virtual void remove_handler(FawkesNetworkHandler *handler);
63
64 virtual void broadcast(FawkesNetworkMessage *msg);
65 virtual void broadcast(unsigned short int component_id,
66 unsigned short int msg_id,
67 void * payload,
68 unsigned int payload_size);
69 virtual void broadcast(unsigned short int component_id, unsigned short int msg_id);
70
71 virtual void send(FawkesNetworkMessage *msg);
72 virtual void
73 send(unsigned int to_clid, unsigned short int component_id, unsigned short int msg_id);
74 virtual void send(unsigned int to_clid,
75 unsigned short int component_id,
76 unsigned short int msg_id,
77 void * payload,
78 unsigned int payload_size);
79 virtual void send(unsigned int to_clid,
80 unsigned short int component_id,
81 unsigned short int msg_id,
83
84 void add_connection(StreamSocket *s) noexcept;
86
87 void force_send();
88
89 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
90protected:
91 virtual void
93 {
95 }
96
97private:
98 ThreadCollector * thread_collector;
99 unsigned int next_client_id;
100 std::vector<NetworkAcceptorThread *> acceptor_threads;
101
102 // key: component id, value: handler
105
106 // key: client id, value: client thread
109
110 FawkesNetworkMessageQueue *inbound_messages;
111};
112
113} // end namespace fawkes
114
115#endif
Network handler abstract base class.
Definition: handler.h:32
Fawkes Network Hub.
Definition: hub.h:34
Fawkes network message content.
A LockQueue of FawkesNetworkMessage to hold messages in inbound and outbound queues.
Definition: message_queue.h:33
Representation of a message that is sent over the network.
Definition: message.h:77
Fawkes Network Thread.
Definition: server_thread.h:49
virtual void broadcast(FawkesNetworkMessage *msg)
Broadcast a message.
void add_connection(StreamSocket *s) noexcept
Add a new connection.
void dispatch(FawkesNetworkMessage *msg)
Dispatch messages.
virtual void add_handler(FawkesNetworkHandler *handler)
Add a handler.
virtual void loop()
Fawkes network thread loop.
virtual ~FawkesNetworkServerThread()
Destructor.
void force_send()
Force sending of all pending messages.
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: server_thread.h:92
virtual void remove_handler(FawkesNetworkHandler *handler)
Remove handler.
virtual void send(FawkesNetworkMessage *msg)
Send a message.
FawkesNetworkServerThread(bool enable_ipv4, bool enable_ipv6, const std::string &listen_ipv4, const std::string &listen_ipv6, unsigned int fawkes_port, ThreadCollector *thread_collector=0)
Constructor.
Map with a lock.
Definition: lock_map.h:36
Interface for handling incoming connections.
TCP stream socket over IP.
Definition: stream.h:32
Thread class encapsulation of pthreads.
Definition: thread.h:46
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:918
Fawkes library namespace.