void InventoryDomain::processVisibilityForMovedEntity(const LocatedEntity& moved_entity, const Location& old_loc, OpVector & res) { if (m_entity.m_contains) { std::vector<LocatedEntity*> visibleEntities; std::unordered_set<int> outfitted; LocatedEntity* rightHandWieldedEntity = nullptr; const OutfitProperty* outfitProperty = m_entity.getPropertyClass<OutfitProperty>("outfit"); if (outfitProperty) { for (auto& entry : outfitProperty->data()) { outfitted.insert(entry.second->getIntId()); } } const EntityProperty* rightHandWieldProperty = m_entity.getPropertyClass<EntityProperty>("right_hand_wield"); if (rightHandWieldProperty) { rightHandWieldedEntity = rightHandWieldProperty->data().get(); } for (auto childEntity : *m_entity.m_contains) { if (childEntity == rightHandWieldedEntity) { visibleEntities.push_back(childEntity); } else if (outfitted.find(childEntity->getIntId()) != outfitted.end()) { visibleEntities.push_back(childEntity); } } std::set<std::string> newVisibleEntities; for (auto visibleEntity : visibleEntities) { if (m_lastVisibleEntities.find(visibleEntity->getId()) == m_lastVisibleEntities.end()) { Anonymous ent; ent->setId(visibleEntity->getId()); ent->setStamp(visibleEntity->getSeq()); Appearance d; d->setArgs1(ent); res.push_back(d); } else { m_lastVisibleEntities.erase(visibleEntity->getId()); } newVisibleEntities.insert(visibleEntity->getId()); } for (auto entityId : m_lastVisibleEntities) { Anonymous ent; ent->setId(entityId); Disappearance d; d->setArgs1(ent); res.push_back(d); } m_lastVisibleEntities = std::move(newVisibleEntities); } }
void Admintest::test_LogoutOperation_other_but_unconnected() { Account_LogoutOperation_called = 0; m_account->m_connection = 0; long cid = m_id_counter++; std::string cid_str = String::compose("%1", cid); Account * ac2 = new Admin(0, "f3332c00-5d2b-45c1-8cf4-3429bdf2845f", "c0e095f0-575c-477c-bafd-2055d6958d4d", cid_str, cid); m_server->addObject(ac2); ASSERT_EQUAL(m_server->getObject(cid_str), ac2); Atlas::Objects::Operation::Logout op; OpVector res; Anonymous arg; arg->setId(cid_str); op->setArgs1(arg); m_account->LogoutOperation(op, res); ASSERT_EQUAL(res.size(), 1u); ASSERT_EQUAL(res.front()->getClassNo(), Atlas::Objects::Operation::ERROR_NO); ASSERT_NULL(Account_LogoutOperation_called); delete ac2; }
void Admintest::test_GetOperation_obj_IG() { long cid = m_id_counter++; std::string cid_str = String::compose("%1", cid); Entity * to = new Entity(cid_str, cid); m_server->m_world.addEntity(to); Atlas::Objects::Operation::Get op; OpVector res; Anonymous arg; arg->setObjtype("obj"); arg->setId(cid_str); op->setArgs1(arg); m_account->GetOperation(op, res); ASSERT_EQUAL(res.size(), 1u); const Operation & reply = res.front(); ASSERT_EQUAL(reply->getClassNo(), Atlas::Objects::Operation::INFO_NO); ASSERT_EQUAL(reply->getArgs().size(), 1u); const Root & reply_arg = reply->getArgs().front(); ASSERT_TRUE(!reply_arg->isDefaultId()); ASSERT_EQUAL(reply_arg->getId(), to->getId()); delete to; }
bool EntityImporterBase::getRule(const std::string & id, OpVector & res) { auto I = mPersistedRules.find(id); if (I == mPersistedRules.end()) { S_LOG_WARNING("Could not find rule with id " << id << "."); return false; } auto definition = I->second; m_state = RULE_WALKING; std::list<std::string> children; extractChildren(definition, children); RuleStackEntry entry = { id, definition, children }; mRuleStack.push_back(entry); Get get; Anonymous arg; arg->setId(id); get->setArgs1(arg); // get->setObjtype("op"); get->setSerialno(newSerialNumber()); res.push_back(get); Anonymous get_arg; get_arg->setId(id); get_arg->setObjtype("obj"); return true; }
void Admintest::test_GetOperation_rule_found() { Atlas::Objects::Operation::Get op; OpVector res; Anonymous arg; arg->setObjtype("class"); arg->setId("root"); op->setArgs1(arg); m_account->GetOperation(op, res); ASSERT_EQUAL(res.size(), 1u); const Operation & reply = res.front(); ASSERT_EQUAL(reply->getClassNo(), Atlas::Objects::Operation::INFO_NO); ASSERT_EQUAL(reply->getArgs().size(), 1u); const Root & reply_arg = reply->getArgs().front(); ASSERT_TRUE(!reply_arg->isDefaultId()); ASSERT_EQUAL(reply_arg->getId(), "root"); }
void Admintest::test_SetOperation_obj_IG() { Account_SetOperation_called = 0; long cid = m_id_counter++; Entity * c = new Entity(compose("%1", cid), cid); m_account->m_charactersDict.insert(std::make_pair(cid, c)); Atlas::Objects::Operation::Set op; OpVector res; Anonymous arg; arg->setObjtype("obj"); arg->setId(c->getId()); op->setArgs1(arg); m_account->SetOperation(op, res); ASSERT_EQUAL(Account_SetOperation_called, m_account); // The operation returned would have come from Account::SetOperation // but that is stubbed out ASSERT_EQUAL(res.size(), 0u); delete c; }
void CreatorClient::del(const std::string & id) { Delete op; Anonymous ent; ent->setId(id); op->setArgs1(ent); op->setFrom(getId()); op->setTo(id); return send(op); }
void RuleTraversalTask::getRule(const std::string & id, OpVector & res) { Get get; Anonymous arg; arg->setId(id); get->setArgs1(arg); get->setObjtype("op"); get->setSerialno(newSerialNo()); mSerial = get->getSerialno(); res.push_back(get); }
LocatedEntity * CharacterClient::look(const std::string & id) { Look op; if (!id.empty()) { Anonymous ent; ent->setId(id); op->setArgs1(ent); } op->setFrom(getId()); return sendLook(op); }
static void lookAtEntity(ClientConnection& con, const std::string & eid, const std::string & loc) { Look l; l->setFrom(con.getCharacterId()); Anonymous lookEnt; lookEnt->setId(eid); l->setArgs1(lookEnt); int serial = con.send(l); verbose( std::cout << "Waiting for In-game look response on connection " << con.getAccount() << std::endl << std::flush; );
void World::clearWorld(OpVector & res) { log(INFO, "Clearing world; deleting all entities."); OpVector ignoredRes; auto& baseWorld = BaseWorld::instance(); if (m_contains) { while (!m_contains->empty()) { auto& entity = *m_contains->begin(); if (entity->isPerceptive()) { //Send a sight of a delete op to the entity so that it knows it has been deleted. Delete delOp; delOp->setTo(entity->getId()); Anonymous delArg; delArg->setId(entity->getId()); delOp->setArgs1(delArg); Sight sToEntity; sToEntity->setArgs1(delOp); sToEntity->setTo(entity->getId()); entity->operation(sToEntity, ignoredRes); } baseWorld.delEntity(entity.get()); } } //Remove all properties except for "id" auto propIter = m_properties.begin(); while(propIter != m_properties.end()) { if (propIter->first != "id") { auto prop = propIter->second; prop->remove(this, propIter->first); delete prop; m_properties.erase(propIter++); } else { ++propIter; } } CalendarProperty* calProp = new CalendarProperty(); calProp->install(this, "calendar"); m_properties["calendar"] = calProp; delete m_contains; m_contains = nullptr; log(INFO, "World cleared of all entities."); }
void Admintest::test_SetOperation_unknown() { Atlas::Objects::Operation::Set op; OpVector res; Anonymous arg; arg->setObjtype("unimportant_unknown_string"); arg->setId("root"); op->setArgs1(arg); m_account->SetOperation(op, res); ASSERT_EQUAL(res.size(), 1u); ASSERT_EQUAL(res.front()->getClassNo(), Atlas::Objects::Operation::ERROR_NO); }
void Admintest::test_GetOperation_unknown() { Atlas::Objects::Operation::Get op; OpVector res; Anonymous arg; arg->setObjtype("unknownobjtype"); arg->setId("1741"); op->setArgs1(arg); m_account->GetOperation(op, res); ASSERT_EQUAL(res.size(), 1u); ASSERT_EQUAL(res.front()->getClassNo(), Atlas::Objects::Operation::ERROR_NO); }
void Admintest::test_GetOperation_obj_unconnected() { m_account->m_connection = 0; Atlas::Objects::Operation::Get op; OpVector res; Anonymous arg; arg->setObjtype("obj"); arg->setId("9287"); op->setArgs1(arg); m_account->GetOperation(op, res); ASSERT_EQUAL(res.size(), 0u); }
void Admintest::test_LogoutOperation_unknown() { long cid = m_id_counter++; Operation op; OpVector res; Anonymous arg; arg->setId(String::compose("%1", cid)); op->setArgs1(arg); m_account->LogoutOperation(op, res); ASSERT_EQUAL(res.size(), 1u); ASSERT_EQUAL(res.front()->getClassNo(), Atlas::Objects::Operation::ERROR_NO); }
void Admintest::test_LogoutOperation_self() { Account_LogoutOperation_called = 0; Operation op; OpVector res; Anonymous arg; arg->setId(m_account->getId()); op->setArgs1(arg); m_account->LogoutOperation(op, res); ASSERT_EQUAL(res.size(), 0u); ASSERT_EQUAL(Account_LogoutOperation_called, m_account); }
void Admintest::test_SetOperation_rule_unknown() { Ruleset_modifyRule_called = false; Atlas::Objects::Operation::Set op; OpVector res; Anonymous arg; arg->setObjtype("class"); arg->setId("unimportant_unmatched_string"); op->setArgs1(arg); m_account->SetOperation(op, res); ASSERT_EQUAL(res.size(), 1u); ASSERT_EQUAL(res.front()->getClassNo(), Atlas::Objects::Operation::ERROR_NO); ASSERT_TRUE(!Ruleset_modifyRule_called); }
void Admintest::test_SetOperation_rule_fail() { Ruleset_modifyRule_called = false; Ruleset_modifyRule_retval = -1; Atlas::Objects::Operation::Set op; OpVector res; Anonymous arg; arg->setObjtype("class"); arg->setId("root"); op->setArgs1(arg); m_account->SetOperation(op, res); ASSERT_EQUAL(res.size(), 1u); ASSERT_EQUAL(res.front()->getClassNo(), Atlas::Objects::Operation::ERROR_NO); ASSERT_TRUE(Ruleset_modifyRule_called); }
void Admintest::test_SetOperation_obj_not_found() { Account_SetOperation_called = 0; long cid = m_id_counter++; Atlas::Objects::Operation::Set op; OpVector res; Anonymous arg; arg->setObjtype("obj"); arg->setId(compose("%1", cid)); op->setArgs1(arg); m_account->SetOperation(op, res); ASSERT_NULL(Account_SetOperation_called); // FIXME No error? Is that right? ASSERT_EQUAL(res.size(), 0u); }
int main() { EntityBuilder::init(); { RuleHandler * rh = new EntityRuleHandler(EntityBuilder::instance()); delete rh; } // check() not a class { RuleHandler * rh = new EntityRuleHandler(EntityBuilder::instance()); Anonymous description; description->setParents(std::list<std::string>(1, "foo")); int ret = rh->check(description); assert(ret == -1); delete rh; } // check() stub says it's a task { RuleHandler * rh = new EntityRuleHandler(EntityBuilder::instance()); stub_isTask_result = true; Anonymous description; description->setObjtype("class"); description->setParents(std::list<std::string>(1, "foo")); int ret = rh->check(description); assert(ret == -1); stub_isTask_result = false; delete rh; } // check() stub says it's not a task { RuleHandler * rh = new EntityRuleHandler(EntityBuilder::instance()); Anonymous description; description->setObjtype("class"); description->setParents(std::list<std::string>(1, "foo")); int ret = rh->check(description); assert(ret == 0); delete rh; } { RuleHandler * rh = new EntityRuleHandler(EntityBuilder::instance()); Anonymous description; description->setId("class_name"); std::string dependent, reason; int ret = rh->install("class_name", "parent_name", description, dependent, reason); assert(ret == 1); assert(dependent == "parent_name"); delete rh; } // Install a rule with addChild rigged to give a correct result { RuleHandler * rh = new EntityRuleHandler(EntityBuilder::instance()); Anonymous description; description->setId("class_name"); std::string dependent, reason; stub_addChild_result = (TypeNode *) malloc(sizeof(TypeNode)); int ret = rh->install("class_name", "parent_name", description, dependent, reason); assert(ret == 1); assert(dependent == "parent_name"); free(stub_addChild_result); stub_addChild_result = 0; delete rh; } { RuleHandler * rh = new EntityRuleHandler(EntityBuilder::instance()); Anonymous description; int ret = rh->update("", description); // FIXME Currently does nothing assert(ret == -1); delete rh; } }
void Interactive::exec(const std::string & cmd, const std::string & arg) { bool reply_expected = true; reply_flag = false; error_flag = false; boost::shared_ptr<ObjectContext> command_context = m_currentContext.lock(); if (!command_context) { std::cout << "ERROR: Context free" << std::endl << std::flush; return; } if (cmd == "stat") { Get g; send(g); } else if (cmd == "install") { size_t space = arg.find(' '); if (space == std::string::npos || space >= (arg.size() - 1)) { std::cout << "usage: install <type id> <parent id>" << std::endl << std::flush; } else { Create c; c->setFrom(m_accountId); Anonymous ent; ent->setId(std::string(arg, 0, space)); ent->setObjtype("class"); ent->setParents(std::list<std::string>(1, std::string(arg, space + 1))); c->setArgs1(ent); send(c); } reply_expected = false; } else if (cmd == "look") { Look l; if (!arg.empty()) { Anonymous cmap; cmap->setId(arg); l->setArgs1(cmap); } l->setSerialno(newSerialNo()); command_context->setFromContext(l); send(l); reply_expected = false; } else if (cmd == "logout") { Logout l; l->setFrom(m_accountId); if (!arg.empty()) { Anonymous lmap; lmap->setId(arg); l->setArgs1(lmap); reply_expected = false; } send(l); } else if (cmd == "say") { Talk t; Anonymous ent; ent->setAttr("say", arg); t->setArgs1(ent); t->setFrom(m_accountId); send(t); } else if (cmd == "help" || cmd == "?") { reply_expected = false; help(); } else if (cmd == "query") { Get g; if (!arg.empty()) { Anonymous cmap; if (::isdigit(arg[0])) { cmap->setObjtype("obj"); } else { cmap->setObjtype("meta"); } cmap->setId(arg); g->setArgs1(cmap); } g->setFrom(m_accountId); send(g); } else if (cmd == "reload") { if (arg.empty()) { reply_expected = false; std::cout << "reload: Argument required" << std::endl << std::flush; } else { Set s; Anonymous tmap; tmap->setObjtype("class"); tmap->setId(arg); s->setArgs1(tmap); s->setFrom(m_accountId); send(s); } } else if (cmd == "get") { Get g; if (!arg.empty()) { Anonymous cmap; if (::isdigit(arg[0])) { cmap->setObjtype("obj"); } else { cmap->setObjtype("meta"); } cmap->setId(arg); g->setArgs1(cmap); } g->setFrom(m_accountId); send(g); } else if (cmd == "monitor") { ClientTask * task = new OperationMonitor; if (runTask(task, arg) == 0) { Monitor m; m->setArgs1(Anonymous()); m->setFrom(m_accountId); send(m); } reply_expected = false; } else if (cmd == "unmonitor") { OperationMonitor * om = dynamic_cast<OperationMonitor *>(m_currentTask); if (om != 0) { Monitor m; m->setFrom(m_accountId); send(m); reply_expected = false; SystemTime now; now.update(); time_t monitor_time = now.seconds() - om->startTime(); std::cout << om->count() << " operations monitored in " << monitor_time << " seconds = " << om->count() / monitor_time << " operations per second" << std::endl << std::flush; endTask(); } } else if (cmd == "connect") { std::vector<std::string> args; tokenize(arg, args); if (args.size() != 2) { std::cout << "usage: connect <hostname> <port>" << std::endl << std::flush; reply_expected = false; } else { Anonymous cmap; cmap->setAttr("hostname", args[0]); cmap->setAttr("port", strtol(args[1].c_str(), 0, 10)); Connect m; m->setArgs1(cmap); // No serialno yet // FIXME add serialno once Juncture context can handle this command_context->setFromContext(m); send(m); } } else if (cmd == "add_agent") { std::string agent_type("creator"); if (!arg.empty()) { agent_type = arg; } Create c; Anonymous cmap; cmap->setParents(std::list<std::string>(1, agent_type)); cmap->setName("cycmd agent"); cmap->setObjtype("obj"); c->setArgs1(cmap); c->setSerialno(newSerialNo()); command_context->setFromContext(c); send(c); } else if (cmd == "delete") { if (arg.empty()) { std::cout << "Please specify the entity to delete" << std::endl << std::flush; reply_expected = false; } else { Delete del; Anonymous del_arg; del_arg->setId(arg); del->setArgs1(del_arg); command_context->setFromContext(del); send(del); reply_expected = false; } } else if (cmd == "find_by_name") { if (arg.empty()) { std::cout << "Please specify the name to search for" << std::endl << std::flush; reply_expected = false; } else { Look l; Anonymous lmap; lmap->setName(arg); l->setArgs1(lmap); l->setSerialno(newSerialNo()); command_context->setFromContext(l); send(l); reply_expected = false; } } else if (cmd == "find_by_type") { if (arg.empty()) { std::cout << "Please specify the type to search for" << std::endl << std::flush; reply_expected = false; } else { Look l; Anonymous lmap; lmap->setParents(std::list<std::string>(1, arg)); l->setArgs1(lmap); l->setSerialno(newSerialNo()); command_context->setFromContext(l); send(l); reply_expected = false; } } else if (cmd == "flush") { if (arg.empty()) { // FIXME usage std::cout << "Please specify the type to flush" << std::endl << std::flush; reply_expected = false; } else { ClientTask * task = new Flusher(command_context); runTask(task, arg); reply_expected = false; } } else if (cmd == "cancel") { if (endTask() != 0) { std::cout << "No task currently running" << std::endl << std::flush; } } else if (cmd == "dump") { if (command_context->repr() != "avatar") { std::cout << "You must have an agent in the world in order to dump the world." << std::endl << std::flush; } else { //Extract the avatar id by "misusing" the setFromContext method Operation op; command_context->setFromContext(op); ClientTask * task = new EntityExporter(m_accountId, op->getFrom()); runTask(task, "world.xml"); reply_expected = false; } } else if (cmd == "restore") { if (command_context->repr() != "avatar") { std::cout << "You must have an agent in the world in order to dump the world." << std::endl << std::flush; } else { //Extract the avatar id by "misusing" the setFromContext method Operation op; command_context->setFromContext(op); ClientTask * task = new EntityImporter(m_accountId, op->getFrom()); runTask(task, "world.xml"); reply_expected = false; } } else if (cmd == "create") { std::vector<std::string> args; tokenize(arg, args); if (args.size() < 1) { std::cout << "usage: create <type> <params> ... " << std::endl << std::flush; } else { Anonymous cmap; cmap->setParents(std::list<std::string>(1, args[0])); cmap->setObjtype("obj"); Create c; c->setArgs1(cmap); c->setSerialno(newSerialNo()); command_context->setFromContext(c); send(c); } reply_expected = false; } else if (cmd == "login") { std::vector<std::string> args; tokenize(arg, args); if (args.size() != 2) { std::cout << "usage: login <username> <password>" << std::endl << std::flush; reply_expected = false; } else { Anonymous cmap; cmap->setAttr("username", args[0]); cmap->setAttr("password", args[1]); Login m; m->setArgs1(cmap); m->setSerialno(newSerialNo()); command_context->setFromContext(m); send(m); } } else { reply_expected = false; std::cout << cmd << ": Command not known" << std::endl << std::flush; } if (!reply_expected) { updatePrompt(); return; } // Wait for reply time_t wait_start_time = time(NULL); while (!reply_flag) { if (time(NULL) - wait_start_time > 5) { std::cout << cmd << ": No reply from server" << std::endl << std::flush; return; } if (select(false) != 0) { return; } } }
int main() { EntityBuilder eb; { RuleHandler * rh = new EntityRuleHandler(&eb); delete rh; } // check() not a class { RuleHandler * rh = new EntityRuleHandler(&eb); Anonymous description; description->setParent("foo"); int ret = rh->check(description); assert(ret == -1); delete rh; } // check() stub says it's not a task { RuleHandler * rh = new EntityRuleHandler(&eb); Anonymous description; description->setObjtype("class"); description->setParent("foo"); int ret = rh->check(description); assert(ret == 0); delete rh; } { RuleHandler * rh = new EntityRuleHandler(&eb); std::map<const TypeNode*, TypeNode::PropertiesUpdate> changes; Anonymous description; description->setId("class_name"); std::string dependent, reason; int ret = rh->install("class_name", "parent_name", description, dependent, reason, changes); assert(ret == 1); assert(dependent == "parent_name"); delete rh; } // Install a rule with addChild rigged to give a correct result { RuleHandler * rh = new EntityRuleHandler(&eb); std::map<const TypeNode*, TypeNode::PropertiesUpdate> changes; Anonymous description; description->setId("class_name"); std::string dependent, reason; stub_addChild_result = (TypeNode *) malloc(sizeof(TypeNode)); int ret = rh->install("class_name", "parent_name", description, dependent, reason, changes); assert(ret == 1); assert(dependent == "parent_name"); free(stub_addChild_result); stub_addChild_result = 0; delete rh; } { RuleHandler * rh = new EntityRuleHandler(&eb); std::map<const TypeNode*, TypeNode::PropertiesUpdate> changes; Anonymous description; int ret = rh->update("", description, changes); // FIXME Currently does nothing assert(ret == -1); delete rh; } }
void Flusher::operation(const Operation & op, OpVector & res) { shared_ptr<ObjectContext> flush_context = m_context.lock(); if (!flush_context) { m_complete = true; return; } if (op->getClassNo() == Atlas::Objects::Operation::SIGHT_NO) { // We have a sight op, check if its the sight of an entity we // want to delete. const std::vector<Root> & args = op->getArgs(); if (args.empty()) { std::cerr << "Got empty sight" << std::endl << std::flush; return; } const Root & arg = args.front(); assert(arg.isValid()); RootEntity sight_ent = smart_dynamic_cast<RootEntity>(arg); if (!sight_ent.isValid()) { return; } if (!sight_ent->hasAttrFlag(Atlas::Objects::ID_FLAG)) { std::cerr << "Got sight no ID" << std::endl << std::flush; return; } if (!sight_ent->hasAttrFlag(Atlas::Objects::PARENTS_FLAG)) { std::cerr << "Got sight no PARENTS" << std::endl << std::flush; return; } if (sight_ent->getParents().empty() || sight_ent->getParents().front() != type) { return; } const std::string & id = sight_ent->getId(); std::cout << "Deleting: " << type << "(" << id << ")" << std::endl << std::flush; // Send a delete to the entity we have seen. Delete d; Anonymous dmap; dmap->setId(id); d->setArgs1(dmap); flush_context->setFromContext(d); d->setTo(id); res.push_back(d); // Send a tick for a short time in the future so that // we can look again once this entity is definitly gone. Tick t; Anonymous tick_arg; tick_arg->setName("flusher"); flush_context->setFromContext(t); t->setTo(t->getFrom()); t->setFutureSeconds(0.1); t->setArgs1(tick_arg); res.push_back(t); } else if (op->getParents().front() == "tick") { // We have a tick op, check if its the one we sent ourselves // to schedule the next look. if (op->getArgs().empty() || op->getArgs().front()->getName() != "flusher") { std::cout << "Not for us" << std::endl << std::flush; return; } // Send another look by type. Look l; Anonymous lmap; lmap->setParents(std::list<std::string>(1, type)); l->setArgs1(lmap); flush_context->setFromContext(l); res.push_back(l); } else if (op->getParents().front() == "unseen") { // We have an unseen op, which signals our last look returned // no results. m_complete = true; } }
void testXML() { RootEntity human; human->setId("foo"); Move move_op; move_op->setFrom(std::string("bar")); std::vector<Root> move_args(1); move_args[0] = human; move_op->setArgs(move_args); Atlas::Message::ListType velocity; velocity.push_back(2.0); velocity.push_back(1.0); velocity.push_back(0.0); human->setVelocityAsList(velocity); // typedef BaseObjectData *(*alloc_func)(); // alloc_func alloc_entity = &Entity::RootEntityDataInstance::alloc; // BaseObjectData *bod = alloc_entity(); //Root human2(bod); Root human2 = Atlas::Objects::factory<Atlas::Objects::Entity::RootEntityData>("root_enitty", Atlas::Objects::Entity::RootEntity()->getClassNo()); std::cout<<"human.id="<<human->getId()<<std::endl; std::cout<<"human2.id="<<human2->getId()<<std::endl; #if 0 typedef std::list<Atlas::Factory<Atlas::Codec >*> FactoryCodecs; FactoryCodecs *myCodecs = &Factory<Codec >::factories(); FactoryCodecs::iterator i; std::cout<<"myCodecs: "<<myCodecs->size(); for (i = myCodecs->begin(); i != myCodecs->end(); ++i) std::cout<<":"<<(*i)->getName(); std::cout<<std::endl; #endif //DebugBridge bridge; TestDecoder bridge; #if USE_FILE fstream stream; std::string atlas_xml_path; char * srcdir_env = getenv("srcdir"); if (srcdir_env != 0) { atlas_xml_path = srcdir_env; atlas_xml_path += "/"; } atlas_xml_path += "../../protocol/spec/atlas.xml"; stream.open(atlas_xml_path, std::ios::in); assert(!!stream); #else std::stringstream stream; #endif // typedef std::list<Atlas::Factory<Atlas::Codec >*> FactoryCodecs; // FactoryCodecs *myCodecs = &Factory<Codec >::factories(); // FactoryCodecs::iterator codec_i; // Atlas::Codec *codec = NULL; // for(codec_i = myCodecs->begin(); codec_i != myCodecs->end(); ++codec_i) // { // std::cout<<(*codec_i)->getName()<<std::endl; // if ((*codec_i)->getName() == "XML") { // codec = (*codec_i)->New(Codec::Parameters(stream, &bridge)); // } // } // assert(codec); Account account; Login l; account->setAttr("id", std::string("al")); account->setAttr("password", std::string("ping")); //list<Message::Object> args(1,account->asObject()); //l->setArgsAsList(args); std::vector<Root> args(1); args[0] = account; l->setArgs(args); //coder->streamObjectsMessage((Root&)l); //<map><list name="args"><map><std::string name="id">al</strin //g></map></list><list name="parents"><std::string>root</std::string></list><std::string name="ob //jtype">op_definition</std::string></map> Atlas::Codec *codec; #if USE_XML codec = new Atlas::Codecs::XML((std::iostream&)stream, bridge); #else codec = new Atlas::Codecs::Packed(stream, bridge); #endif assert(codec); #if USE_FILE while(stream) { codec->poll(); //std::cout<<"--------"<<std::endl; } #else codec->streamBegin(); Atlas::Objects::ObjectsEncoder eno(*codec); // eno.streamObjectsMessage(move_op); eno.streamObjectsMessage(l); Anonymous e; eno.streamObjectsMessage(e); e->setId("foo"); eno.streamObjectsMessage(e); // Atlas::Message::Encoder en(codec); // en.streamObjectsMessage(human->asObject()); codec->streamEnd(); std::cout<<std::endl<<stream.str()<<std::endl; //[$from=bar(args=[$id=foo])][$id=foo] //<atlas><map><std::string name="from">bar</std::string><list name="args"><map><std::string name="id">foo</std::string></map></list></map><map><std::string name="id">foo</std::string></map></atlas> #endif delete codec; }