X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnetwork%2Fserver.cpp;h=a892dedd25a85c79e9ba8edd1f3c60db767855a6;hb=81ee4fbd16b472892b67b35ea85956423a2247ed;hp=73cee24a4f0c2f5d7676b98a507be2f25dcce6fd;hpb=d0af7846e05691d65d8021e46c8f81e8ca05199a;p=r2c2.git diff --git a/source/network/server.cpp b/source/network/server.cpp index 73cee24..a892ded 100644 --- a/source/network/server.cpp +++ b/source/network/server.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "libr2c2/catalogue.h" #include "libr2c2/driver.h" #include "libr2c2/route.h" #include "libr2c2/train.h" @@ -34,6 +35,9 @@ Server::Server(Layout &l): listen_sock.signal_data_available.connect(sigc::mem_fun(this, &Server::incoming_connection)); } +Server::~Server() +{ } + void Server::use_event_dispatcher(IO::EventDispatcher &ed) { event_disp = &ed; @@ -56,7 +60,7 @@ void Server::driver_state_changed() send(pkt); } -void Server::emergency(const string &msg) +void Server::emergency(Block *, const string &msg) { EmergencyPacket pkt; pkt.message = msg; @@ -71,13 +75,12 @@ void Server::train_added(Train &train) TrainInfoPacket pkt; pkt.address = train.get_address(); - pkt.loco_type = train.get_locomotive_type().get_article_number().str(); + pkt.loco_type = layout.get_catalogue().get_name(&train.get_locomotive_type()); pkt.name = train.get_name(); send(pkt); - TrainStatus *status = new TrainStatus(train); - status->set_tag("server:status"); - status->signal_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_status_changed), sigc::ref(train))); + if(!train.get_ai_of_type()) + new TrainStatus(train); } void Server::train_control_changed(const Train &train, const string &control, float value) @@ -107,14 +110,13 @@ void Server::train_ai_event(const Train &train, TrainAI &, const TrainAI::Messag pkt.route = route->get_name(); send(pkt); } -} - -void Server::train_status_changed(const Train &train, const string &status) -{ - TrainStatusPacket pkt; - pkt.address = train.get_address(); - pkt.status = status; - send(pkt); + else if(ev.type=="status-changed") + { + TrainStatusPacket pkt; + pkt.address = train.get_address(); + pkt.status = ev.value.value(); + send(pkt); + } } template @@ -159,7 +161,7 @@ void Server::Connection::handshake_done() comm.send(pkt); } - const set &routes = server.layout.get_routes(); + const set &routes = server.layout.get_all(); for(set::const_iterator i=routes.begin(); i!=routes.end(); ++i) if(!(*i)->is_temporary()) { @@ -168,6 +170,7 @@ void Server::Connection::handshake_done() comm.send(pkt); } + const Catalogue &cat = server.layout.get_catalogue(); const map &trains = server.layout.get_trains(); for(map::const_iterator i=trains.begin(); i!=trains.end(); ++i) { @@ -176,7 +179,7 @@ void Server::Connection::handshake_done() { TrainInfoPacket pkt; pkt.address = train.get_address(); - pkt.loco_type = train.get_locomotive_type().get_article_number().str(); + pkt.loco_type = cat.get_name(&train.get_locomotive_type()); pkt.name = train.get_name(); comm.send(pkt); } @@ -198,14 +201,14 @@ void Server::Connection::handshake_done() pkt.functions = train.get_functions(); comm.send(pkt); } - if(TrainStatus *status = dynamic_cast(train.get_tagged_ai("server:status"))) + if(TrainStatus *status = train.get_ai_of_type()) { TrainStatusPacket pkt; pkt.address = train.get_address(); pkt.status = status->get_status(); comm.send(pkt); } - if(TrainRouter *router = dynamic_cast(train.get_tagged_ai("router"))) + if(TrainRouter *router = train.get_ai_of_type()) { TrainRoutePacket pkt; pkt.address = train.get_address();