[ekiga] Made Opal::Call and Opal::CallManager fetch the services they need at startup



commit 386041b50c5da30465ddbda8422157612b3bc23c
Author: Julien Puydt <jpuydt free fr>
Date:   Wed Jan 23 16:01:11 2013 +0100

    Made Opal::Call and Opal::CallManager fetch the services they need at startup

 lib/engine/components/opal/opal-call-manager.cpp |   28 ++++++++++++++--------
 lib/engine/components/opal/opal-call-manager.h   |    6 +++-
 lib/engine/components/opal/opal-call.cpp         |   19 +++++++++++----
 lib/engine/components/opal/opal-call.h           |   10 ++++++-
 4 files changed, 44 insertions(+), 19 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-call-manager.cpp b/lib/engine/components/opal/opal-call-manager.cpp
index 17bc02e..c18fcac 100644
--- a/lib/engine/components/opal/opal-call-manager.cpp
+++ b/lib/engine/components/opal/opal-call-manager.cpp
@@ -100,9 +100,11 @@ using namespace Opal;
 
 
 /* The class */
-CallManager::CallManager (Ekiga::ServiceCore & _core)
-  : core (_core)
+CallManager::CallManager (Ekiga::ServiceCore& core)
 {
+  call_core = core.get<Ekiga::CallCore> ("call-core");
+  notification_core = core.get<Ekiga::NotificationCore> ("notification-core");
+
   /* Initialise the endpoint parameters */
 #if P_HAS_IPV6
   char * ekiga_ipv6 = getenv("EKIGA_IPV6");
@@ -703,12 +705,16 @@ void CallManager::get_video_options (CallManager::VideoOptions & options) const
 }
 
 void
-CallManager::create_call_in_main (Opal::Call* call)
+CallManager::create_call_in_main (Opal::Call* _call)
 {
-  boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
+  boost::shared_ptr<Opal::Call> call(_call);
+
+  // FIXME: we should check it worked, but what do we do if it doesn't?
+  boost::shared_ptr<Ekiga::CallCore> ccore = call_core.lock ();
+
+  call->set_engine_services (notification_core, ccore);
 
-  call_core->add_call (boost::shared_ptr<Opal::Call>(call),
-		       boost::dynamic_pointer_cast<CallManager>(shared_from_this ()));
+  ccore->add_call (call, boost::dynamic_pointer_cast<CallManager>(shared_from_this ()));
 }
 
 OpalCall *CallManager::CreateCall (void *uri)
@@ -716,9 +722,9 @@ OpalCall *CallManager::CreateCall (void *uri)
   Opal::Call* call = 0;
 
   if (uri != 0)
-    call = new Opal::Call (*this, core, (const char *) uri);
+    call = new Opal::Call (*this, (const char *) uri);
   else
-    call = new Opal::Call (*this, core, "");
+    call = new Opal::Call (*this, "");
 
   Ekiga::Runtime::run_in_main (boost::bind (&CallManager::create_call_in_main, this, call));
 
@@ -843,10 +849,12 @@ CallManager::HandleSTUNResult ()
 void
 CallManager::ReportSTUNError (const std::string error)
 {
-  boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
+  boost::shared_ptr<Ekiga::CallCore> ccore = call_core.lock ();
+  if (!ccore)
+    return;
 
   // notice we're in for an infinite loop if nobody ever reports to the user!
-  if ( !call_core->errors (error)) {
+  if ( !ccore->errors (error)) {
 
     Ekiga::Runtime::run_in_main (boost::bind (&CallManager::ReportSTUNError, this, error),
 				 10);
diff --git a/lib/engine/components/opal/opal-call-manager.h b/lib/engine/components/opal/opal-call-manager.h
index 7acb8b9..e790aa2 100644
--- a/lib/engine/components/opal/opal-call-manager.h
+++ b/lib/engine/components/opal/opal-call-manager.h
@@ -70,7 +70,7 @@ public:
 
     CallManager (Ekiga::ServiceCore & _core);
 
-    virtual ~CallManager ();
+    ~CallManager ();
 
     /**/
     const std::string get_name () const
@@ -154,6 +154,9 @@ public:
     void get_video_options (VideoOptions & options) const;
 
 private:
+    boost::weak_ptr<Ekiga::CallCore> call_core;
+    boost::shared_ptr<Ekiga::NotificationCore> notification_core;
+
     void create_call_in_main (Opal::Call* call);
     OpalCall *CreateCall (void *uri);
     void emit_removed_in_main (Ekiga::Call* call);
@@ -183,7 +186,6 @@ private:
        variables */
     PMutex manager_access_mutex;
 
-    Ekiga::ServiceCore & core;
     Ekiga::CodecList codecs; 
 
     /* used to get the STUNDetector results */
diff --git a/lib/engine/components/opal/opal-call.cpp b/lib/engine/components/opal/opal-call.cpp
index 5fadcf9..2b7a92a 100644
--- a/lib/engine/components/opal/opal-call.cpp
+++ b/lib/engine/components/opal/opal-call.cpp
@@ -46,6 +46,7 @@
 #include "call.h"
 #include "opal-call.h"
 #include "opal-call-manager.h"
+#include "notification-core.h"
 #include "call-core.h"
 
 using namespace Opal;
@@ -94,12 +95,10 @@ private:
 
 
 Opal::Call::Call (Opal::CallManager& _manager,
-		  Ekiga::ServiceCore& _core,
 		  const std::string& uri)
-  : OpalCall (_manager), Ekiga::Call (), core (_core), manager(_manager), remote_uri (uri),
+  : OpalCall (_manager), Ekiga::Call (), manager(_manager), remote_uri (uri),
     call_setup(false), jitter(0), outgoing(false)
 {
-  notification_core = core.get<Ekiga::NotificationCore> ("notification-core");
   re_a_bytes = tr_a_bytes = re_v_bytes = tr_v_bytes = 0.0;
   last_v_tick = last_a_tick = PTime ();
   total_a =
@@ -121,6 +120,13 @@ Opal::Call::~Call ()
 {
 }
 
+void
+Opal::Call::set_engine_services (boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
+				 boost::shared_ptr<Ekiga::CallCore> _call_core)
+{
+  notification_core = _notification_core;
+  call_core = _call_core;
+}
 
 void
 Opal::Call::hang_up ()
@@ -693,7 +699,10 @@ Opal::Call::emit_established_in_main ()
 void
 Opal::Call::emit_missed_in_main ()
 {
-  boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
+  boost::shared_ptr<Ekiga::CallCore> ccore = call_core.lock ();
+  if (!ccore)
+    return;
+
   std::stringstream msg;
 
   missed ();
@@ -701,7 +710,7 @@ Opal::Call::emit_missed_in_main ()
   boost::shared_ptr<Ekiga::Notification> notif (new Ekiga::Notification (Ekiga::Notification::Warning,
                                                                          _("Missed call"), msg.str (),
                                                                          _("Call"),
-                                                                         boost::bind (&Ekiga::CallCore::dial, call_core,
+                                                                         boost::bind (&Ekiga::CallCore::dial, ccore,
                                                                                       get_remote_uri ())));
   notification_core->push_notification (notif);
 }
diff --git a/lib/engine/components/opal/opal-call.h b/lib/engine/components/opal/opal-call.h
index 7d9df90..bfe1b45 100644
--- a/lib/engine/components/opal/opal-call.h
+++ b/lib/engine/components/opal/opal-call.h
@@ -46,6 +46,10 @@
 #ifndef __OPAL_CALL_H__
 #define __OPAL_CALL_H__
 
+namespace Ekiga {
+  class CallCore;
+};
+
 class GMManager;
 
 namespace Opal {
@@ -60,7 +64,6 @@ namespace Opal {
 public:
 
     Call (CallManager &_manager,
-          Ekiga::ServiceCore& _core,
           const std::string & uri);
 
     ~Call ();
@@ -150,6 +153,8 @@ public:
      */
     time_t get_start_time () const;
 
+    void set_engine_services (boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
+			      boost::shared_ptr<Ekiga::CallCore> _call_core);
 
 public:
 
@@ -222,9 +227,10 @@ private:
     /*
      * Variables
      */
-    Ekiga::ServiceCore& core;
+
     CallManager & manager;
     boost::shared_ptr<Ekiga::NotificationCore> notification_core;
+    boost::weak_ptr<Ekiga::CallCore> call_core;
 
     std::string local_party_name;
     std::string remote_party_name;



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