X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnetwork%2Fclient.cpp;h=ac4f018e83d9b72777429aed65bda99d1725d197;hb=754ac497179474d0266b55e881a084fef7d5d6a1;hp=50db7df6d817bdcbb738e4182262de9df2fd275f;hpb=9ddcd066e37e4c72685817c042c30897786ece05;p=r2c2.git diff --git a/source/network/client.cpp b/source/network/client.cpp index 50db7df..ac4f018 100644 --- a/source/network/client.cpp +++ b/source/network/client.cpp @@ -1,7 +1,7 @@ /* $Id$ -This file is part of the MSP Märklin suite -Copyright © 2009 Mikkosoft Productions, Mikko Rasa +This file is part of R²C² +Copyright © 2009-2011 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -10,13 +10,15 @@ Distributed under the GPL using namespace std; using namespace Msp; -namespace Marklin { +namespace R2C2 { Client::Client(const Catalogue &c): catalogue(c), socket(0), comm(0), - event_disp(0) + event_disp(0), + power(false), + halt(false) { } Client::~Client() @@ -43,6 +45,22 @@ void Client::connect(const Net::SockAddr &addr) comm = new Net::Communicator(*socket, proto, *this); } +void Client::set_power(bool p) +{ + DriverStatePacket pkt; + pkt.power = p; + pkt.halt = halt; + send(pkt); +} + +void Client::set_halt(bool h) +{ + DriverStatePacket pkt; + pkt.power = power; + pkt.halt = h; + send(pkt); +} + NetTrain &Client::get_train(unsigned addr) const { map::const_iterator i = trains.find(addr); @@ -51,6 +69,25 @@ NetTrain &Client::get_train(unsigned addr) const return *i->second; } +void Client::receive(const DriverStatePacket &pkt) +{ + if(pkt.power!=power) + { + power = pkt.power; + signal_power_changed.emit(power); + } + if(pkt.halt!=halt) + { + halt = pkt.halt; + signal_halt_changed.emit(halt); + } +} + +void Client::receive(const EmergencyPacket &pkt) +{ + signal_emergency.emit(pkt.message); +} + void Client::receive(const TrainInfoPacket &pkt) { NetTrain *train = new NetTrain(*this, pkt); @@ -88,4 +125,4 @@ void Client::receive(const ErrorPacket &pkt) signal_error.emit(pkt.message); } -} // namespace Marklin +} // namespace R2C2