Mercurial > hg > octave-avbm
diff libgui/src/octave-adapter/octave-link.h @ 15371:eec0d1fcba4f
use Octave singleton style for octave_link class
* octave-link.h, octave-link.cc (class octave_link): Update style to
match other singleton classes in Octave.
Change all uses.
* history-dockwidget.cc, file-editor-tab.cc, main-window.cc,
octave-link.cc, workspace-model.cc: Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 13 Sep 2012 01:03:55 -0400 |
parents | 359098ad343e |
children | 24b5348d38e7 |
line wrap: on
line diff
--- a/libgui/src/octave-adapter/octave-link.h +++ b/libgui/src/octave-adapter/octave-link.h @@ -34,61 +34,124 @@ #include "octave-event-observer.h" #include "octave-event-listener.h" -/** - * \class OctaveLink - * \brief Provides threadsafe access to octave. - * \author Jacob Dawid - * This class is a wrapper around octave and provides threadsafety by - * buffering access operations to octave and executing them in the readline - * event hook, which lives in the octave thread. - */ +// \class OctaveLink +// \brief Provides threadsafe access to octave. +// \author Jacob Dawid +// +// This class is a wrapper around octave and provides thread safety by +// buffering access operations to octave and executing them in the +// readline event hook, which lives in the octave thread. + class octave_link : public octave_event_observer { +protected: + + octave_link (void); + public: - /** Provides a way to access the unique octave_link object. */ - static octave_link * instance () { return &_singleton; } + + ~octave_link (void) { } + + static void launch_octave (void) + { + if (instance_ok ()) + instance->do_launch_octave (); + } + + static void register_event_listener (octave_event_listener *el) + { + if (instance_ok ()) + instance->do_register_event_listener (el); + } + + static void generate_events (void) + { + if (instance_ok ()) + instance->do_generate_events (); + } + + static void process_events (void) + { + if (instance_ok ()) + instance->do_process_events (); + } + + static void post_event (octave_event *e) + { + if (instance_ok ()) + instance->do_post_event (e); + } + + static void about_to_exit (void) + { + if (instance_ok ()) + instance->do_about_to_exit (); + } + + static void entered_readline_hook (void) + { + if (instance_ok ()) + instance->do_entered_readline_hook (); + } - /** Starts octave. */ - void launch_octave (); - void register_event_listener (octave_event_listener *oel); + static void finished_readline_hook (void) + { + if (instance_ok ()) + instance->do_finished_readline_hook (); + } + + static std::string last_working_directory (void) + { + return instance_ok () + ? instance->do_last_working_directory () : std::string (); + } + +private: + + static octave_link *instance; + + static void cleanup_instance (void) { delete instance; instance = 0; } + + // No copying! + + octave_link (const octave_link&); + + octave_link& operator = (const octave_link&); + + static bool instance_ok (void); + + octave_event_listener *event_listener; - void generate_events (); - void process_events (); - void post_event (octave_event *e); + // Thread running octave_main. + octave_main_thread *main_thread; + + // Semaphore to lock access to the event queue. + octave_mutex *event_queue_mutex; + + // Buffer for queueing events until they will be processed. + std::queue <octave_event *> event_queue; + + // Stores the last known current working directory of octave. + std::string last_cwd; + + bool debugging; + + void do_launch_octave (void); + void do_register_event_listener (octave_event_listener *oel); + + void do_generate_events (void); + void do_process_events (void); + void do_post_event (octave_event *e); + + void do_about_to_exit (void); + + void do_entered_readline_hook (void) { } + void do_finished_readline_hook (void) { } + + std::string do_last_working_directory (void); + void event_accepted (octave_event *e); void event_reject (octave_event *e); - - void about_to_exit (); - - void entered_readline_hook (); - void finished_readline_hook (); - - std::string get_last_working_directory (); - -private: - /** Singleton. */ - octave_link (); - ~octave_link (); - - octave_event_listener *_octave_event_listener; - - /** Thread running octave_main. */ - octave_main_thread *_octave_main_thread; +}; - /** Semaphore to lock access to the event queue. */ - octave_mutex *_event_queue_mutex; - - /** Buffer for queueing events until they will be processed. */ - std::queue <octave_event *> _event_queue; - - /** Stores the last known current working directory of octave. */ - std::string _last_working_directory; - bool _debugging_mode_active; - - /** Semaphore to lock access to the performance information. */ - octave_mutex *_performance_information_mutex; - - /** Unique instance. Singelton! */ - static octave_link _singleton; -}; #endif // OCTAVELINK_H