Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1962 runge 1
/*
2
 *
3
 *  Copyright (C) 2010  Mattias Runge
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License along
16
 *  with this program; if not, write to the Free Software Foundation, Inc.,
17
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 */
20
 
21
#ifndef NET_TCPSERVER_H
22
#define NET_TCPSERVER_H
23
 
24
#include <stdint.h>
25
#include <boost/bind.hpp>
26
#include <boost/cast.hpp>
27
#include <boost/asio.hpp>
28
#include <boost/signals2.hpp>
29
#include <boost/shared_ptr.hpp>
30
 
31
#include "types.h"
32
 
33
namespace atom {
34
namespace net {
35
 
36
class TcpServer
37
{
38
public:
39
  typedef boost::shared_ptr<TcpServer>                              Pointer;
40
  typedef boost::signals2::signal<void(SocketId, TcpSocketPointer)> SignalOnNewClient;
41
 
42
  TcpServer(boost::asio::io_service& io_service, unsigned int port, SocketId id);
43
  ~TcpServer();
44
 
45
  void ConnectSlots(const SignalOnNewClient::slot_type& slot_on_new_client);
46
  void Accept();
47
  SocketId GetId();
48
 
49
private:
50
  TcpSocketPointer                new_client_socket_;
51
  boost::asio::ip::tcp::acceptor  acceptor_;
52
  SocketId                        id_;
53
  uint32_t                        port_;
54
  SignalOnNewClient               signal_on_new_client_;
55
 
56
  void AcceptHandler(const boost::system::error_code& error);
57
};
58
 
59
}; // namespace net
60
}; // namespace atom
61
 
62
#endif // NET_TCPCLIENT_H