[nemiver/gtk2-branch] Fix a crash in confmgr



commit aa8f19d77ed3028f00c5023a23aecd66da69c45d
Author: Dodji Seketeli <dodji seketeli org>
Date:   Sun Apr 24 23:00:46 2011 +0200

    Fix a crash in confmgr
    
    	* src/confmgr/nmv-i-conf-mgr.h (load_iface_and_confmgr): Set the
    	loaded configuration manager into the other loaded interface so
    	that the lifetime of the configuration manager is as longer as the
    	lifetime of the other loaded interface object.  Added comment.
    	* src/workbench/nmv-i-workbench.h (IWorkbench::do_init): New
    	pure virtual function.
    	* src/workbench/nmv-workbench.cc
    	(Workbench::set_configuration_manager): New
    	function.
    	(Workbench::do_init): New function.  Use the new
    	Workbench::set_configuration_manager.
    	(Workbench::get_configuration_manager): Factorize to use the new
    	Workbench::set_configuration_manager.

 src/confmgr/nmv-i-conf-mgr.h    |   31 ++++++++++++++++++++++++++-
 src/workbench/nmv-i-workbench.h |    5 +++-
 src/workbench/nmv-workbench.cc  |   45 +++++++++++++++++++++++++++++++-------
 3 files changed, 70 insertions(+), 11 deletions(-)
---
diff --git a/src/confmgr/nmv-i-conf-mgr.h b/src/confmgr/nmv-i-conf-mgr.h
index e5b37a8..fccf5fa 100644
--- a/src/confmgr/nmv-i-conf-mgr.h
+++ b/src/confmgr/nmv-i-conf-mgr.h
@@ -105,6 +105,17 @@ public:
 
 };//end class IConfMgr
 
+/// Load a dynamic module of a given name, query it for an interface
+/// and return it.  But before that, load the proper configuration
+/// manager dynamic module and query its interface.
+///
+/// \param a_dynmod_name the name of dynamic module to load
+///
+/// \param a_iface_name the name of the interface to query from the 
+/// loaded dynamic module
+///
+/// \param a_confmgr an output argument set to a pointer to the
+/// interface of configuration manager that was loaded.
 template<class T>
 SafePtr<T, ObjectRef, ObjectUnref>
 load_iface_and_confmgr (const UString &a_dynmod_name,
@@ -126,13 +137,31 @@ load_iface_and_confmgr (const UString &a_dynmod_name,
     return iface;
 }
 
+/// Load a dynamic module of a given name, query it for an interface
+/// and return it.  But before that, load the proper configuration
+/// manager dynamic module and query its interface.  Initialize the
+/// former interface with the interface of the dynamic module.  This
+/// function template requires that T has an
+/// T::do_init(IConfMgrSafePtr) method.
+///
+/// \param a_dynmod_name the name of dynamic module to load
+///
+/// \param a_iface_name the name of the interface to query from the 
+/// loaded dynamic module
+///
+/// \return a pointer (wrapped in a SafePtr) to the interface which
+/// name is a_iface_name, initialized with the proper interface of the
+/// configuration manager.
 template<class T>
 SafePtr<T, ObjectRef, ObjectUnref>
 load_iface_and_confmgr (const UString &a_dynmod_name,
                         const UString &a_iface_name)
 {
     IConfMgrSafePtr m;
-    return load_iface_and_confmgr<T> (a_dynmod_name, a_iface_name, m);
+    SafePtr<T, ObjectRef, ObjectUnref> result;
+    result = load_iface_and_confmgr<T> (a_dynmod_name, a_iface_name, m);
+    result->do_init (m);
+    return result;
 }
 
 
diff --git a/src/workbench/nmv-i-workbench.h b/src/workbench/nmv-i-workbench.h
index 8890cc7..0ae7531 100644
--- a/src/workbench/nmv-i-workbench.h
+++ b/src/workbench/nmv-i-workbench.h
@@ -139,7 +139,10 @@ public:
     /// \return the perspective that which name matches a_name
     virtual IPerspective* get_perspective (const UString &a_name) = 0;
 
-    /// \return the interface of the configuration manager.
+    /// set the configuration manager used by this interface
+    virtual void do_init (IConfMgrSafePtr &) = 0;
+
+    /// \return the interface of the configuration manager
     virtual IConfMgrSafePtr get_configuration_manager () = 0;
     ///@}
 
diff --git a/src/workbench/nmv-workbench.cc b/src/workbench/nmv-workbench.cc
index b0d9755..1de9ca3 100644
--- a/src/workbench/nmv-workbench.cc
+++ b/src/workbench/nmv-workbench.cc
@@ -128,6 +128,7 @@ public:
     Workbench (DynamicModule *a_dynmod);
     virtual ~Workbench ();
     void do_init (Gtk::Main &a_main);
+    void do_init (IConfMgrSafePtr &);
     void shut_down ();
     Glib::RefPtr<Gtk::ActionGroup> get_default_action_group ();
     Glib::RefPtr<Gtk::ActionGroup> get_debugger_ready_action_group ();
@@ -137,6 +138,7 @@ public:
     void set_title_extension (const UString &a_str);
     Glib::RefPtr<Gtk::UIManager>& get_ui_manager () ;
     IPerspective* get_perspective (const UString &a_name);
+    void set_configuration_manager (IConfMgrSafePtr &);
     IConfMgrSafePtr get_configuration_manager () ;
     Glib::RefPtr<Glib::MainContext> get_main_context () ;
     sigc::signal<void>& shutting_down_signal ();
@@ -341,6 +343,22 @@ Workbench::~Workbench ()
     LOG_D ("delete", "destructor-domain");
 }
 
+/// Initialize the workbench by setting the configuration manager it
+/// is going to use.  This function is usually called by the helper
+/// function template load_iface_and_confmgr.
+///
+/// \param a_conf_mgr the configuration manager to set.
+void
+Workbench::do_init (IConfMgrSafePtr &a_conf_mgr)
+{
+    set_configuration_manager (a_conf_mgr);
+}
+
+/// Initialize the workbench by doing all the graphical plumbling
+/// needed to setup the perspectives held by this workbench.  Calling
+/// this function is mandatory prior to using the workbench.
+///
+/// \param a_main the Gtk main object the workbench is going to use.
 void
 Workbench::do_init (Gtk::Main &a_main)
 {
@@ -512,22 +530,31 @@ Workbench::get_perspective (const UString &a_name)
     return NULL;
 }
 
+/// Set the configuration manager
+void
+Workbench::set_configuration_manager (IConfMgrSafePtr &a_conf_mgr)
+{
+    m_priv->conf_mgr = a_conf_mgr;
+
+    NEMIVER_TRY;
+
+    m_priv->conf_mgr->register_namespace
+        (/*default nemiver namespace*/);
+    m_priv->conf_mgr->register_namespace
+        (CONF_NAMESPACE_DESKTOP_INTERFACE);
+
+    NEMIVER_CATCH;
+}
+
 IConfMgrSafePtr
 Workbench::get_configuration_manager ()
 {
     THROW_IF_FAIL (m_priv);
     if (!m_priv->conf_mgr) {
-
-        m_priv->conf_mgr =
+        IConfMgrSafePtr new_conf_mgr = 
             DynamicModuleManager::load_iface_with_default_manager<IConfMgr>
             (CONFIG_MGR_MODULE_NAME, "IConfMgr");
-
-        NEMIVER_TRY;
-
-        m_priv->conf_mgr->register_namespace (/*default nemiver namespace*/);
-        m_priv->conf_mgr->register_namespace (CONF_NAMESPACE_DESKTOP_INTERFACE);
-
-        NEMIVER_CATCH_NOX;
+        set_configuration_manager (new_conf_mgr);
     }
     THROW_IF_FAIL (m_priv->conf_mgr);
     return m_priv->conf_mgr;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]