Merge pull request #2 from bradbishop/dbus-service

Sample python-dbus, fix Makefile samples.
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 0000000..9e757bc
--- /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-fan/files/Makefile b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-fan/files/Makefile
index b8f103d..8ca27e4 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-fan/files/Makefile
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-fan/files/Makefile
@@ -6,9 +6,9 @@
 LIBS += $(shell pkg-config --libs $(DEPPKGS))
 
 %.o : %.c
-	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
+	$(CC) -c $^ $(CFLAGS) $(INCLUDES) -o $@
 $(EXE): $(OBJS)
-	$(CC) $(LDFLAGS) $(LIBS) $^ -o $@
+	$(CC) $^ $(LDFLAGS) $(LDFLAGS) -o $@
 clean:
 	rm -f $(OBJS) $(EXE) *.o *.d
 distclean: clean
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 6517af0..0000000
--- 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 8076132..0000000
--- 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 0000000..3ef8e85
--- /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 0000000..1c6c505
--- /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 0000000..cd488d5
--- /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 3e4541d..0ea5355 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 @@
 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