File: wb_plugin_be.cpp

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 (134 lines) | stat: -rw-r--r-- 3,520 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright (c) 2008, 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
*/

#include "wb_plugin_be.h"

//--------------------------------------------------------------------------------------------------

void Wb_plugin::grtm(bec::GRTManager *grtm)
{
  _grtm= grtm;
  if (_grtm)
  {
    grt::GRT *grt= _grtm->get_grt();
    _options= grt::DictRef(grt);
  }
}

//--------------------------------------------------------------------------------------------------

void Wb_plugin::exec_task(bool sync)
{
  set_task_proc();

  bec::GRTTask::Ref task = bec::GRTTask::create_task(task_desc(), _grtm->get_dispatcher(), _task_proc_cb);

  scoped_connect(task->signal_message(),boost::bind(&Wb_plugin::process_task_msg, this, _1));
  scoped_connect(task->signal_failed(),boost::bind(&Wb_plugin::process_task_fail, this, _1));
  scoped_connect(task->signal_finished(),boost::bind(&Wb_plugin::process_task_finish, this, _1));

  if (sync)
    _grtm->get_dispatcher()->add_task_and_wait(task);
  else
    _grtm->get_dispatcher()->add_task(task);
}

//--------------------------------------------------------------------------------------------------

void Wb_plugin::process_task_msg(const grt::Message &msg)
{
  switch (msg.type)
  {
  case grt::WarningMsg:
  case grt::ErrorMsg:
  case grt::InfoMsg:
    if (_task_msg_cb)
      _task_msg_cb(msg.type, msg.text);
    break;
  case grt::ProgressMsg:
    if (_task_progress_cb)
      _task_progress_cb(msg.progress, msg.text);
    break;
  default:
    break;
  }
}


void Wb_plugin::process_task_fail(const std::exception &error)
{
  if (_task_fail_cb)
    _task_fail_cb(error.what());
}


void Wb_plugin::process_task_finish(grt::ValueRef res)
{
  _grtm->get_grt()->send_info(grt::StringRef::cast_from(res));
  //_grtm->get_grt()->make_output_visible();
  _grtm->perform_idle_tasks();
  if (_task_fail_cb)
    _task_finish_cb();
}


template<typename T1, typename T2>
T2 get_option(const grt::DictRef &options, const std::string &name)
{
  T2 value = 0;
  if (options.is_valid() && options.has_key(name))
    value= (T2)T1::cast_from(options.get(name));
  return value;
}


int Wb_plugin::get_int_option(const std::string &name)
{
  return get_option<grt::IntegerRef, int>(_options, name);
}


double Wb_plugin::get_double_option(const std::string &name)
{
  return get_option<grt::DoubleRef, double>(_options, name);
}


std::string Wb_plugin::get_string_option(const std::string &name)
{
  return get_option<grt::StringRef, std::string>(_options, name);
}


void Wb_plugin::set_option(const std::string &name, int val)
{
  _options.set(name, grt::IntegerRef(val));
}


void Wb_plugin::set_option(const std::string &name, const double &val)
{
  _options.set(name, grt::DoubleRef(val));
}


void Wb_plugin::set_option(const std::string &name, const std::string &val)
{
  _options.set(name, grt::StringRef(val));
}