3 This file is part of R²C²
4 Copyright © 2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
15 Client::Client(const Catalogue &c):
26 for(map<unsigned, NetTrain *>::iterator i=trains.begin(); i!=trains.end(); ++i)
30 void Client::use_event_dispatcher(Msp::IO::EventDispatcher &ed)
34 event_disp->add(*socket);
37 void Client::connect(const Net::SockAddr &addr)
39 socket = new Net::StreamSocket(addr.get_family());
40 socket->connect(addr);
42 event_disp->add(*socket);
43 comm = new Net::Communicator(*socket, proto, *this);
46 NetTrain &Client::get_train(unsigned addr) const
48 map<unsigned, NetTrain *>::const_iterator i = trains.find(addr);
50 throw KeyError("Unknown train");
54 void Client::receive(const TrainInfoPacket &pkt)
56 NetTrain *train = new NetTrain(*this, pkt);
57 trains[pkt.address] = train;
58 signal_train_added.emit(*train);
61 void Client::receive(const TrainControlPacket &pkt)
63 get_train(pkt.address).process_packet(pkt);
66 void Client::receive(const TrainFunctionPacket &pkt)
68 get_train(pkt.address).process_packet(pkt);
71 void Client::receive(const TrainStatusPacket &pkt)
73 get_train(pkt.address).process_packet(pkt);
76 void Client::receive(const RouteInfoPacket &pkt)
78 routes.push_back(pkt.name);
81 void Client::receive(const TrainRoutePacket &pkt)
83 get_train(pkt.address).process_packet(pkt);
86 void Client::receive(const ErrorPacket &pkt)
88 signal_error.emit(pkt.message);