~lucadestudios/lucadestudios/trunk

« back to all changes in this revision

Viewing changes to engine/src/shared/network/src/shared/network/node.cpp

  • Committer: Sean Hodges
  • Date: 2009-04-27 11:13:39 UTC
  • mfrom: (62.1.18 trunk)
  • Revision ID: seanhodges@bluebottle.com-20090427111339-d0ay5y47wxu3qlj1
Merged with upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <boost/bind.hpp>
 
2
#include <boost/foreach.hpp>
 
3
 
 
4
#include "node.h"
 
5
#include "connection.h"
 
6
 
 
7
namespace lucade {
 
8
namespace network {
 
9
 
 
10
node::node(node_process_ptr process) {
 
11
 
 
12
}
 
13
 
 
14
bool node::start() {
 
15
    on_pre_start(); //Perform any tasks before starting the node
 
16
    //Start the process thread using the node_process
 
17
    _process_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&node_process::run, _process.get())));
 
18
    on_post_start();
 
19
}
 
20
 
 
21
void node::stop() {
 
22
    on_pre_stop();
 
23
 
 
24
    //Disconnect each connection
 
25
    BOOST_FOREACH(connection_ptr cp, _connections) {
 
26
        cp->disconnect(); //Disconnect the connections
 
27
    }
 
28
 
 
29
    _process->stop(); //Tell the process to stop
 
30
    _process_thread->join(); //Wait for the thread to end
 
31
 
 
32
    on_post_stop(); //Trigger any post conditions
 
33
}
 
34
 
 
35
connection_ptr node::spawn_connection(ip_addressv4 to_where) {
 
36
    connection_ptr new_connection(new connection(this, to_where)); //Create the new connection
 
37
    connect_connection(new_connection); //Does the backend specific connecting
 
38
    generate_connection_uid(new_connection); //Generate a unique ID for the connection
 
39
    _connections.push_back(new_connection); //Add the connection to the list
 
40
    return new_connection;
 
41
}
 
42
 
 
43
int node::get_connection_count() const {
 
44
    return static_cast<int>(_connections.size());
 
45
}
 
46
 
 
47
connection_ptr node::get_connection(int id) const {
 
48
 
 
49
}
 
50
 
 
51
}
 
52
}