1a371dd4a7289a0a896e48b2b8e103d1b6474faa
[lordsawar] / src / network-server.h
1 // Copyright (C) 2008 Ole Laursen
2 // Copyright (C) 2008 Ben Asselstine 
3 //
4 //  This program is free software; you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation; either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU Library General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
17 //  02110-1301, USA.
18
19 #ifndef NETWORK_SERVER_H
20 #define NETWORK_SERVER_H
21
22 #include "config.h"
23
24 #include <map>
25 #include <sigc++/signal.h>
26 #include <string>
27
28 #include "network-common.h"
29
30 class _GServer;
31 class _GConn;
32 class NetworkConnection;
33
34 class NetworkServer
35 {
36 public:
37   NetworkServer();
38   ~NetworkServer();
39
40   bool isListening();
41   void startListening(int port);
42   void send(void *conn, MessageType type, const std::string &payload);
43
44   sigc::signal<void, void *, MessageType, std::string> got_message;
45   sigc::signal<void, void *> connection_made;
46   sigc::signal<void, void *> connection_lost;
47   
48   // private callback
49   void gotClientConnection(_GConn* conn);
50
51 private:
52   void onConnectionLost(NetworkConnection *conn);
53   
54   _GServer *server;
55   std::list<NetworkConnection *> connections;
56 };
57
58 #endif