Ejemplo n.º 1
0
void CibIdMgr::assignIds(const CibHelper& helper, const CibParams& cibParams)
{
  // First create Ids for global functions
  const CppCompoundArray& fileAsts = helper.getProgram().getFileAsts();
  for (auto& fileAst : fileAsts)
  {
    assignIds(static_cast<CibCompound*>(fileAst.get()), helper, cibParams, false);
    assignIds(static_cast<CibCompound*>(fileAst.get()), helper, cibParams, true);
  }
}
Ejemplo n.º 2
0
void Server::execute(){

  /* Enable the server to begin accepting clients */
  setListening(true);

  do{
    handleConnections();
  }while( current_connected_players != max_connected_players );

  /* Randomly assign player ids */
  assignIds();

  /* Signal all players that the game is ready to Begin */
  broadcastPacket(PacketFactory::GAMESTART);

  /* Send out the packets for the Dictionary Data */
  broadcastPacket(PacketFactory::TROOPDEF);

  bool keep_playing = true;


  // send init packet for first turn
  sendPacket(PacketFactory::TURNSTART, 0);

  while( keep_playing ){
     keep_playing = handlePacket();
     // std::cout << "keep_playing" << keep_playing << std::endl;
  }
}
Ejemplo n.º 3
0
void CibIdMgr::assignIds(CibCompound*     compound,
                         const CibHelper& helper,
                         const CibParams& cibParams,
                         bool             forGenericProxy)
{
  // if (!compound->isShared())
  //  return;
  if (compound->isTemplated())
  {
    compound->forEachTemplateInstance(
      [&](CibCompound* ins) { this->assignIds(ins, helper, cibParams, forGenericProxy); });
    return;
  }
  if (compound->name().empty())
    return;
  // Dummy loop
  do
  {
    if (!forGenericProxy && !compound->needsBridging() && !compound->isShared())
      break;
    if (forGenericProxy && (!compound->needsGenericProxyDefinition() || compound->getAllVirtualMethods().empty()))
      break;

    const auto className = forGenericProxy ? compound->longName() + "::__zz_cib_GenericProxy" : compound->longName();
    CibIdData* cibIdData = nullptr;
    auto       itr       = cibIdTable_.find(className);
    if (itr == cibIdTable_.end())
    {
      auto clsId = nextClassId_++;
      if (compound->isTemplateInstance())
        compound->setNsName("__zz_cib_Class" + std::to_string(clsId));
      else if (isCppFile(compound))
        compound->setNsName(cibParams.globalNsName());
      const auto classNsName =
        forGenericProxy ? compound->fullNsName() + "::__zz_cib_GenericProxy" : compound->fullNsName();
      cibIdData = addClass(className, classNsName, clsId);
    }
    else
    {
      cibIdData = &itr->second;
      if (compound->isNsNameEmpty())
      {
        if (isCppFile(compound))
          compound->setNsName(cibParams.globalNsName());
        else if (compound->isTemplateInstance())
          compound->setNsName(cibIdData->getFullNsName());
      }
    }
    const auto& methods   = forGenericProxy ? compound->getAllVirtualMethods() : compound->getNeedsBridgingMethods();
    auto        addMethod = [&](const CibFunctionHelper& func) {
      auto&& sig = func.signature(helper);
      if (!cibIdData->hasMethod(func.signature(helper)))
        cibIdData->addMethod(sig, func.procName());
    };
    for (auto& func : methods)
      addMethod(func);
    if (forGenericProxy)
      addMethod(compound->dtor());
    if (!forGenericProxy)
    {
      compound->forEachAncestor(CppAccessType::kPublic, [compound, &cibIdData, &cibParams](const CibCompound* parent) {
        if (parent->isShared() || !parent->isEmpty())
        {
          auto castMethodName = compound->castToBaseName(parent, cibParams);
          if (!cibIdData->hasMethod(castMethodName))
            cibIdData->addMethod(castMethodName, castMethodName);
        }
        return false;
      });
      if (compound->isFacadeLike())
      {
        if (!cibIdData->hasMethod("__zz_cib_get_class_id"))
          cibIdData->addMethod("__zz_cib_get_class_id", "__zz_cib_get_class_id");
      }
      if (compound->needsGenericProxyDefinition())
      {
        if (!cibIdData->hasMethod("__zz_cib_release_proxy"))
          cibIdData->addMethod("__zz_cib_release_proxy", "__zz_cib_release_proxy");
      }
    }
  } while (false);
  for (auto& mem : compound->members())
  {
    if (isPublic(mem) && isNamespaceLike(mem))
    {
      assignIds(CibCompoundEPtr(mem), helper, cibParams, forGenericProxy);
    }
  }
}
Ejemplo n.º 4
0
bool UniPAX::mysql::MySQLManager::assignIds(PersistenceManager& manager)
{
	return assignIds(manager, false);
}
Ejemplo n.º 5
0
MojErr MojDb::putObj(const MojObject& id, MojObject& obj, const MojObject* oldObj,
					 MojDbStorageItem* oldItem, MojDbReq& req, MojDbOp op, bool checkSchema)
{
	MojLogTrace(s_log);

	// if nothing changed, don't do the update
	if (oldObj != NULL && obj == *oldObj)
		return MojErrNone;

	// update revision
	MojInt64 rev;
	MojErr err = nextId(rev);
	MojErrCheck(err);
	err = obj.put(RevKey, rev);
	MojErrCheck(err);

	// assign id
	MojObject putId = id;
	if (putId.undefined()) {
		err = m_idGenerator.id(putId);
		MojErrCheck(err);
		err = obj.put(IdKey, putId);
		MojErrCheck(err);
	}

	// assign ids to subobjects in arrays - only for regular objects
	MojString kindName;
	bool found = false;
	err = obj.get(MojDb::KindKey, kindName, found);
	MojErrCheck(err);
	if (!found)
		MojErrThrow(MojErrDbKindNotSpecified);
	if (!kindName.startsWith(MojDbKindEngine::KindKindIdPrefix)) {
		err = assignIds(obj);
		MojErrCheck(err);
	}

	// validate, update indexes, etc.
	MojTokenSet tokenSet;
	err = m_kindEngine.update(&obj, oldObj, req, op, tokenSet, checkSchema);
	MojErrCheck(err);

	// serialize object
	MojDbObjectHeader header(putId);
	err = header.extractFrom(obj);
	MojErrCheck(err);
	MojBuffer buf;
	err = header.write(buf, m_kindEngine);
	MojErrCheck(err);
	MojObjectWriter writer(buf, &tokenSet);
	err = obj.visit(writer);
	MojErrCheck(err);

	// store it in the db
	if (oldItem) {
		err = m_objDb->update(putId, buf, oldItem, req.txn());
		MojErrCheck(err);
	} else {
		err = m_objDb->insert(putId, buf, req.txn());
		MojErrCheck(err);
	}

	// put header back in the object for response purposes
	err = header.addTo(obj);
	MojErrCheck(err);

	return MojErrNone;
}