[ekiga/ds-opal-refactoring] Opal: Let the Engine handle the Call destruction.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga/ds-opal-refactoring] Opal: Let the Engine handle the Call destruction.
- Date: Tue, 31 Mar 2015 16:14:45 +0000 (UTC)
commit 160f7ccb4cca95b171d4091b098b9f85fd5b2ec2
Author: Damien Sandras <dsandras seconix com>
Date: Sat Mar 28 18:37:26 2015 +0100
Opal: Let the Engine handle the Call destruction.
Boost will delete it when convenient.
Of course, it introduces a leak due to the fact that we use things of
the form:
objects[obj]->add (obj->updated.connect (boost::bind (boost::ref
(object_updated), obj)));
It means that our objects binds on itself with a shared_ptr to itself as
argument. The new boost garbage collector will prevent the object to be
destroyed.
lib/engine/components/opal/opal-call-manager.cpp | 13 --------
lib/engine/components/opal/opal-call-manager.h | 7 ----
lib/engine/components/opal/opal-call.cpp | 5 ++-
.../components/opal/process/opal-endpoint.cpp | 33 ++++++++++++--------
lib/engine/components/opal/process/opal-endpoint.h | 9 +++--
5 files changed, 30 insertions(+), 37 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-call-manager.cpp
b/lib/engine/components/opal/opal-call-manager.cpp
index 328b195..e3d7eff 100644
--- a/lib/engine/components/opal/opal-call-manager.cpp
+++ b/lib/engine/components/opal/opal-call-manager.cpp
@@ -48,8 +48,6 @@
Opal::CallManager::CallManager (Ekiga::ServiceCore& _core,
Opal::EndPoint& _endpoint) : core(_core), endpoint(_endpoint)
{
- endpoint.created_call.connect (boost::bind (&Opal::CallManager::on_created_call, this, _1));
-
/* Setup things */
Ekiga::SettingsCallback setup_cb = boost::bind (&Opal::CallManager::setup, this, _1);
nat_settings = Ekiga::SettingsPtr (new Ekiga::Settings (NAT_SCHEMA, setup_cb));
@@ -294,14 +292,3 @@ void Opal::CallManager::setup (const std::string & setting)
}
}
}
-
-
-void Opal::CallManager::on_created_call (Opal::Call *_call)
-{
- boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
- // beware that opal puts calls in PSafePtr objects,
- // and hence we must not delete them ourselves
-
- boost::shared_ptr<Opal::Call> call(_call, null_deleter2 ());
- call_core->add_call (call);
-}
diff --git a/lib/engine/components/opal/opal-call-manager.h b/lib/engine/components/opal/opal-call-manager.h
index 6027685..18f648a 100644
--- a/lib/engine/components/opal/opal-call-manager.h
+++ b/lib/engine/components/opal/opal-call-manager.h
@@ -133,13 +133,6 @@ protected:
private:
- /* We use a callback instead of directly connecting the signal
- * to the add_call method of the CallCore to prevent boost to
- * keep a reference to the CallCore until the ECallManager is
- * destroyed, which would be a crossed reference.
- */
- void on_created_call (Opal::Call *call);
-
Ekiga::SettingsPtr nat_settings;
Ekiga::SettingsPtr audio_codecs_settings;
Ekiga::SettingsPtr video_codecs_settings;
diff --git a/lib/engine/components/opal/opal-call.cpp b/lib/engine/components/opal/opal-call.cpp
index d23f8b7..0770bb2 100644
--- a/lib/engine/components/opal/opal-call.cpp
+++ b/lib/engine/components/opal/opal-call.cpp
@@ -101,6 +101,7 @@ Opal::Call::Call (Opal::EndPoint& _manager,
call_setup(false), outgoing(false)
{
NoAnswerTimer.SetNotifier (PCREATE_NOTIFIER (OnNoAnswerTimeout));
+ NoAnswerTimer.SetInterval (0, 5);
add_action (Ekiga::ActionPtr (new Ekiga::Action ("hangup", _("Hangup"),
boost::bind (&Call::hang_up, this))));
@@ -112,9 +113,9 @@ Opal::Call::Call (Opal::EndPoint& _manager,
}
}
+
Opal::Call::~Call ()
{
- Ekiga::Runtime::run_in_main (boost::ref (removed));
}
@@ -628,6 +629,8 @@ Opal::Call::OnCleared ()
Ekiga::Runtime::run_in_main (boost::bind (boost::ref (cleared), reason));
else
Ekiga::Runtime::run_in_main (boost::ref (missed));
+
+ Ekiga::Runtime::run_in_main (boost::ref (removed));
}
diff --git a/lib/engine/components/opal/process/opal-endpoint.cpp
b/lib/engine/components/opal/process/opal-endpoint.cpp
index 9b6f047..88b38b8 100644
--- a/lib/engine/components/opal/process/opal-endpoint.cpp
+++ b/lib/engine/components/opal/process/opal-endpoint.cpp
@@ -106,10 +106,8 @@ private:
/* The class */
-Opal::EndPoint::EndPoint (Ekiga::ServiceCore& core)
+Opal::EndPoint::EndPoint (Ekiga::ServiceCore& _core) : core(_core)
{
- call_core = core.get<Ekiga::CallCore> ("call-core");
-
stun_thread = 0;
/* Initialise the endpoint parameters */
@@ -369,7 +367,6 @@ bool Opal::EndPoint::get_unconditional_forward ()
void Opal::EndPoint::set_stun_server (const std::string & server)
{
- std::cout << "Set STUN SERVER TO " << server << std::endl << std::flush;
if (server.empty ())
stun_server = "stun.ekiga.net";
@@ -557,13 +554,28 @@ OpalCall *Opal::EndPoint::CreateCall (void *uri)
else
call = new Opal::Call (*this, "");
- Ekiga::Runtime::run_in_main (boost::bind (boost::ref (created_call), call));
+ Ekiga::Runtime::run_in_main (boost::bind (&Opal::EndPoint::OnCreatedCall, this, call));
return call;
}
void
+Opal::EndPoint::DestroyCall (G_GNUC_UNUSED OpalCall *call)
+{
+}
+
+
+void
+Opal::EndPoint::OnCreatedCall (Opal::Call *_call)
+{
+ boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
+ boost::shared_ptr<Opal::Call> call(_call);
+ call_core->add_call (call);
+}
+
+
+void
Opal::EndPoint::HandleSTUNResult ()
{
gboolean error = false;
@@ -611,16 +623,11 @@ Opal::EndPoint::HandleSTUNResult ()
void
Opal::EndPoint::ReportSTUNError (const std::string error)
{
- boost::shared_ptr<Ekiga::CallCore> ccore = call_core.lock ();
- if (!ccore)
- return;
+ boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
// notice we're in for an infinite loop if nobody ever reports to the user!
- if ( !ccore->errors (error)) {
-
- Ekiga::Runtime::run_in_main (boost::bind (&Opal::EndPoint::ReportSTUNError, this, error),
- 10);
- }
+ if (!call_core->errors (error))
+ Ekiga::Runtime::run_in_main (boost::bind (&Opal::EndPoint::ReportSTUNError, this, error), 10);
}
diff --git a/lib/engine/components/opal/process/opal-endpoint.h
b/lib/engine/components/opal/process/opal-endpoint.h
index 900e225..b7a4ee9 100644
--- a/lib/engine/components/opal/process/opal-endpoint.h
+++ b/lib/engine/components/opal/process/opal-endpoint.h
@@ -83,7 +83,7 @@ namespace Opal {
public:
- EndPoint (Ekiga::ServiceCore & _core);
+ EndPoint (Ekiga::ServiceCore& _core);
~EndPoint ();
@@ -147,10 +147,12 @@ public:
boost::signals2::signal<void(void)> ready;
private:
- boost::weak_ptr<Ekiga::CallCore> call_core;
-
OpalCall *CreateCall (void *uri);
+ void DestroyCall (OpalCall * call);
+
+ void OnCreatedCall (Call *call);
+
void HandleSTUNResult ();
void ReportSTUNError (const std::string error);
@@ -179,6 +181,7 @@ private:
#ifdef HAVE_H323
H323::EndPoint *h323_endpoint;
#endif
+ Ekiga::ServiceCore& core;
};
};
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]