[ekiga] Made the opal bank push information to the SIP endpoint instead of having the SIP endpoint fetch it



commit 29d2d89a5d0244432647e3417f03068ce757a71c
Author: Julien Puydt <jpuydt free fr>
Date:   Fri Feb 8 15:01:20 2013 +0100

    Made the opal bank push information to the SIP endpoint instead of having the SIP endpoint fetch it himself
    
    Now there is not even a weak reference pointing up from the endpoint to the bank (and hence the accounts),
    so I'll be able to simplify the account code a little.

 lib/engine/components/opal/opal-bank.cpp    |   18 +++++++++++
 lib/engine/components/opal/opal-bank.h      |    2 +
 lib/engine/components/opal/opal-main.cpp    |    1 -
 lib/engine/components/opal/sip-endpoint.cpp |   42 +-------------------------
 lib/engine/components/opal/sip-endpoint.h   |   10 +-----
 5 files changed, 24 insertions(+), 49 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 7596c44..e911e11 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -97,6 +97,11 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
 
   sip_endpoint->registration_event.connect (boost::bind(&Opal::Bank::on_registration_event, this, _1, _2, _3));
   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));
+  account_removed.connect (boost::bind (&Opal::Bank::update_sip_endpoint_aor_map, this));
+  update_sip_endpoint_aor_map ();
 }
 
 Opal::Bank::~Bank ()
@@ -388,3 +393,16 @@ Opal::Bank::on_mwi_event (std::string aor,
   if (account)
     account->handle_message_waiting_information (info);
 }
+
+void
+Opal::Bank::update_sip_endpoint_aor_map ()
+{
+  std::map<std::string, std::string> result;
+
+  for (iterator iter = begin ();
+       iter != end ();
+       ++iter)
+    result[(*iter)->get_host ()] = (*iter)->get_aor ();
+
+  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 4678040..41810ed 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -144,6 +144,8 @@ private:
     void on_mwi_event (std::string aor,
 		       std::string info);
 
+    void update_sip_endpoint_aor_map ();
+
   };
 
   /**
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index 5339e15..a12853f 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -131,7 +131,6 @@ struct OPALSpark: public Ekiga::Spark
       core.add (bank);
       contact_core->add_contact_decorator (bank);
       presence_core->add_presentity_decorator (bank);
-      sip_manager->update_bank (bank);
       call_manager->ready.connect (boost::bind (&Opal::Bank::call_manager_ready, &*bank));
       presence_core->add_presence_publisher (bank);
       presence_core->add_presence_fetcher (bank);
diff --git a/lib/engine/components/opal/sip-endpoint.cpp b/lib/engine/components/opal/sip-endpoint.cpp
index faab326..24a23d5 100644
--- a/lib/engine/components/opal/sip-endpoint.cpp
+++ b/lib/engine/components/opal/sip-endpoint.cpp
@@ -903,46 +903,8 @@ Opal::Sip::EndPoint::push_notice_in_main (const std::string uri,
 }
 
 void
-Opal::Sip::EndPoint::update_bank (boost::shared_ptr<Opal::Bank> _bank)
+Opal::Sip::EndPoint::update_aor_map (std::map<std::string, std::string> _accounts)
 {
-  bank = _bank;
-  _bank->account_added.connect (boost::bind (&Opal::Sip::EndPoint::account_added, this, _1));
-  _bank->account_updated.connect (boost::bind (&Opal::Sip::EndPoint::account_updated_or_removed, this, _1));
-  _bank->account_removed.connect (boost::bind (&Opal::Sip::EndPoint::account_updated_or_removed, this, _1));
-  account_updated_or_removed (Ekiga::AccountPtr ()/* unused*/);
-}
-
-void
-Opal::Sip::EndPoint::account_updated_or_removed (Ekiga::AccountPtr /*account*/)
-{
-  /* we don't remember what the account information was, so we need
-   * to clear our current information everytime something changed
-   * (hopefully nobody has hundreds of opal accounts that get updated
-   * often, so performance shouldn't be an issue!
-   */
-
-  { // keep the mutex only to clear the accounts variable...
-    PWaitAndSignal m(aorMutex);
-    accounts.clear ();
-  }
-  { // ... because here we call something which will want that very same mutex!
-    boost::shared_ptr<Opal::Bank> bk = bank.lock ();
-  if (bk)
-    bk->visit_accounts (boost::bind (&Opal::Sip::EndPoint::visit_account, this, _1));
-  }
-}
-
-bool
-Opal::Sip::EndPoint::visit_account (Ekiga::AccountPtr _account)
-{
-  account_added (_account);
-  return true;
-}
-
-void
-Opal::Sip::EndPoint::account_added (Ekiga::AccountPtr _account)
-{
-  Opal::AccountPtr account = boost::dynamic_pointer_cast<Opal::Account> (_account);
   PWaitAndSignal m(aorMutex);
-  accounts[account->get_host ()] = account->get_aor ();
+  accounts = _accounts;
 }
diff --git a/lib/engine/components/opal/sip-endpoint.h b/lib/engine/components/opal/sip-endpoint.h
index 347c0d0..d4d6553 100644
--- a/lib/engine/components/opal/sip-endpoint.h
+++ b/lib/engine/components/opal/sip-endpoint.h
@@ -127,11 +127,10 @@ namespace Opal {
       bool unsubscribe (const Opal::Account & account, const PSafePtr<OpalPresentity> & presentity);
 
 
-      /* Helper */
+      /* Helpers */
       static std::string get_aor_domain (const std::string & aor);
 
-      /* FIXME: doesn't look 100% right */
-      void update_bank (boost::shared_ptr<Opal::Bank> _bank);
+      void update_aor_map (std::map<std::string, std::string> _accounts);
 
       /* OPAL Methods */
       void Register (const std::string username,
@@ -171,10 +170,6 @@ namespace Opal {
 		       std::string name);
       void on_transfer (std::string uri);
 
-      void account_updated_or_removed (Ekiga::AccountPtr account);
-      bool visit_account (Ekiga::AccountPtr account);
-      void account_added (Ekiga::AccountPtr account);
-
       void push_message_in_main (const std::string uri,
 				 const std::string name,
 				 const std::string msg);
@@ -201,7 +196,6 @@ namespace Opal {
 
       unsigned listen_port;
 
-      boost::weak_ptr<Opal::Bank> bank;
       boost::shared_ptr<SIP::Dialect> dialect;
     };
   };


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