[ekiga] Opal: Reorganized more code.



commit bf9e74c78aae13f0f34ff6efc5621bb20ffac3f5
Author: Damien Sandras <dsandras seconix com>
Date:   Sat Jan 17 18:42:11 2015 +0100

    Opal: Reorganized more code.
    
    The SIP & H323 Opal EndPoints/CallProtocolManagers creation has been
    moved from opal-main.cpp to the OpalCallManager, where it belongs.
    
    The Opal Bank & Accounts now only rely on the OpalCallManager and not on
    individual CallProtocolManagers. The Opal Account object now directly
    accesses the Opal Endpoints to register/unregister accounts. This code
    can actually be self-contained into the Opal objects and not rely on
    engine objects. That allows simplifying object lifecycles.
    
    Endpoints are now "setup" when the CallManager signals it is ready. That
    means we do not need direct references to the SIP & H.323 endpoints into
    the CallManager like it was the case.

 lib/engine/components/opal/h323-endpoint.cpp     |    2 +
 lib/engine/components/opal/opal-account.cpp      |   29 ++++++++-------
 lib/engine/components/opal/opal-account.h        |    7 ++--
 lib/engine/components/opal/opal-bank.cpp         |   16 +++-----
 lib/engine/components/opal/opal-bank.h           |    6 +---
 lib/engine/components/opal/opal-call-manager.cpp |   42 ++++++++--------------
 lib/engine/components/opal/opal-call-manager.h   |   10 -----
 lib/engine/components/opal/opal-main.cpp         |   12 +------
 lib/engine/components/opal/sip-endpoint.cpp      |    2 +
 9 files changed, 46 insertions(+), 80 deletions(-)
---
diff --git a/lib/engine/components/opal/h323-endpoint.cpp b/lib/engine/components/opal/h323-endpoint.cpp
index 35e8c53..6b41a19 100644
--- a/lib/engine/components/opal/h323-endpoint.cpp
+++ b/lib/engine/components/opal/h323-endpoint.cpp
@@ -155,6 +155,8 @@ Opal::H323::EndPoint::EndPoint (Opal::CallManager & _manager,
 
   video_codecs_settings = boost::shared_ptr<Ekiga::Settings> (new Ekiga::Settings (VIDEO_CODECS_SCHEMA));
   video_codecs_settings->changed.connect (boost::bind (&EndPoint::setup, this, _1));
+
+  manager.ready.connect (boost::bind (&EndPoint::setup, this, ""));
 }
 
 Opal::H323::EndPoint::~EndPoint ()
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 778011f..90c8b44 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -143,8 +143,6 @@ Opal::Account::build_node(Opal::Account::Type typus,
 
 
 Opal::Account::Account (Opal::Bank & _bank,
-                        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,
@@ -155,8 +153,6 @@ Opal::Account::Account (Opal::Bank & _bank,
   existing_groups(_existing_groups),
   node(_node),
   bank(_bank),
-  sip_endpoint(_sip_endpoint),
-  h323_endpoint(_h323_endpoint),
   presence_core(_presence_core),
   notification_core(_notification_core),
   personal_details(_personal_details),
@@ -236,6 +232,10 @@ Opal::Account::Account (Opal::Bank & _bank,
 
     bank.disable_action ("add-account-ekiga");
   }
+
+  /* We will directly use the OPAL SIP and H.323 EndPoints */
+  sip_endpoint = (Opal::Sip::EndPoint*) call_manager.FindEndPoint ("sip");
+  h323_endpoint = (Opal::H323::EndPoint*) call_manager.FindEndPoint ("h323");
 }
 
 
@@ -493,14 +493,16 @@ Opal::Account::enable ()
   /* Actual registration code */
   switch (type) {
   case Account::H323:
-    h323_endpoint.enable_account (*this);
+    if (h323_endpoint)
+      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);
+    if (sip_endpoint)
+      sip_endpoint->enable_account (*this);
     break;
   }
   updated ();
@@ -519,7 +521,8 @@ Opal::Account::disable ()
   /* Actual unregistration code */
   switch (type) {
   case Account::H323:
-    h323_endpoint.disable_account (*this);
+    if (h323_endpoint)
+      h323_endpoint->disable_account (*this);
     break;
   case Account::SIP:
   case Account::DiamondCard:
@@ -535,14 +538,14 @@ Opal::Account::disable ()
         (*iter)->set_status ("");
       }
 
-      if (type != Account::H323) {
-        sip_endpoint.Unsubscribe (SIPSubscribe::MessageSummary, get_transaction_aor (get_aor ()));
+      if (type != Account::H323 && sip_endpoint) {
+        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;
   }
 
@@ -940,8 +943,8 @@ Opal::Account::handle_registration_event (Ekiga::Account::RegistrationState stat
           fetch ((*iter)->get_uri());
 
         presentity->SetLocalPresence (personal_state, presence_status);
-        if (type != Account::H323) {
-          sip_endpoint.Subscribe (SIPSubscribe::MessageSummary, 3600, get_transaction_aor (get_aor ()));
+        if (type != Account::H323 && sip_endpoint) {
+          sip_endpoint->Subscribe (SIPSubscribe::MessageSummary, 3600, get_transaction_aor (get_aor ()));
         }
       }
       boost::shared_ptr<Ekiga::PersonalDetails> details = personal_details.lock ();
@@ -1337,7 +1340,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 && 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 f308384..d4d4c1f 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -87,8 +87,6 @@ public:
                                  unsigned timeout);
 
     Account (Opal::Bank & bank,
-             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,
@@ -229,6 +227,7 @@ private:
     std::string protocol_name;
 
     bool failed_registration_already_notified;
+
     PSafePtr<OpalPresentity> presentity;
 
     PDECLARE_PresenceChangeNotifier (Account, OnPresenceChange);
@@ -246,8 +245,8 @@ private:
 
     Opal::Bank & bank;
 
-    Opal::Sip::EndPoint& sip_endpoint;
-    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;
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 02a69fc..2ed9af0 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -52,12 +52,8 @@
 
 
 Opal::Bank::Bank (Ekiga::ServiceCore& core,
-                  Opal::CallManager& _call_manager,
-                  Opal::Sip::EndPoint& _sip_endpoint,
-                  Opal::H323::EndPoint& _h323_endpoint):
+                  Opal::CallManager& _call_manager):
   is_call_manager_ready(false),
-  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")),
@@ -91,8 +87,6 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core,
         && xmlStrEqual(BAD_CAST "account", child->name)) {
 
       boost::shared_ptr<Account> account(new Account (*this,
-                                                      sip_endpoint,
-                                                      h323_endpoint,
                                                       presence_core,
                                                       notification_core,
                                                       personal_details,
@@ -119,7 +113,8 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core,
     }
   }
 
-  sip_endpoint.mwi_event.connect (boost::bind(&Opal::Bank::on_mwi_event, this, _1, _2));
+  std::cout << "FIXME" << std::endl << std::flush;
+  //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));
@@ -266,8 +261,6 @@ Opal::Bank::add (Account::Type acc_type,
 
   AccountPtr account
     = AccountPtr(new Opal::Account (*this,
-                                    sip_endpoint,
-                                    h323_endpoint,
                                    presence_core,
                                    notification_core,
                                    personal_details,
@@ -371,6 +364,7 @@ Opal::Bank::on_mwi_event (std::string aor,
 void
 Opal::Bank::update_sip_endpoint_aor_map ()
 {
+  /*
   std::map<std::string, std::string> result;
 
   for (iterator iter = begin ();
@@ -379,6 +373,8 @@ Opal::Bank::update_sip_endpoint_aor_map ()
     result[(*iter)->get_host ()] = (*iter)->get_aor ();
 
   sip_endpoint.update_aor_map (result);
+  */
+  std::cout << "FIXME" << std::endl << std::flush;
 }
 
 
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index c3088f8..9130163 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -63,9 +63,7 @@ namespace Opal
 public:
 
     Bank (Ekiga::ServiceCore& _core,
-          Opal::CallManager& _call_manager,
-          Opal::Sip::EndPoint& _sip_endpoint,
-          Opal::H323::EndPoint& _h323_endpoint);
+          Opal::CallManager& _call_manager);
 
     ~Bank ();
 
@@ -119,8 +117,6 @@ private:
     bool is_call_manager_ready;
 
     CallManager& call_manager;
-    Sip::EndPoint& sip_endpoint;
-    H323::EndPoint& h323_endpoint;
 
     boost::weak_ptr<Ekiga::PresenceCore> presence_core;
     boost::shared_ptr<Ekiga::NotificationCore> notification_core;
diff --git a/lib/engine/components/opal/opal-call-manager.cpp 
b/lib/engine/components/opal/opal-call-manager.cpp
index 0395772..6275dfb 100644
--- a/lib/engine/components/opal/opal-call-manager.cpp
+++ b/lib/engine/components/opal/opal-call-manager.cpp
@@ -153,11 +153,6 @@ CallManager::CallManager (Ekiga::ServiceCore& core)
   video.deviceName = "EKIGA";
   SetVideoInputDevice (video);
 
-  // Create endpoints
-  pcssEP = new GMPCSSEndpoint (*this, core);
-  pcssEP->SetSoundChannelPlayDevice("EKIGA");
-  pcssEP->SetSoundChannelRecordDevice("EKIGA");
-
   // Media formats
   SetMediaFormatOrder (PStringArray ());
   SetMediaFormatMask (PStringArray ());
@@ -210,6 +205,21 @@ CallManager::CallManager (Ekiga::ServiceCore& core)
 
   boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get< Ekiga::PresenceCore > ("presence-core");
   presence_core->push_back (Ekiga::URIActionProviderPtr (this));
+
+  // Create endpoints / CallProtocolManagers
+  pcssEP = new GMPCSSEndpoint (*this, core);
+  pcssEP->SetSoundChannelPlayDevice("EKIGA");
+  pcssEP->SetSoundChannelRecordDevice("EKIGA");
+
+  boost::shared_ptr<Sip::EndPoint> sip_endpoint (new Sip::EndPoint (*this, core),
+                                                 null_deleter ());
+  add_protocol_manager (sip_endpoint);
+
+#ifdef HAVE_H323
+  boost::shared_ptr<H323::EndPoint> h323_endpoint (new H323::EndPoint (*this, core),
+                                                   null_deleter ());
+  add_protocol_manager (h323_endpoint);
+#endif
 }
 
 
@@ -834,11 +844,6 @@ CallManager::HandleSTUNResult ()
     }
     else {
 
-      if (sip_endpoint)
-        sip_endpoint->setup ("listen-port");
-      if (h323_endpoint)
-        h323_endpoint->setup ("listen-port");
-
       ready ();
     }
   }
@@ -910,23 +915,6 @@ CallManager::CreateVideoOutputDevice(const OpalConnection & connection,
 
 
 void
-CallManager::set_sip_endpoint (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint)
-{
-  sip_endpoint = _sip_endpoint;
-  add_protocol_manager (sip_endpoint);
-}
-
-
-#ifdef HAVE_H323
-void
-CallManager::set_h323_endpoint (boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint)
-{
-  h323_endpoint = _h323_endpoint;
-  add_protocol_manager (h323_endpoint);
-}
-#endif
-
-void
 CallManager::setup (const std::string & setting)
 {
   if (setting.empty () || setting == "stun-server") {
diff --git a/lib/engine/components/opal/opal-call-manager.h b/lib/engine/components/opal/opal-call-manager.h
index ed18e37..cacc2f9 100644
--- a/lib/engine/components/opal/opal-call-manager.h
+++ b/lib/engine/components/opal/opal-call-manager.h
@@ -229,16 +229,6 @@ private:
     boost::shared_ptr<Ekiga::Settings> call_options_settings;
     boost::shared_ptr<Ekiga::Settings> call_forwarding_settings;
     boost::shared_ptr<Ekiga::Settings> personal_data_settings;
-
-    /* FIXME: this piece of the api is because the code is getting turned around,
-     * this should disappear at some point! */
-  public:
-    void set_sip_endpoint (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint);
-    boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint;
-#ifdef HAVE_H323
-    void set_h323_endpoint (boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint);
-    boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint;
-#endif
   };
 };
 #endif
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index 092da65..9ab228d 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -114,17 +114,7 @@ struct OPALSpark: public Ekiga::Spark
 
       boost::shared_ptr<CallManager> call_manager (new CallManager (core));
 
-      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);
-
-#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);
-#endif
-
-      boost::shared_ptr<Bank> bank (new Bank (core, *call_manager.get (), *sip_manager.get (), 
*h323_manager.get ()));
+      boost::shared_ptr<Bank> bank (new Bank (core, *call_manager.get ()));
       account_core->add_bank (bank);
       presence_core->add_cluster (bank);
       core.add (bank);
diff --git a/lib/engine/components/opal/sip-endpoint.cpp b/lib/engine/components/opal/sip-endpoint.cpp
index 672a262..7e50266 100644
--- a/lib/engine/components/opal/sip-endpoint.cpp
+++ b/lib/engine/components/opal/sip-endpoint.cpp
@@ -80,6 +80,8 @@ Opal::Sip::EndPoint::EndPoint (Opal::CallManager & _manager,
 
   settings = boost::shared_ptr<Ekiga::Settings> (new Ekiga::Settings (SIP_SCHEMA));
   settings->changed.connect (boost::bind (&EndPoint::setup, this, _1));
+
+  manager.ready.connect (boost::bind (&EndPoint::setup, this, ""));
 }
 
 


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