void StopAndWaitRC::doOnData(const CompoundPtr& compound, Port<Data>) { StopAndWaitRCCommand *command = getCommand(compound->getCommandPool()); assure(command->peer.type == StopAndWaitRCCommand::I, "Received RR frame via 'Data' port"); MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName()); m << " processIncoming(compound), Received I frame " << " expected (NR) " << NR << " received (command->peer.NS) " << command->peer.NS; MESSAGE_END(); // The I-Frame must be either the one we're expecting (NR) or // the one before the one we're expecting (NR-1). If it is NR-1 // it is a duplicate, that we've already acknowledged. May be // our ACK got lost. So we send it again. if(command->peer.NS == NR || command->peer.NS == NR-1) { // As stated above ACK is sent in any case CommandPool* ackPCI = getFUN()->getProxy()->createReply(compound->getCommandPool(), this); ackCompound = CompoundPtr(new Compound(ackPCI)); StopAndWaitRCCommand* ackCommand = activateCommand(ackPCI); ackCommand->peer.type = StopAndWaitRCCommand::RR; ackCommand->peer.NS = NR; MESSAGE_SINGLE(NORMAL, logger, getFUN()->getName() << " Prepared RR frame (ACK) with NS=" << ackCommand->peer.NS << " (the next I frame we're expexcting)"); if (getPortConnector< Port<Ack> >()->hasAcceptor(ackCompound)) { getPortConnector< Port<Ack> >()->getAcceptor(ackCompound)->sendData(ackCompound); ackCompound = CompoundPtr(); } if(command->peer.NS == NR) { MESSAGE_SINGLE(NORMAL, logger, getFUN()->getName() << " This was the next expected I frame"); getDeliverer()->getAcceptor(compound)->onData(compound); NR++; } else { MESSAGE_SINGLE(NORMAL, logger, getFUN()->getName() << " Already received this I frame (duplicate)"); } } else { // this can not happen. wns::Exception e; e << "StopAndWait-ARQ received an I frame that neither (NR) nor (NR-1). " << "This cannot happen and is most probably an implementation error"; throw e; } }
SharMilkRecep DataWorker::insert(const MilkReceptionData &data) { auto deliverer = getDeliverer(data.delivererId()); const auto milkPoint = getMilkPoint(data.milkPointId()); const auto milkRecep = new MilkReception(data.id(), data.deliveryDate(), data.priceLiter(), data.liters(), data.fat(), deliverer.toWeakRef(), milkPoint.toWeakRef()); const auto shared = SharMilkRecep(milkRecep); deliverer->addMilkReception(shared.toWeakRef()); m_milkReceptions.insert(data.id(), shared); return shared; }
void DataWorker::reload() { const QList<milk_id> localities = m_localities.keys(), milkPoints = m_milkPoints.keys(), deliverers = m_deliverers.keys(), milkReceptions = m_milkReceptions.keys(); clear(); for (const auto id: localities) getLocality(id); for (const auto id: milkPoints) getMilkPoint(id); for (const auto id: deliverers) getDeliverer(id); for (const auto id: milkReceptions) getMilkReception(id); }
virtual void processIncoming(const CompoundPtr& compound) { getDeliverer()->getAcceptor(compound)->onData(compound); } // processIncoming