1 #include <msp/core/maputils.h>
9 Client::Client(const Catalogue &c):
22 for(map<unsigned, NetTrain *>::iterator i=trains.begin(); i!=trains.end(); ++i)
26 void Client::use_event_dispatcher(Msp::IO::EventDispatcher &ed)
30 event_disp->add(*socket);
33 void Client::connect(const Net::SockAddr &addr)
35 socket = new Net::StreamSocket(addr.get_family());
36 socket->connect(addr);
38 event_disp->add(*socket);
39 comm = new Net::Communicator(*socket, proto, *this);
42 void Client::set_power(bool p)
44 DriverStatePacket pkt;
50 void Client::set_halt(bool h)
52 DriverStatePacket pkt;
58 NetTrain &Client::get_train(unsigned addr) const
60 return *get_item(trains, addr);
63 void Client::receive(const DriverStatePacket &pkt)
68 signal_power_changed.emit(power);
73 signal_halt_changed.emit(halt);
77 void Client::receive(const EmergencyPacket &pkt)
79 signal_emergency.emit(pkt.message);
82 void Client::receive(const TrainInfoPacket &pkt)
84 NetTrain *train = new NetTrain(*this, pkt);
85 trains[pkt.address] = train;
86 signal_train_added.emit(*train);
89 void Client::receive(const TrainControlPacket &pkt)
91 get_train(pkt.address).process_packet(pkt);
94 void Client::receive(const TrainFunctionPacket &pkt)
96 get_train(pkt.address).process_packet(pkt);
99 void Client::receive(const TrainStatusPacket &pkt)
101 get_train(pkt.address).process_packet(pkt);
104 void Client::receive(const RouteInfoPacket &pkt)
106 routes.push_back(pkt.name);
109 void Client::receive(const TrainRoutePacket &pkt)
111 get_train(pkt.address).process_packet(pkt);
114 void Client::receive(const ErrorPacket &pkt)
116 signal_error.emit(pkt.message);