[ekiga] Presence: API reorganisation.



commit 95d84f932e5aba21af6e06a948b263c075bbd92d
Author: Damien Sandras <dsandras seconix com>
Date:   Mon Jan 19 22:05:09 2015 +0100

    Presence: API reorganisation.
    
    Presentities are handled by Opal Accounts due to another reorganisation
    decided a few months ago. That means that Accounts are responsible to
    fetch/unfetch presence for each of their presentities. Consequently, the
    following changes were introduced:
    - is_supported_uri is now implemented by the PresenceFetchers (ie Opal
      Accounts in this case). The PresenceCore is_suppported_uri
      implementation now relies on the PresenceFetchers instead of
      maintaining its own list of uri_testers (which was error-prone).
    - the Opal Bank is not a PresenceFetcher anymore. If we want global
      presence fetching, we should use the PresenceCore to stay consistent
      with the rest of the code.
    - the Opal Account PresenceFetcher is adding itself to the PresenceCore
      presence fetchers instead of relying on opal-main.cpp to do that work
      manually. Our code is more self-contained.

 lib/engine/components/opal/opal-account.cpp |   51 +++++++++++----------------
 lib/engine/components/opal/opal-account.h   |   15 +++-----
 lib/engine/components/opal/opal-bank.cpp    |   16 ++++++--
 lib/engine/components/opal/opal-bank.h      |    9 -----
 lib/engine/components/opal/opal-main.cpp    |   17 ---------
 lib/engine/presence/presence-core.cpp       |   38 +++++++++----------
 lib/engine/presence/presence-core.h         |   37 ++++++++++---------
 plugins/avahi/avahi-heap.h                  |    1 +
 8 files changed, 76 insertions(+), 108 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 90c8b44..9eca306 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -769,10 +769,6 @@ Opal::Account::on_edit_form_submitted (bool submitted,
 void
 Opal::Account::add_contact ()
 {
-  boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
-  if (!pcore)
-    return;
-
   boost::shared_ptr<Ekiga::FormRequestSimple> request =
     boost::shared_ptr<Ekiga::FormRequestSimple> (new Ekiga::FormRequestSimple (boost::bind 
(&Opal::Account::on_add_contact_form_submitted, this, _1, _2, _3)));
   std::list<std::string> groups = existing_groups ();
@@ -799,10 +795,6 @@ Opal::Account::on_add_contact_form_submitted (bool submitted,
   if (!submitted)
     return false;
 
-  boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
-  if (!pcore)
-    return false;
-
   const std::string name = result.text ("name");
   std::string uri;
   const std::list<std::string> groups = result.editable_list ("groups");
@@ -810,7 +802,7 @@ Opal::Account::on_add_contact_form_submitted (bool submitted,
   uri = result.text ("uri");
   uri = canonize_uri (uri);
 
-  if (pcore->is_supported_uri (uri)) {
+  if (is_supported_uri (uri)) {
 
     xmlNodePtr presnode = Opal::Presentity::build_node (name, uri, groups);
     xmlAddChild (roster_node, presnode);
@@ -829,7 +821,7 @@ Opal::Account::on_add_contact_form_submitted (bool submitted,
   }
   else {
 
-    if (!pcore->is_supported_uri (uri))
+    if (is_supported_uri (uri))
       error = _("You supplied an unsupported address");
     else
       error = _("You already have a contact with this address!");
@@ -844,22 +836,6 @@ Opal::Account::on_consult (const std::string url)
   gm_platform_open_uri (url.c_str ());
 }
 
-
-bool
-Opal::Account::is_myself (const std::string uri) const
-{
-  size_t pos = uri.find ("@");
-  if (pos == string::npos)
-    return false;
-
-  std::string uri_host = uri.substr (++pos);
-  if (uri_host != get_host ())
-    return false;
-
-  return true;
-}
-
-
 void
 Opal::Account::publish (const Ekiga::PersonalDetails& details)
 {
@@ -879,10 +855,10 @@ Opal::Account::publish (const Ekiga::PersonalDetails& details)
 
 
 void
-Opal::Account::fetch (const std::string uri) const
+Opal::Account::fetch (const std::string uri)
 {
   // Check if this is a presentity we watch
-  if (!is_myself (uri))
+  if (!is_supported_uri (uri))
     return;
 
   // Account is disabled, bye
@@ -898,15 +874,30 @@ Opal::Account::fetch (const std::string uri) const
 
 
 void
-Opal::Account::unfetch (const std::string uri) const
+Opal::Account::unfetch (const std::string uri)
 {
-  if (is_myself (uri) && presentity) {
+  if (is_supported_uri (uri) && presentity) {
     presentity->UnsubscribeFromPresence (get_transaction_aor (uri).c_str ());
     Ekiga::Runtime::run_in_main (boost::bind (&Opal::Account::presence_status_in_main, this, uri, "unknown", 
""));
   }
 }
 
 
+bool
+Opal::Account::is_supported_uri (const std::string & uri)
+{
+  size_t pos = uri.find ("@");
+  if (pos == string::npos)
+    return false;
+
+  std::string uri_host = uri.substr (++pos);
+  if (uri_host != get_host ())
+    return false;
+
+  return true;
+}
+
+
 void
 Opal::Account::handle_registration_event (Ekiga::Account::RegistrationState state_,
                                          const std::string info)
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index d4d4c1f..ecbb01c 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -70,7 +70,8 @@ namespace Opal
     public Ekiga::Account,
     public Ekiga::Heap,
     protected Ekiga::RefLister<Presentity>,
-    public Ekiga::PresencePublisher
+    public Ekiga::PresencePublisher,
+    public Ekiga::PresenceFetcher
   {
     friend class Opal::Presentity;
 public:
@@ -184,18 +185,13 @@ public:
     /* This part of the api is the implementation of Ekiga::Heap */
     void visit_presentities (boost::function1<bool, Ekiga::PresentityPtr > visitor) const;
 
-    /* This object is not an Ekiga::PresenceFetcher, but Opal::Bank is,
-     * this is where the information comes from
-     */
-    boost::signals2::signal<void(std::string, std::string)> presence_received;
-    boost::signals2::signal<void(std::string, std::string)> status_received;
-
 protected:
     void on_rename_group (Opal::PresentityPtr pres);
 
 private:
-    void fetch (const std::string uri) const;
-    void unfetch (const std::string uri) const;
+    void fetch (const std::string uri);
+    void unfetch (const std::string uri);
+    bool is_supported_uri (const std::string & uri);
 
     void decide_type ();
 
@@ -210,7 +206,6 @@ private:
                                 Ekiga::Form &result,
                                  std::string& error);
     void on_consult (const std::string url);
-    bool is_myself (const std::string uri) const;
 
     bool on_rename_group_form_submitted (bool submitted,
                                          Ekiga::Form& result,
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 377ee80..6d9b53f 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -106,11 +106,13 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core,
       Ekiga::BankImpl<Account>::add_connection (account, account->Account::questions.connect 
(boost::ref(Ekiga::Bank::questions)));
 
       Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind 
(&Opal::Bank::save, this)));
-      Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref 
(presence_received)));
-      Ekiga::BankImpl<Account>::add_connection (account, account->status_received.connect (boost::ref 
(status_received)));
       Ekiga::BankImpl<Account>::add_connection (account, account->removed.connect (boost::bind 
(&Opal::Bank::on_account_removed, this, account)));
       add_account (account);
       heap_added (account);
+
+      boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+      if (pcore)
+        pcore->add_presence_fetcher (account);
     }
   }
 
@@ -271,12 +273,14 @@ Opal::Bank::add (Account::Type acc_type,
   Ekiga::BankImpl<Account>::add_connection (account, account->presentity_updated.connect (boost::bind 
(boost::ref(presentity_updated), account, _1)));
   Ekiga::BankImpl<Account>::add_connection (account, account->presentity_removed.connect (boost::bind 
(boost::ref(presentity_removed), account, _1)));
   Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind 
(&Opal::Bank::save, this)));
-  Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref 
(presence_received)));
-  Ekiga::BankImpl<Account>::add_connection (account, account->status_received.connect (boost::ref 
(status_received)));
   Ekiga::BankImpl<Account>::add_connection (account, account->removed.connect (boost::bind 
(&Opal::Bank::on_account_removed, this, account)));
   add_account (account);
   heap_added (account);
 
+  boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+  if (pcore)
+    pcore->add_presence_fetcher (account);
+
   if (is_ready && enabled)
     account->enable ();
 }
@@ -334,6 +338,10 @@ Opal::Bank::save () const
 void
 Opal::Bank::on_account_removed (boost::shared_ptr<Account> account)
 {
+  boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+  if (pcore)
+    pcore->remove_presence_fetcher (account);
+
   heap_removed (account);
   remove_account (account);
 }
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index 65258e5..e2a07f7 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -56,7 +56,6 @@ namespace Opal
       public Ekiga::BankImpl<Account>,
       public Ekiga::Cluster,
       public Ekiga::PresencePublisher,
-      public Ekiga::PresenceFetcher,
       public Ekiga::Service
   {
     friend class Account;
@@ -82,14 +81,6 @@ public:
                       std::string username = "",
                       std::string password = "");
 
-    /*
-     * this object is an Ekiga::PresenceFetcher
-     * (but it doesn't take orders : it just makes available to all of
-     * ekiga what it knows -- it is useful to have presence&status in chats)
-     */
-    void fetch (const std::string) {}
-    void unfetch (const std::string) {}
-
 
     /** Find the account with the given address of record in the Bank
      * @param aor is the address of record of the Account or the host to look
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index bf26695..4360fe3 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -62,24 +62,10 @@ struct null_deleter
     { }
 };
 
-static bool
-is_supported_address (const std::string uri)
-{
-#ifdef HAVE_H323
-  if (uri.find ("h323:") == 0)
-    return true;
-#endif
-
-  if (uri.find ("sip:") == 0)
-    return true;
-
-  return false;
-}
 
 /* FIXME: add here an Ekiga::Service which will add&remove publishers,
  * and fetchers
  */
-
 using namespace Opal;
 
 struct OPALSpark: public Ekiga::Spark
@@ -118,12 +104,9 @@ struct OPALSpark: public Ekiga::Spark
       core.add (bank);
       call_manager->setup ();
       presence_core->add_presence_publisher (bank);
-      presence_core->add_presence_fetcher (bank);
 
       call_core->add_manager (call_manager);
 
-      presence_core->add_supported_uri (&is_supported_address); //FIXME
-
       result = true;
     }
 
diff --git a/lib/engine/presence/presence-core.cpp b/lib/engine/presence/presence-core.cpp
index 4fee94e..fcc2aee 100644
--- a/lib/engine/presence/presence-core.cpp
+++ b/lib/engine/presence/presence-core.cpp
@@ -128,6 +128,12 @@ Ekiga::PresenceCore::add_presence_fetcher (boost::shared_ptr<PresenceFetcher> fe
 }
 
 void
+Ekiga::PresenceCore::remove_presence_fetcher (boost::shared_ptr<PresenceFetcher> fetcher)
+{
+  presence_fetchers.remove (fetcher);
+}
+
+void
 Ekiga::PresenceCore::fetch_presence (const std::string uri)
 {
   uri_infos[uri].count++;
@@ -161,6 +167,18 @@ void Ekiga::PresenceCore::unfetch_presence (const std::string uri)
   }
 }
 
+bool Ekiga::PresenceCore::is_supported_uri (const std::string & uri)
+{
+  for (std::list<boost::shared_ptr<PresenceFetcher> >::iterator iter
+       = presence_fetchers.begin ();
+       iter != presence_fetchers.end ();
+       ++iter)
+    if ((*iter)->is_supported_uri (uri))
+      return true;
+
+  return false;
+}
+
 void
 Ekiga::PresenceCore::on_presence_received (const std::string uri,
                                           const std::string presence)
@@ -192,23 +210,3 @@ Ekiga::PresenceCore::publish ()
        ++iter)
     (*iter)->publish (*details);
 }
-
-bool
-Ekiga::PresenceCore::is_supported_uri (const std::string uri) const
-{
-  bool result = false;
-
-  for (std::list<boost::function1<bool, std::string> >::const_iterator iter
-        = uri_testers.begin ();
-       iter != uri_testers.end () && result == false;
-       iter++)
-    result = (*iter) (uri);
-
-  return result;
-}
-
-void
-Ekiga::PresenceCore::add_supported_uri (boost::function1<bool,std::string> tester)
-{
-  uri_testers.push_back (tester);
-}
diff --git a/lib/engine/presence/presence-core.h b/lib/engine/presence/presence-core.h
index 0978766..a7d4935 100644
--- a/lib/engine/presence/presence-core.h
+++ b/lib/engine/presence/presence-core.h
@@ -70,6 +70,13 @@ namespace Ekiga
      */
     virtual void unfetch (const std::string /*uri*/) = 0;
 
+    /* Return true if URI can be handled by the PresenceFetcher,
+     * false otherwise.
+     * @param the URI to test
+     * @return true of the URI can be handled, false otherwise
+     */
+    virtual bool is_supported_uri (const std::string & /*uri*/) = 0;
+
     /** Those signals are emitted whenever this presence fetcher gets
      * presence information about an uri it was required to handle.
      * The information is given as a pair of strings (uri, data).
@@ -193,6 +200,11 @@ namespace Ekiga
      */
     void add_presence_fetcher (boost::shared_ptr<PresenceFetcher> fetcher);
 
+    /** Removes a fetcher from the pool of presentce fetchers.
+     * @param The presence fetcher.
+     */
+    void remove_presence_fetcher (boost::shared_ptr<PresenceFetcher> fetcher);
+
     /** Tells the PresenceCore that someone is interested in presence
      * information for the given uri.
      * @param: The uri for which presence is requested.
@@ -205,6 +217,13 @@ namespace Ekiga
      */
     void unfetch_presence (const std::string uri);
 
+    /* Return true if URI can be handled by the PresenceCore,
+     * false otherwise.
+     * @param the URI to test
+     * @return true of the URI can be handled, false otherwise
+     */
+    bool is_supported_uri (const std::string & uri);
+
     /** Those signals are emitted whenever information has been received
      * about an uri ; the information is a pair of strings (uri, information).
      */
@@ -240,24 +259,6 @@ namespace Ekiga
     std::list<boost::shared_ptr<PresencePublisher> > presence_publishers;
     void publish ();
 
-    /*** API to control which uri are supported by runtime ***/
-  public:
-
-    /** Decides whether an uri is supported by the PresenceCore
-     * @param The uri to test for support
-     * @return True if the uri is supported
-     */
-    bool is_supported_uri (const std::string uri) const;
-
-    /** Adds an uri tester to the PresenceCore
-     * @param The tester
-     */
-    void add_supported_uri (boost::function1<bool,std::string> tester);
-
-  private:
-
-    std::list<boost::function1<bool, std::string> > uri_testers;
-
     /*** LiveObject implementation ***/
 
   public:
diff --git a/plugins/avahi/avahi-heap.h b/plugins/avahi/avahi-heap.h
index a03c99e..79e983d 100644
--- a/plugins/avahi/avahi-heap.h
+++ b/plugins/avahi/avahi-heap.h
@@ -77,6 +77,7 @@ namespace Avahi
     /* the PresenceFetcher interface : we don't do what we're told ;-) */
     void fetch (std::string) {}
     void unfetch (std::string) {}
+    bool is_supported_uri (const std::string &) { return true; }
 
     /* these should be private but are called from C code */
 


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