8 Client::Client(const Catalogue &c):
21 for(map<unsigned, NetTrain *>::iterator i=trains.begin(); i!=trains.end(); ++i)
25 void Client::use_event_dispatcher(Msp::IO::EventDispatcher &ed)
29 event_disp->add(*socket);
32 void Client::connect(const Net::SockAddr &addr)
34 socket = new Net::StreamSocket(addr.get_family());
35 socket->connect(addr);
37 event_disp->add(*socket);
38 comm = new Net::Communicator(*socket, proto, *this);
41 void Client::set_power(bool p)
43 DriverStatePacket pkt;
49 void Client::set_halt(bool h)
51 DriverStatePacket pkt;
57 NetTrain &Client::get_train(unsigned addr) const
59 map<unsigned, NetTrain *>::const_iterator i = trains.find(addr);
61 throw KeyError("Unknown train");
65 void Client::receive(const DriverStatePacket &pkt)
70 signal_power_changed.emit(power);
75 signal_halt_changed.emit(halt);
79 void Client::receive(const EmergencyPacket &pkt)
81 signal_emergency.emit(pkt.message);
84 void Client::receive(const TrainInfoPacket &pkt)
86 NetTrain *train = new NetTrain(*this, pkt);
87 trains[pkt.address] = train;
88 signal_train_added.emit(*train);
91 void Client::receive(const TrainControlPacket &pkt)
93 get_train(pkt.address).process_packet(pkt);
96 void Client::receive(const TrainFunctionPacket &pkt)
98 get_train(pkt.address).process_packet(pkt);
101 void Client::receive(const TrainStatusPacket &pkt)
103 get_train(pkt.address).process_packet(pkt);
106 void Client::receive(const RouteInfoPacket &pkt)
108 routes.push_back(pkt.name);
111 void Client::receive(const TrainRoutePacket &pkt)
113 get_train(pkt.address).process_packet(pkt);
116 void Client::receive(const ErrorPacket &pkt)
118 signal_error.emit(pkt.message);