/**
 * When receive connect_frontend command from frontend, change client status that
 * the account and password are stored to property, and start timer.
 * @param client Frontend that passed this request.
 * @param param Parameter contain account, password, frontend type.
 */
void FrontendConnector::recv_connect_frontend(uv_pipe_t& client, picojson::object& param) {
  const std::string& type = param.at("type").get<std::string>();
  const std::string& account  = param.at("account").get<std::string>();
  const std::string& password = param.at("password").get<std::string>();
  FrontendProperty& property = properties.at(&client);

  assert(property.status == PipeStatus::SETUP);
  assert(!account.empty() && !password.empty());

  if (type == "gui") {
    property.type = FrontendType::GUI;

  } else if (type == "cui") {
    property.type = FrontendType::CUI;

  } else {
    /// @todo error
    assert(false);
  }

  property.account  = account;
  property.password = password;

  if (!connect_timer_enable) {
    uv_timer_start(&connect_timer, on_connect_timer, 0, 1000);
    connect_timer_enable = true;
  }
}
void PlayerProfileEntity::serialize(picojson::object &object) {
	object.insert(make_pair("gender", picojson::value(_gender)));
	object.insert(make_pair("age", picojson::value(_age)));
	object.insert(make_pair("address", picojson::value(_address)));
	object.insert(make_pair("blood", picojson::value(_blood)));
	object.insert(make_pair("constellation", picojson::value(_constellation)));
}
T getValueFromJson( const picojson::object & o, const char * key ) {
    picojson::object::const_iterator it = o.find( key );
    if( it == o.end() ) {
        std::string err = keyNotFoundErrorMessage( key );
        LOG( ERROR ) << err;
        throw err;
    }
    return it->second.get<T>();
}
Beispiel #4
0
 void logoEasingSetup(const int type, const std::string& easing, const picojson::object& params)
 {
   const picojson::array& array = params.find(easing)->second.get<picojson::array>();
   for(u_int i = 0; i < logos_.size(); ++i)
   {
     const picojson::array& a = params.find(array[i].get<std::string>())->second.get<picojson::array>();
     EasingArayVec3(type, a, logos_[i].easing);
   }
 }
/**
 * When receive command from frontend, relay to capable module.
 * @param client Frontend that passed this request.
 * @param content Data contain target module, pid, content of command.
 */
void FrontendConnector::recv_relay_command(uv_pipe_t& client, picojson::object& content) {
  CommandPacket packet = {
    Convert::json2vpid(content.at("pid")),
    Convert::json2nid(content.at("dst_nid")),
    NID::NONE,
    Convert::json2int<Module::Type>(content.at("module")),
    content.at("content").get<picojson::object>()
  };

  Router& router = Router::get_instance();
  router.relay_command(packet, false);
}
Beispiel #6
0
//追加
void SqliteManager::addPicoJsonObject(const std::string &table_name, picojson::object &object)
{
    std::string cols = "";
    std::string values = "";

    picojson::object::iterator it = object.begin();
    while (it != object.end()) {
        cols.append('\''+(*it).first+'\'');
        cols.append(",");

        std::string value;
        if(object[it->first].is<double>()) {
            auto val = cocos2d::Value(object[it->first].get<double>());
            value = std::to_string(val.asInt());
        } else if(object[it->first].is<std::string>()) {
            value = object[it->first].get<std::string>();
        }

        values.append('\''+value+'\'');
        values.append(",");
        it++;
    }

    std::string create_at = "created_at";
    std::string updated_at = "updated_at";
    std::string now_time = "datetime('now', 'localtime')";

    //作成時間
    cols.append('\''+create_at+'\'');
    cols.append(",");
    values.append(now_time);
    values.append(",");

    //更新時間
    cols.append('\''+create_at+'\'');
    cols.append(",");
    values.append(now_time);
    values.append(",");

    cols.pop_back();
    values.pop_back();

    std::string sql = "INSERT INTO "+ table_name +" (" + cols + ") VALUES (" + values + ")";
    CCLOG("sql:%s", sql.c_str());

    _result = this->executeQuery(sql);
    if (_result != SQLITE_OK)
    {
        CCLOG("エラー%d:%s", _result, _error_msg);
    }

}
/**
 *  シリアライズ
 *
 *  @param object JSONオブジェクト
 */
void PlayerUnitEntity::serialize(picojson::object &object) {
	object.insert(make_pair("id", picojson::value(id)));
	object.insert(make_pair("name", picojson::value(name)));
	object.insert(make_pair("unitId", picojson::value(unitId)));
	object.insert(make_pair("condition", picojson::value(condition)));
	picojson::array statuseList;
	for (auto it = statuses.begin(); it != statuses.end(); it++) {
		statuseList.push_back(picojson::value(*it));
	}
	object.insert(make_pair("statuses", picojson::value(statuseList)));
	picojson::array equipmentList;
	for (auto it = equipments.begin(); it != equipments.end(); it++) {
		statuseList.push_back(picojson::value(*it));
	}
	object.insert(make_pair("equipments", picojson::value(equipmentList)));
	picojson::array skillList;
	for (auto it = skills.begin(); it != skills.end(); it++) {
		skillList.push_back(picojson::value(*it));
	}
	object.insert(make_pair("skills", picojson::value(skillList)));
	picojson::array itemList;
	for (auto it = items.begin(); it != items.end(); it++) {
		picojson::object object;
		it->serialize(object);
		itemList.push_back(picojson::value(object));
	}
	object.insert(make_pair("items", picojson::value(itemList)));
}
Beispiel #8
0
//更新
void SqliteManager::savePicoJsonObject(const std::string &table_name, picojson::object &object)
{
    std::string values = "";
    std::string update_id = "";

    picojson::object::iterator it = object.begin();
    while (it != object.end()) {
        values.append('\''+(*it).first+'\'');
        values.append("=");


        std::string value;
        if(object[it->first].is<double>()) {
            auto val = cocos2d::Value(object[it->first].get<double>());
            value = std::to_string(val.asInt());
        } else if(object[it->first].is<std::string>()) {
            value = object[it->first].get<std::string>();
        }

        if ((*it).first == "id") {
            update_id = value;
        }

        values.append('\''+value+'\'');
        values.append(",");
        it++;
    }
    std::string updated_at = "updated_at";
    std::string now_time = "datetime('now', 'localtime')";

    //更新時間
    values.append('\''+updated_at+'\'');
    values.append("=");
    values.append(now_time);

    std::string sql = "UPDATE "+ table_name +" SET " + values + " WHERE id = " + update_id;
    CCLOG("sql:%s", sql.c_str());

    _result = this->executeQuery(sql);
    if (_result != SQLITE_OK)
    {
        CCLOG("エラー%d:%s", _result, _error_msg);
    }

}
bool ApplicationConfig::load(picojson::object& obj)
{
    auto poProcessName = obj.find("processName");
    auto poDefaultEndpointId = obj.find("defaultEndpointId");

    if (poProcessName == obj.end() || poDefaultEndpointId == obj.end()) {
        return false;
    }

    if (!poProcessName->second.is<std::string>() ||
        !poDefaultEndpointId->second.is<std::string>()) {
        return false;
    }

    processName = poProcessName->second.get<std::string>();
    defaultEndpointId = poDefaultEndpointId->second.get<std::string>();
    return true;
}
Beispiel #10
0
 void logoWidgetsSetup(const std::string& widget, const picojson::object& params, const WidgetsMap& widgets)
 {
   const picojson::array& array = params.find(widget)->second.get<picojson::array>();
   for(picojson::array::const_iterator it = array.begin(); it != array.end(); ++it)
   {
     Logo logo;
     logo.widget = widgets.get(it->get<std::string>());
     logos_.push_back(logo);
   }
 }
/**
 * When receive data, call capable methods.
 * @param client Frontend pipe that send this packet.
 * @param data Packet.
 */
void FrontendConnector::on_recv_data(uv_pipe_t& client, picojson::object& data) {
  const std::string& command = data.at("command").get<std::string>();

  if (command == "relay_command") {
    recv_relay_command(client, data);

  } else if (command == "connect_frontend") {
    recv_connect_frontend(client, data);

  } else if (command == "open_file") {
    recv_open_file(client, data);

  } else {
    /// @todo error
    assert(false);
  }
}
void DriverConfig::load(picojson::object& obj)
{
    auto poDriverClsid = obj.find("driverClsid");
    auto poEndpoints = obj.find("endpoints");
    auto poApplications = obj.find("applications");

    if (poDriverClsid != obj.end() &&
        poDriverClsid->second.is<std::string>()) {

        driverClsid = poDriverClsid->second.get<std::string>();
    }

    if (poEndpoints != obj.end() && poEndpoints->second.is<picojson::array>()) {
        for (auto& item : poEndpoints->second.get<picojson::array>()) {
            if (!item.is<picojson::object>()) {
                continue;
            }

            EndpointConfig endpoint;

            endpoint.load(item.get<picojson::object>());
            endpoints.emplace_back(endpoint);
        }
    }

    if (poApplications != obj.end() &&
        poApplications->second.is<picojson::array>()) {
        for (auto& item : poApplications->second.get<picojson::array>()) {
            if (!item.is<picojson::object>()) {
                continue;
            }

            ApplicationConfig application;

            application.load(item.get<picojson::object>());
            applications.emplace_back(application);
        }
    }
}
bool ListingsRepository::validateJsonObject(const picojson::object& obj) const
{
  return obj.find("title") != obj.end() && obj.find("manufacturer") != obj.end() 
    && obj.find("currency") != obj.end() && obj.find("price") != obj.end();
}
/**
 * When receive open_file command from frontend, pass capable method on Router.
 * @param client Frontend that passed this request.
 * @param param Parameter contain a filename to open.
 */
void FrontendConnector::recv_open_file(uv_pipe_t& client, picojson::object& param) {
  Router& router = Router::get_instance();

  router.load_llvm(param.at("filename").get<std::string>(), std::vector<std::string>());
}
Beispiel #15
0
  EarthViewer(const Vec2<int>& size, const float scale, const bool oblong, Touch& touch, Keyinp& keyinp, const std::string& path, const std::string& lang) :
    touch_(touch),
    keyinp_(keyinp),
    size_(size.x / scale, size.y / scale),
    params_(path + "devdata/params.json"),
    scale_(scale),
    aspect_((float)size.x / (float)size.y),
    camera_(Camera::PERSPECTIVE),
    cockpit_(Camera::ORTHOGONAL),
    localize_(lang, path),
    earth_(params_.value().get<picojson::object>()["earth"].get<picojson::object>(), path, camera_),
    rotate_mix_(),
    place_index_()
  {
    DOUT << "EarthViewer()" << std::endl;

    picojson::object& params = params_.value().get<picojson::object>();

    camera_.oblong(oblong);
    SetupCamera(camera_, params["camera"].get<picojson::object>(), aspect_);
    cockpit_.setSize(size.x / scale, size.y / scale);

    {
      picojson::array& array = params["lights"].get<picojson::array>();
      for (picojson::array::iterator it = array.begin(); it != array.end(); ++it)
      {
        Light light;
        SetupLight(light, it->get<picojson::object>());
        lights_.push_back(light);
      }
      earth_.light(lights_);
    }

    env_.touch       = &touch_;
    env_.keyinp      = &keyinp_;
    env_.path        = &path;
    env_.savePath    = &path;
    env_.size        = &size_;
    env_.scale       = scale_;
    env_.params      = &params_;
    env_.task        = &task_;
    env_.camera      = &camera_;
    env_.cockpit     = &cockpit_;
    env_.earth       = &earth_;
    env_.earthLight  = &lights_[0];
    env_.fonts       = &fonts_;
    env_.texMng      = &texMng_;
    env_.localize    = &localize_;

    env_.earth_texture = 0;
    earth_.texture(env_.earth_texture);
    earth_.setRotSpeed(0);

    {
      const std::string& file = params["game"].get<picojson::object>()["places"].get<std::string>();
      Json places = Json(path + file);
      places_ = places.value().get<picojson::object>();
      for (picojson::object::iterator it = places_.begin(); it != places_.end(); ++it)
      {
        place_names_.push_back(&it->first);
      }
    }

    task_.add<Control>(TASK_PRIO_SYS, env_);
    task_.add<Game2DSetup>(TASK_PRIO_2D_TOPPRIO, env_);
    task_.add<GameWorld>(TASK_PRIO_3D_TOPPRIO, env_);
    env_.task->add<PlaceDisp>(TASK_PRIO_2D, env_);
    // task_.add<Equator>(TASK_PRIO_3D, env_);
    task_.add<TouchEft>(TASK_PRIO_3D, env_);
  }