本文整理汇总了C++中sd_bus_message_append函数的典型用法代码示例。如果您正苦于以下问题:C++ sd_bus_message_append函数的具体用法?C++ sd_bus_message_append怎么用?C++ sd_bus_message_append使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sd_bus_message_append函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: property_get_what
static int property_get_what(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
Mount *m = userdata;
const char *d;
assert(bus);
assert(reply);
assert(m);
if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
d = m->parameters_proc_self_mountinfo.what;
else if (m->from_fragment && m->parameters_fragment.what)
d = m->parameters_fragment.what;
else
d = "";
return sd_bus_message_append(reply, "s", d);
}
示例2: transient_kill_set_properties
static int transient_kill_set_properties(sd_bus_message *m) {
assert(m);
if (arg_send_sighup)
return sd_bus_message_append(m, "(sv)", "SendSIGHUP", "b", arg_send_sighup);
else
return 0;
}
示例3: get_group_property
static int get_group_property(sd_bus *bus, const char *path,
const char *interface, const char *property, sd_bus_message *reply,
void *userdata, sd_bus_error *error) {
struct dmmp_path_group *group = userdata;
if (strcmp(property, GROUP_ID) == 0)
return sd_bus_message_append(reply, "u", dmmp_path_group_id_get(group));
if (strcmp(property, GROUP_PRIORITY) == 0)
return sd_bus_message_append(reply, "u", dmmp_path_group_priority_get(group));
if (strcmp(property, GROUP_STATUS) == 0)
return sd_bus_message_append(reply, "s", dmmp_path_group_status_str(
dmmp_path_group_status_get(group)));
// TODO deal with error
return -1;
}
示例4: client_chart
static void client_chart(const char *address) {
_cleanup_bus_message_unref_ sd_bus_message *x = NULL;
size_t csize;
sd_bus *b;
int r;
r = sd_bus_new(&b);
assert_se(r >= 0);
r = sd_bus_set_address(b, address);
assert_se(r >= 0);
r = sd_bus_start(b);
assert_se(r >= 0);
assert_se(sd_bus_call_method(b, ":1.1", "/", "benchmark.server", "Ping", NULL, NULL, NULL) >= 0);
printf("SIZE\tCOPY\tMEMFD\n");
for (csize = 1; csize <= MAX_SIZE; csize *= 2) {
usec_t t;
unsigned n_copying, n_memfd;
printf("%zu\t", csize);
b->use_memfd = 0;
t = now(CLOCK_MONOTONIC);
for (n_copying = 0;; n_copying++) {
transaction(b, csize);
if (now(CLOCK_MONOTONIC) >= t + arg_loop_usec)
break;
}
printf("%u\t", (unsigned) ((n_copying * USEC_PER_SEC) / arg_loop_usec));
b->use_memfd = -1;
t = now(CLOCK_MONOTONIC);
for (n_memfd = 0;; n_memfd++) {
transaction(b, csize);
if (now(CLOCK_MONOTONIC) >= t + arg_loop_usec)
break;
}
printf("%u\n", (unsigned) ((n_memfd * USEC_PER_SEC) / arg_loop_usec));
}
b->use_memfd = 1;
assert_se(sd_bus_message_new_method_call(b, ":1.1", "/", "benchmark.server", "Exit", &x) >= 0);
assert_se(sd_bus_message_append(x, "t", csize) >= 0);
assert_se(sd_bus_send(b, x, NULL) >= 0);
sd_bus_unref(b);
}
示例5: get_handler
static int get_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
struct context *c = userdata;
int r;
log_info("property get for %s called, returning \"%s\".", property, c->something);
r = sd_bus_message_append(reply, "s", c->something);
assert_se(r >= 0);
return 1;
}
示例6: sd_bus_message_new_signal
static struct ipmi_rs *ipmi_dbus_sendrecv(struct ipmi_intf *intf,
struct ipmi_rq *req)
{
sd_bus_message *msg;
int rc;
(void)intf;
rsp.ccode = 0xff;
rc = sd_bus_message_new_signal(bus, &msg, object_path,
interface, "ReceivedMessage");
if (rc < 0) {
lprintf(LOG_ERR, "%s: failed to create message: %s\n",
__func__, strerror(-rc));
goto out;
}
rc = sd_bus_message_append(msg, "yyyy",
++seq,
req->msg.netfn,
req->msg.lun,
req->msg.cmd);
if (rc < 0) {
lprintf(LOG_ERR, "%s: failed to init bytes\n", __func__);
goto out_free;
}
rc = sd_bus_message_append_array(msg, 'y', req->msg.data,
req->msg.data_len);
if (rc < 0) {
lprintf(LOG_ERR, "%s: failed to init body\n", __func__);
goto out_free;
}
rc = sd_bus_send(bus, msg, NULL);
if (rc < 0) {
lprintf(LOG_ERR, "%s: failed to send dbus message\n",
__func__);
goto out_free;
}
for (reply_received = false; !reply_received;) {
rc = sd_bus_wait(bus, -1);
sd_bus_process(bus, NULL);
}
out_free:
sd_bus_message_unref(msg);
out:
return &rsp;
}
示例7: transient_unit_set_properties
static int transient_unit_set_properties(sd_bus_message *m, char **properties) {
char **i;
int r;
r = sd_bus_message_append(m, "(sv)", "Description", "s", arg_description);
if (r < 0)
return r;
STRV_FOREACH(i, properties) {
r = bus_append_unit_property_assignment(m, *i);
if (r < 0)
return r;
}
示例8: bus_property_get_tristate
int bus_property_get_tristate(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
int *tristate = userdata;
return sd_bus_message_append(reply, "b", *tristate > 0);
}
示例9: transient_unit_set_properties
static int transient_unit_set_properties(sd_bus_message *m, char **properties) {
int r;
r = sd_bus_message_append(m, "(sv)", "Description", "s", arg_description);
if (r < 0)
return r;
r = bus_append_unit_property_assignment_many(m, properties);
if (r < 0)
return r;
return 0;
}
示例10: sd_bus_set_property
_public_ int sd_bus_set_property(
sd_bus *bus,
const char *destination,
const char *path,
const char *interface,
const char *member,
sd_bus_error *error,
const char *type, ...) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
va_list ap;
int r;
bus_assert_return(bus, -EINVAL, error);
bus_assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL, error);
bus_assert_return(member_name_is_valid(member), -EINVAL, error);
bus_assert_return(signature_is_single(type, false), -EINVAL, error);
bus_assert_return(!bus_pid_changed(bus), -ECHILD, error);
if (!BUS_IS_OPEN(bus->state)) {
r = -ENOTCONN;
goto fail;
}
r = sd_bus_message_new_method_call(bus, &m, destination, path, "org.freedesktop.DBus.Properties", "Set");
if (r < 0)
goto fail;
r = sd_bus_message_append(m, "ss", strempty(interface), member);
if (r < 0)
goto fail;
r = sd_bus_message_open_container(m, 'v', type);
if (r < 0)
goto fail;
va_start(ap, type);
r = sd_bus_message_appendv(m, type, ap);
va_end(ap);
if (r < 0)
goto fail;
r = sd_bus_message_close_container(m);
if (r < 0)
goto fail;
return sd_bus_call(bus, m, 0, error, NULL);
fail:
return sd_bus_error_set_errno(error, r);
}
示例11: transient_timer_set_properties
static int transient_timer_set_properties(sd_bus_message *m) {
int r;
assert(m);
r = transient_unit_set_properties(m, arg_timer_property);
if (r < 0)
return r;
/* Automatically clean up our transient timers */
r = sd_bus_message_append(m, "(sv)", "RemainAfterElapse", "b", false);
if (r < 0)
return r;
if (arg_on_active) {
r = sd_bus_message_append(m, "(sv)", "OnActiveSec", "t", arg_on_active);
if (r < 0)
return r;
}
if (arg_on_boot) {
r = sd_bus_message_append(m, "(sv)", "OnBootSec", "t", arg_on_boot);
if (r < 0)
return r;
}
if (arg_on_startup) {
r = sd_bus_message_append(m, "(sv)", "OnStartupSec", "t", arg_on_startup);
if (r < 0)
return r;
}
if (arg_on_unit_active) {
r = sd_bus_message_append(m, "(sv)", "OnUnitActiveSec", "t", arg_on_unit_active);
if (r < 0)
return r;
}
if (arg_on_unit_inactive) {
r = sd_bus_message_append(m, "(sv)", "OnUnitInactiveSec", "t", arg_on_unit_inactive);
if (r < 0)
return r;
}
if (arg_on_calendar) {
r = sd_bus_message_append(m, "(sv)", "OnCalendar", "s", arg_on_calendar);
if (r < 0)
return r;
}
return 0;
}
示例12: value_handler
static int value_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *s = NULL;
const char *x;
int r;
assert_se(asprintf(&s, "object %p, path %s", userdata, path) >= 0);
r = sd_bus_message_append(reply, "s", s);
assert_se(r >= 0);
assert_se(x = startswith(path, "/value/"));
assert_se(PTR_TO_UINT(userdata) == 30);
return 1;
}
示例13: cc_Calculator_split_async
int cc_Calculator_split_async(
struct cc_client_Calculator *instance, double value,
cc_Calculator_split_reply_t callback)
{
int result = 0;
struct cc_instance *i;
sd_bus_message *message = NULL;
CC_LOG_DEBUG("invoked cc_Calculator_split_async()\n");
assert(instance);
assert(callback);
i = instance->instance;
assert(i && i->backend && i->backend->bus);
assert(i->service && i->path && i->interface);
if (instance->split_reply_slot) {
CC_LOG_ERROR("unable to call method with already pending reply\n");
return -EBUSY;
}
assert(!instance->split_reply_callback);
result = sd_bus_message_new_method_call(
i->backend->bus, &message, i->service, i->path, i->interface, "split");
if (result < 0) {
CC_LOG_ERROR("unable to create message: %s\n", strerror(-result));
goto fail;
}
result = sd_bus_message_append(message, "d", value);
if (result < 0) {
CC_LOG_ERROR("unable to append message method arguments: %s\n", strerror(-result));
goto fail;
}
result = sd_bus_call_async(
i->backend->bus, &instance->split_reply_slot, message,
&cc_Calculator_split_reply_thunk, instance, CC_DBUS_ASYNC_CALL_TIMEOUT_USEC);
if (result < 0) {
CC_LOG_ERROR("unable to issue method call: %s\n", strerror(-result));
goto fail;
}
instance->split_reply_callback = callback;
fail:
message = sd_bus_message_unref(message);
return result;
}
示例14: append_controller_property
static int append_controller_property(sd_bus *bus, sd_bus_message *m) {
const char *unique;
int r;
assert(bus);
assert(m);
r = sd_bus_get_unique_name(bus, &unique);
if (r < 0)
return log_error_errno(r, "Failed to get unique name: %m");
r = sd_bus_message_append(m, "(sv)", "Controller", "s", unique);
if (r < 0)
return bus_log_create_error(r);
return 0;
}
示例15: main
int main(int argc, char *argv[]) {
struct bus_match_node root = {
.type = BUS_MATCH_ROOT,
};
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
enum bus_match_node_type i;
sd_bus_slot slots[19];
int r;
r = sd_bus_open_system(&bus);
if (r < 0)
return EXIT_TEST_SKIP;
assert_se(match_add(slots, &root, "arg2='wal\\'do',sender='foo',type='signal',interface='bar.x',", 1) >= 0);
assert_se(match_add(slots, &root, "arg2='wal\\'do2',sender='foo',type='signal',interface='bar.x',", 2) >= 0);
assert_se(match_add(slots, &root, "arg3='test',sender='foo',type='signal',interface='bar.x',", 3) >= 0);
assert_se(match_add(slots, &root, "arg3='test',sender='foo',type='method_call',interface='bar.x',", 4) >= 0);
assert_se(match_add(slots, &root, "", 5) >= 0);
assert_se(match_add(slots, &root, "interface='quux.x'", 6) >= 0);
assert_se(match_add(slots, &root, "interface='bar.x'", 7) >= 0);
assert_se(match_add(slots, &root, "member='waldo',path='/foo/bar'", 8) >= 0);
assert_se(match_add(slots, &root, "path='/foo/bar'", 9) >= 0);
assert_se(match_add(slots, &root, "path_namespace='/foo'", 10) >= 0);
assert_se(match_add(slots, &root, "path_namespace='/foo/quux'", 11) >= 0);
assert_se(match_add(slots, &root, "arg1='two'", 12) >= 0);
assert_se(match_add(slots, &root, "member='waldo',arg2path='/prefix/'", 13) >= 0);
assert_se(match_add(slots, &root, "member=waldo,path='/foo/bar',arg3namespace='prefix'", 14) >= 0);
assert_se(match_add(slots, &root, "arg4has='pi'", 15) >= 0);
assert_se(match_add(slots, &root, "arg4has='pa'", 16) >= 0);
assert_se(match_add(slots, &root, "arg4has='po'", 17) >= 0);
assert_se(match_add(slots, &root, "arg4='pi'", 18) >= 0);
bus_match_dump(&root, 0);
assert_se(sd_bus_message_new_signal(bus, &m, "/foo/bar", "bar.x", "waldo") >= 0);
assert_se(sd_bus_message_append(m, "ssssas", "one", "two", "/prefix/three", "prefix.four", 3, "pi", "pa", "po") >= 0);
assert_se(bus_message_seal(m, 1, 0) >= 0);
zero(mask);
assert_se(bus_match_run(NULL, &root, m) == 0);
assert_se(mask_contains((unsigned[]) {
9, 8, 7, 5, 10, 12, 13, 14, 15, 16, 17
}, 11));