]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
epg: 'Template' updating EPG complex object (#4441).
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Wed, 20 Sep 2017 00:57:11 +0000 (01:57 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 9 Oct 2017 14:15:05 +0000 (16:15 +0200)
The _epg_object_set_lang_str has logic for setting lang_str_t.
We can re-use this logic for other objects in the future
(such as string_lists) so create a macro to abstract out
the destroy, compare, and copy functionality so the rest of
the logic can be re-used.

src/epg.c

index ab5a7dc47338a57d2968cddbe16ae27d9c7139f0..a15037dca2aedd5afb55a2e0c2229bbd077b701c 100644 (file)
--- a/src/epg.c
+++ b/src/epg.c
@@ -35,6 +35,7 @@
 #include "epggrab.h"
 #include "imagecache.h"
 #include "notify.h"
+#include "string_list.h"
 
 /* Broadcast hashing */
 #define EPG_HASH_WIDTH 1024
@@ -335,30 +336,36 @@ static int _epg_object_set_str
   return save;
 }
 
-static int _epg_object_set_lang_str
-  ( void *o, lang_str_t **old, const lang_str_t *str,
-    uint32_t *changed, uint32_t cflag )
-{
-  if (!o) return 0;
-  if (changed) *changed |= cflag;
-  if (!*old) {
-    if (!str)
-      return 0;
-  }
-  if (!str) {
-    lang_str_destroy(*old);
-    *old = NULL;
-    _epg_object_set_updated(o);
-    return 1;
-  }
-  if (lang_str_compare(*old, str)) {
-    lang_str_destroy(*old);
-    *old = lang_str_copy(str);
-    _epg_object_set_updated(o);
-    return 1;
-  }
-  return 0;
-}
+/* "Template" for setting objects. */
+#define EPG_OBJECT_SET_FN(FNNAME,TYPE,DESTROY,COMPARE,COPY) \
+static int FNNAME \
+  ( void *o, TYPE **old, const TYPE *new, \
+    uint32_t *changed, uint32_t cflag ) \
+{ \
+  if (!o) return 0; \
+  if (changed) *changed |= cflag; \
+  if (!*old) { \
+    if (!new) \
+      return 0; \
+  } \
+  if (!new) { \
+    DESTROY(*old); \
+    *old = NULL; \
+    _epg_object_set_updated(o); \
+    return 1; \
+  } \
+  if (COMPARE(*old, new)) { \
+    DESTROY(*old); \
+    *old = COPY(new); \
+    _epg_object_set_updated(o); \
+    return 1; \
+  } \
+  return 0; \
+}
+
+
+EPG_OBJECT_SET_FN(_epg_object_set_lang_str,    lang_str_t,    lang_str_destroy,    lang_str_compare,    lang_str_copy)
+#undef EPG_OBJECT_SET_FN
 
 static int _epg_object_set_u8
   ( void *o, uint8_t *old, const uint8_t nval,