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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
/*
* 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
*/
#ifndef _GRT_MANAGER_H_
#define _GRT_MANAGER_H_
#include <grtpp.h>
#include "base/trackable.h"
#include "base/threading.h"
#include "common.h"
#include "grt_dispatcher.h"
#include "grt_shell.h"
#include "grt_value_tree.h"
#include "grt_value_inspector.h"
#include "grt_message_list.h"
#include "wbpublic_public_interface.h"
#include "plugin_manager.h"
#include <boost/signals2/connection.hpp>
namespace bec {
class Clipboard;
/** Manages a GRT context and other associated objects useful for a GRT shell and other apps.
*
* @ingroup begrt
*/
class WBPUBLICBACKEND_PUBLIC_FUNC GRTManager : public base::trackable
{
public:
struct Timer
{
boost::function<bool ()> slot;
GTimeVal next_trigger;
double interval;
Timer(const boost::function<bool ()> &slot, double interval);
bool trigger();
double delay_for_next_trigger(const GTimeVal &now);
};
public:
/** Constructor.
*
* @param threaded enable threading
* @param verbose enable verbose output
*/
GRTManager(bool threaded = true, bool verbose = false);
virtual ~GRTManager();
static GRTManager *get_instance_for(grt::GRT *grt);
void set_basedir(const std::string &path);
std::string get_basedir() { return _basedir; }
void set_datadir(const std::string &path);
std::string get_data_file_path(const std::string &file);
void set_user_datadir(const std::string &path);
std::string get_user_datadir() { return _user_datadir; }
std::string get_tmp_dir();
std::string get_unique_tmp_subdir();
void cleanup_tmp_dir();
void set_module_extensions(const std::list<std::string> &extensions);
void rescan_modules();
int do_scan_modules(const std::string &path, const std::list<std::string> &exts, bool refresh);
void scan_modules_grt(grt::GRT *grt, const std::list<std::string> &extensions, bool refresh);
void set_clipboard(Clipboard *clipb);
Clipboard *get_clipboard() { return _clipboard; }
void set_search_paths(const std::string &module_sp,
const std::string &struct_sp,
const std::string &libraries_sp);
void set_user_extension_paths(const std::string &user_module_path,
const std::string &user_library_path,
const std::string &user_script_path);
std::string get_user_module_path() const { return _user_module_path; }
std::string get_user_library_path() const { return _user_library_path; }
std::string get_user_script_path() const { return _user_script_path; }
// main window statusbar text
void push_status_text(const std::string &message);
void replace_status_text(const std::string &message);
void pop_status_text();
void set_status_slot(const boost::function<void (std::string)> &slot);
void push_cancel_query_callback(const boost::function<bool ()> &slot);
void pop_cancel_query_callback();
public:
GRTDispatcher *get_dispatcher() const { return _dispatcher.get(); };
grt::GRT *get_grt() const { return _grt; };
void initialize(bool init_python, const std::string &loader_module_path= "");
bool initialize_shell(const std::string &shell_type);
bool cancel_idle_tasks();
void perform_idle_tasks();
PluginManager *get_plugin_manager() const { return _plugin_manager; }
bool is_threaded() { return _threaded; }
bool in_main_thread();
// shell
ShellBE *get_shell();
void execute_grt_task(const std::string &title,
const boost::function<grt::ValueRef (grt::GRT*)> &function,
const boost::function<void (grt::ValueRef)> &finished_cb);
// message displaying (as dialogs)
void show_error(const std::string &message, const std::string &detail, bool important= true);
void show_warning(const std::string &title, const std::string &message, bool important= false);
void show_message(const std::string &title, const std::string &message, bool important= false);
MessageListStorage *get_messages_list();
//
void set_app_option_slots(const boost::function<grt::ValueRef (std::string)> &slot,
const boost::function<void (std::string, grt::ValueRef)> &set_slot);
grt::ValueRef get_app_option(const std::string &name);
std::string get_app_option_string(const std::string &name);
long get_app_option_int(const std::string &name, long default_= 0);
void set_app_option(const std::string &name, const grt::ValueRef &value);
boost::signals2::connection run_once_when_idle(const boost::function<void ()> &func);
boost::signals2::connection run_once_when_idle(base::trackable *owner, const boost::function<void ()> &func);
void block_idle_tasks();
void unblock_idle_tasks();
Timer *run_every(const boost::function<bool ()> &slot, double seconds);
void cancel_timer(Timer *timer);
double delay_for_next_timeout();
void set_timeout_request_slot(const boost::function<void ()> &slot);
void flush_timers();
void terminate() { _terminated= true; };
bool terminated() { return _terminated; };
void reset_termination() {_terminated= false; };
void set_db_file_path(const std::string &db_file_path) { _db_file_path= db_file_path; }
std::string get_db_file_path() { return _db_file_path; }
bool has_unsaved_changes() { return _has_unsaved_changes; }
void has_unsaved_changes(bool has_unsaved_changes) { _has_unsaved_changes= has_unsaved_changes; }
// use for advisory locks on grt globals tree
// ex: UI should not refresh layer and catalog trees while a plugin is running
bool try_soft_lock_globals_tree();
void soft_lock_globals_tree();
void soft_unlock_globals_tree();
bool is_globals_tree_locked();
public:
boost::function<void (bec::ArgumentPool&)> update_plugin_arguments_pool; // set by WBContext
bec::MenuItemList get_plugin_context_menu_items(const std::list<std::string> &groups,
const bec::ArgumentPool &argument_pool);
bool check_plugin_runnable(const app_PluginRef &plugin, const bec::ArgumentPool &argpool,
bool debug_output= false);
void open_object_editor(const GrtObjectRef &object, bec::GUIPluginFlags flags = bec::NoFlags);
protected:
grt::GRT *_grt;
bool _has_unsaved_changes;
GRTDispatcher::Ref _dispatcher;
base::Mutex _idle_mutex;
base::Mutex _timer_mutex;
public:
void add_dispatcher(bec::GRTDispatcher::Ref disp);
void remove_dispatcher(bec::GRTDispatcher *disp);
protected:
typedef std::map<GRTDispatcher::Ref, void*> DispMap;
DispMap _disp_map;
base::Mutex _disp_map_mutex;
PluginManager *_plugin_manager;
Clipboard *_clipboard;
ShellBE *_shell;
MessageListStorage *_messages_list;
boost::function<void (std::string)> _status_text_slot;
std::list<Timer*> _timers;
std::set<Timer*> _cancelled_timers;
boost::function<void ()> _timeout_request;
// Using two signals to manage the idle tasks
boost::signals2::signal<void ()> _idle_signals[2];
int _current_idle_signal;
int _idle_blocked;
std::list<std::string> _module_extensions;
std::string _basedir;
std::string _datadir;
std::string _user_datadir;
std::string _module_pathlist;
std::string _struct_pathlist;
std::string _libraries_pathlist;
std::string _db_file_path;
std::string _user_module_path;
std::string _user_library_path;
std::string _user_script_path;
boost::function<grt::ValueRef (std::string)> _get_app_option_slot;
boost::function<void (std::string, grt::ValueRef)> _set_app_option_slot;
bool _threaded;
bool _verbose;
int _globals_tree_soft_lock_count;
virtual bool load_structs();
virtual bool load_modules();
virtual bool load_libraries();
virtual bool init_module_loaders(const std::string &loader_module_path, bool init_python);
bool init_loaders(const std::string &loader_module_path, bool init_python);
void flush_shell_output();
private:
bool _terminated; // true if application termination was requested by the BE or a plugin.
static std::map<grt::GRT*,GRTManager*> _instances;
grt::ValueRef setup_grt(grt::GRT *grt);
void shell_write(const std::string &text);
void task_error_cb(const std::exception &error, const std::string &title);
};
};
#endif /* _GRT_MANAGER_H_ */
|