ekiga r6225 - in trunk: . lib/engine/components/avahi-publisher lib/engine/presence/avahi lib/engine/protocol/skel src/endpoints



Author: dsandras
Date: Sun Apr 27 09:48:16 2008
New Revision: 6225
URL: http://svn.gnome.org/viewvc/ekiga?rev=6225&view=rev

Log:
Finished AVAHI presence publisher. It is now able to get the port and
protocol from the Ekiga::CallManager through newly added
get_protocol_name and get_interface methods. Added some const's. Added
the possibility to broadcast the status message through ZeroConf.


Modified:
   trunk/ChangeLog
   trunk/lib/engine/components/avahi-publisher/avahi-publisher.cpp
   trunk/lib/engine/components/avahi-publisher/avahi-publisher.h
   trunk/lib/engine/presence/avahi/avahi-heap.cpp
   trunk/lib/engine/protocol/skel/call-core.cpp
   trunk/lib/engine/protocol/skel/call-core.h
   trunk/lib/engine/protocol/skel/call-manager.h
   trunk/src/endpoints/sip.cpp
   trunk/src/endpoints/sip.h

Modified: trunk/lib/engine/components/avahi-publisher/avahi-publisher.cpp
==============================================================================
--- trunk/lib/engine/components/avahi-publisher/avahi-publisher.cpp	(original)
+++ trunk/lib/engine/components/avahi-publisher/avahi-publisher.cpp	Sun Apr 27 09:48:16 2008
@@ -38,12 +38,16 @@
 
 
 #include <iostream>
+#include <sstream>
 
 #include "config.h"
 
 #include "avahi-publisher.h"
 #include "personal-details.h"
 
+#include "call-core.h"
+#include "call-manager.h"
+
 using namespace Avahi;
 
 
@@ -153,9 +157,23 @@
     name = NULL;
   }
 
+  Ekiga::CallCore *call_core = dynamic_cast<Ekiga::CallCore *> (core.get ("call-core"));
+  if (call_core) {
+
+    to_publish.clear ();
+    Ekiga::CallCore::const_iterator it;
+    for (it = call_core->begin (); it != call_core->end (); it++) {
+
+      const Ekiga::CallManager::Interface & interface = (*it)->get_interface ();
+      const std::string & protocol = (*it)->get_protocol_name ();
+      to_publish [protocol] = interface;
+    }
+  }
+
   name = g_strdup (details.get_display_name ().c_str ());
   short_status = "presence-" + details.get_short_status ();
   text_record = avahi_string_list_add_printf (text_record, "presence=%s", short_status.c_str ());
+  text_record = avahi_string_list_add_printf (text_record, "status=%s", details.get_long_status ().c_str ());
   text_record = avahi_string_list_add (text_record, "software=Ekiga/" PACKAGE_VERSION);
 
   if (client && group) {
@@ -178,30 +196,40 @@
 
 bool PresencePublisher::connect () 
 {
+  bool success = true;
   int ret = 0;
 
   if (group != NULL) {
-  
-    ret = avahi_entry_group_add_service_strlst (group,
-						AVAHI_IF_UNSPEC,
-						AVAHI_PROTO_UNSPEC,
-						(AvahiPublishFlags) 0,
-						name,
-						ZC_SIP,
-						NULL,
-						NULL,
-						5060,
-						text_record);
-    if (ret >= 0) {
-
-      /* Commit changes */
-      ret = avahi_entry_group_commit (group);
-      if (ret < 0) 
-        return false;
+
+    std::map<std::string, Ekiga::CallManager::Interface>::const_iterator it;
+    for (it = to_publish.begin (); it != to_publish.end (); it++) {
+
+      std::stringstream srv;
+      srv << "_" << (*it).first << "._" << (*it).second.protocol;
+
+      ret = avahi_entry_group_add_service_strlst (group,
+                                                  AVAHI_IF_UNSPEC,
+                                                  AVAHI_PROTO_UNSPEC,
+                                                  (AvahiPublishFlags) 0,
+                                                  name,
+                                                  srv.str ().c_str (),
+                                                  NULL,
+                                                  NULL,
+                                                  (*it).second.port,
+                                                  text_record);
+      if (ret >= 0) {
+
+        /* Commit changes */
+        ret = avahi_entry_group_commit (group);
+        if (ret < 0) 
+          success = false;
+      }
+      else
+        success = false;
     }
   }
 
-  return true;
+  return success;
 }
 
 

Modified: trunk/lib/engine/components/avahi-publisher/avahi-publisher.h
==============================================================================
--- trunk/lib/engine/components/avahi-publisher/avahi-publisher.h	(original)
+++ trunk/lib/engine/components/avahi-publisher/avahi-publisher.h	Sun Apr 27 09:48:16 2008
@@ -50,9 +50,7 @@
 #include "presence-core.h"
 #include "services.h"
 
-/* Zeroconf Service Type */
-#define ZC_H323 "_h323._tcp"
-#define ZC_SIP "_sip._udp"
+#include "call-manager.h"
 
 class Ekiga::PersonalDetails;
 
@@ -100,6 +98,8 @@
 
     AvahiGLibPoll *glib_poll;
     const AvahiPoll *poll_api;
+
+    std::map<std::string, Ekiga::CallManager::Interface> to_publish;
   };
 };
 #endif

Modified: trunk/lib/engine/presence/avahi/avahi-heap.cpp
==============================================================================
--- trunk/lib/engine/presence/avahi/avahi-heap.cpp	(original)
+++ trunk/lib/engine/presence/avahi/avahi-heap.cpp	Sun Apr 27 09:48:16 2008
@@ -252,6 +252,7 @@
 {
   std::string software;
   std::string presence;
+  std::string status;
   bool already_known = false;
   char good_address[AVAHI_ADDRESS_STR_MAX];
   gchar *url = NULL;
@@ -274,8 +275,9 @@
 	    std::string value (cvalue);
 	    if (key == "presence") 
               presence = value;
-	    
-	    if (key == "software")
+            else if (key == "status") 
+              status = value;
+            else if (key == "software")
 	      software = value;
 	  }
 	  if (ckey != NULL) free (ckey);
@@ -291,7 +293,7 @@
 	if ((*iter).get_name () == name) {
 
 	  /* known contact has been updated */
-          (*iter).set_status ("");
+          (*iter).set_status (status);
 	  (*iter).set_presence (presence);
 	  (*iter).updated.emit ();
           already_known = true;
@@ -303,7 +305,7 @@
 	avahi_address_snprint (good_address, sizeof (good_address), address);
 	url = g_strdup_printf ("sip:%s:%d", good_address, port);
 	presentity = new Presentity (core, name, url);
-	presentity->set_status ("");
+	presentity->set_status (status);
 	presentity->set_presence (presence);
 	add_presentity (*presentity);
 	g_free (url);

Modified: trunk/lib/engine/protocol/skel/call-core.cpp
==============================================================================
--- trunk/lib/engine/protocol/skel/call-core.cpp	(original)
+++ trunk/lib/engine/protocol/skel/call-core.cpp	Sun Apr 27 09:48:16 2008
@@ -65,12 +65,24 @@
 }
 
 
+CallCore::const_iterator CallCore::begin () const
+{
+  return managers.begin ();
+}
+
+
 CallCore::iterator CallCore::end ()
 {
   return managers.end (); 
 }
 
 
+CallCore::const_iterator CallCore::end () const
+{
+  return managers.end (); 
+}
+
+
 bool CallCore::dial (const std::string uri)
 {
   for (std::set<CallManager *>::iterator iter = managers.begin ();

Modified: trunk/lib/engine/protocol/skel/call-core.h
==============================================================================
--- trunk/lib/engine/protocol/skel/call-core.h	(original)
+++ trunk/lib/engine/protocol/skel/call-core.h	Sun Apr 27 09:48:16 2008
@@ -55,13 +55,13 @@
 
   class CallManager;
 
-
   class CallCore
     : public Service
     {
 
   public:
       typedef std::set<CallManager *>::iterator iterator;
+      typedef std::set<CallManager *>::const_iterator const_iterator;
 
       /** The constructor
        */
@@ -103,11 +103,13 @@
        * @return iterator to beginning
        */
       iterator begin ();
+      const_iterator begin () const;
 
       /** Return iterator to end
        * @return iterator to end 
        */
       iterator end ();
+      const_iterator end () const;
 
       /** This signal is emitted when a Ekiga::CallManager has been
        * added to the CallCore Service.

Modified: trunk/lib/engine/protocol/skel/call-manager.h
==============================================================================
--- trunk/lib/engine/protocol/skel/call-manager.h	(original)
+++ trunk/lib/engine/protocol/skel/call-manager.h	Sun Apr 27 09:48:16 2008
@@ -54,6 +54,14 @@
     {
 
   public:
+      class Interface
+        {
+      public:
+          std::string protocol;
+          std::string interface;
+          unsigned port;
+        };
+
 
       /* The constructor
        */
@@ -89,7 +97,7 @@
        * @return the interface on which we are accepting calls. Generally,
        * under the form protocol:IP:port.
        */
-      virtual const std::string & get_interface () const = 0;
+      virtual const Interface & get_interface () const = 0;
 
 
       /*

Modified: trunk/src/endpoints/sip.cpp
==============================================================================
--- trunk/src/endpoints/sip.cpp	(original)
+++ trunk/src/endpoints/sip.cpp	Sun Apr 27 09:48:16 2008
@@ -55,6 +55,7 @@
   presence_core (*(dynamic_cast<Ekiga::PresenceCore *> (core.get ("presence-core")))),
   runtime (*(dynamic_cast<Ekiga::Runtime *> (core.get ("runtime"))))
 {
+  protocol_name = "sip";
   uri_prefix = "sip:";
   udp_min = 5000;
   udp_max = 5100; 
@@ -93,13 +94,13 @@
 
 const std::string & GMSIPEndpoint::get_protocol_name () const
 {
-  return uri_prefix;
+  return protocol_name;
 }
 
 
-const std::string & GMSIPEndpoint::get_interface () const
+const Ekiga::CallManager::Interface & GMSIPEndpoint::get_interface () const
 {
-  return listener;
+  return interface;
 }
 
 
@@ -303,6 +304,9 @@
   std::stringstream str;
   RemoveListener (NULL);
 
+  interface.protocol = "udp";
+  interface.interface = "*";
+
   str << "udp$*:" << port;
   if (!StartListeners (PStringArray (str.str ().c_str ()))) {
 
@@ -312,12 +316,14 @@
 
       if (StartListeners (PStringArray (str.str ().c_str ()))) {
 
-        listener = str.str ();
+        interface.port = port;
         return true;
       }
       port++;
     }
   }
+  else
+    interface.port = port;
 
   return false;
 }

Modified: trunk/src/endpoints/sip.h
==============================================================================
--- trunk/src/endpoints/sip.h	(original)
+++ trunk/src/endpoints/sip.h	Sun Apr 27 09:48:16 2008
@@ -76,7 +76,7 @@
 
   const std::string & get_protocol_name () const;
 
-  const std::string & get_interface () const;
+  const Ekiga::CallManager::Interface & get_interface () const;
 
   bool send_message (const std::string uri, 
                      const std::string message);
@@ -254,7 +254,9 @@
   Ekiga::PresenceCore & presence_core;
   Ekiga::Runtime & runtime;
 
-  std::string listener;
+  Ekiga::CallManager::Interface interface;
+
+  std::string protocol_name;
   std::string uri_prefix;
   std::string forward_uri;
 



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