summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-07-28 16:15:54 +0200
committerinfirit <[email protected]>2014-07-28 16:15:54 +0200
commit7ae5c8ac22ae22bb03e338d7b9bc3895b0902d56 (patch)
tree1fc6c17de638c876bc98c7b25cd61aa7a732c8d6 /src
parent9bc2242b445893389e0cc01f7377b522268edb29 (diff)
downloadeom-7ae5c8ac22ae22bb03e338d7b9bc3895b0902d56.tar.bz2
eom-7ae5c8ac22ae22bb03e338d7b9bc3895b0902d56.tar.xz
Use G_DEFINE_INTERFACE for EomMetadataReader
Based pm eog commit 200ff4ea06b05554c349d5321f25b087c078cf33 From Felix Riemann <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/eom-metadata-reader.c88
1 files changed, 34 insertions, 54 deletions
diff --git a/src/eom-metadata-reader.c b/src/eom-metadata-reader.c
index 702f357..187cb06 100644
--- a/src/eom-metadata-reader.c
+++ b/src/eom-metadata-reader.c
@@ -28,21 +28,7 @@
#include "eom-metadata-reader-png.h"
#include "eom-debug.h"
-
-GType
-eom_metadata_reader_get_type (void)
-{
- static GType reader_type = 0;
-
- if (G_UNLIKELY (reader_type == 0)) {
- reader_type = g_type_register_static_simple (G_TYPE_INTERFACE,
- "EomMetadataReader",
- sizeof (EomMetadataReaderInterface),
- NULL, 0, NULL, 0);
- }
-
- return reader_type;
-}
+G_DEFINE_INTERFACE (EomMetadataReader, eom_metadata_reader, G_TYPE_INVALID)
EomMetadataReader*
eom_metadata_reader_new (EomMetadataFileType type)
@@ -85,51 +71,24 @@ eom_metadata_reader_consume (EomMetadataReader *emr, const guchar *buf, guint le
void
eom_metadata_reader_get_exif_chunk (EomMetadataReader *emr, guchar **data, guint *len)
{
- EomMetadataReaderInterface *iface;
-
g_return_if_fail (data != NULL && len != NULL);
- iface = EOM_METADATA_READER_GET_INTERFACE (emr);
-
- if (iface->get_raw_exif) {
- iface->get_raw_exif (emr, data, len);
- } else {
- g_return_if_fail (data != NULL && len != NULL);
-
- *data = NULL;
- *len = 0;
- }
+ EOM_METADATA_READER_GET_INTERFACE (emr)->get_raw_exif (emr, data, len);
}
#ifdef HAVE_EXIF
ExifData*
eom_metadata_reader_get_exif_data (EomMetadataReader *emr)
{
- gpointer exif_data = NULL;
- EomMetadataReaderInterface *iface;
-
- iface = EOM_METADATA_READER_GET_INTERFACE (emr);
-
- if (iface->get_exif_data)
- exif_data = iface->get_exif_data (emr);
-
- return (ExifData *)exif_data;
+ return EOM_METADATA_READER_GET_INTERFACE (emr)->get_exif_data (emr);
}
#endif
#ifdef HAVE_EXEMPI
XmpPtr
-eom_metadata_reader_get_xmp_data (EomMetadataReader *emr )
+eom_metadata_reader_get_xmp_data (EomMetadataReader *emr)
{
- gpointer xmp_data = NULL;
- EomMetadataReaderInterface *iface;
-
- iface = EOM_METADATA_READER_GET_INTERFACE (emr);
-
- if (iface->get_xmp_ptr)
- xmp_data = iface->get_xmp_ptr (emr);
-
- return xmp_data;
+ return EOM_METADATA_READER_GET_INTERFACE (emr)->get_xmp_ptr (emr);
}
#endif
@@ -137,14 +96,35 @@ eom_metadata_reader_get_xmp_data (EomMetadataReader *emr )
cmsHPROFILE
eom_metadata_reader_get_icc_profile (EomMetadataReader *emr)
{
- EomMetadataReaderInterface *iface;
- gpointer profile = NULL;
-
- iface = EOM_METADATA_READER_GET_INTERFACE (emr);
+ return EOM_METADATA_READER_GET_INTERFACE (emr)->get_icc_profile (emr);
+}
+#endif
- if (iface->get_icc_profile)
- profile = iface->get_icc_profile (emr);
+/* Default vfunc that simply clears the output if not overriden by the
+ implementing class. This mimics the old behavour of get_exif_chunk(). */
+static void
+_eom_metadata_reader_default_get_raw_exif (EomMetadataReader *emr,
+ guchar **data, guint *length)
+{
+ g_return_if_fail (data != NULL && length != NULL);
+ *data = NULL;
+ *length = 0;
+}
- return profile;
+/* Default vfunc that simply returns NULL if not overriden by the implementing
+ class. Mimics the old fallback behaviour of the getter functions. */
+static gpointer
+_eom_metadata_reader_default_get_null (EomMetadataReader *emr)
+{
+ return NULL;
+}
+static void
+eom_metadata_reader_default_init (EomMetadataReaderInterface *iface)
+{
+ /* consume and finished are required to be implemented */
+ /* Not-implemented funcs return NULL by default */
+ iface->get_raw_exif = _eom_metadata_reader_default_get_raw_exif;
+ iface->get_exif_data = _eom_metadata_reader_default_get_null;
+ iface->get_icc_profile = _eom_metadata_reader_default_get_null;
+ iface->get_xmp_ptr = _eom_metadata_reader_default_get_null;
}
-#endif