void Client::handle_read(const boost::system::error_code& e, const size_t size) { if(!e) { std::istream bufReader(&_buf); std::string buf; std::getline(bufReader, buf, '\n'); char packetType; bufReader >> packetType; switch((Packet::PacketType)packetType) { case Packet::Task: { Packet::PacketTask pt; { boost::archive::text_iarchive tia(bufReader); tia >> pt; } std::cout << "new task!" << std::endl; ProcessResults pr = processTask(pt.programs()); Packet::PacketTaskAchieved pta(pr.scores, pr.newPrograms); { std::ostream bufWriter(&_responseBuf); { boost::archive::text_oarchive toa(bufWriter); toa << pta; } bufWriter << "\n"; // the end delimiter } boost::asio::write(_sock, _responseBuf); } break; case Packet::Stop: _state = Quitting; return; break; default: // if the packetType is not recognized break; } }
void ConnectivityAgentMsgProxy::OnRequest(iviLink::Ipc::MsgID id, UInt8 const* pPayload, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize, iviLink::Ipc::DirectionID) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); Message const* req = reinterpret_cast<Message const*>(pPayload); assert(req->header.size + sizeof(Message) == payloadSize); assert(bufferSize >= sizeof(Message)); UInt8 role = 0; CBufferReader bufReader(req->data, req->header.size); switch (req->header.type) { case CA_SC_CONNECTION_ESTABLISHED: { BaseError err = bufReader.read(role); if (err.isNoError()) { LOG4CPLUS_INFO(logger, "CA_SC_CONNECTION_ESTABLISHED role = " + convertIntegerToString(role)); onCounterCAConnected(role); } else { LOG4CPLUS_WARN(logger, "CA_SC_CONNECTION_ESTABLISHED err = " + static_cast<std::string>(err)); } } break; case CA_SC_CONNECTION_LOST: onCounterCADisconnected(); break; default: break; } bufferSize = 0; }