[Spice-devel] [PATCH spice-gtk v2 1/4] Glib applications only include spice-client.h

Jonathon Jongsma jjongsma at redhat.com
Thu Sep 24 15:20:26 PDT 2015


Generate a compiler error if an application attempts to include a
different header.
---
 doc/reference/Makefile.am | 2 +-
 src/Makefile.am           | 1 +
 src/channel-cursor.c      | 2 +-
 src/channel-cursor.h      | 4 ++++
 src/channel-display.c     | 2 +-
 src/channel-display.h     | 4 ++++
 src/channel-inputs.c      | 2 +-
 src/channel-inputs.h      | 4 ++++
 src/channel-main.c        | 2 +-
 src/channel-main.h        | 4 ++++
 src/channel-playback.c    | 2 +-
 src/channel-playback.h    | 4 ++++
 src/channel-port.c        | 2 +-
 src/channel-port.h        | 4 ++++
 src/channel-record.c      | 2 +-
 src/channel-record.h      | 4 ++++
 src/channel-smartcard.c   | 2 +-
 src/channel-smartcard.h   | 4 ++++
 src/channel-usbredir.c    | 2 +-
 src/channel-usbredir.h    | 4 ++++
 src/channel-webdav.c      | 2 +-
 src/channel-webdav.h      | 4 ++++
 src/smartcard-manager.c   | 2 +-
 src/smartcard-manager.h   | 4 ++++
 src/spice-audio.c         | 2 +-
 src/spice-audio.h         | 4 ++++
 src/spice-channel.c       | 2 +-
 src/spice-channel.h       | 4 ++++
 src/spice-client.h        | 4 ++++
 src/spice-option.h        | 4 ++++
 src/spice-session.c       | 2 +-
 src/spice-session.h       | 4 ++++
 src/spice-types.h         | 4 ++++
 src/spice-uri.c           | 2 +-
 src/spice-uri.h           | 4 ++++
 src/spice-util.c          | 2 +-
 src/spice-version.h.in    | 4 ++++
 src/usb-device-manager.c  | 2 +-
 src/usb-device-manager.h  | 4 ++++
 39 files changed, 99 insertions(+), 18 deletions(-)

diff --git a/doc/reference/Makefile.am b/doc/reference/Makefile.am
index ed94138..2d13863 100644
--- a/doc/reference/Makefile.am
+++ b/doc/reference/Makefile.am
@@ -54,7 +54,7 @@ IGNORE_HFILES=					\
 	$(NULL)
 
 # CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library.
-GTKDOC_CFLAGS = -I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/src -I$(top_builddir)/src $(SPICE_GLIB_CFLAGS) $(SPICE_GTK_CFLAGS) $(COMMON_CFLAGS)
+GTKDOC_CFLAGS = -I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/src -I$(top_builddir)/src $(SPICE_GLIB_CFLAGS) $(SPICE_GTK_CFLAGS) $(COMMON_CFLAGS) -DSPICE_COMPILATION
 GTKDOC_LIBS = $(top_builddir)/src/libspice-client-glib-2.0.la $(top_builddir)/src/libspice-client-gtk-$(SPICE_GTK_API_VERSION).la $(GTK_LIBS)
 
 include $(top_srcdir)/gtk-doc.make
diff --git a/src/Makefile.am b/src/Makefile.am
index cf02198..a035a2a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,6 +79,7 @@ endif
 KEYMAP_GEN = $(srcdir)/keymap-gen.pl
 
 SPICE_COMMON_CPPFLAGS =						\
+	-DSPICE_COMPILATION						\
 	-DG_LOG_DOMAIN=\"GSpice\"				\
 	-DSPICE_NO_DEPRECATED					\
 	-DSPICE_GTK_LOCALEDIR=\"${SPICE_GTK_LOCALEDIR}\"	\
diff --git a/src/channel-cursor.c b/src/channel-cursor.c
index e6514a2..6a9d60a 100644
--- a/src/channel-cursor.c
+++ b/src/channel-cursor.c
@@ -32,7 +32,7 @@
  * @section_id:
  * @see_also: #SpiceChannel, and the GTK widget #SpiceDisplay
  * @stability: Stable
- * @include: channel-cursor.h
+ * @include: spice-client.h
  *
  * The Spice protocol defines a set of messages for controlling cursor
  * shape and position on the remote display area. The cursor changes
diff --git a/src/channel-cursor.h b/src/channel-cursor.h
index 5b5ed47..df64ac2 100644
--- a/src/channel-cursor.h
+++ b/src/channel-cursor.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_CURSOR_CHANNEL_H__
 #define __SPICE_CLIENT_CURSOR_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include "spice-client.h"
 
 G_BEGIN_DECLS
diff --git a/src/channel-display.c b/src/channel-display.c
index c3a504f..9f9d62a 100644
--- a/src/channel-display.c
+++ b/src/channel-display.c
@@ -46,7 +46,7 @@
  * @section_id:
  * @see_also: #SpiceChannel, and the GTK widget #SpiceDisplay
  * @stability: Stable
- * @include: channel-display.h
+ * @include: spice-client.h
  *
  * A class that handles the rendering of the remote display and inform
  * of its updates.
diff --git a/src/channel-display.h b/src/channel-display.h
index 88e60d9..8904d68 100644
--- a/src/channel-display.h
+++ b/src/channel-display.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_DISPLAY_CHANNEL_H__
 #define __SPICE_CLIENT_DISPLAY_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include "spice-client.h"
 
 G_BEGIN_DECLS
diff --git a/src/channel-inputs.c b/src/channel-inputs.c
index 93cfd2e..7572bff 100644
--- a/src/channel-inputs.c
+++ b/src/channel-inputs.c
@@ -28,7 +28,7 @@
  * @section_id:
  * @see_also: #SpiceChannel, and the GTK widget #SpiceDisplay
  * @stability: Stable
- * @include: channel-inputs.h
+ * @include: spice-client.h
  *
  * Spice supports sending keyboard key events and keyboard leds
  * synchronization. The key events are sent using
diff --git a/src/channel-inputs.h b/src/channel-inputs.h
index 8933116..0d76ba5 100644
--- a/src/channel-inputs.h
+++ b/src/channel-inputs.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_INPUTS_CHANNEL_H__
 #define __SPICE_CLIENT_INPUTS_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include "spice-client.h"
 
 G_BEGIN_DECLS
diff --git a/src/channel-main.c b/src/channel-main.c
index 6e66401..6701f93 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -39,7 +39,7 @@
  * @section_id:
  * @see_also: #SpiceChannel, and the GTK widget #SpiceDisplay
  * @stability: Stable
- * @include: channel-main.h
+ * @include: spice-client.h
  *
  * The main channel is the Spice session control channel. It handles
  * communication initialization (channels list), migrations, mouse
diff --git a/src/channel-main.h b/src/channel-main.h
index 86bb46b..f0fe57d 100644
--- a/src/channel-main.h
+++ b/src/channel-main.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_MAIN_CHANNEL_H__
 #define __SPICE_CLIENT_MAIN_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include "spice-client.h"
 
 G_BEGIN_DECLS
diff --git a/src/channel-playback.c b/src/channel-playback.c
index 020f809..a124cbb 100644
--- a/src/channel-playback.c
+++ b/src/channel-playback.c
@@ -33,7 +33,7 @@
  * @section_id:
  * @see_also: #SpiceChannel, and #SpiceAudio
  * @stability: Stable
- * @include: channel-playback.h
+ * @include: spice-client.h
  *
  * #SpicePlaybackChannel class handles an audio playback stream. The
  * audio data is received via #SpicePlaybackChannel::playback-data
diff --git a/src/channel-playback.h b/src/channel-playback.h
index 9cf68cf..36851ca 100644
--- a/src/channel-playback.h
+++ b/src/channel-playback.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_PLAYBACK_CHANNEL_H__
 #define __SPICE_CLIENT_PLAYBACK_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include "spice-client.h"
 
 G_BEGIN_DECLS
diff --git a/src/channel-port.c b/src/channel-port.c
index 222074c..6e01caa 100644
--- a/src/channel-port.c
+++ b/src/channel-port.c
@@ -30,7 +30,7 @@
  * @section_id:
  * @see_also: #SpiceChannel
  * @stability: Stable
- * @include: channel-port.h
+ * @include: spice-client.h
  *
  * A Spice port channel carry arbitrary data between the Spice client
  * and the Spice server. It may be used to provide additional
diff --git a/src/channel-port.h b/src/channel-port.h
index 08c15dc..158e18a 100644
--- a/src/channel-port.h
+++ b/src/channel-port.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_PORT_CHANNEL_H__
 #define __SPICE_CLIENT_PORT_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include <gio/gio.h>
 #include "spice-channel.h"
 
diff --git a/src/channel-record.c b/src/channel-record.c
index a44c860..08269c9 100644
--- a/src/channel-record.c
+++ b/src/channel-record.c
@@ -33,7 +33,7 @@
  * @section_id:
  * @see_also: #SpiceChannel, and #SpiceAudio
  * @stability: Stable
- * @include: channel-record.h
+ * @include: spice-client.h
  *
  * #SpiceRecordChannel class handles an audio recording stream. The
  * audio stream should start when #SpiceRecordChannel::record-start is
diff --git a/src/channel-record.h b/src/channel-record.h
index 20a9ad3..60c146c 100644
--- a/src/channel-record.h
+++ b/src/channel-record.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_RECORD_CHANNEL_H__
 #define __SPICE_CLIENT_RECORD_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include "spice-client.h"
 
 G_BEGIN_DECLS
diff --git a/src/channel-smartcard.c b/src/channel-smartcard.c
index d91c9a0..942f973 100644
--- a/src/channel-smartcard.c
+++ b/src/channel-smartcard.c
@@ -36,7 +36,7 @@
  * @section_id:
  * @see_also: #SpiceSmartcardManager, #SpiceSession
  * @stability: API Stable (channel in development)
- * @include: channel-smartcard.h
+ * @include: spice-client.h
  *
  * The Spice protocol defines a set of messages to forward smartcard
  * information from the Spice client to the VM. This channel handles
diff --git a/src/channel-smartcard.h b/src/channel-smartcard.h
index 28c8b88..a96aa0a 100644
--- a/src/channel-smartcard.h
+++ b/src/channel-smartcard.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_SMARTCARD_CHANNEL_H__
 #define __SPICE_CLIENT_SMARTCARD_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include "spice-client.h"
 
 G_BEGIN_DECLS
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 89f5c9d..c236ee7 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -44,7 +44,7 @@
  * @title: USB Redirection Channel
  * @section_id:
  * @stability: API Stable (channel in development)
- * @include: channel-usbredir.h
+ * @include: spice-client.h
  *
  * The Spice protocol defines a set of messages to redirect USB devices
  * from the Spice client to the VM. This channel handles these messages.
diff --git a/src/channel-usbredir.h b/src/channel-usbredir.h
index 0cc4fbf..72368fc 100644
--- a/src/channel-usbredir.h
+++ b/src/channel-usbredir.h
@@ -21,6 +21,10 @@
 #ifndef __SPICE_CLIENT_USBREDIR_CHANNEL_H__
 #define __SPICE_CLIENT_USBREDIR_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include "spice-client.h"
 
 G_BEGIN_DECLS
diff --git a/src/channel-webdav.c b/src/channel-webdav.c
index 06db70d..e72c92c 100644
--- a/src/channel-webdav.c
+++ b/src/channel-webdav.c
@@ -33,7 +33,7 @@
  * @section_id:
  * @see_also: #SpiceChannel
  * @stability: Stable
- * @include: channel-webdav.h
+ * @include: spice-client.h
  *
  * The "webdav" channel exports a directory to the guest for file
  * manipulation (read/write/copy etc). The underlying protocol is
diff --git a/src/channel-webdav.h b/src/channel-webdav.h
index 7940706..fb25763 100644
--- a/src/channel-webdav.h
+++ b/src/channel-webdav.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_WEBDAV_CHANNEL_H__
 #define __SPICE_WEBDAV_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include <gio/gio.h>
 #include "spice-client.h"
 #include "channel-port.h"
diff --git a/src/smartcard-manager.c b/src/smartcard-manager.c
index 0cce42b..8e0d239 100644
--- a/src/smartcard-manager.c
+++ b/src/smartcard-manager.c
@@ -40,7 +40,7 @@
  * @section_id:
  * @see_also:
  * @stability: Stable
- * @include: smartcard-manager.h
+ * @include: spice-client.h
  *
  * #SpiceSmartcardManager monitors smartcard reader plugging/unplugging,
  * and smartcard insertions/removals. It also provides methods to handle
diff --git a/src/smartcard-manager.h b/src/smartcard-manager.h
index 2a7fd48..4cfbeb2 100644
--- a/src/smartcard-manager.h
+++ b/src/smartcard-manager.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_SMARTCARD_MANAGER_H__
 #define __SPICE_SMARTCARD_MANAGER_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 G_BEGIN_DECLS
 
 #include "spice-types.h"
diff --git a/src/spice-audio.c b/src/spice-audio.c
index 3114a0a..75742d7 100644
--- a/src/spice-audio.c
+++ b/src/spice-audio.c
@@ -26,7 +26,7 @@
  * @section_id:
  * @see_also: #SpiceRecordChannel, and #SpicePlaybackChannel
  * @stability: Stable
- * @include: spice-audio.h
+ * @include: spice-client.h
  *
  * A class that handles the playback and record channels for your
  * application, and connect them to the default sound system.
diff --git a/src/spice-audio.h b/src/spice-audio.h
index 0bf625b..5bf487f 100644
--- a/src/spice-audio.h
+++ b/src/spice-audio.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_AUDIO_H__
 #define __SPICE_CLIENT_AUDIO_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include <glib-object.h>
 #include <gio/gio.h>
 #include "spice-util.h"
diff --git a/src/spice-channel.c b/src/spice-channel.c
index 2ce52c7..d459ec4 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -63,7 +63,7 @@ static gboolean channel_connect(SpiceChannel *channel, gboolean tls);
  * @section_id:
  * @see_also: #SpiceSession, #SpiceMainChannel and other channels
  * @stability: Stable
- * @include: spice-channel.h
+ * @include: spice-client.h
  *
  * #SpiceChannel is the base class for the different kind of Spice
  * channel connections, such as #SpiceMainChannel, or
diff --git a/src/spice-channel.h b/src/spice-channel.h
index f465572..6214071 100644
--- a/src/spice-channel.h
+++ b/src/spice-channel.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_CHANNEL_H__
 #define __SPICE_CLIENT_CHANNEL_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 G_BEGIN_DECLS
 
 #include <gio/gio.h>
diff --git a/src/spice-client.h b/src/spice-client.h
index 5a4d838..aaa6775 100644
--- a/src/spice-client.h
+++ b/src/spice-client.h
@@ -22,6 +22,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#define __SPICE_CLIENT_H_INSIDE__
+
 /* spice-protocol */
 #include <spice/enums.h>
 #include <spice/protocol.h>
@@ -88,4 +90,6 @@ GQuark spice_client_error_quark(void);
 
 G_END_DECLS
 
+#undef __SPICE_CLIENT_H_INSIDE__
+
 #endif /* __SPICE_CLIENT_CLIENT_H__ */
diff --git a/src/spice-option.h b/src/spice-option.h
index ce24f65..6675ad2 100644
--- a/src/spice-option.h
+++ b/src/spice-option.h
@@ -18,6 +18,10 @@
 #ifndef SPICE_OPTION_H
 #define SPICE_OPTION_H
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include <glib.h>
 #include "spice-session.h"
 
diff --git a/src/spice-session.c b/src/spice-session.c
index e1d9997..85640a5 100644
--- a/src/spice-session.c
+++ b/src/spice-session.c
@@ -134,7 +134,7 @@ struct _SpiceSessionPrivate {
  * @section_id:
  * @see_also: #SpiceChannel, and the GTK widget #SpiceDisplay
  * @stability: Stable
- * @include: spice-session.h
+ * @include: spice-client.h
  *
  * The #SpiceSession class handles all the #SpiceChannel connections.
  * It's also the class that contains connections informations, such as
diff --git a/src/spice-session.h b/src/spice-session.h
index 56f6959..82662e1 100644
--- a/src/spice-session.h
+++ b/src/spice-session.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_SESSION_H__
 #define __SPICE_CLIENT_SESSION_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include <glib-object.h>
 #include "spice-types.h"
 #include "spice-uri.h"
diff --git a/src/spice-types.h b/src/spice-types.h
index f149094..2d34c71 100644
--- a/src/spice-types.h
+++ b/src/spice-types.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_CLIENT_TYPES_H__
 #define __SPICE_CLIENT_TYPES_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 G_BEGIN_DECLS
 
 /* SpiceSession */
diff --git a/src/spice-uri.c b/src/spice-uri.c
index 82aefdb..e2c5c9a 100644
--- a/src/spice-uri.c
+++ b/src/spice-uri.c
@@ -30,7 +30,7 @@
  * @title: SpiceURI
  * @section_id:
  * @stability: Stable
- * @include: spice-uri.h
+ * @include: spice-client.h
  *
  * A SpiceURI represents a (parsed) URI.
  * Since: 0.24
diff --git a/src/spice-uri.h b/src/spice-uri.h
index 65ffd0a..20685ba 100644
--- a/src/spice-uri.h
+++ b/src/spice-uri.h
@@ -18,6 +18,10 @@
 #ifndef __SPICE_URI_H__
 #define __SPICE_URI_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include <glib-object.h>
 
 G_BEGIN_DECLS
diff --git a/src/spice-util.c b/src/spice-util.c
index b4bc085..84ed94a 100644
--- a/src/spice-util.c
+++ b/src/spice-util.c
@@ -33,7 +33,7 @@
  * @title: Utilities
  * @section_id:
  * @stability: Stable
- * @include: spice-util.h
+ * @include: spice-client.h
  *
  * Various functions for debugging and informational purposes.
  */
diff --git a/src/spice-version.h.in b/src/spice-version.h.in
index 49164f8..373a793 100644
--- a/src/spice-version.h.in
+++ b/src/spice-version.h.in
@@ -18,6 +18,10 @@
 #ifndef __SPICE_VERSION_H__
 #define __SPICE_VERSION_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 /**
  * SECTION:spice-version
  * @short_description: Spice-Gtk version checking
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index 777fdf0..c62f56e 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -64,7 +64,7 @@
  * @section_id:
  * @see_also:
  * @stability: Stable
- * @include: usb-device-manager.h
+ * @include: spice-client.h
  *
  * #SpiceUsbDeviceManager monitors USB redirection channels and USB
  * devices plugging/unplugging. If #SpiceUsbDeviceManager:auto-connect
diff --git a/src/usb-device-manager.h b/src/usb-device-manager.h
index c1e3f76..2e11bb7 100644
--- a/src/usb-device-manager.h
+++ b/src/usb-device-manager.h
@@ -21,6 +21,10 @@
 #ifndef __SPICE_USB_DEVICE_MANAGER_H__
 #define __SPICE_USB_DEVICE_MANAGER_H__
 
+#if !defined(__SPICE_CLIENT_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#error "Only <spice-client.h> can be included directly"
+#endif
+
 #include "spice-client.h"
 #include <gio/gio.h>
 
-- 
2.1.0



More information about the Spice-devel mailing list