[Telepathy-commits] [telepathy-qt4/master] Add Connection.Interface.Hats example from telepathy-glib to demonstrate extensibility

Olli Salli olli.salli at collabora.co.uk
Mon Sep 29 13:05:12 PDT 2008


---
 Makefile.am                                       |    2 +-
 configure.ac                                      |    9 ++
 examples/Makefile.am                              |    1 +
 examples/extensions/Connection_Interface_Hats.xml |  139 +++++++++++++++++++++
 examples/extensions/Makefile.am                   |  105 ++++++++++++++++
 examples/extensions/all.xml                       |   16 +++
 examples/extensions/cli-connection.cpp            |    2 +
 examples/extensions/cli-connection.h              |    6 +
 examples/extensions/connection.xml                |    9 ++
 examples/extensions/types.cpp                     |    1 +
 examples/extensions/types.h                       |    6 +
 11 files changed, 295 insertions(+), 1 deletions(-)
 create mode 100644 examples/Makefile.am
 create mode 100644 examples/extensions/Connection_Interface_Hats.xml
 create mode 100644 examples/extensions/Makefile.am
 create mode 100644 examples/extensions/all.xml
 create mode 100644 examples/extensions/cli-connection.cpp
 create mode 100644 examples/extensions/cli-connection.h
 create mode 100644 examples/extensions/connection.xml
 create mode 100644 examples/extensions/types.cpp
 create mode 100644 examples/extensions/types.h

diff --git a/Makefile.am b/Makefile.am
index 434d158..96b5e87 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = m4 tools spec TelepathyQt4
+SUBDIRS = m4 tools spec TelepathyQt4 examples
 
 DISTCHECK_CONFIGURE_FLAGS = --disable-debug
 
diff --git a/configure.ac b/configure.ac
index 9236bbe..69bc13c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -140,6 +140,13 @@ PKG_CHECK_MODULES(QTDBUS, [QtDBus >= 4.5])
 AC_SUBST(QTDBUS_CFLAGS)
 AC_SUBST(QTDBUS_LIBS)
 
+dnl We want the examples to be able to use TP_QT4_CXXFLAGS, TP_QT4_LIBS
+dnl as though they were independent programs
+TP_QT4_CXXFLAGS='-I${top_builddir} -I${top_srcdir}'
+TP_QT4_LIBS='${top_builddir}/TelepathyQt4/libtelepathy-qt4.la'
+AC_SUBST(TP_QT4_CFLAGS)
+AC_SUBST(TP_QT4_LIBS)
+
 dnl Check for code generation tools
 PYTHON=
 AC_CHECK_PROGS([PYTHON], [python2.5 python])
@@ -164,5 +171,7 @@ AC_OUTPUT( Makefile \
 	   TelepathyQt4/TelepathyQt4.pc \
 	   tools/Makefile \
 	   m4/Makefile \
+	   examples/Makefile \
+	   examples/extensions/Makefile \
 )
 
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..1b5c62d
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = extensions
diff --git a/examples/extensions/Connection_Interface_Hats.xml b/examples/extensions/Connection_Interface_Hats.xml
new file mode 100644
index 0000000..daa6e22
--- /dev/null
+++ b/examples/extensions/Connection_Interface_Hats.xml
@@ -0,0 +1,139 @@
+<?xml version="1.0" ?>
+<node name="/Connection_Interface_Hats"
+  xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
+  <tp:copyright> Copyright (C) 2007 Collabora Ltd.</tp:copyright>
+  <tp:copyright> Copyright (C) 2007 Nokia Corporation</tp:copyright>
+  <tp:license>
+    Copying and distribution of this file, with or without modification,
+    are permitted in any medium without royalty provided the copyright
+    notice and this notice are preserved.
+  </tp:license>
+  <interface name="com.example.Telepathy.Connection.Interface.Hats"
+    tp:causes-havoc='a silly example'>
+    <tp:requires interface="org.freedesktop.Telepathy.Connection"/>
+
+    <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
+      This interface is an example of how Telepathy can be extended.
+      For the purposes of this example, we pretend we're an organisation
+      example.com that's adding a proprietary extension to Telepathy,
+      so the extension is not in the main Telepathy namespace.
+    </tp:docstring>
+
+    <tp:struct name="Contact_Hat" array-name="Contact_Hat_List">
+      <tp:docstring>A data structure representing a contact and their
+        hat.</tp:docstring>
+      <tp:member type="u" name="Contact" tp:type="Contact_Handle">
+        <tp:docstring>The contact wearing the hat.</tp:docstring>
+      </tp:member>
+      <tp:member type="s" name="Color">
+        <tp:docstring>The color of the hat</tp:docstring>
+      </tp:member>
+      <tp:member type="u" name="Style" tp:type="Hat_Style">
+        <tp:docstring>The style of the hat</tp:docstring>
+      </tp:member>
+      <tp:member type="a{sv}" name="Properties" tp:type="String_Variant_Map">
+        <tp:docstring>Optional key-value pairs describing extended
+          properties of the hat.</tp:docstring>
+      </tp:member>
+    </tp:struct>
+
+    <tp:enum name="Hat_Style" type="u">
+      <tp:enumvalue suffix="None" value="0">
+        <tp:docstring>There is no hat. color MUST be the empty
+          string and properties MUST be an empty mapping.</tp:docstring>
+      </tp:enumvalue>
+      <tp:enumvalue suffix="Other" value="1">
+        <tp:docstring>An unspecified type of hat.</tp:docstring>
+      </tp:enumvalue>
+      <tp:enumvalue suffix="Fedora" value="2">
+        <tp:docstring>A fedora, which MAY be red.</tp:docstring>
+      </tp:enumvalue>
+      <tp:enumvalue suffix="Knitted" value="3">
+        <tp:docstring>A knitted hat, with or without a bobble.</tp:docstring>
+      </tp:enumvalue>
+      <tp:enumvalue suffix="Bowler" value="4">
+        <tp:docstring>A bowler hat, as worn by stereotypical English
+          businessmen.</tp:docstring>
+      <tp:enumvalue suffix="Helmet" value="5">
+        <tp:docstring>A hat with protective qualities.</tp:docstring>
+      </tp:enumvalue>
+      </tp:enumvalue>
+    </tp:enum>
+
+    <signal name="HatsChanged">
+      <tp:docstring>
+        Emitted when the contact's hat has changed.
+      </tp:docstring>
+      <arg name="Contact" type="u" tp:type="Contact_Handle">
+        <tp:docstring>
+          The handle representing the contact's ID on the server
+        </tp:docstring>
+      </arg>
+      <arg name="Color" type="s">
+        <tp:docstring>
+          The color of the contact's hat.
+        </tp:docstring>
+      </arg>
+      <arg name="Style" type="u" tp:type="Hat_Style">
+        <tp:docstring>
+          The style of the contact's hat.
+        </tp:docstring>
+      </arg>
+      <arg name="Properties" type="a{sv}" tp:type="String_Variant_Map">
+        <tp:docstring>
+          There's always an a{sv}. Perhaps there's some special religious
+          reason.
+        </tp:docstring>
+      </arg>
+    </signal>
+
+    <method name="GetHats">
+      <tp:docstring>
+        Request a list of the hats worn by the given contacts.
+      </tp:docstring>
+      <arg direction="in" name="Contact" type="au" tp:type="Contact_Handle[]">
+        <tp:docstring>
+          The handles of the contacts whose hats are requested
+        </tp:docstring>
+      </arg>
+      <arg direction="out" name="Hats" type="a(usua{sv})"
+        tp:type="Contact_Hat[]">
+        <tp:docstring>
+          A list of contacts and their hats.
+        </tp:docstring>
+      </arg>
+      <tp:possible-errors>
+        <tp:error name="org.freedesktop.Telepathy.Error.Disconnected"/>
+        <tp:error name="org.freedesktop.Telepathy.Error.NetworkError"/>
+        <tp:error name="org.freedesktop.Telepathy.Error.InvalidHandle"/>
+        <tp:error name="org.freedesktop.Telepathy.Error.PermissionDenied"/>
+        <tp:error name="org.freedesktop.Telepathy.Error.NotAvailable"/>
+      </tp:possible-errors>
+    </method>
+
+    <method name="SetHat">
+      <tp:docstring>
+        Indicate that the hat currently being worn by the local user
+        has changed.
+      </tp:docstring>
+      <arg name="Color" type="s" direction="in">
+        <tp:docstring>
+          The color of the contact's hat.
+        </tp:docstring>
+      </arg>
+      <arg name="Style" type="u" tp:type="Hat_Style" direction="in">
+        <tp:docstring>
+          The style of the contact's hat.
+        </tp:docstring>
+      </arg>
+      <arg name="Properties" type="a{sv}" tp:type="String_Variant_Map"
+        direction="in">
+        <tp:docstring>
+          There's always an a{sv}...
+        </tp:docstring>
+      </arg>
+    </method>
+
+  </interface>
+</node>
+<!-- vim:set sw=2 sts=2 et ft=xml: -->
diff --git a/examples/extensions/Makefile.am b/examples/extensions/Makefile.am
new file mode 100644
index 0000000..e8b8fe6
--- /dev/null
+++ b/examples/extensions/Makefile.am
@@ -0,0 +1,105 @@
+# This directory is an example of how to build extensions to the spec.
+# Typically this would be in a top-level extensions/ directory.
+
+# In this example we build an optional interface for Telepathy Connections,
+# so we specify Telepathy::Client::Connection as the main interface for the
+# generated proxies with "--mainiface=Telepathy::Client::Connection'. The
+# generated proxies will have a convenience constructors for associating the
+# proxy with the same remote object an instance of the main interface class
+# is associated with. We could instead have made an optional interface for any
+# other class, or by leaving that option out entirely we could have made an
+# extension that will work on QDBusAbstractInterface or any subclass of it.
+#
+# For stand-alone interfaces (for which the interface itself should be considered
+# the main interface) --mainiface should be specified as fully namespaced name
+# of the interface class itself.
+
+tools_dir = $(top_srcdir)/tools
+
+AM_CXXFLAGS = \
+    $(ERROR_CXXFLAGS) \
+    @QTCORE_CFLAGS@ \
+    @QTDBUS_CFLAGS@ \
+    $(TP_QT4_CXXFLAGS)
+
+EXTRA_DIST = \
+    all.xml \
+    connection.xml \
+    Connection_Interface_Hats.xml
+
+noinst_LTLIBRARIES = libexample-extensions.la
+
+libexample_extensions_la_LIBADD = \
+    $(TP_QT4_LIBS)
+
+# The client-specific parts are built into a separate .o file, so the linker
+# can discard them when linking services. The service-specific parts are
+# in svc-*.c, so we don't need an extensions-svc.c.
+libexample_extensions_la_SOURCES = \
+    cli-connection.cpp \
+    cli-connection.h \
+    types.cpp \
+    types.h
+
+nodist_libexample_extensions_la_SOURCES = \
+    _gen/constants.h \
+    _gen/cli-connection.h \
+    _gen/cli-connection-body.hpp \
+    _gen/cli-connection.moc.hpp \
+    _gen/types.h \
+    _gen/types-body.hpp
+
+BUILT_SOURCES = \
+    _gen/all.xml \
+    _gen/connection.xml \
+    $(nodist_libexample_extensions_la_SOURCES)
+
+CLEANFILES = $(BUILT_SOURCES)
+
+# Generated files which can be generated for all categories simultaneously
+
+_gen/all.xml: all.xml $(wildcard *.xml)
+	$(mkdir_p) _gen
+	$(PYTHON) $(top_srcdir)/tools/xincludator.py \
+		$< > $@
+
+_gen/constants.h: _gen/all.xml \
+		$(top_srcdir)/tools/qt4-constants-gen.py
+	$(PYTHON) $(top_srcdir)/tools/qt4-constants-gen.py \
+		--namespace='Example' \
+		--str-constant-prefix='EXAMPLE_' \
+		--specxml=$< \
+		> $@.tmp && mv $@.tmp $@
+
+_gen/types.h _gen/types-body.hpp: _gen/all.xml \
+		$(top_srcdir)/tools/qt4-types-gen.py
+	$(PYTHON) $(top_srcdir)/tools/qt4-types-gen.py \
+		--namespace='Example' \
+		--declfile='_gen/types.h' \
+		--implfile='_gen/types-body.hpp' \
+		--realinclude='types.h' \
+		--specxml=$< \
+		--extraincludes='<TelepathyQt4/Types>'
+
+# Things generated per interface group
+
+_gen/connection.xml: connection.xml $(wildcard *.xml)
+	$(mkdir_p) _gen
+	$(PYTHON) $(top_srcdir)/tools/xincludator.py \
+		$< > $@
+
+_gen/cli-connection-body.hpp _gen/cli-connection.h: _gen/connection.xml \
+	_gen/all.xml $(tools_dir)/qt4-client-gen.py
+	$(PYTHON) $(tools_dir)/qt4-client-gen.py \
+		--namespace='Example::Client' \
+		--typesnamespace='Example' \
+		--headerfile=_gen/cli-connection.h \
+		--implfile=_gen/cli-connection-body.hpp \
+		--realinclude='../cli-connection.h' \
+		--specxml=_gen/all.xml \
+		--ifacexml=$< \
+		--extraincludes='<TelepathyQt4/Client/Connection>,"types.h"' \
+		--mainiface='Telepathy::Client::ConnectionInterface'
+
+%.moc.hpp: %.h _gen/constants.h _gen/types.h
+	$(MOC) @QTCORE_CFLAGS@ @QTDBUS_CFLAGS@ -I$(top_builddir) -I$(top_srcdir) -i $< -o $@
diff --git a/examples/extensions/all.xml b/examples/extensions/all.xml
new file mode 100644
index 0000000..52bbbe3
--- /dev/null
+++ b/examples/extensions/all.xml
@@ -0,0 +1,16 @@
+<tp:spec
+  xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
+  xmlns:xi="http://www.w3.org/2001/XInclude">
+
+<tp:title>Extensions for 'extended' examples</tp:title>
+
+<xi:include href="connection.xml"/>
+
+<tp:generic-types>
+  <tp:external-type name="Contact_Handle" type="u"
+    from="Telepathy specification"/>
+  <tp:external-type name="String_Variant_Map" type="a{sv}"
+    from="Telepathy specification"/>
+</tp:generic-types>
+
+</tp:spec>
diff --git a/examples/extensions/cli-connection.cpp b/examples/extensions/cli-connection.cpp
new file mode 100644
index 0000000..8940160
--- /dev/null
+++ b/examples/extensions/cli-connection.cpp
@@ -0,0 +1,2 @@
+#include "cli-connection.h"
+#include "_gen/cli-connection.moc.hpp"
diff --git a/examples/extensions/cli-connection.h b/examples/extensions/cli-connection.h
new file mode 100644
index 0000000..fc07d25
--- /dev/null
+++ b/examples/extensions/cli-connection.h
@@ -0,0 +1,6 @@
+#ifndef _Example_Client_Connection_HEADER_GUARD_
+#define _Example_Client_Connection_HEADER_GUARD_
+
+#include "_gen/cli-connection.h"
+
+#endif
diff --git a/examples/extensions/connection.xml b/examples/extensions/connection.xml
new file mode 100644
index 0000000..242fb1f
--- /dev/null
+++ b/examples/extensions/connection.xml
@@ -0,0 +1,9 @@
+<tp:spec
+  xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
+  xmlns:xi="http://www.w3.org/2001/XInclude">
+
+<tp:title>Connection extensions for 'extended' example</tp:title>
+
+<xi:include href="Connection_Interface_Hats.xml"/>
+
+</tp:spec>
diff --git a/examples/extensions/types.cpp b/examples/extensions/types.cpp
new file mode 100644
index 0000000..49bc41d
--- /dev/null
+++ b/examples/extensions/types.cpp
@@ -0,0 +1 @@
+#include "_gen/types-body.hpp"
diff --git a/examples/extensions/types.h b/examples/extensions/types.h
new file mode 100644
index 0000000..fb4ad9c
--- /dev/null
+++ b/examples/extensions/types.h
@@ -0,0 +1,6 @@
+#ifndef _Example_Types_HEADER_GUARD_
+#define _Example_Types_HEADER_GUARD_
+
+#include "_gen/types.h"
+
+#endif
-- 
1.5.6.5




More information about the Telepathy-commits mailing list