void XMLMessage::setBean(XMLMessageBean* bean) { char *xmlText = bean->encode(); if (xmlText != NULL) { ByteArray bytes(xmlText, strlen(xmlText)); setPayload(&bytes); } else setPayload(NULL); }
Message::Message(quint32 pNo, Member* sender, quint32 cmd, QByteArray payload) { setPacketNo(pNo); setSender(sender); setCommand(cmd); setPayload(payload); }
void MigrationVerifyActor::handleVerifyRequest(const idgs::actor::ActorMessagePtr& msg) { pb::MigrationVerifyRequest* request = NULL; if (msg->getPayload()) { request = dynamic_cast<pb::MigrationVerifyRequest*>(msg->getPayload().get()); } if (request && request->has_schema_name() && request->has_store_name()) { auto datastore = idgs::store::idgs_store_module()->getDataStore(); auto store = datastore->getStore(request->schema_name(), request->store_name()); if (!store) { LOG(ERROR) << "store " << request->schema_name() << "." << request->store_name() << " is not found."; auto payload = std::make_shared<pb::MigrationVerifyResponse>(); payload->set_result_code(static_cast<int32_t>(RC_STORE_NOT_FOUND)); auto respMsg = msg->createResponse(); respMsg->setOperationName("VERIFY_RESPONSE"); respMsg->setPayload(payload); idgs::actor::sendMessage(respMsg); return; } if (store->getStoreConfig()->getStoreConfig().partition_type() != idgs::store::pb::PARTITION_TABLE) { LOG(ERROR) << "store " << request->schema_name() << "." << request->store_name() << " is not a partition store."; auto payload = std::make_shared<pb::MigrationVerifyResponse>(); payload->set_result_code(static_cast<int32_t>(RC_STORE_NOT_FOUND)); auto respMsg = msg->createResponse(); respMsg->setOperationName("VERIFY_RESPONSE"); respMsg->setPayload(payload); idgs::actor::sendMessage(respMsg); return; } } clientMsg = msg; auto& members = idgs_application()->getMemberManager()->getMemberTable(); auto it = members.begin(); for (; it != members.end(); ++ it) { if (it->isLocalStore() && (it->getState() == idgs::pb::MS_PREPARED || it->getState() == idgs::pb::MS_ACTIVE)) { auto reqMsg = createActorMessage(); reqMsg->setOperationName("LOCAL_VERIFY_REQUEST"); reqMsg->setDestMemberId(it->getId()); reqMsg->setDestActorId(actorId); reqMsg->setPayload(msg->getPayload()); idgs::actor::sendMessage(reqMsg); ++ memberSize; } } }
Packet::Packet(string packetData){ // Parse the packet into the object stringstream deserializer(packetData); string type; deserializer >> type; string d; string t; string dateTime; deserializer >> d; deserializer >> t; stringstream dateTimeStream; dateTimeStream << d << " " << t; dateTime = dateTimeStream.str(); const char * timeBuffer =dateTime.c_str(); tm date; strptime(timeBuffer, "%Y-%m-%d %H:%M:%S", &date); time_t packetTime = mktime(&date); setTimeSent(packetTime); int life; deserializer >> life; setLifeTime(life); int pno; deserializer >> pno; setPacketNumber(pno); int hop; deserializer >> hop; hop++; setHopCount(hop); string src; deserializer >> src; setSourceAddress(src); string dest; deserializer >> dest; setDestinationAddress(dest); stringstream payloadStream; payloadStream << deserializer.rdbuf(); string pay = payloadStream.str(); pay = pay.substr(1, pay.length()); setPayload(pay); }
// rxPacket - Function to read the frame received. void XBeeLib::rxPacket() { int index; int size; int length; int payloadPosition; if(getCoordinatorEnabled() == 1){ size = 8; length = 22; payloadPosition = 14; } else{ size = 1; length = 9; payloadPosition = 8; } clearReceived(); char frame[size]; index = 0; if(Serial.available() > length){ Serial.println(); for(int i = 0; i <= length; i++){ if((i >= payloadPosition) && (i < length)){ frame[index] = Serial.read(); addReceived((String)((char)frame[index])); Serial.print(frame[index], HEX); Serial.print(" "); index++; } else{ Serial.print(Serial.read(), HEX); Serial.print(" "); } } Serial.print("\n<<< "); Serial.println(getReceived()); if(getCoordinatorEnabled() == 0){ if(getReceived() == "r"){ //setConfigure(); } if(getReceived() == "s"){ //setSleepMode(); } if(getReceived() == "t"){ setPayload(getStatus()); txRequest(getPayloadAddress()); } } } }
/*! \brief Create a Smart Poster record based on the record passed through the argument. Internalizes and parses the payload of the original record. */ NdefNfcSpRecord::NdefNfcSpRecord(const QNdefRecord &other) : QNdefRecord(QNdefRecord::NfcRtd, "Sp"), recordUri(NULL), recordAction(NULL), recordSize(NULL), recordType(NULL), recordImage(NULL) { setPayload(other.payload()); }
/*! \brief Create an empty Smart Poster (Sp) record. Note that in order to write a Smart Poster to a tag, you have to at least add the URL. An empty Smart Poster record is not valid according to the specs. */ NdefNfcSpRecord::NdefNfcSpRecord() : QNdefRecord(QNdefRecord::NfcRtd, "Sp"), recordUri(NULL), recordAction(NULL), recordSize(NULL), recordType(NULL), recordImage(NULL) { setPayload(QByteArray(0, char(0))); }
// Note; doit-on passer en dynamique ??? // si l'o anbMessage createIDMessage (unsigned char txID) { anbMessage msg; setTxID (&msg, txID); setRxID (&msg, _BDCAST_ADDR); setType (&msg, ID_MSG); setSize (&msg, 0); setPayload (&msg, NULL); return msg; }
anbMessage createACKMessage (unsigned char txID, unsigned char rxID) { anbMessage msg; setTxID (&msg, txID); setRxID (&msg, rxID); setType (&msg, ACK_MSG); setSize (&msg, 0); setPayload (&msg, NULL); return msg; }
DeviceInfoPacket::DeviceInfoPacket(int width, int height, String userID) { mWidth=width; mHeight=height; mUserID=userID; sprintf(buffer, "%4d%4d0123456789", 720, 1280); header=new PacketHeader(DEVICE_INFO, 18); setHeader(header); setPayload((byte*)buffer); }
anbMessage createDATAMessage (unsigned char txID, unsigned char rxID, char* payload, unsigned char payloadSize) { anbMessage msg; setTxID (&msg, txID); setRxID (&msg, rxID); setType (&msg, DATA_MSG); setSize (&msg, payloadSize); setPayload (&msg, payload); return msg; }
/*! Sets the locale of the text record to \a locale. */ void QNdefNfcTextRecord::setLocale(const QString &locale) { QByteArray p = payload(); quint8 status = p.isEmpty() ? 0 : p.at(0); quint8 codeLength = status & 0x3f; quint8 newStatus = (status & 0xd0) | locale.length(); p[0] = newStatus; p.replace(1, codeLength, locale.toAscii()); setPayload(p); }
Message::Message() { d = new MessageData; qRegisterMetaType<Message>("Message"); setType( "" ); setPayload( "" ); setSenderID( 0 ); setGroupID( 0 ); setSeconds( 0 ); setUseconds( 0 ); setBridgeID( 0 ); setHist( false ); setName( "Unknown" ); setSender( 0 ); }
/*! \sa PacketProcessor */ Packet& PacketProcessor::buildIPPacket(string p_DestinationIP, string p_SourceIP, string p_Payload) { //store the arguments m_DestinationIP = p_DestinationIP; m_SourceIP = p_SourceIP; m_Payload = p_Payload; //set version m_PacketBuffer[0] = (unsigned char)setSubField((unsigned)m_PacketBuffer[0], VERSION, 7, 4); //set standard header length m_PacketBuffer[0] = (unsigned char)setSubField((unsigned)m_PacketBuffer[0], IHL, 3, 0); //set the second field to zero (DSCP[7-2] and ECN[1-0]) //set identification setMultipleFields(&m_PacketBuffer[5], m_Identification++, SHORT); //set flags clearBit(&m_PacketBuffer[6], 7); //reserved clearBit(&m_PacketBuffer[6], 6); //Don't fragment DF clearBit(&m_PacketBuffer[6], 5); //More fragments MF //set fragment offset //set TTL m_PacketBuffer[8] = TTL; //set Protocol m_PacketBuffer[9] = PROTOCOL; //set source IP m_Converter.ipToUChar(m_SourceIP, &m_PacketBuffer[12]); //set destination IP m_Converter.ipToUChar(m_DestinationIP, &m_PacketBuffer[16]); //set paylod and packet length setMultipleFields(&m_PacketBuffer[3], setPayload(&m_PacketBuffer[20]), SHORT); addCheckSum(m_PacketBuffer); //set the IP packet into the frame m_Frame.setPDU(m_PacketBuffer); resetPacketBuffer(); return m_Frame; }
HardwareState::HardwareState() { // set initial states and values of modules setEnergy((MIN_PROPER_VOLTAGE + MAX_PROPER_VOLTAGE)/2); setEnergyCurrent(MAX_PROPER_CURRENT); setEnergyStatus(MODULE_ON); setTemperature((MAX_PROPER_TEMPERATURE + MIN_PROPER_TEMPERATURE)/2); setTemperatureStatus(MODULE_ON); setPayload(1); setPayloadStatus(MODULE_STANDBY); setSband(1); setSbandStatus(MODULE_STANDBY); setSolarPanels(1); setSolarPanelsStatus(MODULE_ON); setThermalControl(1); setThermalControlStatus(MODULE_STANDBY); }
void EthernetFrame::build(MacAddress& dstMac, MacAddress& srcMac, NetworkData* newPayload /* = 0 */, const PayloadType newPayloadType /* = Eth_MaxType */) { ACE_TRACE("EthernetFrame::build"); throwIfInitialized(); setInitialized_(true); if ( newPayload ) setUnitLength(estimate_length(newPayload->getUnitLength(), preambleLength_, typeLen_)); else setUnitLength(estimate_length(0, preambleLength_, typeLen_)); if (preambleLength_ == LinuxTap) { setPreambleType(newPayloadType); } setDstAddr(dstMac); setSrcAddr(srcMac); setEtherType(newPayloadType); if ( newPayload) setPayload(newPayload); }
Message::Message( QString type, QByteArray payload, quint64 senderID, quint64 groupID, quint32 seconds, quint32 useconds, quint32 bridgeID, bool hist , QString name, Target* sender ) { d = new MessageData; qRegisterMetaType<Message>("Message"); setType( type ); setPayload( payload ); setSenderID( senderID ); setGroupID( groupID ); setSeconds( seconds ); setUseconds( useconds ); setBridgeID( bridgeID ); setHist( hist ); setName( name ); setSender( sender ); }
void PairStoreDelegateRddPartition::handleRddTransform(const idgs::actor::ActorMessagePtr& msg) { if (!active) { active = true; } transform(); rddLocal->setPartitionState(partition, TRANSFORM_COMPLETE); shared_ptr<RddResponse> response = make_shared<RddResponse>(); response->set_partition(partition); response->set_result_code(RRC_SUCCESS); auto respMsg = createActorMessage(); respMsg->setDestActorId(rddLocal->getRddId().actor_id()); respMsg->setDestMemberId(rddLocal->getRddId().member_id()); respMsg->setOperationName(PARTITION_TRANSFORM_COMPLETE); respMsg->setPayload(response); sendMessage(respMsg); }
/*! Sets the enconding of the contents to \a encoding. */ void QNdefNfcTextRecord::setEncoding(Encoding encoding) { QByteArray p = payload(); quint8 status = p.isEmpty() ? 0 : p.at(0); QString string = text(); if (encoding == Utf8) status &= ~0x80; else status |= 0x80; p[0] = status; setPayload(p); setText(string); }
/*! Sets the contents of the text record to \a text. */ void QNdefNfcTextRecord::setText(const QString text) { if (payload().isEmpty()) setLocale(QLocale().name()); QByteArray p = payload(); quint8 status = p.at(0); bool utf16 = status & 0x80; quint8 codeLength = status & 0x3f; p.truncate(1 + codeLength); QTextCodec *codec = QTextCodec::codecForName(utf16 ? "UTF-16BE" : "UTF-8"); p += codec->fromUnicode(text); setPayload(p); }
void PairStoreDelegateRddPartition::handleActionRequest(const idgs::actor::ActorMessagePtr& msg) { ActionRequest* request = dynamic_cast<ActionRequest*>(msg->getPayload().get()); DVLOG(3) << getPartitionName() << " run " << request->action_op_name() << " action"; shared_ptr<ActionResponse> response = make_shared<ActionResponse>(); response->set_action_id(request->action_id()); response->set_partition(partition); ActionMgr& actionMgr = *idgs_rdd_module()->getActionManager(); const ActionPtr& action = actionMgr.get(request->action_op_name()); RddResultCode code = RRC_SUCCESS; if (action.get()) { if (rddLocal->isReplicatedRdd() && partition > 0) { code = RRC_SUCCESS; } else { action::ActionContext ctx; if (ctx.initContext(&msg, &rddLocal->getKeyTemplate(), &rddLocal->getValueTemplate())) { code = action->action(&ctx, this); if (code == RRC_SUCCESS) { auto& result = ctx.getPartitionResult(); for (int32_t i = 0; i < result.size(); ++i) { response->add_action_value(result[i].toString()); } } } else { code = RRC_INVALID_ACTION_PARAM; } } } else { LOG(ERROR)<< "action " << request->action_op_name() << " is not registered."; code = RRC_ACTION_NOT_FOUND; } response->set_result_code(code); VLOG(2) << getPartitionName() << " process " << request->action_op_name() << " action done."; auto respMsg = msg->createResponse(); respMsg->setOperationName(RDD_ACTION_RESPONSE); respMsg->setPayload(response); idgs::actor::sendMessage(respMsg); }
anbMessage unserializeMessage (char* msgBuffer) { anbMessage msg; char *visitor = msgBuffer; setTxID (&msg, (unsigned char) *visitor); ++visitor; setRxID (&msg, (unsigned char) *visitor); ++visitor; setType (&msg, (unsigned char) *visitor); ++visitor; setSize (&msg, (unsigned char) *visitor); if (getSize (&msg) != 0) { createPayload (&msg, getSize (&msg)); ++visitor; setPayload (&msg, visitor); } return msg; }
void MigrationVerifyActor::handleVerifyResponse(const idgs::actor::ActorMessagePtr& msg) { auto response = dynamic_cast<pb::MigrationVerifyResponse*>(msg->getPayload().get()); memberData.insert(std::pair<int32_t, pb::MemberMigrationData>(msg->getSourceMemberId(), response->member_data(0))); if (memberData.size() == memberSize) { auto payload = std::make_shared<pb::MigrationVerifyResponse>(); payload->set_result_code(static_cast<int32_t>(RC_SUCCESS)); auto it = memberData.begin(); for (; it != memberData.end(); ++ it) { payload->add_member_data()->CopyFrom(it->second); } auto respMsg = clientMsg->createResponse(); respMsg->setOperationName("VERIFY_RESPONSE"); respMsg->setPayload(payload); idgs::actor::sendMessage(respMsg); memberData.clear(); memberSize = 0; } }
// copy constructor SFPacket::SFPacket(const SFPacket &pPacket) { length = pPacket.getLength(); type = pPacket.getType(); seqno = pPacket.getSeqno(); setPayload(pPacket.getPayload(), length); }
void MigrationVerifyActor::handleLocalVerifyRequest(const idgs::actor::ActorMessagePtr& msg) { pb::MigrationVerifyRequest* request = NULL; if (msg->getPayload()) { request = dynamic_cast<pb::MigrationVerifyRequest*>(msg->getPayload().get()); } auto datastore = idgs::store::idgs_store_module()->getDataStore(); std::vector<idgs::store::StorePtr> stores; if (request && request->has_schema_name() && request->has_store_name()) { auto store = datastore->getStore(request->schema_name(), request->store_name()); stores.push_back(store); } else { datastore->getStores(stores); } auto app = idgs_application(); auto cluster = app->getClusterFramework(); auto pcnt = cluster->getPartitionCount(); auto bkcnt = cluster->getClusterConfig()->max_replica_count() - 1; auto local = cluster->getLocalMember()->getId(); auto partitionMgr = app->getPartitionManager(); auto payload = std::make_shared<pb::MigrationVerifyResponse>(); payload->set_result_code(static_cast<int32_t>(RC_SUCCESS)); auto memberData = payload->add_member_data(); memberData->set_member_id(local); for (int32_t i = 0; i < stores.size(); ++ i) { auto& store = stores.at(i); auto& storeConfigWrapper = store->getStoreConfig(); if (storeConfigWrapper->getStoreConfig().partition_type() == idgs::store::pb::PARTITION_TABLE) { auto pstore = dynamic_cast<idgs::store::PartitionedStore*>(store.get()); auto& schemaName = store->getStoreConfig()->getSchema(); auto& storeName = store->getStoreConfig()->getStoreConfig().name(); auto storeData = memberData->add_store_data(); storeData->set_schema_name(schemaName); storeData->set_store_name(storeName); for (int32_t p = 0; p < pcnt; ++ p) { auto partition = partitionMgr->getPartition(p); for (int32_t pos = 0; pos < bkcnt + 1; ++ pos) { if (partition->getMemberId(pos) == local) { auto partitionData = storeData->add_partition_data(); partitionData->set_partition_id(p); partitionData->set_position(pos); partitionData->set_member_id(local); partitionData->set_size(pstore->dataSize(p)); VLOG(0) << schemaName << "." << storeName << " partition " << p << "(" << pos << ") data size " << partitionData->size() << " on member " << local; std::shared_ptr<idgs::store::StoreMap> map; pstore->snapshotStore(p, map); auto it = map->iterator(); while (it->hasNext()) { idgs::store::StoreOption ps; storeConfigWrapper->calculatePartitionInfo(it->key(), &ps); ps.memberId = partitionMgr->getPartition(ps.partitionId)->getMemberId(pos); auto keyPartition = partitionData->add_key_partition(); keyPartition->set_key_partition_id(ps.partitionId); keyPartition->set_key_member_id(ps.memberId); it->next(); } } } } } } auto respMsg = msg->createResponse(); respMsg->setOperationName("VERIFY_RESPONSE"); respMsg->setPayload(payload); idgs::actor::sendMessage(respMsg); }
void Widget::_receive( Msg * _pMsg ) { State state = m_state; switch( _pMsg->type() ) { case MsgType::MouseEnter: if( m_bPressed ) state.setPressed(true); else state.setHovered(true); break; case MsgType::MouseLeave: state.setHovered(false); // Also clears any pressed flag. break; case MsgType::MousePress: { auto pMsg = static_cast<MousePressMsg*>(_pMsg); if( pMsg->button() == MouseButton::Left ) { if( state.isHovered() ) state.setPressed(true); m_bPressed = true; } break; } case MsgType::MouseRelease: { auto pMsg = static_cast<MouseReleaseMsg*>(_pMsg); if( pMsg->button() == MouseButton::Left ) { if( state.isHovered() ) state.setPressed(false); m_bPressed = false; } break; } case MsgType::FocusGained: state.setFocused(true); break; case MsgType::FocusLost: state.setFocused(false); break; case MsgType::DropPick: { auto pMsg = static_cast<DropPickMsg*>(_pMsg); if (!pMsg->hasPayload()) { pMsg->setPayload(Payload::create()); } break; } case MsgType::DropEnter: state.setTargeted(true); break; case MsgType::DropLeave: state.setTargeted(false); break; default: break; } if( state != m_state ) _setState( state ); }
void StoreMigrationSourceActor::handleMigrationRequest(const idgs::actor::ActorMessagePtr& msg) { // migration data if (it->hasNext()) { std::shared_ptr<pb::MigrationData> payload = std::make_shared<pb::MigrationData>(); size_t cnt = 0; auto mode = static_cast<protobuf::SerdesMode>(msg->getSerdesType()); while (it->hasNext() && cnt < batchSize) { auto data = payload->add_data(); data->set_operation_name(OP_INTERNAL_INSERT); protobuf::ProtoSerdesHelper::serialize(mode, it->key().get(), data->mutable_key()); protobuf::ProtoSerdesHelper::serialize(mode, it->value().get().get(), data->mutable_value()); ++ cnt; it->next(); } auto reqMsg = msg->createResponse(); reqMsg->setOperationName(MIGRATION_DATA); reqMsg->setPayload(payload); idgs::actor::postMessage(reqMsg); return; } // migration store cache if (!redoLog.empty()) { std::shared_ptr<pb::MigrationData> payload = std::make_shared<pb::MigrationData>(); auto mode = static_cast<protobuf::SerdesMode>(msg->getSerdesType()); size_t cnt = 0; while (!redoLog.empty() && cnt < batchSize) { MigrationRedoLog info; redoLog.try_pop(info); if (!info.key) { continue; } auto data = payload->add_data(); data->set_operation_name(info.opName); protobuf::ProtoSerdesHelper::serialize(mode, info.key.get(), data->mutable_key()); if (info.value) { protobuf::ProtoSerdesHelper::serialize(mode, info.value.get(), data->mutable_value()); } ++ cnt; } auto reqMsg = msg->createResponse(); reqMsg->setOperationName(MIGRATION_DATA); reqMsg->setPayload(payload); idgs::actor::postMessage(reqMsg); return; } auto& wrapper = pstore->getStoreConfig(); auto& schemaName = wrapper->getSchema(); auto& storeName = wrapper->getStoreConfig().name(); auto payload = std::make_shared<pb::StoreMigrationComplete>(); payload->set_schema_name(schemaName); payload->set_store_name(storeName); payload->set_data_size(map->size()); auto respMsg = msg->createResponse(); respMsg->setOperationName(STORE_MIGRATION_COMPLETE); respMsg->setPayload(payload); DVLOG(2) << "store " << schemaName << "." << storeName << " of partition " << partId << " migration complete on source member "; idgs::actor::sendMessage(respMsg); terminate(); }
void set_datagram_pfwd_challenge(uint8_t* packet , challenge_t challenge){ setPayload(packet,DATAGRAM_PFWD_CHALLENGE_DISP, CHALLENGE_LEN_BYTE, challenge); }