Exemplo n.º 1
0
void Driver::HandleLoadDatabaseContentEvent(events::LoadDatabaseContentRequestEvent* ev) {
  QObject* sender = ev->sender();
  NotifyProgress(sender, 0);
  events::LoadDatabaseContentResponceEvent::value_type res(ev->value());
  std::string patternResult = common::MemSPrintf(SSDB_GET_KEYS_PATTERN_1ARGS_I, res.count_keys);
  FastoObjectCommandIPtr cmd = CreateCommandFast(patternResult, common::Value::C_INNER);
  NotifyProgress(sender, 50);
  common::Error err = Execute(cmd);
  if (err && err->isError()) {
    res.setErrorInfo(err);
  } else {
    FastoObject::childs_t rchildrens = cmd->Childrens();
    if (rchildrens.size()) {
      CHECK_EQ(rchildrens.size(), 1);
      FastoObjectArray* array = dynamic_cast<FastoObjectArray*>(rchildrens[0].get());  // +
      if (!array) {
        goto done;
      }
      common::ArrayValue* ar = array->Array();
      if (!ar) {
        goto done;
      }

      for (size_t i = 0; i < ar->size(); ++i) {
        std::string key;
        if (ar->getString(i, &key)) {
          NKey k(key);
          FastoObjectCommandIPtr cmd_ttl =
              CreateCommandFast(common::MemSPrintf("TTL %s", key), common::Value::C_INNER);
          LOG_COMMAND(cmd_ttl);
          ttl_t ttl = NO_TTL;
          common::Error err = impl_->TTL(key, &ttl);
          if (err && err->isError()) {
            k.SetTTL(NO_TTL);
          } else {
            k.SetTTL(ttl);
          }

          NValue empty_val(common::Value::createEmptyValueFromType(common::Value::TYPE_STRING));
          NDbKValue ress(k, empty_val);
          res.keys.push_back(ress);
        }
      }

      err = impl_->DBkcount(&res.db_keys_count);
      DCHECK(!err);
    }
  }
done:
  NotifyProgress(sender, 75);
  Reply(sender, new events::LoadDatabaseContentResponceEvent(this, res));
  NotifyProgress(sender, 100);
}
Exemplo n.º 2
0
void SsdbDriver::handleLoadDatabaseContentEvent(events::LoadDatabaseContentRequestEvent *ev) {
  QObject* sender = ev->sender();
  notifyProgress(sender, 0);
    events::LoadDatabaseContentResponceEvent::value_type res(ev->value());
    char patternResult[1024] = {0};
    common::SNPrintf(patternResult, sizeof(patternResult), GET_KEYS_PATTERN_1ARGS_I,
                     res.count_keys);
    FastoObjectIPtr root = FastoObject::createRoot(patternResult);
  notifyProgress(sender, 50);
    FastoObjectCommand* cmd = createCommand<SsdbCommand>(root, patternResult,
                                                         common::Value::C_INNER);
    common::Error er = execute(cmd);
    if (er && er->isError()) {
      res.setErrorInfo(er);
    } else {
      FastoObject::child_container_type rchildrens = cmd->childrens();
      if (rchildrens.size()) {
        DCHECK_EQ(rchildrens.size(), 1);
        FastoObjectArray* array = dynamic_cast<FastoObjectArray*>(rchildrens[0]);
        if (!array) {
          goto done;
        }
        common::ArrayValue* ar = array->array();
        if (!ar) {
          goto done;
        }

        for (size_t i = 0; i < ar->size(); ++i) {
          std::string key;
          bool isok = ar->getString(i, &key);
          if (isok) {
            NKey k(key);
            NDbKValue ress(k, NValue());
            res.keys.push_back(ress);
          }
        }
      }
    }
done:
  notifyProgress(sender, 75);
    reply(sender, new events::LoadDatabaseContentResponceEvent(this, res));
  notifyProgress(sender, 100);
}
std::string CDataBase::makeFilenameOfHash( const CFixedHash &fixed_hash ) const {
    char filename_chars[] = "0123456789ABCDEF";
    unsigned int filename_length =  ( CFixedHash::length + 3 ) / 4;
    char *res = new char[ filename_length + 1 ];
    res[ filename_length ] = 0;
    int pow = 1;
    for( unsigned int a = 0; a < CFixedHash::length; ++a ) {
        if( a % 4 == 0 ) {
            pow = 1;
            res[ filename_length - a / 4 - 1 ] = 0;
        } else {
            pow *= 2;
        }
        if( fixed_hash.getHash()[CFixedHash::length - a - 1] == Raspoznavayka::arrow_up ) {
            res[ filename_length - a / 4 - 1 ] += pow;
        }
    }
    for( unsigned int a = 0; a < filename_length; ++a ) {
        res[a] = filename_chars[ static_cast< unsigned char >( res[a] ) ];
    }
    std::string ress( res );
    delete res;
    return hash_file_subdir + ress + hash_file_extension;
}
Exemplo n.º 4
0
sf::Vector3i Crafter::getRessources() const{
    sf::Vector3i ress(_nbIron, _nbGold, _nbRuby);
    return ress;
}
Exemplo n.º 5
0
void Driver::HandleLoadDatabaseContentEvent(events::LoadDatabaseContentRequestEvent* ev) {
  QObject* sender = ev->sender();
  NotifyProgress(sender, 0);
  events::LoadDatabaseContentResponceEvent::value_type res(ev->value());
  std::string patternResult =
      common::MemSPrintf(GET_KEYS_PATTERN_3ARGS_ISI, res.cursor_in, res.pattern, res.count_keys);
  FastoObjectCommandIPtr cmd = CreateCommandFast(patternResult, common::Value::C_INNER);
  NotifyProgress(sender, 50);
  common::Error er = Execute(cmd);
  if (er && er->isError()) {
    res.setErrorInfo(er);
  } else {
    FastoObject::childs_t rchildrens = cmd->Childrens();
    if (rchildrens.size()) {
      CHECK_EQ(rchildrens.size(), 1);
      FastoObjectArray* array = dynamic_cast<FastoObjectArray*>(rchildrens[0].get());  // +
      if (!array) {
        goto done;
      }

      common::ArrayValue* arm = array->Array();
      if (!arm->size()) {
        goto done;
      }

      std::string cursor;
      bool isok = arm->getString(0, &cursor);
      if (!isok) {
        goto done;
      }

      res.cursor_out = common::ConvertFromString<uint64_t>(cursor);

      rchildrens = array->Childrens();
      if (!rchildrens.size()) {
        goto done;
      }

      FastoObject* obj = rchildrens[0].get();
      FastoObjectArray* arr = dynamic_cast<FastoObjectArray*>(obj);  // +
      if (!arr) {
        goto done;
      }

      common::ArrayValue* ar = arr->Array();
      if (ar->empty()) {
        goto done;
      }

      for (size_t i = 0; i < ar->size(); ++i) {
        std::string key;
        if (ar->getString(i, &key)) {
          NKey k(key);
          NValue empty_val(common::Value::createEmptyValueFromType(common::Value::TYPE_STRING));
          NDbKValue ress(k, empty_val);
          res.keys.push_back(ress);
        }
      }

      common::Error err = impl_->DBkcount(&res.db_keys_count);
      DCHECK(!err);
    }
  }
done:
  NotifyProgress(sender, 75);
  Reply(sender, new events::LoadDatabaseContentResponceEvent(this, res));
  NotifyProgress(sender, 100);
}