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;
sd_bus_reply_method_error(m, error); return result; } result = sd_bus_reply_method_return(m, "i", status); if (result < 0) { CC_LOG_ERROR("unable to send method reply: %s\n", strerror(-result)); return result; } /* Successful method invocation must return >0 */ return 1; } static const sd_bus_vtable vtable_Smartie[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("ring", "", "i", &cc_Smartie_ring_thunk, 0), SD_BUS_METHOD("hangup", "", "i", &cc_Smartie_hangup_thunk, 0), SD_BUS_VTABLE_END }; int cc_server_Smartie_new( const char *address, const struct cc_server_Smartie_impl *impl, void *data, struct cc_server_Smartie **instance) { int result; struct cc_server_Smartie *ii; struct cc_instance *i; CC_LOG_DEBUG("invoked cc_server_Smartie_new\n"); assert(address); assert(impl);
#include <systemd/sd-bus.h> const sd_bus_vtable example2[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD((const char*)1, (const char*)2, (const char*)3, (sd_bus_message_handler_t)4, 0), SD_BUS_SIGNAL((const char*)5, (const char*)6, 0), SD_BUS_PROPERTY((const char*)7, (const char*)8, (sd_bus_property_get_t)9, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_WRITABLE_PROPERTY((const char*)10, (const char*)11, (sd_bus_property_get_t)12, (sd_bus_property_set_t)13, 0, 0), SD_BUS_PROPERTY((const char*)14, (const char*)15, NULL, 16, 0), SD_BUS_VTABLE_END, }; const size_t example2_size = sizeof(example2);
} sysfs_value[count]='\0'; fclose(fp); return 0; } /* * ----------------------------------------------- * Dbus Services offered by this LED controller * ----------------------------------------------- */ static const sd_bus_vtable led_control_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("setOn", "", "i", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("setOff", "", "i", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("setBlinkFast", "", "i", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("setBlinkSlow", "", "i", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetLedState", "", "is", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END, }; /* * --------------------------------------------- * Interested in all files except standard ones * --------------------------------------------- */ int led_select(const struct dirent *entry) { if( (strcmp(entry->d_name, ".") == 0) ||
#include "dbus-snapshot.h" int bus_snapshot_method_remove(sd_bus_message *message, void *userdata, sd_bus_error *error) { Snapshot *s = userdata; int r; assert(message); assert(s); r = mac_selinux_unit_access_check(UNIT(s), message, "stop", error); if (r < 0) return r; r = bus_verify_manage_units_async(UNIT(s)->manager, message, error); if (r < 0) return r; if (r == 0) return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ snapshot_remove(s); return sd_bus_reply_method_return(message, NULL); } const sd_bus_vtable bus_snapshot_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Cleanup", "b", bus_property_get_bool, offsetof(Snapshot, cleanup), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_METHOD("Remove", NULL, NULL, bus_snapshot_method_remove, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END };
/* And for everybody else consult PolicyKit */ r = bus_verify_manage_units_async(j->unit->manager, message, error); if (r < 0) return r; if (r == 0) return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ } job_finish_and_invalidate(j, JOB_CANCELED, true); return sd_bus_reply_method_return(message, NULL); } const sd_bus_vtable bus_job_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("Cancel", NULL, NULL, bus_job_method_cancel, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_PROPERTY("Id", "u", NULL, offsetof(Job, id), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Unit", "(so)", property_get_unit, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("JobType", "s", property_get_type, offsetof(Job, type), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("State", "s", property_get_state, offsetof(Job, state), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_VTABLE_END }; static int send_new_signal(sd_bus *bus, void *userdata) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; _cleanup_free_ char *p = NULL; Job *j = userdata; int r; assert(bus); assert(j);
static short freeIds[MAX_CLIENT_ID] = {-1}; static usec_t clientTimeout[MAX_CLIENT_ID] = {0}; static int lastAllocatedId = 0; static int openSlots = MAX_CLIENT_ID; static int lastFreedSlot = -1; static int fd = 0; static char identity[64] = {'0'}; static char path[64] = {'0'}; static long version = 0; static long timeout = 0; static const sd_bus_vtable watchdogPmon[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("DevicePath", "", "s", DevicePath, 0), SD_BUS_METHOD("Identity", "", "s", Identity, 0), SD_BUS_METHOD("Version", "", "x", Version, 0), SD_BUS_METHOD("GetTimeout", "", "x", GetTimeoutDbus, 0), SD_BUS_METHOD("GetTimeleft", "", "x", GetTimeleftDbus, 0), SD_BUS_METHOD("PmonInit", "t", "u", PmonInit, 0), SD_BUS_METHOD("PmonPing", "u", "b", PmonPing, 0), SD_BUS_METHOD("PmonRemove", "u", "b", PmonRemove, 0), SD_BUS_VTABLE_END }; static int Timeout(sd_event_source *source, usec_t usec, void *userdata) { int cmd = DBUSHUTDOWN; do
#include "selinux-access.h" #include "unit.h" #include "snapshot.h" #include "dbus-unit.h" #include "dbus-snapshot.h" int bus_snapshot_method_remove(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { Snapshot *s = userdata; int r; assert(bus); assert(message); assert(s); r = selinux_unit_access_check(UNIT(s), bus, message, "stop", error); if (r < 0) return r; snapshot_remove(s); return sd_bus_reply_method_return(message, NULL); } const sd_bus_vtable bus_snapshot_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("Remove", NULL, NULL, bus_snapshot_method_remove, 0), SD_BUS_PROPERTY("Cleanup", "b", bus_property_get_bool, offsetof(Snapshot, cleanup), 0), SD_BUS_VTABLE_END };
if (r == -ESTALE) return sd_bus_error_setf(error, BUS_ERROR_SCOPE_NOT_RUNNING, "Scope %s is not running, cannot abandon.", UNIT(s)->id); return sd_bus_reply_method_return(message, NULL); } static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, scope_result, ScopeResult); const sd_bus_vtable bus_scope_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Controller", "s", NULL, offsetof(Scope, controller), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_SIGNAL("RequestStop", NULL, 0), SD_BUS_METHOD("Abandon", NULL, NULL, bus_scope_abandon, 0), SD_BUS_VTABLE_END }; static int bus_scope_set_transient_property( Scope *s, const char *name, sd_bus_message *message, UnitSetPropertiesMode mode, sd_bus_error *error) { int r; assert(s); assert(name); assert(message);
rsp.ccode = recv_cc; rsp.data_len = n; memcpy(rsp.data, data, rsp.data_len); reply_received = true; } out: sd_bus_reply_method_return(msg, "x", 0); return 0; } static const sd_bus_vtable dbus_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_SIGNAL("ReceivedMessage", "yyyyay", 0), SD_BUS_METHOD("sendMessage", "yyyyyay", "x", ipmi_dbus_method_send_message, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END }; static int ipmi_dbus_setup(struct ipmi_intf *intf) { const char *name; int rc; rc = sd_bus_default(&bus); if (rc < 0) { lprintf(LOG_ERR, "Can't connect to session bus: %s\n", strerror(-rc)); return -1; }
return sd_bus_error_setf(error, BUS_ERROR_SCOPE_NOT_RUNNING, "Scope %s is not running, cannot abandon.", UNIT(s)->id); if (r < 0) return r; return sd_bus_reply_method_return(message, NULL); } static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, scope_result, ScopeResult); const sd_bus_vtable bus_scope_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Controller", "s", NULL, offsetof(Scope, controller), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_SIGNAL("RequestStop", NULL, 0), SD_BUS_METHOD("Abandon", NULL, NULL, bus_scope_method_abandon, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END }; static int bus_scope_set_transient_property( Scope *s, const char *name, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error) { int r; assert(s); assert(name); assert(message);
return bus_image_common_set_limit(NULL, message, NULL, userdata, error); } const sd_bus_vtable image_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Image, name), 0), SD_BUS_PROPERTY("Path", "s", NULL, offsetof(Image, path), 0), SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Image, type), 0), SD_BUS_PROPERTY("ReadOnly", "b", bus_property_get_bool, offsetof(Image, read_only), 0), SD_BUS_PROPERTY("CreationTimestamp", "t", NULL, offsetof(Image, crtime), 0), SD_BUS_PROPERTY("ModificationTimestamp", "t", NULL, offsetof(Image, mtime), 0), SD_BUS_PROPERTY("Usage", "t", NULL, offsetof(Image, usage), 0), SD_BUS_PROPERTY("Limit", "t", NULL, offsetof(Image, limit), 0), SD_BUS_PROPERTY("UsageExclusive", "t", NULL, offsetof(Image, usage_exclusive), 0), SD_BUS_PROPERTY("LimitExclusive", "t", NULL, offsetof(Image, limit_exclusive), 0), SD_BUS_METHOD("GetOSRelease", NULL, "a{ss}", bus_image_method_get_os_release, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetMedatadata", "as", "saya{say}", bus_image_method_get_metadata, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetState", NULL, "s", bus_image_method_get_state, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("Attach", "assbs", "a(sss)", bus_image_method_attach, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("Detach", "b", "a(sss)", bus_image_method_detach, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("Remove", NULL, NULL, bus_image_method_remove, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("MarkReadOnly", "b", NULL, bus_image_method_mark_read_only, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("SetLimit", "t", NULL, bus_image_method_set_limit, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END }; int bus_image_path(Image *image, char **ret) { assert(image); assert(ret); if (!image->discoverable)
return sd_bus_reply_method_return(m, "x", rc); } else { return sd_bus_reply_method_return(m, "x", bt_resp); } } //------------------------------------------- // Function pointer of APIs exposed via Dbus //------------------------------------------- static const sd_bus_vtable host_services_vtable[] = { SD_BUS_VTABLE_START(0), // Takes No("") arguments -but- returns a value of type 64 bit integer("x") SD_BUS_METHOD("SoftPowerOff", "", "x", &soft_power_off, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END, }; //------------------------------------------------------ // Called by IPMID as part of the start up // ----------------------------------------------------- int start_host_service(sd_bus *bus, sd_bus_slot *slot) { int rc = 0; /* Install the object */ rc = sd_bus_add_object_vtable(bus, &slot, "/org/openbmc/HostServices", /* object path */ "org.openbmc.HostServices", /* interface name */
return sd_bus_reply_method_return(message, NULL); } const sd_bus_vtable image_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Image, name), 0), SD_BUS_PROPERTY("Path", "s", NULL, offsetof(Image, path), 0), SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Image, type), 0), SD_BUS_PROPERTY("ReadOnly", "b", bus_property_get_bool, offsetof(Image, read_only), 0), SD_BUS_PROPERTY("CreationTimestamp", "t", NULL, offsetof(Image, crtime), 0), SD_BUS_PROPERTY("ModificationTimestamp", "t", NULL, offsetof(Image, mtime), 0), SD_BUS_PROPERTY("Usage", "t", NULL, offsetof(Image, usage), 0), SD_BUS_PROPERTY("Limit", "t", NULL, offsetof(Image, limit), 0), SD_BUS_PROPERTY("UsageExclusive", "t", NULL, offsetof(Image, usage_exclusive), 0), SD_BUS_PROPERTY("LimitExclusive", "t", NULL, offsetof(Image, limit_exclusive), 0), SD_BUS_METHOD("Remove", NULL, NULL, bus_image_method_remove, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("Rename", "s", NULL, bus_image_method_rename, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("Clone", "sb", NULL, bus_image_method_clone, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("MarkReadOnly", "b", NULL, bus_image_method_mark_read_only, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("SetLimit", "t", NULL, bus_image_method_set_limit, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END }; static int image_flush_cache(sd_event_source *s, void *userdata) { Manager *m = userdata; Image *i; assert(s); assert(m); while ((i = hashmap_steal_first(m->image_cache)))
c_time = time_time(); r = sd_bus_emit_signal(bus, OBJ, INT, "Spam", "dts", c_time, payload_size, pl); if (r < 0) { fprintf(stderr, "Failed to emit signal: %s\n", strerror(-r)); free(pl); return sd_bus_reply_method_return(m, "t", i); } } free(pl); return sd_bus_reply_method_return(m, "t", num_signals); } static const sd_bus_vtable signal_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("SpamSignal", "tt", "t", generate_signals, 0), SD_BUS_VTABLE_END }; int main(int argc, char *argv[]) { sd_bus_slot *slot = NULL; int r; char *mode = NULL; if (argc != 2) { fprintf(stderr, "syntax: %s [server|client]\n", argv[0]); return 1; } mode = argv[1];
} static int emit_object_removed(sd_bus_message *m, void *userdata, sd_bus_error *error) { int r; assert_se(sd_bus_emit_object_removed(sd_bus_message_get_bus(m), "/value/a/x") >= 0); r = sd_bus_reply_method_return(m, NULL); assert_se(r >= 0); return 1; } static const sd_bus_vtable vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("AlterSomething", "s", "s", something_handler, 0), SD_BUS_METHOD("Exit", "", "", exit_handler, 0), SD_BUS_WRITABLE_PROPERTY("Something", "s", get_handler, set_handler, 0, 0), SD_BUS_WRITABLE_PROPERTY("AutomaticStringProperty", "s", NULL, NULL, offsetof(struct context, automatic_string_property), 0), SD_BUS_WRITABLE_PROPERTY("AutomaticIntegerProperty", "u", NULL, NULL, offsetof(struct context, automatic_integer_property), 0), SD_BUS_METHOD("NoOperation", NULL, NULL, NULL, 0), SD_BUS_METHOD("EmitInterfacesAdded", NULL, NULL, emit_interfaces_added, 0), SD_BUS_METHOD("EmitInterfacesRemoved", NULL, NULL, emit_interfaces_removed, 0), SD_BUS_METHOD("EmitObjectAdded", NULL, NULL, emit_object_added, 0), SD_BUS_METHOD("EmitObjectRemoved", NULL, NULL, emit_object_removed, 0), SD_BUS_VTABLE_END }; static const sd_bus_vtable vtable2[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("NotifyTest", "", "", notify_test, 0),
***/ #include "bus-introspect.h" #include "log.h" static int prop_get(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) { return -EINVAL; } static int prop_set(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) { return -EINVAL; } static const sd_bus_vtable vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("Hello", "ssas", "a(uu)", NULL, 0), SD_BUS_METHOD("DeprecatedHello", "", "", NULL, SD_BUS_VTABLE_DEPRECATED), SD_BUS_METHOD("DeprecatedHelloNoReply", "", "", NULL, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_METHOD_NO_REPLY), SD_BUS_SIGNAL("Wowza", "sss", 0), SD_BUS_SIGNAL("DeprecatedWowza", "ut", SD_BUS_VTABLE_DEPRECATED), SD_BUS_WRITABLE_PROPERTY("AProperty", "s", prop_get, prop_set, 0, 0), SD_BUS_PROPERTY("AReadOnlyDeprecatedProperty", "(ut)", prop_get, 0, SD_BUS_VTABLE_DEPRECATED), SD_BUS_PROPERTY("ChangingProperty", "t", prop_get, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("Invalidating", "t", prop_get, 0, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), SD_BUS_PROPERTY("Constant", "t", prop_get, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_PROPERTY_EXPLICIT), SD_BUS_VTABLE_END }; int main(int argc, char *argv[]) { struct introspect intro;
static const sd_bus_vtable hostname_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Hostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("StaticHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_STATIC_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("PrettyHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_PRETTY_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("IconName", "s", property_get_icon_name, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("Chassis", "s", property_get_chassis, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("Deployment", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_DEPLOYMENT, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("Location", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_LOCATION, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("KernelName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_NAME, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("KernelRelease", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_RELEASE, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("KernelVersion", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_VERSION, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("OperatingSystemPrettyName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_PRETTY_NAME, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("OperatingSystemCPEName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_CPE_NAME, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_METHOD("SetHostname", "sb", NULL, method_set_hostname, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("SetStaticHostname", "sb", NULL, method_set_static_hostname, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("SetPrettyHostname", "sb", NULL, method_set_pretty_hostname, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("SetIconName", "sb", NULL, method_set_icon_name, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("SetChassis", "sb", NULL, method_set_chassis, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("SetDeployment", "sb", NULL, method_set_deployment, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("SetLocation", "sb", NULL, method_set_location, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END, }; static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; assert(c); assert(event);
static int method_close_notification(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { // TODO printf("D-BUS CloseNotification\n"); return 0; } static int method_get_server_information(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { printf("D-BUS GetServerInformation\n"); return sd_bus_reply_method_return(m, "ssss", "kirstu", "siiptuo", "0.1", "1.2"); } static const sd_bus_vtable vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("GetCapabilities", "", "as", method_get_capabilities, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("Notify", "susssasa{sv}i", "u", method_notify, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("CloseNotification", "u", "", method_close_notification, SD_BUS_VTABLE_METHOD_NO_REPLY), SD_BUS_METHOD("GetServerInformation", "", "ssss", method_get_server_information, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_SIGNAL("NotificationClosed", "uu", 0), SD_BUS_SIGNAL("ActionInvoked", "us", 0), SD_BUS_VTABLE_END }; int kirstu_dbus_init(void) { int r = sd_bus_default_user(&bus); if (r < 0) { fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r)); exit(EXIT_FAILURE); }