1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
8 static const char introspection
[] =
9 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
12 " <interface name=\"org.freedesktop.systemd1.Unit\">"
13 " <property name=\"Id\" type=\"s\" access=\"read\"/>"
14 " <property name=\"Description\" type=\"s\" access=\"read\"/>"
15 " <property name=\"LoadState\" type=\"s\" access=\"read\"/>"
16 " <property name=\"ActiveState\" type=\"s\" access=\"read\"/>"
17 " <property name=\"LoadPath\" type=\"s\" access=\"read\"/>"
18 " <property name=\"ActiveEnterTimestamp\" type=\"t\" access=\"read\"/>"
19 " <property name=\"ActiveExitTimestamp\" type=\"t\" access=\"read\"/>"
20 " <property name=\"CanReload\" type=\"b\" access=\"read\"/>"
21 " <property name=\"CanStart\" type=\"b\" access=\"read\"/>"
22 " <property name=\"Job\" type=\"(uo)\" access=\"read\"/>"
24 BUS_PROPERTIES_INTERFACE
25 BUS_INTROSPECTABLE_INTERFACE
28 static int bus_unit_append_id(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
39 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_STRING
, &id
))
45 static int bus_unit_append_description(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
54 d
= unit_description(u
);
56 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_STRING
, &d
))
62 static int bus_unit_append_load_state(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
71 state
= unit_load_state_to_string(u
->meta
.load_state
);
73 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_STRING
, &state
))
79 static int bus_unit_append_active_state(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
88 state
= unit_active_state_to_string(unit_active_state(u
));
90 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_STRING
, &state
))
96 static int bus_unit_append_can_reload(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
105 b
= unit_can_reload(u
);
107 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_BOOLEAN
, &b
))
113 static int bus_unit_append_can_start(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
122 b
= unit_can_start(u
);
124 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_BOOLEAN
, &b
))
130 static int bus_unit_append_job(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
140 if (!dbus_message_iter_open_container(i
, DBUS_TYPE_STRUCT
, NULL
, &sub
))
145 if (!(p
= job_dbus_path(u
->meta
.job
)))
148 if (!dbus_message_iter_append_basic(&sub
, DBUS_TYPE_UINT32
, &u
->meta
.job
->id
) ||
149 !dbus_message_iter_append_basic(&sub
, DBUS_TYPE_OBJECT_PATH
, &p
)) {
156 /* No job, so let's fill in some placeholder
157 * data. Since we need to fill in a valid path we
158 * simple point to ourselves. */
160 if (!(p
= unit_dbus_path(u
)))
163 if (!dbus_message_iter_append_basic(&sub
, DBUS_TYPE_UINT32
, &id
) ||
164 !dbus_message_iter_append_basic(&sub
, DBUS_TYPE_OBJECT_PATH
, &p
)) {
172 if (!dbus_message_iter_close_container(i
, &sub
))
178 static DBusHandlerResult
bus_unit_message_dispatch(Unit
*u
, DBusMessage
*message
) {
180 const BusProperty properties
[] = {
181 { "org.freedesktop.systemd1.Unit", "Id", bus_unit_append_id
, "s", u
},
182 { "org.freedesktop.systemd1.Unit", "Description", bus_unit_append_description
, "s", u
},
183 { "org.freedesktop.systemd1.Unit", "LoadState", bus_unit_append_load_state
, "s", u
},
184 { "org.freedesktop.systemd1.Unit", "ActiveState", bus_unit_append_active_state
, "s", u
},
185 { "org.freedesktop.systemd1.Unit", "LoadPath", bus_property_append_string
, "s", u
->meta
.load_path
},
186 { "org.freedesktop.systemd1.Unit", "ActiveEnterTimestamp", bus_property_append_uint64
, "t", &u
->meta
.active_enter_timestamp
},
187 { "org.freedesktop.systemd1.Unit", "ActiveExitTimestamp", bus_property_append_uint64
, "t", &u
->meta
.active_exit_timestamp
},
188 { "org.freedesktop.systemd1.Unit", "CanReload", bus_unit_append_can_reload
, "b", u
},
189 { "org.freedesktop.systemd1.Unit", "CanStart", bus_unit_append_can_start
, "b", u
},
190 { "org.freedesktop.systemd1.Unit", "Job", bus_unit_append_job
, "(uo)", u
},
191 { NULL
, NULL
, NULL
, NULL
, NULL
}
194 return bus_default_message_handler(u
->meta
.manager
, message
, introspection
, properties
);
197 static DBusHandlerResult
bus_unit_message_handler(DBusConnection
*connection
, DBusMessage
*message
, void *data
) {
206 log_debug("Got D-Bus request: %s.%s() on %s",
207 dbus_message_get_interface(message
),
208 dbus_message_get_member(message
),
209 dbus_message_get_path(message
));
211 if ((r
= manager_get_unit_from_dbus_path(m
, dbus_message_get_path(message
), &u
)) < 0) {
214 return DBUS_HANDLER_RESULT_NEED_MEMORY
;
217 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
219 return bus_send_error_reply(m
, message
, NULL
, r
);
222 return bus_unit_message_dispatch(u
, message
);
225 const DBusObjectPathVTable bus_unit_vtable
= {
226 .message_function
= bus_unit_message_handler