Limited example C dbus service and client
PATCH 1/1 Limited example C dbus service and client
daemons/lvmdbusd directory contains a sample service written in C (lvmdbusd.c) and client (example_client.c). The service and client are using auto generated code from gdbus-codegen. This tool uses the api.xml file as input and generates a header file and implementation file to be used for the API.
This sample service at the moment is limited to:
- Retrieving the VGs/PVs/LVs
- Removing a LV
The service is implemented using the lvm2app API, so functionality in what the properties contain is limited to what is available in the library. I choose the API in this example instead of trying to re-work the existing code as the dbus bit is more important than showing the lvm bits at the moment. As this is a service, the implementation is free to change at will as long as the API remains the same.
The client shows how to use the object manager to retrieve all the objects in one shot and to iterate through them. It also has a monitor mode so that signals can be seen when objects get created/deleted/updated etc.
I initially tried to use the existing lvm code and integrate with the client code, but I rejected that approach as the lvm reporting code appears to be quite tightly coupled with the lvm internals which represent the data. Thus the sample client code is more of an example on how to get data using the C dbus API more than fitting it into existing lvm client code.
Disclaimer, this was my first exposure to the C dbus and coding a service & client so I'm not making any suggestions that it's the best use of the APIs or the best overall design. It's just an example.
Note: configure updates were not checked in as the auto updated changes exceed line length for emailing a patch.
Regards,
Tony
--- Makefile.in | 9 +- configure.in | 5 + daemons/Makefile.in | 6 +- daemons/lvmdbusd/Makefile.in | 43 ++ daemons/lvmdbusd/api.xml | 178 +++++++++ daemons/lvmdbusd/example_client.c | 218 +++++++++++ daemons/lvmdbusd/lvmdbusd.c | 765 +++++++++++++++++++++++++++++++++++++ make.tmpl.in | 3 + 8 files changed, 1222 insertions(+), 5 deletions(-) create mode 100644 daemons/lvmdbusd/Makefile.in create mode 100644 daemons/lvmdbusd/api.xml create mode 100644 daemons/lvmdbusd/example_client.c create mode 100644 daemons/lvmdbusd/lvmdbusd.c
Makefile.in +6 -3
@@ -18,7 +18,7 @@ top_builddir = @top_builddir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ -SUBDIRS = conf daemons include lib libdaemon libdm man scripts tools +SUBDIRS = conf include lib libdaemon libdm man scripts tools ifeq ("@UDEV_RULES@", "yes") SUBDIRS += udev
@@ -36,14 +36,17 @@ ifeq ("@PYTHON_BINDINGS@", "yes") SUBDIRS += python endif +# Daemons needs to get built after liblvm for lvmdbusd +SUBDIRS += daemons + ifeq ($(MAKECMDGOALS),clean) SUBDIRS += test endif # FIXME Should use intermediate Makefiles here! ifeq ($(MAKECMDGOALS),distclean) SUBDIRS = conf include man test scripts \ - libdaemon lib tools daemons libdm \ - udev po liblvm python \ + libdaemon lib tools libdm \ + udev po liblvm python daemons \ unit-tests/datastruct unit-tests/mm unit-tests/regex tools.distclean: test.distclean endif
configure.in +5 -0
@@ -799,6 +799,8 @@ if test "$BUILDOPENAIS" = yes; then CHECKCPG=yes fi +PKG_CHECK_MODULES([GIO], [gio-unix-2.0]) + dnl -- Below are checks for libraries common to more than one build. dnl -- Check confdb library.
@@ -1836,6 +1838,8 @@ AC_SUBST(SACKPT_CFLAGS) AC_SUBST(SACKPT_LIBS) AC_SUBST(SALCK_CFLAGS) AC_SUBST(SALCK_LIBS) +AC_SUBST(GIO_CFLAGS) +AC_SUBST(GIO_LIBS) AC_SUBST(SELINUX_LIBS) AC_SUBST(SELINUX_PC) AC_SUBST(SNAPSHOTS)
@@ -1896,6 +1900,7 @@ daemons/dmeventd/plugins/snapshot/Makefile daemons/dmeventd/plugins/thin/Makefile daemons/lvmetad/Makefile daemons/lvmpolld/Makefile +daemons/lvmdbusd/Makefile conf/Makefile conf/example.conf conf/lvmlocal.conf
daemons/Makefile.in +4 -2
@@ -15,7 +15,9 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ -.PHONY: dmeventd clvmd cmirrord lvmetad lvmpolld +.PHONY: dmeventd clvmd cmirrord lvmetad lvmpolld lvmdbusd + +SUBDIRS += lvmdbusd ifneq ("@CLVMD@", "none") SUBDIRS += clvmd
@@ -41,7 +43,7 @@ ifeq ("@BUILD_LVMPOLLD@", "yes") endif ifeq ($(MAKECMDGOALS),distclean) - SUBDIRS = clvmd cmirrord dmeventd lvmetad lvmpolld + SUBDIRS = clvmd cmirrord dmeventd lvmetad lvmpolld lvmdbusd endif include $(top_builddir)/make.tmpl
daemons/lvmdbusd/Makefile.in new file +43 -0
43 lines not on this page · raw message
daemons/lvmdbusd/api.xml new file +178 -0
178 lines not on this page · raw message
daemons/lvmdbusd/example_client.c new file +218 -0
219 lines not on this page · raw message
daemons/lvmdbusd/lvmdbusd.c new file +765 -0
765 lines not on this page · raw message
make.tmpl.in +3 -0
@@ -64,6 +64,9 @@ BLKID_LIBS = @BLKID_LIBS@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@ TESTING = @TESTING@ +GIO_CFLAGS = @GIO_CFLAGS@ +GIO_LIBS = @GIO_LIBS@ + # Setup directory variables prefix = @prefix@ exec_prefix = @exec_prefix@
Signature · 1 line
1.7.1