elliptics_storage_t::elliptics_storage_t(context_t& context, const std::string& name, const Json::Value& args): category_type(context, name, args), m_context(context), m_log(new log_t(context, name)), m_log_adapter(m_log, args.get("verbosity", DNET_LOG_ERROR).asUInt()), m_node(m_log_adapter), m_session(m_node) { Json::Value nodes(args["nodes"]); if(nodes.empty() || !nodes.isObject()) { throw configuration_error_t("no nodes has been specified"); } Json::Value::Members node_names(nodes.getMemberNames()); for(Json::Value::Members::const_iterator it = node_names.begin(); it != node_names.end(); ++it) { try { m_node.add_remote( it->c_str(), nodes[*it].asInt() ); } catch(const std::runtime_error& e) { // Do nothing. Yes. Really. We only care if no remote nodes were added at all. } } Json::Value groups(args["groups"]); if(groups.empty() || !groups.isArray()) { throw configuration_error_t("no groups has been specified"); } std::transform( groups.begin(), groups.end(), std::back_inserter(m_groups), digitizer() ); m_session.add_groups(m_groups); }
elliptics_node_t::elliptics_node_t(const std::string &config) { Json::Reader reader; Json::Value root; reader.parse(config, root); m_elog.reset(new elliptics::file_logger(root["log"].asString().c_str(), root["log-level"].asInt())); m_node.reset(new elliptics::node(*m_elog)); m_session.reset(new elliptics::session(*m_node)); Json::Value groups(root["groups"]); if (groups.empty() || !groups.isArray()) throw ioremap::elliptics::error(-ENOENT, "no groups has been specified"); std::vector<int> group_numbers; std::transform(groups.begin(), groups.end(), std::back_inserter(group_numbers), json_digitizer()); m_session->set_groups(group_numbers); if (m_session->get_groups().size() == 0) throw ioremap::elliptics::error(-ENOENT, "elliptics_topology_t: no groups added, exiting"); Json::Value nodes(root["nodes"]); if (nodes.empty() || !nodes.isObject()) throw ioremap::elliptics::error(-ENOENT, "no nodes has been specified"); Json::Value::Members node_names(nodes.getMemberNames()); for(Json::Value::Members::const_iterator it = node_names.begin(); it != node_names.end(); ++it) { try { m_node->add_remote(it->c_str(), nodes[*it].asInt()); } catch(const ioremap::elliptics::error&) { } } if (m_session->state_num() == 0) throw ioremap::elliptics::error(-ENOENT, "elliptics_topology_t: no remote nodes added, exiting"); }
void LuaContext::PushJson(const Json::Value& value) { if (value.isString()) { const std::string s = value.asString(); lua_pushlstring(lua_, s.c_str(), s.size()); } else if (value.isDouble()) { lua_pushnumber(lua_, value.asDouble()); } else if (value.isInt()) { lua_pushinteger(lua_, value.asInt()); } else if (value.isUInt()) { lua_pushinteger(lua_, value.asUInt()); } else if (value.isBool()) { lua_pushboolean(lua_, value.asBool()); } else if (value.isNull()) { lua_pushnil(lua_); } else if (value.isArray()) { lua_newtable(lua_); // http://lua-users.org/wiki/SimpleLuaApiExample for (Json::Value::ArrayIndex i = 0; i < value.size(); i++) { // Push the table index (note the "+1" because of Lua conventions) lua_pushnumber(lua_, i + 1); // Push the value of the cell PushJson(value[i]); // Stores the pair in the table lua_rawset(lua_, -3); } } else if (value.isObject()) { lua_newtable(lua_); Json::Value::Members members = value.getMemberNames(); for (Json::Value::Members::const_iterator it = members.begin(); it != members.end(); ++it) { // Push the index of the cell lua_pushlstring(lua_, it->c_str(), it->size()); // Push the value of the cell PushJson(value[*it]); // Stores the pair in the table lua_rawset(lua_, -3); } } else { throw OrthancException(ErrorCode_JsonToLuaTable); } }