1
#include <boost/bind.hpp>
2
#include <boost/foreach.hpp>
5
#include "connection.h"
10
node::node(node_process_ptr process) {
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())));
24
//Disconnect each connection
25
BOOST_FOREACH(connection_ptr cp, _connections) {
26
cp->disconnect(); //Disconnect the connections
29
_process->stop(); //Tell the process to stop
30
_process_thread->join(); //Wait for the thread to end
32
on_post_stop(); //Trigger any post conditions
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;
43
int node::get_connection_count() const {
44
return static_cast<int>(_connections.size());
47
connection_ptr node::get_connection(int id) const {