예제 #1
0
void TrustedConnectionCreatorintegration::test_external_op_puppet_nonexistant()
{
    // Dispatching a Talk external op from the creator, to the creator should
    // result in it being passed directly to the normal op dispatch,
    // shortcutting the world.

    m_creator->m_externalMind = new ExternalMind(*m_creator);
    m_creator->m_externalMind->linkUp(m_connection);

    Entity * other = new Entity(compose("%1", m_id_counter), m_id_counter++);
    other->setType(m_creatorType);
    m_server->m_world.addEntity(other);

    Atlas::Objects::Operation::Talk op;
    op->setFrom(m_creator->getId());
    op->setTo(compose("%1", m_id_counter++));

    m_connection->externalOperation(op, *m_connection);

    // Operation should be via world dispatch, as if it was from the Entity
    // we are puppeting.
    ASSERT_TRUE(m_Link_send_sent.isValid());
    ASSERT_EQUAL(m_Link_send_sent->getParents().front(),
                 "unseen");
    ASSERT_TRUE(!m_Link_send_sent->isDefaultTo());
    ASSERT_EQUAL(m_Link_send_sent->getTo(), m_creator->getId());
}
예제 #2
0
void Entity::operation(const Operation & op, OpVector & res)
{
    if (m_script != 0 &&
        m_script->operation(op->getParents().front(), op, res) != 0) {
        return;
    }

    auto J = m_delegates.equal_range(op->getClassNo());
    HandlerResult hr = OPERATION_IGNORED;
    for (;J.first != J.second; ++J.first) {
        HandlerResult hr_call = callDelegate(J.first->second, op, res);
        //We'll record the most blocking of the different results only.
        if (hr != OPERATION_BLOCKED) {
            if (hr_call != OPERATION_IGNORED) {
                hr = hr_call;
            }
        }
        // How to access the property? We need a non-const pointer to call
        // operation, but to get this easily we need to force instantiation
        // from the type dict, making properties way less efficient.
        // Making the operation() method const strongly limits the usefulness
        // of delegates, but if we fetch the pointer the hard way, we then
        // require the method to handle instantiation on demand.
        //
        // Can we make a clean way to handle the property in the general case
        // handle instantiation itself? Making it responsible for copying
        // itself on instantiation would be faster than the
        // get/set/PropertyManager currently required in in modProperty.
    }
    //If the operation was blocked we shouldn't send it on to the entity.
    if (hr == OPERATION_BLOCKED) {
        return;
    }
    return callOperation(op, res);
}
예제 #3
0
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;
    }
}
예제 #4
0
void OperationMonitor::operation(const Operation & op, OpVector &) {
    ++op_count;
    std::cout << op->getParents().front() << "(from=\"" << op->getFrom()
              << "\",to=\"" << op->getTo() << "\")"
              << std::endl << std::flush;
}