当前位置: 首页>>代码示例>>C++>>正文


C++ context_t类代码示例

本文整理汇总了C++中context_t的典型用法代码示例。如果您正苦于以下问题:C++ context_t类的具体用法?C++ context_t怎么用?C++ context_t使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了context_t类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pool

pool_ptr pool(context_t& context, const std::string& name) {
    auto pool = context.config().component_group("postgres").get(name);
    if(!pool) {
        throw error_t(std::errc::argument_out_of_domain, "postgres component with name '{}' not found", name);
    }
    return context.repository().get<pool_t>("postgres", context, name, pool->args());
}
开发者ID:3Hren,项目名称:cocaine-plugins,代码行数:7,代码来源:pool.cpp

示例2: getContext

/* compute the current binary context */
void ContextTree::getContext(const history_t &h, context_t &context) const {

    context.clear();
    for (size_t i=0; i < m_depth; ++i) {
        context.push_back(h[h.size()-i-1]);
    }
}
开发者ID:floringogianu,项目名称:SkipCTS,代码行数:8,代码来源:ctw.cpp

示例3: unicorn

/**
 * Unicorn trait for service creation.
 * Trait to create unicorn service by name. All instances are cached by name as it is done in storage.
 */
unicorn_ptr
unicorn(context_t& context, const std::string& name) {
    auto unicorn = context.config().unicorns().get(name);
    if(!unicorn) {
        throw error_t(error::component_not_found, "unicorn component \"{}\" not found in the config", name);
    }
    return context.repository().get<unicorn_t>(unicorn->type(), context, name, unicorn->args());
}
开发者ID:cocaine,项目名称:cocaine-core,代码行数:12,代码来源:unicorn.cpp

示例4: metrics

actor_base<Protocol>::actor_base(context_t& context, io::dispatch_ptr_t prototype) :
    m_context(context),
    m_log(context.log("core/asio", {{"service", prototype->name()}})),
    metrics(new metrics_t{
        context.metrics_hub().counter<std::int64_t>(cocaine::format("{}.connections.accepted", prototype->name())),
        context.metrics_hub().counter<std::int64_t>(cocaine::format("{}.connections.rejected", prototype->name()))
    }),
    m_prototype(std::move(prototype))
{}
开发者ID:3Hren,项目名称:cocaine-core,代码行数:9,代码来源:actor.cpp

示例5: category_type

multicast_t::multicast_t(context_t& context, interface& locator, const std::string& name, const dynamic_t& args):
    category_type(context, locator, name, args),
    m_context(context),
    m_log(context.log(name)),
    m_locator(locator),
    m_cfg(args.to<multicast_cfg_t>()),
    m_socket(locator.asio()),
    m_timer(locator.asio())
{
    m_socket.open(m_cfg.endpoint.protocol());
    m_socket.set_option(socket_base::reuse_address(true));

    if(m_cfg.endpoint.address().is_v4()) {
        m_socket.bind(udp::endpoint(address_v4::any(), m_cfg.endpoint.port()));
    } else {
        m_socket.bind(udp::endpoint(address_v6::any(), m_cfg.endpoint.port()));
    }

    if(args.as_object().count("interface")) {
        auto interface = args.as_object().at("interface");

        if(m_cfg.endpoint.address().is_v4()) {
            m_socket.set_option(multicast::outbound_interface(interface.to<ip::address>().to_v4()));
        } else {
            m_socket.set_option(multicast::outbound_interface(interface.as_uint()));
        }
    }

    m_socket.set_option(multicast::enable_loopback(args.as_object().at("loopback", false).as_bool()));
    m_socket.set_option(multicast::hops(args.as_object().at("hops", 1u).as_uint()));

    COCAINE_LOG_INFO(m_log, "joining multicast group '%s'", m_cfg.endpoint)(
        "uuid", m_locator.uuid()
    );

    m_socket.set_option(multicast::join_group(m_cfg.endpoint.address()));

    const auto announce = std::make_shared<announce_t>();

    m_socket.async_receive_from(buffer(announce->buffer.data(), announce->buffer.size()),
        announce->endpoint,
        std::bind(&multicast_t::on_receive, this, ph::_1, ph::_2, announce)
    );

    m_signals = std::make_shared<dispatch<context_tag>>(name);
    m_signals->on<context::prepared>(std::bind(&multicast_t::on_publish, this, std::error_code()));

    context.listen(m_signals, m_locator.asio());
}
开发者ID:b-xiang,项目名称:cocaine-core,代码行数:49,代码来源:multicast.cpp

示例6: app_dispatch_t

    app_dispatch_t(context_t& context, const std::string& name, std::shared_ptr<overseer_t> overseer_) :
        dispatch<io::app_tag>(name),
        log(context.log(format("%s/dispatch", name))),
        overseer(std::move(overseer_))
    {
        on<io::app::enqueue>(std::make_shared<slot_type>(
            std::bind(&app_dispatch_t::on_enqueue, this, ph::_1, ph::_2, ph::_3)
        ));

        on<io::app::info>(std::bind(&app_dispatch_t::on_info, this));

        // TODO: Temporary here to test graceful app terminating.
        on<io::app::test>([&](const std::string& v) {
            COCAINE_LOG_DEBUG(log, "processing test '%s' event", v);

            if (v == "0") {
                overseer.lock()->terminate();
            } else {
                std::vector<std::string> slaves;
                {
                    auto pool = overseer.lock()->get_pool();
                    for (const auto& p : *pool) {
                        slaves.push_back(p.first);
                    }
                }

                for (auto& s : slaves) {
                    overseer.lock()->despawn(s, overseer_t::despawn_policy_t::graceful);
                }
            }
        });
    }
开发者ID:arssher,项目名称:cocaine-core,代码行数:32,代码来源:app.cpp

示例7:

adhoc_t::adhoc_t(context_t& context, const std::string& _local_uuid, const std::string& name, const dynamic_t& args):
    category_type(context, _local_uuid, name, args),
    m_log(context.log(name))
{
    std::random_device rd;
    m_random_generator.seed(rd());
}
开发者ID:3Hren,项目名称:cocaine-core,代码行数:7,代码来源:adhoc.cpp

示例8:

logging_t::logging_t(context_t& context, io::reactor_t& reactor, const std::string& name, const Json::Value& args):
    category_type(context, reactor, name, args)
{
    auto logger = std::ref(context.logger());

    using cocaine::logging::logger_concept_t;

    on<io::logging::emit>("emit", std::bind(&logger_concept_t::emit, logger, _1, _2, _3));
    on<io::logging::verbosity>("verbosity", std::bind(&logger_concept_t::verbosity, logger));
}
开发者ID:diunko,项目名称:cocaine-core,代码行数:10,代码来源:logging.cpp

示例9:

logging_t::logging_t(context_t& context, io::reactor_t& reactor, const std::string& name, const Json::Value& args):
    api::service_t(context, reactor, name, args),
    implementation<io::logging_tag>(context, name)
{
    auto logger = std::ref(context.logger());

    using cocaine::logging::logger_concept_t;

    on<io::logging::emit>(std::bind(&logger_concept_t::emit, logger, _1, _2, _3));
    on<io::logging::verbosity>(std::bind(&logger_concept_t::verbosity, logger));
}
开发者ID:andrewpsp,项目名称:cocaine-core,代码行数:11,代码来源:logging.cpp

示例10:

agent_t::agent_t(
	context_t ctx )
	:	m_current_state_ptr( &st_default )
	,	m_was_defined( false )
	,	m_state_listener_controller( new impl::state_listener_controller_t )
	,	m_handler_finder{
			// Actual handler finder is dependent on msg_tracing status.
			impl::internal_env_iface_t{ ctx.env() }.is_msg_tracing_enabled() ?
				&agent_t::handler_finder_msg_tracing_enabled :
				&agent_t::handler_finder_msg_tracing_disabled }
	,	m_subscriptions(
			ctx.options().query_subscription_storage_factory()( self_ptr() ) )
	,	m_message_limits(
			message_limit::impl::info_storage_t::create_if_necessary(
				ctx.options().giveout_message_limits() ) )
	,	m_env( ctx.env() )
	,	m_event_queue( nullptr )
	,	m_direct_mbox(
			impl::internal_env_iface_t{ ctx.env() }.create_mpsc_mbox(
				self_ptr(),
				m_message_limits.get() ) )
		// It is necessary to enable agent subscription in the
		// constructor of derived class.
	,	m_working_thread_id( so_5::query_current_thread_id() )
	,	m_agent_coop( 0 )
	,	m_priority( ctx.options().query_priority() )
{
}
开发者ID:crystax,项目名称:android-vendor-sobjectizer,代码行数:28,代码来源:agent.cpp

示例11:

actor_t::actor_t(context_t& context, std::shared_ptr<io::reactor_t> reactor, std::unique_ptr<api::service_t> service):
    m_context(context),
    m_log(context.log(service->prototype().name())),
    m_reactor(reactor)
{
    const io::basic_dispatch_t* prototype = &service->prototype();

    // Aliasing the pointer to the service to point to the dispatch (sub-)object.
    m_prototype = std::shared_ptr<const io::basic_dispatch_t>(
        std::shared_ptr<api::service_t>(std::move(service)),
        prototype
    );
}
开发者ID:bdacode,项目名称:cocaine-core,代码行数:13,代码来源:actor.cpp

示例12: createNodesInCurrentContext

/* create (if necessary) all of the nodes in the current context */
void ContextTree::createNodesInCurrentContext(const context_t &context) {

    CTNode **ctn = &m_root;

    for (size_t i = 0; i < context.size(); i++) {
        ctn = &((*ctn)->m_child[context[i]]);
        if (*ctn == NULL) {
            void *p = m_ctnode_pool.malloc();
            assert(p != NULL);  // TODO: make more robust
            *ctn = new (p) CTNode();
        }
    }
}
开发者ID:floringogianu,项目名称:SkipCTS,代码行数:14,代码来源:ctw.cpp

示例13: identity

auth_t::auth_t(context_t& context):
    m_context(context),
    m_log(context.log("crypto")),
    m_evp_md_context(EVP_MD_CTX_create())
{
    ERR_load_crypto_strings();

    // NOTE: Allowing the exception to propagate here, as this is a fatal error.
    std::vector<std::string> keys(
        context.get<api::storage_t>("storage/core")->list("keys")
    );

    for(std::vector<std::string>::const_iterator it = keys.begin();
        it != keys.end();
        ++it)
    {
        std::string identity(*it);

        std::string object(
            context.get<api::storage_t>("storage/core")->get<std::string>("keys", identity)
        );

        if(object.empty()) {
            COCAINE_LOG_ERROR(m_log, "key for user '%s' is malformed", identity);
            continue;
        }

        // Read the key into the BIO object.
        BIO * bio = BIO_new_mem_buf(const_cast<char*>(object.data()), object.size());
        EVP_PKEY * pkey = NULL;
        
        pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL);
            
        if(pkey != NULL) {
            m_keys.emplace(identity, pkey);
        } else { 
            COCAINE_LOG_ERROR(
                m_log,
                "key for user '%s' is invalid - %s",
                identity, 
                ERR_reason_error_string(ERR_get_error())
            );
        }

        BIO_free(bio);
    }
    
    COCAINE_LOG_INFO(m_log, "loaded %llu public key(s)", m_keys.size());
}
开发者ID:SSE4,项目名称:cocaine-core,代码行数:49,代码来源:auth.cpp

示例14:

execution_unit_t::execution_unit_t(context_t& context):
    m_asio(new io_service()),
    m_chamber(new io::chamber_t("core:asio", m_asio)),
    m_cron(*m_asio)
{
    m_log = context.log("core:asio", {
        attribute::make("engine", boost::lexical_cast<std::string>(m_chamber->thread_id()))
    });

    m_asio->post(std::bind(&gc_action_t::operator(),
                           std::make_shared<gc_action_t>(this, boost::posix_time::seconds(kCollectionInterval))
                          ));

    COCAINE_LOG_DEBUG(m_log, "engine started");
}
开发者ID:arssher,项目名称:cocaine-core,代码行数:15,代码来源:engine.cpp

示例15: system_error

process_t::process_t(context_t& context, const std::string& name, const dynamic_t& args):
    category_type(context, name, args),
    m_context(context),
    m_log(context.log(name)),
    m_name(name),
    m_working_directory(fs::path(args.as_object().at("spool", "/var/spool/cocaine").as_string()) / name)
{
#ifdef COCAINE_ALLOW_CGROUPS
    int rv = 0;

    if((rv = cgroup_init()) != 0) {
        throw std::system_error(rv, cgroup_category(), "unable to initialize cgroups");
    }

    m_cgroup = cgroup_new_cgroup(m_name.c_str());

    // NOTE: Looks like if this is not done, then libcgroup will chown everything as root.
    cgroup_set_uid_gid(m_cgroup, getuid(), getgid(), getuid(), getgid());

    for(auto type = args.as_object().begin(); type != args.as_object().end(); ++type) {
        if(!type->second.is_object() || type->second.as_object().empty()) {
            continue;
        }

        cgroup_controller* ptr = cgroup_add_controller(m_cgroup, type->first.c_str());

        for(auto it = type->second.as_object().begin(); it != type->second.as_object().end(); ++it) {
            COCAINE_LOG_INFO(m_log, "setting cgroup controller '%s' parameter '%s' to '%s'",
                type->first, it->first, boost::lexical_cast<std::string>(it->second)
            );

            try {
                it->second.apply(cgroup_configurator_t(ptr, it->first.c_str()));
            } catch(const cocaine::error_t& e) {
                COCAINE_LOG_ERROR(m_log, "unable to set cgroup controller '%s' parameter '%s' - %s",
                    type->first, it->first, e.what()
                );
            }
        }
    }

    if((rv = cgroup_create_cgroup(m_cgroup, false)) != 0) {
        cgroup_free(&m_cgroup);

        throw std::system_error(rv, cgroup_category(), "unable to create cgroup");
    }
#endif
}
开发者ID:myutwo,项目名称:cocaine-core,代码行数:48,代码来源:process.cpp


注:本文中的context_t类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。