control_dbus.c (fac3689e77d37aca9c85dafabf921a847b1c4e02) control_dbus.c (68a24c9ea5ce11c87fab22a3f4648c7d88c98fee)
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include <assert.h>
4#include <errno.h>
5#include <stdlib.h>
6#include <systemd/sd-bus.h>
7
8#include "common.h"
9#include "dbus.h"
10#include "control_dbus.h"
11#include "mboxd.h"
12
13typedef int (*control_action)(struct mbox_context *context);
14
15static int control_dbus_directive(sd_bus_message *m, void *userdata,
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include <assert.h>
4#include <errno.h>
5#include <stdlib.h>
6#include <systemd/sd-bus.h>
7
8#include "common.h"
9#include "dbus.h"
10#include "control_dbus.h"
11#include "mboxd.h"
12
13typedef int (*control_action)(struct mbox_context *context);
14
15static int control_dbus_directive(sd_bus_message *m, void *userdata,
16 sd_bus_error *ret_error,
16 sd_bus_error *ret_error __attribute__((unused)),
17 control_action action)
18{
19 struct mbox_context *context;
20 sd_bus_message *n;
21 int rc;
22
23 if (!action) {
24 MSG_ERR("No action provided\n");
17 control_action action)
18{
19 struct mbox_context *context;
20 sd_bus_message *n;
21 int rc;
22
23 if (!action) {
24 MSG_ERR("No action provided\n");
25 return -EINVAL;
25 return -EINVAL;
26 }
27
28 context = (struct mbox_context *) userdata;
29 if (!context) {
30 MSG_ERR("DBUS Internal Error\n");
31 return -EINVAL;
32 }
33

--- 40 unchanged lines hidden (view full) ---

74
75static int control_dbus_suspend(sd_bus_message *m, void *userdata,
76 sd_bus_error *ret_error)
77{
78 return control_dbus_directive(m, userdata, ret_error, control_suspend);
79}
80
81static int control_dbus_resume(sd_bus_message *m, void *userdata,
26 }
27
28 context = (struct mbox_context *) userdata;
29 if (!context) {
30 MSG_ERR("DBUS Internal Error\n");
31 return -EINVAL;
32 }
33

--- 40 unchanged lines hidden (view full) ---

74
75static int control_dbus_suspend(sd_bus_message *m, void *userdata,
76 sd_bus_error *ret_error)
77{
78 return control_dbus_directive(m, userdata, ret_error, control_suspend);
79}
80
81static int control_dbus_resume(sd_bus_message *m, void *userdata,
82 sd_bus_error *ret_error)
82 sd_bus_error *ret_error __attribute__((unused)))
83{
84 struct mbox_context *context;
85 sd_bus_message *n;
86 bool modified;
87 int rc;
88
89 context = (struct mbox_context *) userdata;
90 if (!context) {

--- 16 unchanged lines hidden (view full) ---

107 MSG_ERR("sd_bus_message_new_method_return failed: %d\n", rc);
108 return rc;
109 }
110
111 return sd_bus_send(NULL, n, NULL);
112}
113
114static int control_dbus_set_backend(sd_bus_message *m, void *userdata,
83{
84 struct mbox_context *context;
85 sd_bus_message *n;
86 bool modified;
87 int rc;
88
89 context = (struct mbox_context *) userdata;
90 if (!context) {

--- 16 unchanged lines hidden (view full) ---

107 MSG_ERR("sd_bus_message_new_method_return failed: %d\n", rc);
108 return rc;
109 }
110
111 return sd_bus_send(NULL, n, NULL);
112}
113
114static int control_dbus_set_backend(sd_bus_message *m, void *userdata,
115 sd_bus_error *ret_error)
115 sd_bus_error *ret_error __attribute__((unused)))
116{
117 struct mbox_context *context;
118 struct backend backend;
119 sd_bus_message *n;
120 const char *name;
121 int rc;
122
123 context = (struct mbox_context *) userdata;

--- 68 unchanged lines hidden (view full) ---

192 return rc;
193 }
194
195 rc = sd_bus_send(NULL, n, NULL);
196 sd_bus_message_unref(n);
197 return rc;
198}
199
116{
117 struct mbox_context *context;
118 struct backend backend;
119 sd_bus_message *n;
120 const char *name;
121 int rc;
122
123 context = (struct mbox_context *) userdata;

--- 68 unchanged lines hidden (view full) ---

192 return rc;
193 }
194
195 rc = sd_bus_send(NULL, n, NULL);
196 sd_bus_message_unref(n);
197 return rc;
198}
199
200static int control_dbus_get_u8(sd_bus *bus, const char *path,
201 const char *interface, const char *property,
200static int control_dbus_get_u8(sd_bus *bus __attribute__((unused)),
201 const char *path,
202 const char *interface __attribute__((unused)),
203 const char *property,
202 sd_bus_message *reply, void *userdata,
204 sd_bus_message *reply, void *userdata,
203 sd_bus_error *ret_error)
205 sd_bus_error *ret_error __attribute__((unused)))
204{
205 struct mbox_context *context = userdata;
206 uint8_t value;
207
208 assert(!strcmp(MBOX_DBUS_OBJECT, path));
209
210 if (!strcmp("DaemonState", property)) {
211 value = control_daemon_state(context);

--- 46 unchanged lines hidden ---
206{
207 struct mbox_context *context = userdata;
208 uint8_t value;
209
210 assert(!strcmp(MBOX_DBUS_OBJECT, path));
211
212 if (!strcmp("DaemonState", property)) {
213 value = control_daemon_state(context);

--- 46 unchanged lines hidden ---