summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@us.ibm.com>2015-09-17 23:39:49 +0300
committerBrad Bishop <bradleyb@us.ibm.com>2015-09-21 16:35:03 +0300
commit3609840037f4056044e9e3d20e19a0182baca1da (patch)
tree291e67671fb7cb6cbb4492349a53b7d3f6846e16
parent69ab6052f9c7d443c8966131b633eb18b3bed23d (diff)
downloadopenbmc-3609840037f4056044e9e3d20e19a0182baca1da.tar.xz
Example D-Bus service implementation
Provided an example service implementation in obmc-phosphor-qemu
-rw-r--r--meta-phosphor/classes/obmc-phosphor-dbus-service.bbclass17
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/Makefile15
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/obmc-phosphor-qemu.c13
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/obmc-phosphor-qemu.py71
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/org.openbmc.examples.services.Service0.conf8
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/org.openbmc.examples.services.Service1.conf8
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/obmc-phosphor-qemu.bb9
7 files changed, 112 insertions, 29 deletions
diff --git a/meta-phosphor/classes/obmc-phosphor-dbus-service.bbclass b/meta-phosphor/classes/obmc-phosphor-dbus-service.bbclass
new file mode 100644
index 000000000..9e757bcaa
--- /dev/null
+++ b/meta-phosphor/classes/obmc-phosphor-dbus-service.bbclass
@@ -0,0 +1,17 @@
+# Common code for applications providing a D-Bus service.
+
+# Class users should define DBUS_SERVICES prior to including.
+
+python() {
+ services = d.getVar('DBUS_SERVICES', True).split()
+ uris = " ".join( [ 'file://' + s + '.conf' for s in services ] )
+ d.appendVar('SRC_URI', uris)
+}
+
+do_install_append() {
+ # install the service configuration files
+ install -d ${D}${sysconfdir}/dbus-1/system.d
+ for s in ${DBUS_SERVICES}; do
+ install ${WORKDIR}/$s.conf ${D}${sysconfdir}/dbus-1/system.d/$s.conf
+ done
+}
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/Makefile b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/Makefile
deleted file mode 100644
index 6517af089..000000000
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-EXE = obmc-phosphor-qemu
-OBJS = $(EXE).o
-PACKAGES= gio-unix-2.0 glib-2.0
-INCLUDES += $(shell pkg-config --cflags $(PACKAGES))
-LIBS += $(shell pkg-config --libs $(PACKAGES))
-CC = $(CROSS_COMPILE)gcc
-
-%.o : %.c
- $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
-$(EXE): $(OBJS)
- $(CC) $(LDFLAGS) $(LIBS) $^ -o $@
-clean:
- rm -f $(OBJS) $(EXE) *.o *.d
-distclean: clean
- rm -f *.c~ *.h~ *.sh~ Makefile~ config.mk~
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/obmc-phosphor-qemu.c b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/obmc-phosphor-qemu.c
deleted file mode 100644
index 8076132eb..000000000
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/obmc-phosphor-qemu.c
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-
-int main(int argc, char *argv[])
-{
- printf("obmc-phosphor-qemu...\n");
-
- while(1)
- sleep(5);
-
- exit(EXIT_SUCCESS);
-}
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/obmc-phosphor-qemu.py b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/obmc-phosphor-qemu.py
new file mode 100644
index 000000000..3ef8e852e
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/obmc-phosphor-qemu.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+
+# Contributors Listed Below - COPYRIGHT 2015
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+
+import sys
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+import gobject
+
+SERVICE_PREFIX = 'org.openbmc.examples.services'
+IFACE_PREFIX = 'org.openbmc.examples.interfaces'
+BASE_OBJ_PATH = '/org/openbmc/examples/'
+
+class SampleObjectOne(dbus.service.Object):
+ def __init__(self, bus, name):
+ super(SampleObjectOne, self).__init__(bus, name)
+
+ @dbus.service.method(IFACE_PREFIX + '.Interface0', 's', 's')
+ def echo(self, val):
+ return str(type(self).__name__) + ": " + val
+
+class SampleObjectTwo(SampleObjectOne):
+ def __init__(self, bus, name):
+ super(SampleObjectTwo, self).__init__(bus, name)
+ self.map = {}
+
+ @dbus.service.method(IFACE_PREFIX + '.Interface1', 'ss', '')
+ def set_a_value_in_the_dict(self, key, value):
+ self.map[key] = value
+
+ @dbus.service.method(IFACE_PREFIX + '.Interface1', 's', 's')
+ def get_a_value_from_the_dict(self, key):
+ return self.map.get(key, "set a value first")
+
+ @dbus.service.method(IFACE_PREFIX + '.Interface1', '', 's')
+ def get_all_values_from_the_dict(self):
+ return " ".join( [ x+ ':' + self.map[x] for x in self.map.keys() ] )
+
+if __name__ == '__main__':
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+ bus = dbus.SystemBus()
+
+ services = []
+ services.append(dbus.service.BusName(SERVICE_PREFIX + '.Service0', bus))
+ services.append(dbus.service.BusName(SERVICE_PREFIX + '.Service1', bus))
+
+ objs = []
+ objs.append(SampleObjectOne(bus, BASE_OBJ_PATH + 'path0/Obj'))
+ objs.append(SampleObjectTwo(bus, BASE_OBJ_PATH + 'path1/Obj'))
+
+ mainloop = gobject.MainLoop()
+
+ print "obmc-phosphor-qemu starting..."
+ mainloop.run()
+
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/org.openbmc.examples.services.Service0.conf b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/org.openbmc.examples.services.Service0.conf
new file mode 100644
index 000000000..1c6c5057e
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/org.openbmc.examples.services.Service0.conf
@@ -0,0 +1,8 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+ <policy user="root">
+ <allow own="org.openbmc.examples.services.Service0"/>
+ <allow send_destination="org.openbmc.examples.services.Service0"/>
+ </policy>
+</busconfig>
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/org.openbmc.examples.services.Service1.conf b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/org.openbmc.examples.services.Service1.conf
new file mode 100644
index 000000000..cd488d588
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/org.openbmc.examples.services.Service1.conf
@@ -0,0 +1,8 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+ <policy user="root">
+ <allow own="org.openbmc.examples.services.Service1"/>
+ <allow send_destination="org.openbmc.examples.services.Service1"/>
+ </policy>
+</busconfig>
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/obmc-phosphor-qemu.bb b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/obmc-phosphor-qemu.bb
index 3e4541d13..0ea535525 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/obmc-phosphor-qemu.bb
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/obmc-phosphor-qemu.bb
@@ -2,4 +2,11 @@ SUMMARY = "Phosphor OpenBMC BSP Example Application"
DESCRIPTION = "Phosphor OpenBMC QEMU BSP example implementation."
PR = "r1"
-inherit obmc-phosphor-c-daemon
+inherit obmc-phosphor-py-daemon
+
+DBUS_SERVICES = " \
+ org.openbmc.examples.services.Service0 \
+ org.openbmc.examples.services.Service1 \
+ "
+
+inherit obmc-phosphor-dbus-service