Exemplo n.º 1
0
 void operator()()
 {
     boost::asynchronous::continuation_result<Return> task_res = this->this_task_result();
     try
     {
         auto if_clause = if_clause_;
         auto then_clause = then_clause_;
         auto else_clause = else_clause_;
         // TODO C++14 move capture if possible
         cont_.on_done(
         [task_res,if_clause,then_clause,else_clause]
         (std::tuple<boost::asynchronous::expected<typename Continuation::return_type> >&& continuation_res)mutable
         {
             try
             {
                 auto res = std::get<0>(continuation_res).get();
                 if (if_clause(res))
                 {
                     auto then_cont = then_clause(std::move(res));
                     then_cont.on_done(
                         [task_res](std::tuple<boost::asynchronous::expected<Return> >&& then_res)mutable
                         {
                             task_res.set_value(std::move(std::get<0>(then_res).get()));
                         }
                     );
                 }
                 else
                 {
                     auto else_cont = else_clause(std::move(res));
                     else_cont.on_done(
                         [task_res](std::tuple<boost::asynchronous::expected<Return> >&& then_res)mutable
                         {
                             task_res.set_value(std::move(std::get<0>(then_res).get()));
                         }
                     );
                 }
             }
             catch(std::exception& e)
             {
                 task_res.set_exception(boost::copy_exception(e));
             }
         }
         );
     }
     catch(std::exception& e)
     {
         task_res.set_exception(boost::copy_exception(e));
     }
 }
Exemplo n.º 2
0
gboolean
qof_commit_edit_part2(QofInstance *inst,
                      void (*on_error)(QofInstance *, QofBackendError),
                      void (*on_done)(QofInstance *),
                      void (*on_free)(QofInstance *))
{
    QofInstancePrivate *priv;
    QofBackend * be;
    gboolean dirty;

    priv = GET_PRIVATE(inst);
    dirty = priv->dirty;

    /* See if there's a backend.  If there is, invoke it. */
    be = qof_book_get_backend(priv->book);
    if (be && qof_backend_commit_exists(be))
    {
        QofBackendError errcode;

        /* clear errors */
        do
        {
            errcode = qof_backend_get_error(be);
        }
        while (ERR_BACKEND_NO_ERR != errcode);

        qof_backend_run_commit(be, inst);
        errcode = qof_backend_get_error(be);
        if (ERR_BACKEND_NO_ERR != errcode)
        {
            /* XXX Should perform a rollback here */
            priv->do_free = FALSE;

            /* Push error back onto the stack */
            qof_backend_set_error (be, errcode);
            if (on_error)
                on_error(inst, errcode);
            return FALSE;
        }
        /* XXX the backend commit code should clear dirty!! */
        priv->dirty = FALSE;
    }
//    if (dirty && qof_get_alt_dirty_mode() &&
//        !(priv->infant && priv->do_free)) {
//      qof_collection_mark_dirty(priv->collection);
//      qof_book_mark_dirty(priv->book);
//    }
    priv->infant = FALSE;

    if (priv->do_free)
    {
        if (on_free)
            on_free(inst);
        return TRUE;
    }

    if (on_done)
        on_done(inst);
    return TRUE;
}
Exemplo n.º 3
0
static void plaintext_handshake(grpc_exec_ctx *exec_ctx, void *arg,
                                grpc_endpoint *endpoint, const char *host,
                                void (*on_done)(grpc_exec_ctx *exec_ctx,
                                                void *arg,
                                                grpc_endpoint *endpoint)) {
  on_done(exec_ctx, arg, endpoint);
}
Exemplo n.º 4
0
static void ssl_handshake(grpc_exec_ctx *exec_ctx, void *arg,
                          grpc_endpoint *tcp, const char *host,
                          gpr_timespec deadline,
                          void (*on_done)(grpc_exec_ctx *exec_ctx, void *arg,
                                          grpc_endpoint *endpoint)) {
  grpc_channel_security_connector *sc = NULL;
  const unsigned char *pem_root_certs = NULL;
  on_done_closure *c = gpr_malloc(sizeof(*c));
  size_t pem_root_certs_size = grpc_get_default_ssl_roots(&pem_root_certs);
  if (pem_root_certs == NULL || pem_root_certs_size == 0) {
    gpr_log(GPR_ERROR, "Could not get default pem root certs.");
    on_done(exec_ctx, arg, NULL);
    gpr_free(c);
    return;
  }
  c->func = on_done;
  c->arg = arg;
  c->handshake_mgr = grpc_handshake_manager_create();
  GPR_ASSERT(httpcli_ssl_channel_security_connector_create(
                 pem_root_certs, pem_root_certs_size, host, &sc) ==
             GRPC_SECURITY_OK);
  grpc_channel_security_connector_add_handshakers(exec_ctx, sc,
                                                  c->handshake_mgr);
  grpc_handshake_manager_do_handshake(
      exec_ctx, c->handshake_mgr, tcp, NULL /* channel_args */, deadline,
      NULL /* acceptor */, on_handshake_done, c /* user_data */);
  GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "httpcli");
}
Exemplo n.º 5
0
Arquivo: job.cpp Projeto: Tyilo/tpie
void job::done() {
	if (m_state != job_running)
		throw tpie::exception("Bad job state");

	--m_dependencies;
	if (m_dependencies) return;

	m_state = job_idle;

	if (m_parent) m_parent->done();
	m_done.notify_all();
	on_done();
}
opkg_build::opkg_build(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::opkg_build)
{
    ui->setupUi(this);
    ui->progressBar->hide();
    QObject::connect(&build_thread_obj,SIGNAL(input_status(QString)),this,SLOT(on_input_statu(QString)));
    QObject::connect(&build_thread_obj,SIGNAL(change_statu_word(QString)),this,SLOT(on_change_statu_word(QString)));
    QObject::connect(&build_thread_obj,SIGNAL(change_progress(int)),this,SLOT(on_change_progress(int)));
    QObject::connect(&build_thread_obj,SIGNAL(done()),this,SLOT(on_done()));
    QObject::connect(this,SIGNAL(make_start(QString,QString,QString,QString,QString,QString)),&build_thread_obj,SIGNAL(build_start(QString,QString,QString,QString,QString,QString)));
    build_thread_obj.start();
}
Exemplo n.º 7
0
 void operator()()
 {
     boost::asynchronous::continuation_result<typename Continuation::return_type>
             task_res = this->this_task_result();
     try
     {
         auto if_clause = if_clause_;
         auto then_clause = then_clause_;
         // TODO C++14 move capture if possible
         cont_.on_done(
         [task_res,if_clause,then_clause]
         (std::tuple<boost::asynchronous::expected<typename Continuation::return_type> >&& continuation_res)
         {
             try
             {
                 auto res = std::get<0>(continuation_res).get();
                 if (std::get<0>(res))
                 {
                     // if handled, just forward
                     task_res.set_value(std::move(res));
                 }
                 else if(if_clause(std::get<1>(res)))
                 {
                     auto then_cont = then_clause(std::move(std::get<1>(res)));
                     then_cont.on_done(
                         [task_res](std::tuple<boost::asynchronous::expected<
                                         typename std::tuple_element<1,typename Continuation::return_type>::type> >&& then_res)
                         {
                             task_res.set_value(std::make_tuple(true,std::move(std::get<0>(then_res).get())));
                         }
                     );
                 }
                 else
                 {
                     task_res.set_value(std::move(res));
                 }
             }
             catch(std::exception& e)
             {
                 task_res.set_exception(boost::copy_exception(e));
             }
         }
         );
     }
     catch(std::exception& e)
     {
         task_res.set_exception(boost::copy_exception(e));
     }
 }
Exemplo n.º 8
0
	/// Called when a job finished.
	void BehaviorEngine::onJobDone_() {
		// Invoke the done handler and pop the job.
		BehaviorJob & job = queue_.front();
		if (job.on_done_) job.on_done_();
		queue_.pop_front();
		
		//std::cout << "Dequeing job " << job.name_ << ", size " << queue_.size() << std::endl;
		
		// Process the rest of the queue.
		if (queue_.size()) {
			unqueue_();
		// If the queue is empty, inform interested parties.
		} else {
			on_done();
		}
	}
Exemplo n.º 9
0
    void operator()()
    {
        boost::asynchronous::continuation_result<Container> task_res = this->this_task_result();
        try
        {
            // if we can insert without reallocating, we are done fast.
            if (m_container.size() + 1 <= m_container.capacity() )
            {
                m_container.push_back(m_value);
                task_res.set_value(std::move(m_container));
                return;
            }
            // reallocate
            boost::shared_ptr<Container> c = boost::make_shared<Container>(std::move(m_container));
            auto v = m_value;
            auto capacity = c->calc_new_capacity(c->size());
            auto cont = c->async_reallocate(capacity,c->size());
            cont.on_done([task_res,c,v,capacity]
                           (std::tuple<boost::asynchronous::expected<typename Container::internal_data_type> >&& res)mutable
            {
                try
                {
                    // reallocation has already been done, ok to call push_back directly
                    c->set_internal_data(std::move(std::get<0>(res).get()),capacity);
                    c->push_back(v);
                    task_res.set_value(std::move(*c));
                }
                catch(std::exception& e)
                {
                    task_res.set_exception(boost::copy_exception(e));
                }
            });

        }
        catch(std::exception& e)
        {
            task_res.set_exception(boost::copy_exception(e));
        }
    }
Exemplo n.º 10
0
static void ssl_handshake(grpc_exec_ctx *exec_ctx, void *arg,
                          grpc_endpoint *tcp, const char *host,
                          void (*on_done)(grpc_exec_ctx *exec_ctx, void *arg,
                                          grpc_endpoint *endpoint)) {
  grpc_channel_security_connector *sc = NULL;
  const unsigned char *pem_root_certs = NULL;
  on_done_closure *c = gpr_malloc(sizeof(*c));
  size_t pem_root_certs_size = grpc_get_default_ssl_roots(&pem_root_certs);
  if (pem_root_certs == NULL || pem_root_certs_size == 0) {
    gpr_log(GPR_ERROR, "Could not get default pem root certs.");
    on_done(exec_ctx, arg, NULL);
    gpr_free(c);
    return;
  }
  c->func = on_done;
  c->arg = arg;
  GPR_ASSERT(httpcli_ssl_channel_security_connector_create(
                 pem_root_certs, pem_root_certs_size, host, &sc) ==
             GRPC_SECURITY_OK);
  grpc_channel_security_connector_do_handshake(
      exec_ctx, sc, tcp, on_secure_transport_setup_done, c);
  GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "httpcli");
}
Exemplo n.º 11
0
static void plaintext_handshake(void *arg, grpc_endpoint *endpoint,
                                const char *host,
                                void (*on_done)(void *arg,
                                                grpc_endpoint *endpoint)) {
  on_done(arg, endpoint);
}
    void operator()()
    {
        boost::asynchronous::continuation_result<Range> task_res = this->this_task_result();
        // advance up to cutoff
        Iterator it = boost::asynchronous::detail::find_cutoff(beg_,cutoff_,end_);
        if (it == end_)
        {
            Range temp = std::move(boost::asynchronous::geometry::detail::pairwise_union<Iterator,Range>(beg_,end_));
            while(temp.size() > 1)
            {
                temp = std::move(boost::asynchronous::geometry::detail::pairwise_union<Iterator,Range>(temp.begin(),temp.end()));
            }
            task_res.set_value(std::move(temp));
        }
        else
        {
            auto task_name = this->get_name();
            auto prio = prio_;
            auto cutoff = cutoff_;
            auto overlay_cutoff = overlay_cutoff_;
            auto partition_cutoff = partition_cutoff_;

            boost::asynchronous::create_callback_continuation_job<Job>(
                        // called when subtasks are done, set our result
                        [task_res,task_name,prio,cutoff,overlay_cutoff,partition_cutoff]
                        (std::tuple<boost::asynchronous::expected<Range>,boost::asynchronous::expected<Range> > res)
                        {
                            try
                            {
                                // start parallel union
                                auto sub1 = std::move(std::get<0>(res).get());
                                auto sub2 = std::move(std::get<1>(res).get());
                                typedef typename boost::range_value<Range>::type Element;
                                auto cont = boost::asynchronous::geometry::parallel_union<Element,Element,Element,Job>
                                        (*(sub1.begin()),*(sub2.begin()),overlay_cutoff,partition_cutoff,task_name,prio);
                                cont.on_done([task_res](std::tuple<boost::asynchronous::expected<Element> >&& res_p_union)
                                {
                                    try
                                    {
                                        Range merge_res;
                                        merge_res.emplace_back(std::move(std::get<0>(res_p_union).get()));
                                        task_res.set_value(std::move(merge_res));
                                    }
                                    catch(std::exception& e)
                                    {
                                        task_res.set_exception(boost::copy_exception(e));
                                    }
                                });
                            }
                            catch(std::exception& e)
                            {
                                task_res.set_exception(boost::copy_exception(e));
                            }
                        },
                        // recursive tasks
                        parallel_geometry_union_of_x_helper<Iterator,Range,Job>
                            (beg_,it,cutoff_,overlay_cutoff_,partition_cutoff_,this->get_name(),prio_),
                        parallel_geometry_union_of_x_helper<Iterator,Range,Job>
                            (it,end_,cutoff_,overlay_cutoff_,partition_cutoff_,this->get_name(),prio_)
            );
        }
    }