本文整理汇总了C++中RootOperation类的典型用法代码示例。如果您正苦于以下问题:C++ RootOperation类的具体用法?C++ RootOperation怎么用?C++ RootOperation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RootOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createCharacter
void ClientConnection::createCharacter(const RootOperation& op)
{
static unsigned int charCounter = 0;
char charId[64];
::snprintf(charId, 64, "_customChar_%d", ++charCounter);
RootEntity ent = smart_dynamic_cast<RootEntity>(op->getArgs().front());
ent->setId(charId);
ent->setLoc("_world");
m_server->m_world[charId] = ent;
StringList children(m_server->m_world["_world"]->getContains());
children.push_back(charId);
m_server->m_world["_world"]->setContains(children);
Agent* ag = new Agent(this, charId);
ag->setEntityVisible(charId, true);
m_agents[charId] = ag;
Info info;
info->setArgs1(m_server->m_world[charId]);
info->setFrom(charId);
info->setTo(m_account); // I *think* this is right
info->setRefno(op->getSerialno());
send(info);
}
示例2: fail
void ClientConnection::poll()
{
if (m_stream.eof()) {
fail();
return;
}
if (m_acceptor)
{
negotiate();
}
else
{
m_codec->poll();
while (!m_objDeque.empty())
{
RootOperation op = smart_dynamic_cast<RootOperation>(m_objDeque.front());
if (!op.isValid())
throw InvalidOperation("ClientConnection recived something that isn't an op");
dispatch(op);
m_objDeque.pop_front();
}
}
}
示例3: Character
void ServerAccounttest::test_createObject_success_refo()
{
long cid = m_id_counter++;
TestWorld_addNewEntity_ret_value = new Character(compose("%1", cid), cid);
std::string type_str("unimportant_string");
RootEntity arg;
RootOperation op;
op->setSerialno(44295);
OpVector res;
m_account->createObject(type_str, arg, op, res);
ASSERT_EQUAL(res.size(), 1u);
const RootOperation & reply = res.front();
ASSERT_EQUAL(reply->getClassNo(),
Atlas::Objects::Operation::INFO_NO);
ASSERT_TRUE(!reply->isDefaultRefno());
ASSERT_EQUAL(reply->getRefno(), op->getSerialno());
delete TestWorld_addNewEntity_ret_value;
TestWorld_addNewEntity_ret_value = 0;
}
示例4: accept
bool AccountContext::accept(const RootOperation& op) const
{
std::cout << "Checking account context to see if it matches"
<< std::endl << std::flush;
if (m_refNo != 0L && !op->isDefaultRefno() && op->getRefno() == m_refNo) {
return true;
}
return false;
}
示例5: postForDispatch
void Connection::postForDispatch(const Root& obj)
{
RootOperation op = smart_dynamic_cast<RootOperation>(obj);
assert(op.isValid());
m_opDeque.push_back(op);
#ifdef ATLAS_LOG
std::stringstream debugStream;
Atlas::Codecs::Bach debugCodec(debugStream, *this /* dummy */);
Atlas::Objects::ObjectsEncoder debugEncoder(debugCodec);
debugEncoder.streamObjectsMessage(obj);
debugStream << std::flush;
std::cout << "posted for re-dispatch:" << debugStream.str() << std::endl;
#endif
}
示例6: activateCharacter
void ClientConnection::activateCharacter(const std::string& charId, const RootOperation& op)
{
// special magic testing IDs
if (charId == "_fail_") {
sendError("deliberate", op);
return;
}
assert(entityIsCharacter(charId));
//debug() << "activation, inbound op's serial is " << op->getSerialno();
if (m_agents.count(charId)) {
sendError("duplicate character action", op);
return;
}
Agent* ag = new Agent(this, charId);
m_agents[charId] = ag;
Info info;
info->setArgs1(m_server->m_world[charId]);
info->setFrom(charId);
info->setTo(m_account); // I *think* this is right
info->setRefno(op->getSerialno());
send(info);
ag->processOp(op); // process as normal
}
示例7: sendError
void ClientConnection::sendError(const std::string& msg, const RootOperation& op)
{
Error errOp;
errOp->setRefno(op->getSerialno());
errOp->setTo(op->getFrom());
Root arg0;
arg0->setAttr("message", msg);
std::vector<Root>& args = errOp->modifyArgs();
args.push_back(arg0);
args.push_back(op);
send(errOp);
}
示例8: debugCodec
void Connection::objectArrived(const Root& obj)
{
#ifdef ATLAS_LOG
std::stringstream debugStream;
Atlas::Codecs::Bach debugCodec(debugStream, *this /* dummy */);
Atlas::Objects::ObjectsEncoder debugEncoder(debugCodec);
debugEncoder.streamObjectsMessage(obj);
debugStream << std::flush;
std::cout << "received:" << debugStream.str() << std::endl;
#endif
RootOperation op = smart_dynamic_cast<RootOperation>(obj);
if (op.isValid()) {
m_opDeque.push_back(op);
} else
error() << "Con::objectArrived got non-op";
}
示例9: dispatchOOG
void ClientConnection::dispatchOOG(const RootOperation& op)
{
switch (op->getClassNo()) {
case LOOK_NO:
processOOGLook(smart_dynamic_cast<Look>(op));
return;
case MOVE_NO:
return;
case TALK_NO: {
Talk tk = smart_dynamic_cast<Talk>(op);
processTalk(tk);
return;
}
case LOGOUT_NO: {
Logout logout = smart_dynamic_cast<Logout>(op);
Info logoutInfo;
logoutInfo->setArgs1(logout);
logoutInfo->setTo(m_account);
logoutInfo->setRefno(logout->getSerialno());
send(logoutInfo);
return;
}
case CREATE_NO: {
const StringList& arg0Parents(op->getArgs().front()->getParents());
if (arg0Parents.front() == "__fail__") {
sendError("bad type for char creation", op);
return;
}
if (arg0Parents.front() == "settler") {
createCharacter(op);
return;
}
}
default:
error() << "clientConnection failed to handle OOG op";
} // of classNo switch
}
示例10: assert
LocatedEntity * CreatorClient::make(const RootEntity & entity)
{
Create op;
op->setArgs1(entity);
op->setFrom(getId());
op->setTo(getId());
OpVector result;
if (sendAndWaitReply(op, result) != 0) {
std::cerr << "No reply to make" << std::endl << std::flush;
return NULL;
}
assert(!result.empty());
const Operation & res = result.front();
if (!res.isValid()) {
std::cerr << "NULL reply to make" << std::endl << std::flush;
return NULL;
}
// FIXME Make this more robust against an info response
if (res->getClassNo() == Atlas::Objects::Operation::SIGHT_NO) {
if (res->getArgs().empty()) {
std::cerr << "Reply to make has no args" << std::endl << std::flush;
return NULL;
}
RootOperation arg = smart_dynamic_cast<RootOperation>(res->getArgs().front());
if (!arg.isValid()) {
std::cerr << "Arg of reply to make is not an operation"
<< std::endl << std::flush;
return NULL;
}
if (arg->getClassNo() != Atlas::Objects::Operation::CREATE_NO) {
std::cerr << "Reply to make isn't sight of create"
<< std::endl << std::flush;
return NULL;
}
return handleMakeResponse(arg, res->getSeconds());
} else if (res->getClassNo() == Atlas::Objects::Operation::INFO_NO) {
return handleMakeResponse(res, res->getSeconds());
} else {
std::cerr << "Reply to make isn't sight or info"
<< std::endl << std::flush;
return NULL;
}
}
示例11: handleServerInfo
void Connection::handleServerInfo(const RootOperation& op)
{
RootEntity svr = smart_dynamic_cast<RootEntity>(op->getArgs().front());
if (!svr.isValid()) {
error() << "server INFO argument object is broken";
return;
}
m_info.processServer(svr);
GotServerInfo.emit();
}
示例12: objectArrived
/// \brief Function call from the base class when an object arrives from the
/// server
///
/// @param obj Object that has arrived from the server
void AtlasStreamClient::objectArrived(const Root & obj)
{
RootOperation op = Atlas::Objects::smart_dynamic_cast<RootOperation>(obj);
if (!op.isValid()) {
std::cerr << "ERROR: Non op object received from server"
<< std::endl << std::flush;;
if (!obj->isDefaultParents() && !obj->getParents().empty()) {
std::cerr << "NOTICE: Unexpected object has parent "
<< obj->getParents().front()
<< std::endl << std::flush;
}
if (!obj->isDefaultObjtype()) {
std::cerr << "NOTICE: Unexpected object has objtype "
<< obj->getObjtype()
<< std::endl << std::flush;
}
return;
}
mOps.push_back(op);
}
示例13: negotiate
void Commander::recv()
{
if (m_channel.eof()) return;
if (m_acceptor)
negotiate();
else {
m_codec->poll();
while (!m_objDeque.empty())
{
RootOperation op = smart_dynamic_cast<RootOperation>(m_objDeque.front());
if (!op.isValid())
throw InvalidOperation("Commander received something that isn't an op");
dispatch(op);
m_objDeque.pop_front();
}
}
}
示例14: operation
void ClientConnection::operation(const RootOperation & op)
{
if (debug_flag) {
std::stringstream ss;
ss << "I: " << op->getParents().front() << " : ";
Atlas::Message::QueuedDecoder decoder;
Atlas::Codecs::XML codec(ss, ss, decoder);
Atlas::Objects::ObjectsEncoder encoder(codec);
encoder.streamObjectsMessage(op);
ss << std::flush;
debug(std::cerr << ss.str() << std::endl;);
}
示例15: handleSightOp
Router::RouterResult EntityRouter::handleSightOp(const RootOperation& op)
{
const std::vector<Root>& args = op->getArgs();
if (op->getClassNo() == MOVE_NO) {
//If we get a MOVE op for an entity that's not visible, it means that the entity has moved
//within our field of vision without sending an Appear op first. We should treat this as a
//regular Appear op and issue a Look op back, to get more info.
if (!m_entity->isVisible()) {
m_entity->getView()->sendLookAt(m_entity->getId());
}
// sight of move, we handle as a specialization of set.
assert(!args.empty());
const Root & arg = args.front();
// break out LOC, which MOVE ops are allowed to update
if (arg->hasAttr("loc")) {
m_entity->setLocationFromAtlas(arg->getAttr("loc").asString());
}
m_entity->setFromRoot(arg, true /* movement allowed */);
return HANDLED;
}
if (op->instanceOf(IMAGINARY_NO)) {
if (args.empty())
error() << "entity " << m_entity->getId() << " sent imaginary with no args: " << op;
else
m_entity->onImaginary(args.front());
return HANDLED;
}
// explicitly do NOT handle set ops here, since they can
// validly change multiple entities - handled by the IGRouter
return IGNORED;
}