[ekiga/ds-opal-refactoring] Opal: Reorganized process destruction.



commit 9b07f4e3a03c9f056556480ad2a4ace24c8be753
Author: Damien Sandras <dsandras seconix com>
Date:   Sun Mar 22 16:01:30 2015 +0100

    Opal: Reorganized process destruction.
    
    Shutting down endpoints and cleaning up factories are executed by Opal
    when the process is being destroyed. However, it triggers segfaults when
    using static PMutex instances in OpalGloballyUniqueID for example.
    
    That is why we clean things up preventively.
    
    An engine_close method has been added. It allows manual cleaning when
    required for some parts of the engine.

 lib/engine/audiooutput/audiooutput-core.cpp        |    2 +-
 lib/engine/components/opal/opal-main.cpp           |   24 +++++++++++
 lib/engine/components/opal/opal-main.h             |    1 +
 .../components/opal/process/opal-endpoint.cpp      |    1 -
 .../components/opal/process/opal-process.cpp       |   44 ++++++++++---------
 lib/engine/components/opal/process/opal-process.h  |    2 +
 lib/engine/engine.cpp                              |    6 +++
 lib/engine/engine.h                                |    2 +
 lib/engine/gui/gtk-frontend/ekiga-app.cpp          |    2 +
 9 files changed, 61 insertions(+), 23 deletions(-)
---
diff --git a/lib/engine/audiooutput/audiooutput-core.cpp b/lib/engine/audiooutput/audiooutput-core.cpp
index 7dc3854..0bf9cbf 100644
--- a/lib/engine/audiooutput/audiooutput-core.cpp
+++ b/lib/engine/audiooutput/audiooutput-core.cpp
@@ -118,7 +118,7 @@ AudioOutputCore::~AudioOutputCore ()
   PWaitAndSignal m_pri(core_mutex[primary]);
   PWaitAndSignal m_sec(core_mutex[secondary]);
 
-  audio_event_scheduler->quit ();
+  delete audio_event_scheduler;
 
   for (std::set<AudioOutputManager*>::iterator iter = managers.begin ();
        iter != managers.end ();
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index e84ffe5..96b3e22 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -211,3 +211,27 @@ opal_init (Ekiga::KickStart& kickstart)
   boost::shared_ptr<Ekiga::Spark> spark (new OPALSpark);
   kickstart.add_spark (spark);
 }
+
+
+void
+opal_close (Ekiga::ServiceCore& core)
+{
+  // First remove all Opal::Accounts from our Bank.
+  //
+  // Do it forcibly so we're sure the accounts are freed before our
+  // reference to the endpoints. Indeed they try to unregister from
+  // presence when killed, and that gives a crash if the call manager
+  // is already gone!
+  boost::shared_ptr<Bank> bank = core.get<Bank> ("opal-account-store");
+  boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
+  boost::shared_ptr<Ekiga::AccountCore> account_core = core.get<Ekiga::AccountCore> ("account-core");
+
+  bank->clear ();
+  account_core->remove_bank (bank);
+  presence_core->remove_presence_publisher (bank);
+  presence_core->remove_cluster (bank);
+  core.remove (bank);
+
+  // Then execute precleanup routines
+  GnomeMeeting::Process ()->Exit ();
+}
diff --git a/lib/engine/components/opal/opal-main.h b/lib/engine/components/opal/opal-main.h
index 1161c16..14f4294 100644
--- a/lib/engine/components/opal/opal-main.h
+++ b/lib/engine/components/opal/opal-main.h
@@ -48,4 +48,5 @@ GnomeMeeting &opal_init_pprocess (int argc,
 // Must be called after opal_init_pprocess.
 void opal_init (Ekiga::KickStart& kickstart);
 
+void opal_close (Ekiga::ServiceCore& core);
 #endif
diff --git a/lib/engine/components/opal/process/opal-endpoint.cpp 
b/lib/engine/components/opal/process/opal-endpoint.cpp
index 8bae5c7..f378938 100644
--- a/lib/engine/components/opal/process/opal-endpoint.cpp
+++ b/lib/engine/components/opal/process/opal-endpoint.cpp
@@ -178,7 +178,6 @@ Opal::EndPoint::~EndPoint ()
 {
   if (stun_thread)
     stun_thread->WaitForTermination ();
-  ClearAllCalls (OpalConnection::EndedByLocalUser, true);
 
   g_async_queue_unref (queue);
 }
diff --git a/lib/engine/components/opal/process/opal-process.cpp 
b/lib/engine/components/opal/process/opal-process.cpp
index 8d1119d..14b76d3 100644
--- a/lib/engine/components/opal/process/opal-process.cpp
+++ b/lib/engine/components/opal/process/opal-process.cpp
@@ -52,31 +52,13 @@ GnomeMeeting::GnomeMeeting () : PProcess("", "", MAJOR_VERSION, MINOR_VERSION, B
   GM = this;
 }
 
+
 GnomeMeeting::~GnomeMeeting ()
 {
-  std::cout << "PPROCESS END Start" << std::endl << std::flush;
-  // First remove all Opal::Accounts from our Bank.
-  //
-  // Do it forcibly so we're sure the accounts are freed before our
-  // reference to the endpoints. Indeed they try to unregister from
-  // presence when killed, and that gives a crash if the call manager
-  // is already gone!
-  /*
-     bank->clear ();
-     acore->remove_bank (bank);
-
-     boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
-     pcore->remove_presence_publisher (bank);
-     pcore->remove_cluster (bank);
-
-     core.remove (bank);
-
-     std::cout << "bank use count" << bank.use_count () << std::endl << std::flush;
-   */
-
-  std::cout << "PPROCESS END END" << std::endl << std::flush;
+  delete endpoint;
 }
 
+
 GnomeMeeting *
 GnomeMeeting::Process ()
 {
@@ -95,6 +77,26 @@ void GnomeMeeting::Start (Ekiga::ServiceCore& core)
 }
 
 
+void GnomeMeeting::Exit ()
+{
+  // Shutting down endpoints and cleaning up factories
+  // are executed by Opal when the process is being
+  // destroyed. However, it triggers segfaults when
+  // using static PMutex instances in OpalGloballyUniqueID
+  // for example.
+  //
+  // That is why we clean things up preventively.
+
+  // Shutdown all endpoints
+  endpoint->ShutDownEndpoints ();
+
+  // Clean up factories
+  PProcessStartupFactory::KeyList_T list = PProcessStartupFactory::GetKeyList();
+  for (PProcessStartupFactory::KeyList_T::const_iterator it = list.begin(); it != list.end(); ++it)
+    PProcessStartupFactory::CreateInstance(*it)->OnShutdown();
+}
+
+
 Opal::EndPoint&
 GnomeMeeting::GetEndPoint ()
 {
diff --git a/lib/engine/components/opal/process/opal-process.h 
b/lib/engine/components/opal/process/opal-process.h
index 421c2fe..1cf57a6 100644
--- a/lib/engine/components/opal/process/opal-process.h
+++ b/lib/engine/components/opal/process/opal-process.h
@@ -72,6 +72,8 @@ class GnomeMeeting : public PProcess
 
   void Start (Ekiga::ServiceCore& core);
 
+  void Exit ();
+
   static GnomeMeeting *Process ();
 
   Opal::EndPoint& GetEndPoint ();
diff --git a/lib/engine/engine.cpp b/lib/engine/engine.cpp
index 2c509ed..f8ce327 100644
--- a/lib/engine/engine.cpp
+++ b/lib/engine/engine.cpp
@@ -203,3 +203,9 @@ engine_init (Ekiga::ServiceCore& core,
   core.dump (std::cout);
 #endif
 }
+
+
+void engine_close (Ekiga::ServiceCore& core)
+{
+  opal_close (core);
+}
diff --git a/lib/engine/engine.h b/lib/engine/engine.h
index e50afe2..99426b8 100644
--- a/lib/engine/engine.h
+++ b/lib/engine/engine.h
@@ -48,6 +48,8 @@ void engine_init (Ekiga::ServiceCore& core,
                   int argc,
                   char *argv[]);
 
+void engine_close (Ekiga::ServiceCore& core);
+
 /**
  * @}
  */
diff --git a/lib/engine/gui/gtk-frontend/ekiga-app.cpp b/lib/engine/gui/gtk-frontend/ekiga-app.cpp
index de1247c..5c46715 100644
--- a/lib/engine/gui/gtk-frontend/ekiga-app.cpp
+++ b/lib/engine/gui/gtk-frontend/ekiga-app.cpp
@@ -571,6 +571,8 @@ gm_application_shutdown (GApplication *app)
       gtk_widget_destroy (GTK_WIDGET (windows_it->data));
   }
 
+  engine_close (self->priv->core);
+
   delete self->priv;
   self->priv = NULL;
 


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