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 CalDavClient::startQuickSync() { FUNCTION_CALL_TRACE; mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::UTC())); mKCal::ExtendedStorage::Ptr storage = calendar->defaultStorage(calendar); storage->open(); storage->load(QDateTime::currentDateTime().toUTC().addMonths(-6).date(), QDateTime::currentDateTime().toUTC().addMonths(12).date()); // we add 2 seconds to ensure that the timestamp doesn't // fall prior to when the calendar db commit fs sync finalises. KDateTime fromDate(lastSyncTime().addSecs(2)); LOG_DEBUG("\n\nLAST SYNC TIME = " << fromDate.toString() << "\n\n"); KCalCore::Incidence::List inserted; KCalCore::Incidence::List modified; KCalCore::Incidence::List deleted; QString errorString; if (!loadStorageChanges(storage, fromDate, &inserted, &modified, &deleted, &errorString)) { storage->close(); calendar->close(); syncFinished(Buteo::SyncResults::INTERNAL_ERROR, errorString); return; } LOG_DEBUG("Changes: inserted = " << inserted.count() << "modified = " << modified.count() << "deleted = " << deleted.count()); if (inserted.isEmpty() && modified.isEmpty() && deleted.isEmpty()) { // no local changes to send, just do a REPORT to pull updates from server retrieveETags(); } else { for (int i=0; i<inserted.count(); i++) { Put *put = new Put(mNAManager, &mSettings); mRequests.insert(put); connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished())); put->createEvent(inserted[i]); } for (int i=0; i<modified.count(); i++) { Put *put = new Put(mNAManager, &mSettings); mRequests.insert(put); connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished())); put->updateEvent(modified[i]); } for (int i=0; i<deleted.count(); i++) { Delete *del = new Delete(mNAManager, &mSettings); mRequests.insert(del); connect(del, SIGNAL(finished()), this, SLOT(nonReportRequestFinished())); del->deleteEvent(deleted[i]); } } storage->close(); calendar->close(); }
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 NotebookSyncAgent::sendLocalChanges() { NOTEBOOK_FUNCTION_CALL_TRACE; KCalCore::Incidence::List inserted; KCalCore::Incidence::List modified; KCalCore::Incidence::List deleted; if (!loadLocalChanges(mChangesSinceDate, &inserted, &modified, &deleted)) { emitFinished(Buteo::SyncResults::INTERNAL_ERROR, "Unable to load changes for calendar: " + mServerPath); return; } if (inserted.isEmpty() && modified.isEmpty() && deleted.isEmpty()) { LOG_DEBUG("No changes to send!"); emitFinished(Buteo::SyncResults::NO_ERROR, "Done, no local changes for " + mServerPath); return; } LOG_DEBUG("Total changes for" << mServerPath << ":" << "inserted = " << inserted.count() << "modified = " << modified.count() << "deleted = " << deleted.count()); for (int i=0; i<inserted.count(); i++) { Put *put = new Put(mNAManager, mSettings); mRequests.insert(put); connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished())); put->createEvent(mServerPath, inserted[i]); } for (int i=0; i<modified.count(); i++) { Put *put = new Put(mNAManager, mSettings); mRequests.insert(put); connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished())); put->updateEvent(mServerPath, modified[i], mLocalETags.value(modified[i]->uid())); } for (int i=0; i<deleted.count(); i++) { Delete *del = new Delete(mNAManager, mSettings); mRequests.insert(del); connect(del, SIGNAL(finished()), this, SLOT(nonReportRequestFinished())); del->deleteEvent(mServerPath, deleted[i]); } }
AbstractSql::ProcessResultPointerType delete_process_delete(AbstractSql *self, const Engine &engine, ParameterContainer *parameterContainer, QMap<QString, QString>&, QMap<QString, AbstractSql::ProcessResultPointerType>&) { Delete* deleteSql = dynamic_cast<Delete*>(self); Q_ASSERT_X(deleteSql != 0, "delete friend function process_delete", "self pointer cast fail"); if(0 == deleteSql){ throw ErrorInfo(QString("delete friend function process_delete self pointer cast fail")); } QSharedPointer<AbstractSql::ProcessResult> result(new AbstractSql::ProcessResult); result->isNull = false; result->type = AbstractSql::ProcessResultType::String; result->value = QVariant(QString(deleteSql->m_specifications.value(Delete::SPECIFICATION_DELETE).toString()).arg(deleteSql->resolveTable(deleteSql->m_table, engine, parameterContainer))); return result; }
void test_opChange(string toTest, Copy &c, Move &v, Delete &d) { if (toTest == "change_op") { int answer; string newOp; cout << "Which operator would you like to change?:" << endl; cout << "1. " << c.getOp() << endl; cout << "2. " << v.getOp() << endl; cout << "3. " << d.getOp() << endl; cin >> answer; switch (answer) { case 1: cout << "What would you like to change it to?:" << endl; cin >> newOp; c.setOp(newOp); cout << "Operator changed" << endl; break; case 2: cout << "What would you like to change it to?:" << endl; cin >> newOp; v.setOp(newOp); cout << "Operator changed" << endl; break; case 3: cout << "What would you like to change it to?: " << endl; cin >> newOp; d.setOp(newOp); cout << "Operator changed" << endl; break; default: cout << "Not a valid option." << endl; break; } }
void Commander::dispatch(const RootOperation& op) { Appearance appear = smart_dynamic_cast<Appearance>(op); if (appear.isValid()) { assert(op->hasAttr("for")); Agent* ag = m_server->findAgentForEntity(op->getAttr("for").asString()); if (ag) { ag->setEntityVisible(op->getTo(), true); } else { // doesn't exist yet, mark as visible if / when the agent is created Agent::setEntityVisibleForFutureAgent(op->getTo(), op->getAttr("for").asString()); } } Disappearance disap = smart_dynamic_cast<Disappearance>(op); if (disap.isValid()) { assert(op->hasAttr("for")); Agent* ag = m_server->findAgentForEntity(op->getAttr("for").asString()); if (ag) ag->setEntityVisible(op->getTo(), false); } Create cr = smart_dynamic_cast<Create>(op); if (cr.isValid()) { std::vector<Root> args(op->getArgs()); assert(!args.empty()); RootEntity ent = smart_dynamic_cast<RootEntity>(args.front()); assert(ent.isValid()); static int idCounter = 900; char buf[32]; snprintf(buf, 32, "_created_%d", ++idCounter); std::string id(buf); ent->setId(id); std::string loc = ent->getLoc(); assert(m_server->m_world.count(loc)); StringList children(m_server->m_world[loc]->getContains()); children.push_back(id); m_server->m_world[loc]->setContains(children); m_server->m_world[id] = ent; Create bcr(cr); bcr->setArgs1(ent); Agent::broadcastSight(bcr); } Delete del = smart_dynamic_cast<Delete>(op); if (del.isValid()) { std::vector<Root> args(op->getArgs()); assert(!args.empty()); std::string id = args.front()->getId(); assert(m_server->m_world.count(id)); m_server->m_world.erase(id); Agent::broadcastSight(op); } Move mv = smart_dynamic_cast<Move>(op); if (mv.isValid()) { RootEntity ent = m_server->getEntity(op->getTo()); std::vector<Root> args(op->getArgs()); if (args.front()->hasAttr("loc")) { std::string newLocId = args.front()->getAttr("loc").asString(); RootEntity oldLoc = m_server->getEntity(ent->getLoc()), newLoc = m_server->getEntity(newLocId); ent->setLoc(newLocId); // modify stamps? oldLoc->modifyContains().remove(ent->getId()); newLoc->modifyContains().push_back(ent->getId()); } if (args.front()->hasAttr("pos")) ent->setPosAsList(args.front()->getAttr("pos").asList()); // handle velocity changes Agent::broadcastSight(op); return; } Sound snd = smart_dynamic_cast<Sound>(op); if (snd.isValid()) { std::vector<Root> args(op->getArgs()); assert(!args.empty()); if (snd->hasAttr("broadcast")) { Agent::broadcastSound(smart_dynamic_cast<RootOperation>(args.front())); } } Sight st = smart_dynamic_cast<Sight>(op); if (st.isValid()) { if (st->hasAttr("broadcast")) { std::vector<Root> args(op->getArgs()); assert(!args.empty()); Agent::broadcastSight(smart_dynamic_cast<RootOperation>(args.front())); } } Set s = smart_dynamic_cast<Set>(op); if (s.isValid()) { std::vector<Root> args(op->getArgs()); for (unsigned int A=0; A < args.size(); ++A) { std::string eid = args[A]->getId(); RootEntity entity = m_server->getEntity(eid); Root::const_iterator I = args[A]->begin(); for (; I != args[A]->end(); ++I) { if ((I->first == "id") || (I->first == "parents") || (I->first == "objtype")) { continue; } assert(I->first != "loc"); entity->setAttr(I->first, I->second); } } Agent::broadcastSight(s); } Action act = smart_dynamic_cast<Action>(op); if (act.isValid()) { std::vector<Root> args(op->getArgs()); if (act->getParents().front() == "command") { std::string cid = args[0]->getAttr("cid").asString(); if (cid == "socket-shutdown") { std::string acc = args[0]->getAttr("acc").asString(); ClientConnection* cc = m_server->getConnectionForAccount(acc); assert(cc); cc->shutdown(); } else if (cid == "add-many-objects") { m_server->addManyObjects(args[0]->getAttr("acc").asString()); } else if (cid == "set-world-time") { /* double t = */ args[0]->getAttr("seconds").asFloat(); } else { std::cerr << "unknown command " << cid << std::endl; } } // of command action case } // of action case }
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; } }
/// \brief Handle an Info op response sent as reply to a teleport request /// /// @param op The Info op sent back as reply to a teleport request /// @param res The result set of replies void Peer::peerTeleportResponse(const Operation &op, OpVector &res) { log(INFO, "Got a peer teleport response"); // Response to a Create op const std::vector<Root> & args = op->getArgs(); if (args.size() < 1) { log(ERROR, "Malformed args in Info op"); return; } const Root & arg = args.front(); if (op->isDefaultRefno()) { log(ERROR, "Response to teleport has no refno"); return; } long iid = op->getRefno(); CommPeer *peer = dynamic_cast<CommPeer*>(&m_commClient); if(peer == 0) { log(ERROR, "Unable to get CommPeer object"); return; } TeleportMap::iterator I = m_teleports.find(iid); if (I == m_teleports.end()) { log(ERROR, "Info op for unknown create"); return; } TeleportState *s = I->second; assert (s != NULL); s->setCreated(); log(INFO, String::compose("Entity with ID %1 replicated on peer", iid)); // This is the sender entity. This is retreived again rather than // relying on a pointer (in the TeleportState object perhaps) as the // entity might have been deleted in the time between sending and response Entity * entity = BaseWorld::instance().getEntity(iid); if (entity == 0) { log(ERROR, String::compose("No entity found with ID: %1", iid)); // Clean up the teleport state object m_teleports.erase(I); return; } // If entity has a mind, add extra information in the Logout op if (s->isMind()) { Character * chr = dynamic_cast<Character *>(entity); if (!chr) { log(ERROR, "Entity is not a character"); return; } if (chr->m_externalMind == 0) { log(ERROR, "No external mind (though teleport state claims it)"); return; } ExternalMind * mind = dynamic_cast<ExternalMind*>(chr->m_externalMind); if (mind == 0 || !mind->isConnected()) { log(ERROR, "Mind is NULL or not connected"); return; } std::vector<Root> logout_args; Anonymous op_arg; op_arg->setId(entity->getId()); logout_args.push_back(op_arg); Anonymous ip_arg; ip_arg->setAttr("teleport_host", peer->getHost()); ip_arg->setAttr("teleport_port", peer->getPort()); ip_arg->setAttr("possess_key", s->getPossessKey()); ip_arg->setAttr("possess_entity_id", arg->getId()); logout_args.push_back(ip_arg); Logout logoutOp; logoutOp->setArgs(logout_args); logoutOp->setTo(entity->getId()); OpVector temp; mind->operation(logoutOp, temp); log(INFO, "Sent random key to connected mind"); } // FIXME Remove from the world cleanly, not delete. // Delete the entity from the current world Delete delOp; Anonymous del_arg; del_arg->setId(entity->getId()); delOp->setArgs1(del_arg); delOp->setTo(entity->getId()); entity->sendWorld(delOp); log(INFO, "Deleted entity from current server"); logEvent(EXPORT_ENT, String::compose("%1 - %2 Exported entity", getId(), entity->getId())); // Clean up the teleport state object m_teleports.erase(I); }
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; } } }