File: grt_threaded_task.h

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (116 lines) | stat: -rw-r--r-- 3,787 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* 
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the
 * License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#pragma once

#include "base/trackable.h"
#include "wbpublic_public_interface.h"
#include "grt/grt_manager.h"

class WBPUBLICBACKEND_PUBLIC_FUNC GrtThreadedTask : public base::trackable
{
public:
  typedef boost::shared_ptr<GrtThreadedTask> Ref;
public:
  static Ref create() { return Ref(new GrtThreadedTask()); }
  static Ref create(bec::GRTManager *grtm) { return Ref(new GrtThreadedTask(grtm)); }
  static Ref create(const GrtThreadedTask::Ref parent_task) { return Ref(new GrtThreadedTask(parent_task)); }
public:
  virtual ~GrtThreadedTask();
  void disconnect_callbacks();
protected:
  GrtThreadedTask();
  GrtThreadedTask(bec::GRTManager *grtm);
  GrtThreadedTask(const GrtThreadedTask::Ref parent_task);

public:
  bec::GRTManager * grtm() const { return _grtm; }
  void grtm(bec::GRTManager *grtm);

  bool is_busy() { return _dispatcher && _dispatcher->get_busy(); }
private:
  bec::GRTManager *_grtm;

private:
  const bec::GRTDispatcher::Ref & dispatcher();
private:
  bec::GRTDispatcher::Ref _dispatcher;

private:
  bec::GRTTask::Ref _task;
  GrtThreadedTask::Ref _parent_task;

public:
  const GrtThreadedTask::Ref parent_task() const { return _parent_task; }
  void parent_task(const GrtThreadedTask::Ref val);

  const bec::GRTTask::Ref task(); // Returns the underlying grt task.

private:
  void on_starting(const bec::GRTTaskBase::Ref task);

public:
  std::string desc() { return _desc; }
  void desc(const std::string &desc) { _desc= desc; }
private:
  std::string _desc;

public:
  void send_task_res_msg(bool value) { _send_task_res_msg= value; }
private:
  bool _send_task_res_msg;

public:
  typedef boost::function<grt::StringRef (grt::GRT *)> Proc_cb;
  typedef boost::function<int (int, const std::string&, const std::string&)> Msg_cb;
  typedef boost::function<int (float, const std::string&)> Progress_cb;
  typedef boost::function<void ()> Finish_cb;
  typedef boost::function<void (const std::string&)> Fail_cb;

public:
  void exec(bool sync= false, Proc_cb proc_cb= Proc_cb());
  void send_msg(int msg_type, const std::string &msg, const std::string &detail= "");
  void send_progress(float percentage, const std::string &msg, const std::string &detail= "");

public:
  void msg_cb(Msg_cb cb) { _msg_cb= cb; }
  const Msg_cb &msg_cb() { return _msg_cb; }
  
  void progress_cb(Progress_cb cb) { _progress_cb= cb; }
  void finish_cb(Finish_cb cb, bool onetime=false) { _finish_cb= cb; _onetime_finish_cb = onetime; }
  void fail_cb(Fail_cb cb, bool onetime=false) { _fail_cb= cb; _onetime_fail_cb = onetime; }
  void proc_cb(Proc_cb cb) { _proc_cb= cb; }

private:
  void process_msg(const grt::Message &msgs);
  void process_finish(grt::ValueRef res);
  void process_fail(const std::exception &error);

private:
  Proc_cb _proc_cb;
  Msg_cb _msg_cb;
  Progress_cb _progress_cb;
  Finish_cb _finish_cb;
  bool _onetime_finish_cb;
  Fail_cb _fail_cb;
  bool _onetime_fail_cb;

public:
  void execute_in_main_thread(const boost::function<void ()> &function, bool wait, bool force_queue);
};