//------------------------------------------------------------------------------ // Set slot functions //------------------------------------------------------------------------------ bool StoresMgr::setSlotStores(const base::PairStream* const msg) { // First let our base class do everything that it needs to. BaseClass::setSlotStores(msg); // --- // Clear all previous stores and assigned weapons // --- weaponsList = nullptr; externalList = nullptr; fuelList = nullptr; gunPtr = nullptr; // --- // Use the stores list that the Stores class just processed. base::PairStream* stores = getStores(); if (stores != nullptr){ // Create the new weapons list that contains all weapons { base::PairStream* newWeapons = new base::PairStream(); searchAndAdd(stores, typeid(Weapon), newWeapons); if (newWeapons->entries() > 0) weaponsList = newWeapons; newWeapons->unref(); } // Create the new external stores list that contains all // non-weapon, external stores (e.g., fuel tanks, pods, guns) { base::PairStream* newExternal = new base::PairStream(); searchAndAdd(stores, typeid(ExternalStore), newExternal); if (newExternal->entries() > 0) externalList = newExternal; newExternal->unref(); } // Create the new fuel tank list that contains all fuel tanks { base::PairStream* newFuel = new base::PairStream(); searchAndAdd(stores, typeid(FuelTank), newFuel); if (newFuel->entries() > 0) fuelList = newFuel; newFuel->unref(); } // Find the primary gun; i.e., the first gun found on our stores base::List::Item* item = stores->getFirstItem(); while (item != nullptr && gunPtr == nullptr) { base::Pair* pair = static_cast<base::Pair*>(item->getValue()); Gun* p = dynamic_cast<Gun*>(pair->object()); if (p != nullptr) gunPtr = p; item = item->getNext(); } stores->unref(); stores = nullptr; } return true; }
// Default external equipment jettison event handler bool Stores::onJettisonEvent(ExternalStore* const sys) { bool ok = false; if (sys != 0) { Basic::PairStream* list = getStores(); if (list != 0) { // First, make sure it's one of ours! bool found = false; Basic::List::Item* item = list->getFirstItem(); while (item != 0 && !found) { Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue()); found = (sys == pair->object()); // is it a match? item = item->getNext(); } if (found) { // Send a jettison event to the system ok = sys->event(JETTISON_EVENT); } list->unref(); list = 0; } } return ok; }
// Default weapon jettison event handler bool Stores::onJettisonEvent(Weapon* const wpn) { bool ok = false; if (wpn != nullptr) { Basic::PairStream* list = getStores(); if (list != nullptr) { // First, make sure it's one of ours! bool found = false; Basic::List::Item* item = list->getFirstItem(); while (item != nullptr && !found) { Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue()); found = (wpn == pair->object()); // is it a match? item = item->getNext(); } if (found) { // Send a jettison event to the weapon ok = wpn->event(JETTISON_EVENT); } list->unref(); list = nullptr; } } return ok; }
//------------------------------------------------------------------------------ // Reset() //------------------------------------------------------------------------------ void Stores::reset() { BaseClass::reset(); // Reset all of the stores Basic::PairStream* stores = getStores(); if (stores != 0) { resetStores(stores); stores->unref(); stores = 0; } }
//------------------------------------------------------------------------------ // Default function to jettison all jettisonable stores //------------------------------------------------------------------------------ bool Stores::jettisonAll() { // Notify the external stores that we're shutting down Basic::PairStream* list = getStores(); if (list != 0) { Basic::List::Item* item = list->getFirstItem(); while (item != 0) { Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue()); Basic::Component* p = static_cast<Basic::Component*>( pair->object() ); p->event(JETTISON_EVENT); item = item->getNext(); } list->unref(); list = 0; } return true; }
//------------------------------------------------------------------------------ // updateData() -- update non-time critical stuff here //------------------------------------------------------------------------------ void SimpleStoresMgr::updateData(const double dt) { BaseClass::updateData(dt); // --- // Get the current weapon data // --- { Weapon* wpn = static_cast<Weapon*>(getCurrentWeapon()); if (wpn != nullptr) { // Weapon ID curWpnID = wpn->getWeaponID(); // Number of this type weapon int count = 0; base::PairStream* list = getStores(); if (list != nullptr) { const base::List::Item* item = list->getFirstItem(); while (item != nullptr) { const base::Pair* pair = static_cast<const base::Pair*>(item->getValue()); if (pair != nullptr) { const Weapon* s = dynamic_cast<const Weapon*>( pair->object() ); if ( s != nullptr && s->isMode(Player::INACTIVE) && std::strcmp(s->getFactoryName(), wpn->getFactoryName()) == 0 ) { count++; } } item = item->getNext(); } list->unref(); list = nullptr; } nCurWpn = count; wpn->unref(); wpn = nullptr; } else { curWpnID = 0; nCurWpn = 0; } } }
//------------------------------------------------------------------------------ // shutdownNotification() -- We're shutting down //------------------------------------------------------------------------------ bool StoresMgr::shutdownNotification() { // Notify the external stores that we're shutting down base::PairStream* list = getStores(); if (list != nullptr) { base::List::Item* item = list->getFirstItem(); while (item != nullptr) { base::Pair* pair = static_cast<base::Pair*>(item->getValue()); base::Component* p = static_cast<base::Component*>(pair->object()); p->event(SHUTDOWN_EVENT); item = item->getNext(); } list->unref(); list = nullptr; } // Clear our stores setSlotStores(nullptr); return BaseClass::shutdownNotification(); }
//------------------------------------------------------------------------------ // updateData() -- update non-time critical stuff here //------------------------------------------------------------------------------ void Stores::updateData(const LCreal dt) { // Update our non-weapon, external stores, which need to act as // active systems attached to our ownship player. { Basic::PairStream* list = getStores(); if (list != 0) { Basic::List::Item* item = list->getFirstItem(); while (item != 0) { Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue()); ExternalStore* p = dynamic_cast<ExternalStore*>( pair->object() ); if (p != 0) p->updateData(dt); item = item->getNext(); } list->unref(); list = 0; } } BaseClass::updateData(dt); }
//------------------------------------------------------------------------------ // shutdownNotification() -- We're shutting down //------------------------------------------------------------------------------ bool StoresMgr::shutdownNotification() { // Notify the external stores that we're shutting down Basic::PairStream* list = getStores(); if (list != 0) { Basic::List::Item* item = list->getFirstItem(); while (item != 0) { Basic::Pair* pair = (Basic::Pair*)(item->getValue()); Basic::Component* p = (Basic::Component*)( pair->object() ); p->event(SHUTDOWN_EVENT); item = item->getNext(); } list->unref(); list = 0; } // Clear our stores setSlotStores(0); return BaseClass::shutdownNotification(); }
//------------------------------------------------------------------------------ // serialize //------------------------------------------------------------------------------ std::ostream& Stores::serialize(std::ostream& sout, const int i, const bool slotsOnly) const { int j = 0; if ( !slotsOnly ) { indent(sout,i); sout << "( " << getFactoryName() << std::endl; j = 4; } indent(sout,i+j); sout << "numStations: " << getNumberOfStations() << std::endl; { // List of external stores const Basic::PairStream* list = getStores(); if (list != 0) { indent(sout,i+j); sout << "stores: {" << std::endl; list->serialize(sout,i+j+4,slotsOnly); indent(sout,i+j); sout << "}" << std::endl; list->unref(); } } indent(sout,i+j); sout << "selected: " << getSelectedStation() << std::endl; BaseClass::serialize(sout,i+j,true); if ( !slotsOnly ) { indent(sout,i); sout << ")" << std::endl; } return sout; }
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); }