std::shared_ptr<core::Processor> ExecutionPlan::createProcessor(const std::string &processor_name, const std::string &name) { utils::Identifier uuid; id_generator_->generate(uuid); auto custom_proc = custom_processors.find(processor_name); if(custom_proc != custom_processors.end()) { auto ontrigger_c_func = custom_proc->second.ontr_cb; auto onschedule_c_func = custom_proc->second.onsc_cb; auto ontrigger_wrapper_func = [ontrigger_c_func](core::ProcessSession * session, core::ProcessContext * context) { if(ontrigger_c_func) { ontrigger_c_func(reinterpret_cast<processor_session *>(session), reinterpret_cast<processor_context *>(context)); } }; auto onschedule_wrapper_func = [onschedule_c_func](core::ProcessContext * context) { if (onschedule_c_func) { onschedule_c_func(reinterpret_cast<processor_context*>(context)); } }; return createCallback(nullptr, ontrigger_wrapper_func, onschedule_wrapper_func); } auto ptr = core::ClassLoader::getDefaultClassLoader().instantiate(processor_name, uuid); if (nullptr == ptr) { return nullptr; } std::shared_ptr<core::Processor> processor = std::static_pointer_cast<core::Processor>(ptr); processor->setName(name); return processor; }
Future<void> StrandPrivate::async(boost::function<void()> cb, qi::SteadyClockTimePoint tp) { boost::shared_ptr<Callback> cbStruct = createCallback(cb); cbStruct->promise = qi::Promise<void>(boost::bind(&StrandPrivate::cancel, this, cbStruct)); qiLogDebug() << "Scheduling job id " << cbStruct->id << " at " << qi::to_string(tp); cbStruct->asyncFuture = _eventLoop.async(boost::bind( &StrandPrivate::enqueue, this, cbStruct), tp); return cbStruct->promise.future(); }
std::shared_ptr<core::Processor> ExecutionPlan::addCallback(void *obj, std::function<void(core::ProcessSession*, core::ProcessContext *)> ontrigger_callback, std::function<void(core::ProcessContext *)> onschedule_callback) { if (finalized) { return nullptr; } auto proc = createCallback(obj, ontrigger_callback, onschedule_callback); if (!proc) return nullptr; return addProcessor(proc, CallbackProcessorName, core::Relationship("success", "description"), true); }
Future<void> StrandPrivate::async(boost::function<void()> cb, qi::Duration delay) { boost::shared_ptr<Callback> cbStruct = createCallback(cb); cbStruct->promise = qi::Promise<void>(boost::bind(&StrandPrivate::cancel, this, cbStruct)); qiLogDebug() << "Scheduling job id " << cbStruct->id << " in " << qi::to_string(delay); if (delay.count()) cbStruct->asyncFuture = _eventLoop.async(boost::bind( &StrandPrivate::enqueue, this, cbStruct), delay); else enqueue(cbStruct); return cbStruct->promise.future(); }