[ekiga] Opal: Sanitized Services and shared_ptr usage.



commit e02c058850aff79e4fff2133a07f2c2e62c02429
Author: Damien Sandras <dsandras seconix com>
Date:   Sat Jan 17 16:34:16 2015 +0100

    Opal: Sanitized Services and shared_ptr usage.
    
    This is the first step towards complete cleaning of the OPAL
    implementation regarding Services and shared_ptr.
    
    The H.323 and SIP EndPoints are not services anymore. There is no point
    in having them added to the Services core.
    
    Their respective objects are now passed as references to the Opal Bank
    and Accounts which are using them instead of using share_ptr's. This
    prevents having cyclic references, most notably when objects should be
    destroyed. Accounts should be destroyed before Banks, which should in
    turn be destroyed before the EndPoints. shared_ptr's are useless in this
    can as we control the objects lifetime.

 lib/engine/components/opal/h323-endpoint.h       |    9 ---------
 lib/engine/components/opal/opal-account.cpp      |   18 +++++++++---------
 lib/engine/components/opal/opal-account.h        |    8 ++++----
 lib/engine/components/opal/opal-bank.cpp         |   12 +++++++-----
 lib/engine/components/opal/opal-bank.h           |    8 +++++---
 lib/engine/components/opal/opal-call-manager.cpp |    1 +
 lib/engine/components/opal/opal-main.cpp         |    8 ++------
 lib/engine/components/opal/sip-endpoint.h        |    8 --------
 8 files changed, 28 insertions(+), 44 deletions(-)
---
diff --git a/lib/engine/components/opal/h323-endpoint.h b/lib/engine/components/opal/h323-endpoint.h
index df14e25..ebf65e1 100644
--- a/lib/engine/components/opal/h323-endpoint.h
+++ b/lib/engine/components/opal/h323-endpoint.h
@@ -56,7 +56,6 @@ namespace Opal {
   namespace H323 {
 
     class EndPoint : public H323EndPoint,
-                    public Ekiga::Service,
                     public Ekiga::CallProtocolManager
     {
       PCLASSINFO(EndPoint, H323EndPoint);
@@ -67,14 +66,6 @@ namespace Opal {
 
       ~EndPoint ();
 
-      /* Service */
-      const std::string get_name () const
-      { return "opal-h323-endpoint"; }
-
-      const std::string get_description () const
-      { return "\tObject managing H.323 objects with the Opal library"; }
-
-
       /* CallProtocolManager */
       bool dial (const std::string & uri);
       bool transfer (const std::string & uri,
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index d2558ad..9fcfa36 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -143,8 +143,8 @@ Opal::Account::build_node(Opal::Account::Type typus,
 
 
 Opal::Account::Account (Opal::Bank & _bank,
-                        boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
-                        boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint,
+                        Opal::Sip::EndPoint& _sip_endpoint,
+                        Opal::H323::EndPoint& _h323_endpoint,
                        boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
                        boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
                        boost::shared_ptr<Ekiga::PersonalDetails> _personal_details,
@@ -493,14 +493,14 @@ Opal::Account::enable ()
   /* Actual registration code */
   switch (type) {
   case Account::H323:
-    h323_endpoint->enable_account (*this);
+    h323_endpoint.enable_account (*this);
     break;
   case Account::SIP:
   case Account::DiamondCard:
   case Account::Ekiga:
   default:
     // Register the given aor to the given registrar
-    sip_endpoint->enable_account (*this);
+    sip_endpoint.enable_account (*this);
     break;
   }
   updated ();
@@ -519,7 +519,7 @@ Opal::Account::disable ()
   /* Actual unregistration code */
   switch (type) {
   case Account::H323:
-    h323_endpoint->disable_account (*this);
+    h323_endpoint.disable_account (*this);
     break;
   case Account::SIP:
   case Account::DiamondCard:
@@ -536,13 +536,13 @@ Opal::Account::disable ()
       }
 
       if (type != Account::H323) {
-        sip_endpoint->Unsubscribe (SIPSubscribe::MessageSummary, get_transaction_aor (get_aor ()));
+        sip_endpoint.Unsubscribe (SIPSubscribe::MessageSummary, get_transaction_aor (get_aor ()));
       }
 
       presentity->Close ();
     }
     // Register the given aor to the given registrar
-    sip_endpoint->disable_account (*this);
+    sip_endpoint.disable_account (*this);
     break;
   }
 
@@ -941,7 +941,7 @@ Opal::Account::handle_registration_event (Ekiga::Account::RegistrationState stat
 
         presentity->SetLocalPresence (personal_state, presence_status);
         if (type != Account::H323) {
-          sip_endpoint->Subscribe (SIPSubscribe::MessageSummary, 3600, get_transaction_aor (get_aor ()));
+          sip_endpoint.Subscribe (SIPSubscribe::MessageSummary, 3600, get_transaction_aor (get_aor ()));
         }
       }
       boost::shared_ptr<Ekiga::PersonalDetails> details = personal_details.lock ();
@@ -1337,7 +1337,7 @@ Opal::Account::decide_type ()
 const std::string
 Opal::Account::get_transaction_aor (const std::string & aor) const
 {
-  if (sip_endpoint->IsRegistered (get_aor () + ";transport=tcp"))
+  if (sip_endpoint.IsRegistered (get_aor () + ";transport=tcp"))
     return aor + ";transport=tcp";
   else
     return aor;
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index d71fec7..9d4b1d4 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -87,8 +87,8 @@ public:
                                  unsigned timeout);
 
     Account (Opal::Bank & bank,
-             boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
-             boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint,
+             Opal::Sip::EndPoint& _sip_endpoint,
+             Opal::H323::EndPoint& _h323_endpoint,
             boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
             boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
             boost::shared_ptr<Ekiga::PersonalDetails> _personal_details,
@@ -246,8 +246,8 @@ private:
 
     Opal::Bank & bank;
 
-    boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint;
-    boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint;
+    Opal::Sip::EndPoint& sip_endpoint;
+    Opal::H323::EndPoint& h323_endpoint;
     boost::weak_ptr<Ekiga::PresenceCore> presence_core;
     boost::weak_ptr<Ekiga::NotificationCore> notification_core;
     boost::weak_ptr<Ekiga::PersonalDetails> personal_details;
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 09cddad..171a3ad 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -51,10 +51,12 @@
 #include "h323-endpoint.h"
 
 
-Opal::Bank::Bank (Ekiga::ServiceCore& core):
+Opal::Bank::Bank (Ekiga::ServiceCore& core,
+                  Opal::Sip::EndPoint& _sip_endpoint,
+                  Opal::H323::EndPoint& _h323_endpoint):
   is_call_manager_ready(false),
-  sip_endpoint(core.get<Opal::Sip::EndPoint> ("opal-sip-endpoint")),
-  h323_endpoint(core.get<Opal::H323::EndPoint> ("opal-h323-endpoint")),
+  sip_endpoint(_sip_endpoint),
+  h323_endpoint(_h323_endpoint),
   presence_core(core.get<Ekiga::PresenceCore> ("presence-core")),
   notification_core(core.get<Ekiga::NotificationCore> ("notification-core")),
   personal_details(core.get<Ekiga::PersonalDetails> ("personal-details")),
@@ -116,7 +118,7 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
     }
   }
 
-  sip_endpoint->mwi_event.connect (boost::bind(&Opal::Bank::on_mwi_event, this, _1, _2));
+  sip_endpoint.mwi_event.connect (boost::bind(&Opal::Bank::on_mwi_event, this, _1, _2));
 
   account_added.connect (boost::bind (&Opal::Bank::update_sip_endpoint_aor_map, this));
   account_updated.connect (boost::bind (&Opal::Bank::update_sip_endpoint_aor_map, this));
@@ -375,7 +377,7 @@ Opal::Bank::update_sip_endpoint_aor_map ()
        ++iter)
     result[(*iter)->get_host ()] = (*iter)->get_aor ();
 
-  sip_endpoint->update_aor_map (result);
+  sip_endpoint.update_aor_map (result);
 }
 
 
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index e651c69..89869be 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -62,7 +62,9 @@ namespace Opal
     friend class Account;
 public:
 
-    Bank (Ekiga::ServiceCore &_core);
+    Bank (Ekiga::ServiceCore& _core,
+          Opal::Sip::EndPoint& _sip_endpoint,
+          Opal::H323::EndPoint& _h323_endpoint);
 
     ~Bank ();
 
@@ -115,8 +117,8 @@ public:
 private:
     bool is_call_manager_ready;
 
-    boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint;
-    boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint;
+    Sip::EndPoint& sip_endpoint;
+    H323::EndPoint& h323_endpoint;
     boost::weak_ptr<Ekiga::PresenceCore> presence_core;
     boost::shared_ptr<Ekiga::NotificationCore> notification_core;
     boost::shared_ptr<Ekiga::PersonalDetails> personal_details;
diff --git a/lib/engine/components/opal/opal-call-manager.cpp 
b/lib/engine/components/opal/opal-call-manager.cpp
index 6c9180d..0395772 100644
--- a/lib/engine/components/opal/opal-call-manager.cpp
+++ b/lib/engine/components/opal/opal-call-manager.cpp
@@ -215,6 +215,7 @@ CallManager::CallManager (Ekiga::ServiceCore& core)
 
 CallManager::~CallManager ()
 {
+  std::cout << "CallManager exit " << std::endl << std::flush;
   if (stun_thread)
     stun_thread->WaitForTermination ();
   ClearAllCalls (OpalConnection::EndedByLocalUser, true);
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index a661046..86a4f1c 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -102,12 +102,11 @@ struct OPALSpark: public Ekiga::Spark
     boost::shared_ptr<Ekiga::VideoOutputCore> videooutput_core = core.get<Ekiga::VideoOutputCore> 
("videooutput-core");
     boost::shared_ptr<Ekiga::PersonalDetails> personal_details = core.get<Ekiga::PersonalDetails> 
("personal-details");
     boost::shared_ptr<Bank> account_store = core.get<Bank> ("opal-account-store");
-    Ekiga::ServicePtr sip_endpoint = core.get ("opal-sip-endpoint");
 
     if (contact_core && presence_core && call_core && chat_core
        && account_core && audioinput_core && videoinput_core
        && audiooutput_core && videooutput_core && personal_details
-       && !account_store && !sip_endpoint) {
+       && !account_store) {
 
       PIPSocket::SetSuppressCanonicalName (true);  // avoid long delays
 
@@ -119,17 +118,14 @@ struct OPALSpark: public Ekiga::Spark
       boost::shared_ptr<Sip::EndPoint> sip_manager (new Sip::EndPoint (*call_manager, core), null_deleter 
());
       sip_manager->setup ();
       call_manager->set_sip_endpoint (sip_manager);
-      core.add (sip_manager);
 
 #ifdef HAVE_H323
       boost::shared_ptr<H323::EndPoint> h323_manager (new H323::EndPoint (*call_manager, core), null_deleter 
());
       h323_manager->setup ();
       call_manager->set_h323_endpoint (h323_manager);
-      core.add (h323_manager);
 #endif
 
-
-      boost::shared_ptr<Bank> bank (new Bank (core));
+      boost::shared_ptr<Bank> bank (new Bank (core, *sip_manager.get (), *h323_manager.get ()));
       account_core->add_bank (bank);
       presence_core->add_cluster (bank);
       core.add (bank);
diff --git a/lib/engine/components/opal/sip-endpoint.h b/lib/engine/components/opal/sip-endpoint.h
index 28f4b42..77e9fc4 100644
--- a/lib/engine/components/opal/sip-endpoint.h
+++ b/lib/engine/components/opal/sip-endpoint.h
@@ -58,7 +58,6 @@ namespace Opal {
   namespace Sip {
 
     class EndPoint : public SIPEndPoint,
-                    public Ekiga::Service,
                     public Ekiga::CallProtocolManager
     {
       PCLASSINFO(EndPoint, SIPEndPoint);
@@ -76,13 +75,6 @@ namespace Opal {
       /* Set up endpoint: all options or a specific setting */
       void setup (std::string setting = "");
 
-      /* Service */
-      const std::string get_name () const
-      { return "opal-sip-endpoint"; }
-
-      const std::string get_description () const
-      { return "\tObject managing SIP objects with the Opal library"; }
-
 
       /* Chat subsystem */
       bool send_message (const std::string & uri,


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