[glib/gdbus-actions: 1/3] add GContextual interface
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/gdbus-actions: 1/3] add GContextual interface
- Date: Thu, 2 Sep 2010 01:49:49 +0000 (UTC)
commit 5e0d795d21fa937b9f26c5330eb52db0b505ea22
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Sep 1 19:31:22 2010 +0200
add GContextual interface
docs/reference/gio/gio-docs.xml | 1 +
docs/reference/gio/gio-sections.txt | 19 +++++++
docs/reference/gio/gio.types | 1 +
gio/Makefile.am | 2 +
gio/gcontextual.c | 102 +++++++++++++++++++++++++++++++++++
gio/gcontextual.h | 70 ++++++++++++++++++++++++
gio/gio.h | 1 +
gio/gio.symbols | 8 +++
gio/giotypes.h | 1 +
9 files changed, 205 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gio/gio-docs.xml b/docs/reference/gio/gio-docs.xml
index d6c8361..191d52d 100644
--- a/docs/reference/gio/gio-docs.xml
+++ b/docs/reference/gio/gio-docs.xml
@@ -165,6 +165,7 @@
</chapter>
<chapter id="application">
<title>Application support</title>
+ <xi:include href="xml/gcontextual.xml"/>
<xi:include href="xml/gactiongroup.xml"/>
<xi:include href="xml/gsimpleactiongroup.xml"/>
<xi:include href="xml/gaction.xml"/>
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index f2f97bf..4bc3d24 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -2863,3 +2863,22 @@ G_TYPE_PROXY
<SUBSECTION Private>
g_proxy_get_type
</SECTION>
+
+<SECTION>
+<FILE>gcontextual</FILE>
+<TITLE>GContextual</TITLE>
+GContextual
+GContextualInterface
+
+<SUBSECTION>
+g_contextual_push_context
+g_contextual_pop_context
+
+<SUBSECTION Standard>
+G_CONTEXTUAL
+G_CONTEXTUAL_GET_IFACE
+G_IS_CONTEXTUAL
+G_TYPE_CONTEXTUAL
+<SUBSECTION Private>
+g_contextual_get_type
+</SECTION>
diff --git a/docs/reference/gio/gio.types b/docs/reference/gio/gio.types
index 7ebd6c4..a38c46c 100644
--- a/docs/reference/gio/gio.types
+++ b/docs/reference/gio/gio.types
@@ -13,6 +13,7 @@ g_buffered_input_stream_get_type
g_buffered_output_stream_get_type
g_cancellable_get_type
g_charset_converter_get_type
+g_contextual_get_type
g_converter_get_type
g_converter_flags_get_type
g_converter_input_stream_get_type
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 4618a12..78676dd 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -139,6 +139,7 @@ application_headers = \
gsimpleactiongroup.h \
gaction.h \
gsimpleaction.h \
+ gcontextual.h \
gapplication.h
application_sources = \
@@ -146,6 +147,7 @@ application_sources = \
gsimpleactiongroup.c \
gaction.c \
gsimpleaction.c \
+ gcontextual.c \
gapplication.c
local_sources = \
diff --git a/gio/gcontextual.c b/gio/gcontextual.c
new file mode 100644
index 0000000..d9730e9
--- /dev/null
+++ b/gio/gcontextual.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This program 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 of the licence 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#include "config.h"
+#include "gcontextual.h"
+
+G_DEFINE_INTERFACE (GContextual, g_contextual, G_TYPE_OBJECT)
+
+/**
+ * SECTION:gcontextual
+ * @title: GContextual
+ * @short_description: an interface for classes that have
+ * context-sensitive method invocations
+ *
+ * #GContexual is an interface used by classes that have one or more
+ * context-sensitive methods. Context-sensitive methods are methods
+ * that may behave differently depending on the context from which they
+ * are called.
+ *
+ * The context is always provided as a #GVariant in the form of a
+ * dictionary mapping strings to variants.
+ *
+ * When a caller wishes to provide context to a given call, they should
+ * use g_contextual_push_context() to push the context, then make the
+ * call, then pop the context using g_contextual_pop_context().
+ *
+ * It is up to the caller to ensure that the above sequence of calls is
+ * made as "tightly" as possible. The caller may not assume that
+ * context pertains only to a single thread or only to a single instance
+ * of a particular class. This implies that classes implementing
+ * #GContextual are usually not usable from multiple threads unless
+ * special steps have been taken (eg: the use of #GPrivate).
+ **/
+
+void
+g_contextual_default_init (GContextualInterface *iface)
+{
+}
+
+/**
+ * g_contextual_push_context:
+ * @contextual: a #GContextual
+ * @context: the new context
+ *
+ * Pushes context information into @contextual.
+ *
+ * The context must be a dictionary mapping strings to variants (ie:
+ * #GVariantType '<literal>a{sv}</literal>').
+ *
+ * Since: 2.26
+ **/
+void
+g_contextual_push_context (GContextual *contextual,
+ GVariant *context)
+{
+ g_return_if_fail (G_IS_CONTEXTUAL (contextual));
+ g_return_if_fail (g_variant_is_of_type (context, G_VARIANT_TYPE ("a{sv}")));
+
+ return G_CONTEXTUAL_GET_IFACE (contextual)
+ ->push_context (contextual, context);
+}
+
+/**
+ * g_contextual_pop_context:
+ * @contextual: a #GContextual
+ * @context: the context given to g_contextual_push_context()
+ *
+ * Reverses the effect of a previous call to
+ * g_contextual_push_context().
+ *
+ * @context must be the same value as was given to the earlier call.
+ *
+ * Since: 2.26
+ **/
+void
+g_contextual_pop_context (GContextual *contextual,
+ GVariant *context)
+{
+ g_return_if_fail (G_IS_CONTEXTUAL (contextual));
+ g_return_if_fail (g_variant_is_of_type (context, G_VARIANT_TYPE ("a{sv}")));
+
+ return G_CONTEXTUAL_GET_IFACE (contextual)
+ ->pop_context (contextual, context);
+}
diff --git a/gio/gcontextual.h b/gio/gcontextual.h
new file mode 100644
index 0000000..eacede0
--- /dev/null
+++ b/gio/gcontextual.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This program 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 of the licence 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
+#error "Only <gio/gio.h> can be included directly."
+#endif
+
+#ifndef __G_CONTEXTUAL_H__
+#define __G_CONTEXTUAL_H__
+
+#include <gio/giotypes.h>
+
+G_BEGIN_DECLS
+
+#define G_TYPE_CONTEXTUAL (g_contextual_get_type ())
+#define G_CONTEXTUAL(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
+ G_TYPE_CONTEXTUAL, GContextual))
+#define G_IS_CONTEXTUAL(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
+ G_TYPE_CONTEXTUAL))
+#define G_CONTEXTUAL_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), \
+ G_TYPE_CONTEXTUAL, GContextualInterface))
+
+typedef struct _GContextualInterface GContextualInterface;
+
+/**
+ * GContextualInterface:
+ * @push_context: set the context that will be used for future calls
+ * @pop_context: reverse the effect of a prior call to push_context
+ *
+ * Since: 2.26
+ */
+struct _GContextualInterface
+{
+ GTypeInterface g_iface;
+
+ void (* push_context) (GContextual *contextual,
+ GVariant *context);
+ void (* pop_context) (GContextual *contextual,
+ GVariant *context);
+};
+
+GType g_contextual_get_type (void) G_GNUC_CONST;
+
+void g_contextual_push_context (GContextual *contextual,
+ GVariant *context);
+
+void g_contextual_pop_context (GContextual *contextual,
+ GVariant *context);
+
+G_END_DECLS
+
+#endif /* __G_CONTEXTUAL_H__ */
diff --git a/gio/gio.h b/gio/gio.h
index db1f13b..b21bba4 100644
--- a/gio/gio.h
+++ b/gio/gio.h
@@ -40,6 +40,7 @@
#include <gio/gcancellable.h>
#include <gio/gcharsetconverter.h>
#include <gio/gcontenttype.h>
+#include <gio/gcontextual.h>
#include <gio/gconverter.h>
#include <gio/gconverterinputstream.h>
#include <gio/gconverteroutputstream.h>
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 53dd90f..3d1069e 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -1925,3 +1925,11 @@ g_simple_action_new_stateful
g_simple_action_set_enabled
#endif
#endif
+
+#if IN_HEADER(__G_CONTEXTUAL_H__)
+#if IN_FILE(__G_CONTEXTUAL_C__)
+g_contextual_get_type
+g_contextual_push_context
+g_contextual_pop_context
+#endif
+#endif
diff --git a/gio/giotypes.h b/gio/giotypes.h
index ecd1dc0..9d084ed 100644
--- a/gio/giotypes.h
+++ b/gio/giotypes.h
@@ -47,6 +47,7 @@ typedef struct _GSimplePermission GSimplePermission;
typedef struct _GZlibCompressor GZlibCompressor;
typedef struct _GZlibDecompressor GZlibDecompressor;
+typedef struct _GContextual GContextual;
typedef struct _GSimpleActionGroup GSimpleActionGroup;
typedef struct _GActionGroup GActionGroup;
typedef struct _GSimpleAction GSimpleAction;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]