[glibmm: 2/8] initial wrapping of Resolver, SrvTarget



commit f365326dd970083f339b393ea3ae0efcf3ce091c
Author: Jonathon Jongsma <jonathon quotidian org>
Date:   Wed Jun 17 22:37:14 2009 -0500

    initial wrapping of Resolver, SrvTarget

 .gitignore                              |    4 +
 ChangeLog                               |   12 +++
 gio/src/Makefile_list_of_hg.am_fragment |    2 +-
 gio/src/resolver.ccg                    |  128 +++++++++++++++++++++++++++++++
 gio/src/resolver.hg                     |   87 +++++++++++++++++++++
 gio/src/srvtarget.ccg                   |   25 ++++++
 gio/src/srvtarget.hg                    |   55 +++++++++++++
 tools/m4/convert_gio.m4                 |    4 +-
 8 files changed, 315 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index f6ac1a7..eadb81e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -128,8 +128,12 @@ gio/giomm/mountoperation.cc
 gio/giomm/mountoperation.h
 gio/giomm/outputstream.cc
 gio/giomm/outputstream.h
+gio/giomm/resolver.cc
+gio/giomm/resolver.h
 gio/giomm/seekable.cc
 gio/giomm/seekable.h
+gio/giomm/srvtarget.cc
+gio/giomm/srvtarget.h
 gio/giomm/themedicon.cc
 gio/giomm/themedicon.h
 gio/giomm/unixinputstream.cc
diff --git a/ChangeLog b/ChangeLog
index abdf325..6691e8b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-06-17  Jonathon Jongsma  <jonathon quotidian org>
+
+	Initial wrapping for SrvTarget, Resolver
+
+	* .gitignore:
+	* gio/src/Makefile_list_of_hg.am_fragment:
+	* gio/src/resolver.ccg: Added.
+	* gio/src/resolver.hg: Added.
+	* gio/src/srvtarget.ccg: Added
+	* gio/src/srvtarget.hg: Added.
+	* tools/m4/convert_gio.m4:
+
 2009-06-17  Hubert Figuiere  <hub figuiere net>
 
 	* gio/src/file.hg: 
diff --git a/gio/src/Makefile_list_of_hg.am_fragment b/gio/src/Makefile_list_of_hg.am_fragment
index 1c55d04..302e841 100644
--- a/gio/src/Makefile_list_of_hg.am_fragment
+++ b/gio/src/Makefile_list_of_hg.am_fragment
@@ -9,7 +9,7 @@ files_general_hg = appinfo.hg asyncresult.hg cancellable.hg drive.hg emblem.hg e
 				   fileattributeinfolist.hg fileenumerator.hg fileicon.hg fileinfo.hg fileinputstream.hg fileiostream.hg fileoutputstream.hg \
 				   filemonitor.hg filterinputstream.hg filteroutputstream.hg filenamecompleter.hg \
 				   icon.hg inetaddress.hg inputstream.hg iostream.hg loadableicon.hg memoryoutputstream.hg mount.hg mountoperation.hg outputstream.hg \
-				   seekable.hg volume.hg volumemonitor.hg bufferedinputstream.hg \
+				   resolver.hg seekable.hg srvtarget.hg volume.hg volumemonitor.hg bufferedinputstream.hg \
 				   bufferedoutputstream.hg datainputstream.hg dataoutputstream.hg enums.hg \
 				   memoryinputstream.hg themedicon.hg
 
diff --git a/gio/src/resolver.ccg b/gio/src/resolver.ccg
new file mode 100644
index 0000000..f861e5a
--- /dev/null
+++ b/gio/src/resolver.ccg
@@ -0,0 +1,128 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2008 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+
+#if 0
+namespace Glib
+{
+namespace Container_Helpers
+{
+
+template <>
+struct TypeTraits<Gio::SrvTarget >
+{
+  typedef Gio::SrvTarget CppType;
+  typedef GSrvTarget* CType;
+  typedef GSrvTarget* CTypeNonConst;
+
+  static CType   to_c_type      (const CppType& item)
+  { return item.gobj(); }
+
+  static CppType to_cpp_type    (const CType& item)
+  {
+    return Glib::wrap(item, true /* take_copy */);
+  }
+
+  static void    release_c_type (CType item)
+  {
+    g_srv_target_free(item);
+  }
+};
+
+
+} // namespace Container_Helpers
+} // namespace Glib
+#endif
+
+namespace Gio
+{
+
+Glib::RefPtr<Resolver> Resolver::get_default()
+{
+    return Glib::wrap(g_resolver_get_default());
+}
+
+void Resolver::set_default(const Glib::RefPtr<Resolver>& resolver)
+{
+    g_resolver_set_default(Glib::unwrap(resolver));
+}
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+Glib::ListHandle< Glib::RefPtr<InetAddress> > Resolver::lookup_by_name(const Glib::ustring& hostname)
+#else
+Glib::ListHandle< Glib::RefPtr<InetAddress> > Resolver::lookup_by_name(const Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error)
+#endif
+{
+  GError* gerror = 0;
+  Glib::ListHandle< Glib::RefPtr<InetAddress> > retvalue = Glib::ListHandle< Glib::RefPtr<InetAddress> >(g_resolver_lookup_by_name(gobj(), hostname.c_str(), NULL, &(gerror)), Glib::OWNERSHIP_SHALLOW);
+  if(gerror)
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    ::Glib::Error::throw_exception(gerror);
+#else
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  return retvalue;
+}
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+Glib::ustring Resolver::lookup_by_address(const Glib::RefPtr<InetAddress>& address)
+#else
+Glib::ustring Resolver::lookup_by_address(const Glib::RefPtr<InetAddress>& address, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  GError* gerror = 0;
+  Glib::ustring retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_resolver_lookup_by_address(gobj(), const_cast<GInetAddress*>(Glib::unwrap(address)), NULL, &(gerror)));
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  return retvalue;
+
+}
+
+/*
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+Glib::ListHandle<SrvTarget> Resolver::lookup_service(const Glib::ustring& service, const Glib::ustring& protocol, const Glib::ustring& domain)
+#else
+Glib::ListHandle<SrvTarget> Resolver::lookup_service(const Glib::ustring& service, const Glib::ustring& protocol, const Glib::ustring& domain, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  GError* gerror = 0;
+  Glib::ListHandle<SrvTarget> retvalue = Glib::ListHandle<SrvTarget>(g_resolver_lookup_service(gobj(), service.c_str(), protocol.c_str(), domain.c_str(), NULL, &(gerror)), Glib::OWNERSHIP_SHALLOW);
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  return retvalue;
+
+}
+*/
+
+
+} //namespace Gio
diff --git a/gio/src/resolver.hg b/gio/src/resolver.hg
new file mode 100644
index 0000000..31573b6
--- /dev/null
+++ b/gio/src/resolver.hg
@@ -0,0 +1,87 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2009 jonathon jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/object.h>
+#include <giomm/inetaddress.h>
+#include <giomm/cancellable.h>
+#include <giomm/srvtarget.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(glibmm/private/object_p.h)
+
+namespace Gio
+{
+
+/** Asynchronous and cancellable DNS resolver
+ *
+ * Resolver provides cancellable synchronous and asynchronous DNS resolution,
+ * for hostnames (lookup_by_address(), lookup_by_name() and their async
+ * variants) and SRV (service) records (lookup_service()).
+ *
+ * NetworkAddress and NetworkService provide wrappers around Resolver
+ * functionality that also implement SocketConnectable, making it easy to
+ * connect to a remote host/service.
+ *
+ * @newin2p22
+ */
+class Resolver
+: public Glib::Object
+{
+  _CLASS_GOBJECT(Resolver, GResolver, G_RESOLVER, Glib::Object, GObject)
+
+protected:
+
+public:
+  static Glib::RefPtr<Resolver> get_default();
+  _IGNORE(g_resolver_get_default)
+  static void set_default(const Glib::RefPtr<Resolver>& resolver);
+  _IGNORE(g_resolver_set_default)
+
+  // g_resolver_free_addresses is just a C convenience function
+  _IGNORE(g_resolver_free_addresses)
+
+#m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<InetAddress> >',`$2($3, Glib::OWNERSHIP_SHALLOW)')
+  _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<InetAddress> > lookup_by_name(const Glib::ustring& hostname, const Glib::RefPtr<Cancellable>& cancellable), g_resolver_lookup_by_name, errthrow)
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    Glib::ListHandle< Glib::RefPtr<InetAddress> > lookup_by_name(const Glib::ustring& hostname);
+#else
+    Glib::ListHandle< Glib::RefPtr<InetAddress> > lookup_by_name(const Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error);
+#endif
+  //TODO lookup_by_name_async
+
+#m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<InetAddress> >',`$2($3, Glib::OWNERSHIP_SHALLOW)')
+  _WRAP_METHOD(Glib::ustring lookup_by_address(const Glib::RefPtr<InetAddress>& address, const Glib::RefPtr<Cancellable>& cancellable), g_resolver_lookup_by_address, errthrow)
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    Glib::ustring lookup_by_address(const Glib::RefPtr<InetAddress>& address);
+#else
+    Glib::ustring lookup_by_address(const Glib::RefPtr<InetAddress>& address, std::auto_ptr<Glib::Error>& error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+  //TODO lookup_by_address_async
+
+#m4 _CONVERSION(`GList*',`Glib::ListHandle<SrvTarget>',`$2($3, Glib::OWNERSHIP_SHALLOW)')
+  _WRAP_METHOD(Glib::ListHandle<SrvTarget> lookup_service(const Glib::ustring& service, const Glib::ustring& protocol, const Glib::ustring& domain, const Glib::RefPtr<Cancellable>& cancellable), g_resolver_lookup_service, errthrow)
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    Glib::ListHandle<SrvTarget> lookup_service(const Glib::ustring& service, const Glib::ustring& protocol, const Glib::ustring& domain);
+#else
+    Glib::ListHandle<SrvTarget> lookup_service(const Glib::ustring& service, const Glib::ustring& protocol, const Glib::ustring& domain, std::auto_ptr<Glib::Error>& error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+  //TODO lookup_service_async
+};
+
+} // namespace Gio
diff --git a/gio/src/srvtarget.ccg b/gio/src/srvtarget.ccg
new file mode 100644
index 0000000..c146baa
--- /dev/null
+++ b/gio/src/srvtarget.ccg
@@ -0,0 +1,25 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2008 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+
+namespace Gio
+{
+
+} //namespace Gio
diff --git a/gio/src/srvtarget.hg b/gio/src/srvtarget.hg
new file mode 100644
index 0000000..c44ecd0
--- /dev/null
+++ b/gio/src/srvtarget.hg
@@ -0,0 +1,55 @@
+/* Copyright (C) 2009 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+_DEFS(giomm,gio)
+
+namespace Gio
+{
+
+/** DNS SRV record target
+ *
+ * SRV (service) records are used by some network protocols to provide
+ * service-specific aliasing and load-balancing. For example, XMPP (Jabber) uses
+ * SRV records to locate the XMPP server for a domain; rather than connecting
+ * directly to "example.com" or assuming a specific server hostname like
+ * "xmpp.example.com", an XMPP client would look up the "xmpp-client" SRV record
+ * for "example.com", and then connect to whatever host was pointed to by that
+ * record.
+ *
+ * You can use Resolver::lookup_service() or Resolver::lookup_service_async()
+ * to find the SrvTargets for a given service. However, if you are simply
+ * planning to connect to the remote service, you can use NetworkService's
+ * SocketConnectable interface and not need to worry about SrvTarget at all.
+ *
+ * @newin2p22
+ */
+class SrvTarget
+{
+  _CLASS_BOXEDTYPE(SrvTarget, GSrvTarget, NONE, g_srv_target_copy, g_srv_target_free)
+public:
+  SrvTarget(const Glib::ustring& hostname, guint16 port, guint16 priority, guint16 weight);
+
+  _IGNORE(g_srv_target_copy, g_srv_target_free)
+
+  _WRAP_METHOD(Glib::ustring get_hostname() const, g_srv_target_get_hostname)
+  _WRAP_METHOD(guint16 get_port() const, g_srv_target_get_port)
+  _WRAP_METHOD(guint16 get_priority() const, g_srv_target_get_priority)
+  _WRAP_METHOD(guint16 get_weight() const, g_srv_target_get_weight)
+
+};
+
+} // namespace Gio
diff --git a/tools/m4/convert_gio.m4 b/tools/m4/convert_gio.m4
index b7da980..5245601 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -89,7 +89,9 @@ _CONVERSION(`Glib::RefPtr<Icon>',`GIcon*',__CONVERT_REFPTR_TO_P)
 _CONVERSION(`Glib::RefPtr<const Icon>',`GIcon*',__CONVERT_CONST_REFPTR_TO_P)
 
 _CONVERSION(`const Glib::RefPtr<Emblem>&',`GEmblem*',__CONVERT_CONST_REFPTR_TO_P)
-_CONVERSION(`const Glib::RefPtr<Emblem>&',`GEmblem*',__CONVERT_CONST_REFPTR_TO_P)
+
+# InetAddress
+_CONVERSION(`const Glib::RefPtr<InetAddress>&',`GInetAddress*',__CONVERT_CONST_REFPTR_TO_P)
 
 # InputStream
 _CONVERSION(`const Glib::RefPtr<InputStream>&',`GInputStream*',__CONVERT_CONST_REFPTR_TO_P)



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