summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta-phosphor/classes/obmc-phosphor-sdbus-service.bbclass9
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/Makefile17
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/obmc-phosphor-example-sdbus.c117
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/obmc-phosphor-example-sdbus.service8
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/org.openbmc.examples.SDBusService0.conf8
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/org.openbmc.examples.SDBusService1.conf8
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/obmc-phosphor-example-sdbus.bb10
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-fan/obmc-phosphor-fand.bb2
-rw-r--r--meta-phosphor/conf/machine/include/sample.inc4
9 files changed, 180 insertions, 3 deletions
diff --git a/meta-phosphor/classes/obmc-phosphor-sdbus-service.bbclass b/meta-phosphor/classes/obmc-phosphor-sdbus-service.bbclass
new file mode 100644
index 000000000..8a9853c6a
--- /dev/null
+++ b/meta-phosphor/classes/obmc-phosphor-sdbus-service.bbclass
@@ -0,0 +1,9 @@
+# Common code for applications providing a D-Bus service using sd-bus bindings.
+
+# Class users should define DBUS_SERVICES prior to including.
+
+DEPENDS += "systemd"
+RDEPENDS_${PN} += "libsystemd"
+
+inherit obmc-phosphor-dbus-service
+inherit obmc-phosphor-c-daemon
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/Makefile b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/Makefile
new file mode 100644
index 000000000..5166fdf59
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/Makefile
@@ -0,0 +1,17 @@
+EXE = obmc-phosphor-example-sdbus
+OBJS = $(EXE).o
+DEPPKGS = libsystemd
+CC ?= $(CROSS_COMPILE)gcc
+INCLUDES += $(shell pkg-config --cflags $(DEPPKGS))
+LIBS += $(shell pkg-config --libs $(DEPPKGS))
+
+%.o : %.c
+ echo $(CFLAGS)
+ echo $(INCLUDES)
+ $(CC) -c $< $(CFLAGS) $(INCLUDES) -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-example-sdbus/files/obmc-phosphor-example-sdbus.c b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/obmc-phosphor-example-sdbus.c
new file mode 100644
index 000000000..a66bb555c
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/obmc-phosphor-example-sdbus.c
@@ -0,0 +1,117 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <systemd/sd-bus.h>
+
+static int method_echo(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
+ char *str;
+ const char *intf = sd_bus_message_get_interface(m),
+ *path = sd_bus_message_get_path(m);
+ sd_bus *bus = sd_bus_message_get_bus(m);
+
+ char response[512] = {0};
+ int r;
+
+ /* Read the parameters */
+ r = sd_bus_message_read(m, "s", &str);
+ if (r < 0) {
+ fprintf(stderr, "Failed to parse parameters: %s\n", strerror(-r));
+ return r;
+ }
+
+ r = sd_bus_emit_signal(bus, path, intf, "MethodInvoked", "ss",
+ "Echo method was invoked", path);
+ if (r < 0) {
+ fprintf(stderr, "Failed to emit signal: %s\n", strerror(-r));
+ return r;
+ }
+
+ strncat(response, path, 128);
+ strcat(response, " says ");
+ strncat(response, str, 128);
+
+ /* Reply with the response */
+ return sd_bus_reply_method_return(m, "s", &response);
+}
+
+static const sd_bus_vtable echo_vtable[] = {
+ SD_BUS_VTABLE_START(0),
+ SD_BUS_METHOD("Echo", "s", "s", method_echo, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_SIGNAL("MethodInvoked", "s", 0),
+ SD_BUS_VTABLE_END
+};
+
+int main(int argc, char *argv[]) {
+ sd_bus_slot *slot = NULL;
+ sd_bus *bus = NULL;
+ int r;
+ char **acquired = NULL, **activatable = NULL, **i;
+
+ /* Connect to the user bus this time */
+ r = sd_bus_open_system(&bus);
+ if (r < 0) {
+ fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));
+ goto finish;
+ }
+
+ /* Install an object */
+ r = sd_bus_add_object_vtable(bus,
+ &slot,
+ "/org/openbmc/examples/path0/SDBusObj", /* object path */
+ "org.openbmc.examples.Echo", /* interface name */
+ echo_vtable,
+ NULL);
+ if (r < 0) {
+ fprintf(stderr, "Failed to issue method call: %s\n", strerror(-r));
+ goto finish;
+ }
+
+ /* Install an object */
+ r = sd_bus_add_object_vtable(bus,
+ &slot,
+ "/org/openbmc/examples/path1/SDBusObj", /* object path */
+ "org.openbmc.examples.Echo", /* interface name */
+ echo_vtable,
+ NULL);
+ if (r < 0) {
+ fprintf(stderr, "Failed to issue method call: %s\n", strerror(-r));
+ goto finish;
+ }
+
+ /* Take a well-known service name so that clients can find us */
+ r = sd_bus_request_name(bus, "org.openbmc.examples.SDBusService0", 0);
+ if (r < 0) {
+ fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-r));
+ goto finish;
+ }
+
+ r = sd_bus_request_name(bus, "org.openbmc.examples.SDBusService1", 0);
+ if (r < 0) {
+ fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-r));
+ goto finish;
+ }
+
+ for (;;) {
+ /* Process requests */
+ r = sd_bus_process(bus, NULL);
+ if (r < 0) {
+ fprintf(stderr, "Failed to process bus: %s\n", strerror(-r));
+ goto finish;
+ }
+ if (r > 0) /* we processed a request, try to process another one, right-away */
+ continue;
+
+ /* Wait for the next request to process */
+ r = sd_bus_wait(bus, (uint64_t) -1);
+ if (r < 0) {
+ fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r));
+ goto finish;
+ }
+ }
+
+finish:
+ sd_bus_slot_unref(slot);
+ sd_bus_unref(bus);
+
+ return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/obmc-phosphor-example-sdbus.service b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/obmc-phosphor-example-sdbus.service
new file mode 100644
index 000000000..dcce7326b
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/obmc-phosphor-example-sdbus.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Phosphor OpenBMC QEMU application example
+
+[Service]
+ExecStart=/usr/sbin/obmc-phosphor-example-sdbus
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/org.openbmc.examples.SDBusService0.conf b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/org.openbmc.examples.SDBusService0.conf
new file mode 100644
index 000000000..45af4f4b6
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/org.openbmc.examples.SDBusService0.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.SDBusService0"/>
+ <allow send_destination="org.openbmc.examples.SDBusService0"/>
+ </policy>
+</busconfig>
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/org.openbmc.examples.SDBusService1.conf b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/org.openbmc.examples.SDBusService1.conf
new file mode 100644
index 000000000..5a7bfb84e
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/files/org.openbmc.examples.SDBusService1.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.SDBusService1"/>
+ <allow send_destination="org.openbmc.examples.SDBusService1"/>
+ </policy>
+</busconfig>
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/obmc-phosphor-example-sdbus.bb b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/obmc-phosphor-example-sdbus.bb
new file mode 100644
index 000000000..373500747
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/obmc-phosphor-example-sdbus.bb
@@ -0,0 +1,10 @@
+SUMMARY = "Phosphor OpenBMC BSP Example Application"
+DESCRIPTION = "Phosphor OpenBMC QEMU BSP example implementation."
+PR = "r1"
+
+DBUS_SERVICES = " \
+ org.openbmc.examples.SDBusService0 \
+ org.openbmc.examples.SDBusService1 \
+ "
+
+inherit obmc-phosphor-sdbus-service
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-fan/obmc-phosphor-fand.bb b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-fan/obmc-phosphor-fand.bb
index c83e825fb..13c4b70aa 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-fan/obmc-phosphor-fand.bb
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-fan/obmc-phosphor-fand.bb
@@ -3,4 +3,4 @@ DESCRIPTION = "Phosphor OpenBMC fan management reference implementation."
PR = "r1"
inherit obmc-phosphor-fan-mgmt
-inherit obmc-phosphor-c-daemon
+inherit obmc-phosphor-sdbus-service
diff --git a/meta-phosphor/conf/machine/include/sample.inc b/meta-phosphor/conf/machine/include/sample.inc
index 3b67e8d3d..89ad0ece8 100644
--- a/meta-phosphor/conf/machine/include/sample.inc
+++ b/meta-phosphor/conf/machine/include/sample.inc
@@ -6,10 +6,10 @@ OBMC_MACHINE_FEATURES += "\
"
VIRTUAL-RUNTIME_obmc-phosphor-fan-ctl = " \
- obmc-phosphor-example-pydbus \
+ obmc-phosphor-example-sdbus \
"
VIRTUAL-RUNTIME_obmc-phosphor-sensor-ctl = " \
- obmc-phosphor-example-pydbus \
+ obmc-phosphor-example-sdbus \
"
VIRTUAL-RUNTIME_obmc-phosphor-chassis-ctl = " \
obmc-phosphor-example-pydbus \
OpenPOWER on IntegriCloud