~lucadestudios/lucadestudios/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef NODE_H_INCLUDED
#define NODE_H_INCLUDED

#include <vector>
#include <boost/thread.hpp>

#include "ip_addressv4.h"
#include "node_process.h"

namespace lucade {
namespace network {

class connection;
typedef boost::shared_ptr<connection> connection_ptr;

class packet;

class node {
public:
    node(node_process_ptr process);

    bool start();
    void stop();

    connection_ptr spawn_connection(ip_addressv4 toWhere=ip_addressv4());
    int get_connection_count() const;
    connection_ptr get_connection(int id) const;
private:
    void queue_packet(boost::shared_ptr<packet> packetToSend); ///!< Queues a packet to send via the node_process
    node_process_ptr _process;
    boost::shared_ptr<boost::thread> _process_thread;

    std::vector<connection_ptr> _connections;

    virtual void on_pre_start() = 0;
    virtual void on_post_start() = 0;
    virtual void on_pre_stop() = 0;
    virtual void on_post_stop() = 0;

friend class connection;
};

typedef boost::shared_ptr<node> node_ptr;
}
}

#endif // NODE_H_INCLUDED