>From caa492290a84bc3a8c3a20c7cb836b49636156b5 Mon Sep 17 00:00:00 2001
From: Stef Walter <stefw@redhat.com>
Date: Fri, 10 Jan 2014 11:08:16 +0100
Subject: [PATCH 5/6] sbus: Generate constants from interface definitions

This is not strictly necessary, but avoids duplicating data
in mulitple places, and makes the interface definitions
benefit dbus callers (a little).

After applying this commit you may need to 'make clean' as
the codegen has changed.
---
 src/monitor/monitor_iface_generated.h         | 22 ++++++++++++++++++++++
 src/providers/data_provider_iface_generated.h | 21 +++++++++++++++++++++
 src/sbus/sbus_codegen                         | 21 +++++++++++++++++++++
 src/tests/sbus_codegen_tests.c                | 15 +++++++++++++++
 src/tests/sbus_codegen_tests_generated.h      | 17 +++++++++++++++++
 5 files changed, 96 insertions(+)

diff --git a/src/monitor/monitor_iface_generated.h b/src/monitor/monitor_iface_generated.h
index cde7749..bd55661 100644
--- a/src/monitor/monitor_iface_generated.h
+++ b/src/monitor/monitor_iface_generated.h
@@ -6,6 +6,28 @@
 #include "sbus/sssd_dbus.h"
 
 /* ------------------------------------------------------------------------
+ * DBus Constants
+ *
+ * Various constants of interface and method names mostly for use by clients
+ */
+
+/* constants for org.freedesktop.sssd.monitor */
+#define MON_SRV_IFACE "org.freedesktop.sssd.monitor"
+#define MON_SRV_IFACE_GETVERSION "getVersion"
+#define MON_SRV_IFACE_REGISTERSERVICE "RegisterService"
+
+/* constants for org.freedesktop.sssd.service */
+#define MON_CLI_IFACE "org.freedesktop.sssd.service"
+#define MON_CLI_IFACE_PING "ping"
+#define MON_CLI_IFACE_RESINIT "resInit"
+#define MON_CLI_IFACE_SHUTDOWN "shutDown"
+#define MON_CLI_IFACE_GOOFFLINE "goOffline"
+#define MON_CLI_IFACE_RESETOFFLINE "resetOffline"
+#define MON_CLI_IFACE_ROTATELOGS "rotateLogs"
+#define MON_CLI_IFACE_CLEARMEMCACHE "clearMemcache"
+#define MON_CLI_IFACE_CLEARENUMCACHE "clearEnumCache"
+
+/* ------------------------------------------------------------------------
  * DBus Vtable handler structures
  *
  * These structures are filled in by implementors of the different
diff --git a/src/providers/data_provider_iface_generated.h b/src/providers/data_provider_iface_generated.h
index 0851964..fc37aa8 100644
--- a/src/providers/data_provider_iface_generated.h
+++ b/src/providers/data_provider_iface_generated.h
@@ -6,6 +6,27 @@
 #include "sbus/sssd_dbus.h"
 
 /* ------------------------------------------------------------------------
+ * DBus Constants
+ *
+ * Various constants of interface and method names mostly for use by clients
+ */
+
+/* constants for org.freedesktop.sssd.dataprovider */
+#define DATA_PROVIDER_IFACE "org.freedesktop.sssd.dataprovider"
+#define DATA_PROVIDER_IFACE_REGISTERSERVICE "RegisterService"
+#define DATA_PROVIDER_IFACE_PAMHANDLER "pamHandler"
+#define DATA_PROVIDER_IFACE_SUDOHANDLER "sudoHandler"
+#define DATA_PROVIDER_IFACE_AUTOFSHANDLER "autofsHandler"
+#define DATA_PROVIDER_IFACE_HOSTHANDLER "hostHandler"
+#define DATA_PROVIDER_IFACE_GETDOMAINS "getDomains"
+#define DATA_PROVIDER_IFACE_GETACCOUNTINFO "getAccountInfo"
+
+/* constants for org.freedesktop.sssd.dataprovider_rev */
+#define DATA_PROVIDER_REV_IFACE "org.freedesktop.sssd.dataprovider_rev"
+#define DATA_PROVIDER_REV_IFACE_UPDATECACHE "updateCache"
+#define DATA_PROVIDER_REV_IFACE_INITGRCHECK "initgrCheck"
+
+/* ------------------------------------------------------------------------
  * DBus Vtable handler structures
  *
  * These structures are filled in by implementors of the different
diff --git a/src/sbus/sbus_codegen b/src/sbus/sbus_codegen
index 86aeff0..d2fe507 100755
--- a/src/sbus/sbus_codegen
+++ b/src/sbus/sbus_codegen
@@ -295,6 +295,17 @@ def header_vtable(iface, methods):
 
     out("};")
 
+def header_constants(iface):
+    out("")
+    out("/* constants for %s */", iface.name)
+    out("#define %s \"%s\"", iface.c_name().upper(), iface.name)
+    for meth in iface.methods:
+        out("#define %s \"%s\"", meth.fq_c_name().upper(), meth.name)
+    for sig in iface.signals:
+        out("#define %s \"%s\"", sig.fq_c_name().upper(), sig.name)
+    for prop in iface.properties:
+        out("#define %s \"%s\"", prop.fq_c_name().upper(), prop.name)
+
 def generate_header(ifaces, filename):
     basename = os.path.basename(filename)
     guard = "__%s__" % re.sub(r'([^_A-Z0-9])', "_", basename.upper())
@@ -308,6 +319,16 @@ def generate_header(ifaces, filename):
 
     out("")
     out("/* ------------------------------------------------------------------------")
+    out(" * DBus Constants")
+    out(" *")
+    out(" * Various constants of interface and method names mostly for use by clients")
+    out(" */")
+
+    for iface in ifaces:
+        header_constants(iface)
+
+    out("")
+    out("/* ------------------------------------------------------------------------")
     out(" * DBus Vtable handler structures")
     out(" *")
     out(" * These structures are filled in by implementors of the different")
diff --git a/src/tests/sbus_codegen_tests.c b/src/tests/sbus_codegen_tests.c
index 39856fa..7386756 100644
--- a/src/tests/sbus_codegen_tests.c
+++ b/src/tests/sbus_codegen_tests.c
@@ -144,6 +144,20 @@ START_TEST(test_vtable)
 }
 END_TEST
 
+START_TEST(test_constants)
+{
+    ck_assert_str_eq(COM_PLANETEXPRESS_SHIP, "com.planetexpress.Ship");
+    ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_MOVEUNIVERSE, "MoveUniverse");
+    ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_CRASH_NOW, "Crash");
+    ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_BECAMESENTIENT, "BecameSentient");
+    ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_COLOR, "Color");
+
+    /* constants for com.planetexpress.Pilot */
+    ck_assert_str_eq(TEST_PILOT, "com.planetexpress.Pilot");
+    ck_assert_str_eq(TEST_PILOT_FULLNAME, "FullName");
+}
+END_TEST
+
 Suite *create_suite(void)
 {
     Suite *s = suite_create("sbus_codegen");
@@ -156,6 +170,7 @@ Suite *create_suite(void)
     tcase_add_test(tc, test_properties);
     tcase_add_test(tc, test_signals);
     tcase_add_test(tc, test_vtable);
+    tcase_add_test(tc, test_constants);
 
     /* Add all test cases to the test suite */
     suite_add_tcase(s, tc);
diff --git a/src/tests/sbus_codegen_tests_generated.h b/src/tests/sbus_codegen_tests_generated.h
index 3f76215..f41eca7 100644
--- a/src/tests/sbus_codegen_tests_generated.h
+++ b/src/tests/sbus_codegen_tests_generated.h
@@ -6,6 +6,23 @@
 #include "sbus/sssd_dbus.h"
 
 /* ------------------------------------------------------------------------
+ * DBus Constants
+ *
+ * Various constants of interface and method names mostly for use by clients
+ */
+
+/* constants for com.planetexpress.Ship */
+#define COM_PLANETEXPRESS_SHIP "com.planetexpress.Ship"
+#define COM_PLANETEXPRESS_SHIP_MOVEUNIVERSE "MoveUniverse"
+#define COM_PLANETEXPRESS_SHIP_CRASH_NOW "Crash"
+#define COM_PLANETEXPRESS_SHIP_BECAMESENTIENT "BecameSentient"
+#define COM_PLANETEXPRESS_SHIP_COLOR "Color"
+
+/* constants for com.planetexpress.Pilot */
+#define TEST_PILOT "com.planetexpress.Pilot"
+#define TEST_PILOT_FULLNAME "FullName"
+
+/* ------------------------------------------------------------------------
  * DBus Vtable handler structures
  *
  * These structures are filled in by implementors of the different
-- 
1.8.5.3

