/*
Generated by sbus code generator
Copyright (C) 2017 Red Hat
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include
#include
#include "${sbus-path}/sbus_sync.h"
#include "${sbus-path}/sbus_sync_private.h"
#include "${sbus-path}/sbus_message.h"
#include "${sbus-path}/interface/sbus_iterator_readers.h"
#include "${sbus-path}/interface_dbus/sbus_dbus_client_sync.h"
#include "${header:arguments}"
#include "${header:client_properties}"
static errno_t
sbus_method_in_${input-signature}_out_${output-signature}
(TALLOC_CTX *mem_ctx,
struct sbus_sync_connection *conn,
struct sbus_sync_connection *conn,
DBusMessage *raw_message
const char *bus,
const char *path,
const char *iface,
const char *method,
${type} arg${index}
,
DBusMessage **_reply)
,
${type} _arg${index})
{
TALLOC_CTX *tmp_ctx;
struct _sbus_invoker_args_${input-signature} in;
struct _sbus_invoker_args_${output-signature} *out;
DBusMessage *reply;
errno_t ret;
tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory!\n");
return ENOMEM;
}
out = talloc_zero(tmp_ctx, struct _sbus_invoker_args_${output-signature});
if (out == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Unable to allocate space for output parameters!\n");
ret = ENOMEM;
goto done;
}
in.arg${index} = arg${index};
ret = sbus_sync_call_method(tmp_ctx, conn, raw_message, NULL, NULL,
dbus_message_get_path(raw_message),
dbus_message_get_interface(raw_message),
dbus_message_get_member(raw_message),
NULL, &reply);
ret = sbus_sync_call_method(tmp_ctx, conn, NULL,
(sbus_invoker_writer_fn)_sbus_invoker_write_${input-signature},
bus, path, iface, method, &in, &reply);
ret = sbus_sync_call_method(tmp_ctx, conn, NULL, NULL,
bus, path, iface, method, NULL, &reply);
if (ret != EOK) {
goto done;
}
/* Bounded reference cannot be unreferenced with dbus_message_unref.
* For that reason we do not allow NULL memory context as it would
* result in leaking the message memory. */
if (mem_ctx == NULL) {
ret = EINVAL;
goto done;
}
ret = sbus_message_bound_steal(mem_ctx, reply);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to steal message [%d]: %s\n",
ret, sss_strerror(ret));
goto done;
}
*_reply = reply;
ret = sbus_read_output(out, reply, (sbus_invoker_reader_fn)_sbus_invoker_read_${output-signature}, out);
if (ret != EOK) {
goto done;
}
*_arg${index} = out->arg${index};
*_arg${index} = talloc_steal(mem_ctx, out->arg${index});
ret = EOK;
done:
talloc_free(tmp_ctx);
return ret;
}
errno_t
sbus_call_${token}
(TALLOC_CTX *mem_ctx,
struct sbus_sync_connection *conn,
struct sbus_sync_connection *conn,
DBusMessage *raw_message
const char *busname,
const char *object_path,
${type} arg_${name}
,
DBusMessage **_reply)
,
${type} _arg_${name})
{
return sbus_method_in_${input-signature}_out_${output-signature}(mem_ctx, conn,
raw_message
busname, object_path, "${iface}", "${method}", arg_${name}
,
_reply);
,
_arg_${name});
}
static void
sbus_emit_signal_${input-signature}
(struct sbus_sync_connection *conn,
DBusMessage *raw_message)
const char *path,
const char *iface,
const char *signal_name,
${type} arg${index})
{
struct _sbus_invoker_args_${input-signature} args;
args.arg${index} = arg${index};
sbus_sync_call_signal(conn, raw_message, NULL,
dbus_message_get_path(raw_message),
dbus_message_get_interface(raw_message),
dbus_message_get_member(raw_message), NULL);
sbus_sync_call_signal(conn, NULL, (sbus_invoker_writer_fn)_sbus_invoker_write_${input-signature},
path, iface, signal_name, &args);
sbus_sync_call_signal(conn, NULL, NULL, path, iface, signal_name, NULL);
}
void
sbus_sync_emit_${token}
(struct sbus_sync_connection *conn,
DBusMessage *raw_message)
const char *object_path,
${type} arg_${name})
{
sbus_emit_signal_${input-signature}(conn, raw_message);
sbus_emit_signal_${input-signature}(conn, object_path,
"${iface}", "${signal}", arg_${name});
}
static errno_t
sbus_get_${output-signature}
(TALLOC_CTX *mem_ctx,
struct sbus_sync_connection *conn,
struct sbus_sync_connection *conn,
const char *bus,
const char *path,
const char *iface,
const char *property,
${output-type} _value)
{
TALLOC_CTX *tmp_ctx;
struct _sbus_invoker_args_${output-signature} *out;
sbus_value_reader_fn reader;
sbus_value_reader_talloc_fn reader_talloc;
DBusMessage *reply;
errno_t ret;
tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory!\n");
return ENOMEM;
}
out = talloc_zero(tmp_ctx, struct _sbus_invoker_args_${output-signature});
if (out == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Unable to allocate space for output parameters!\n");
ret = ENOMEM;
goto done;
}
ret = sbus_call_DBusProperties_Get(tmp_ctx, conn,
bus, path, iface, property, &reply);
if (ret != EOK) {
goto done;
}
reader = NULL(sbus_value_reader_fn)sbus_iterator_read_${output-signature};
reader_talloc = (sbus_value_reader_talloc_fn)sbus_iterator_read_${output-signature}NULL;
ret = sbus_parse_get_message(out, reader, reader_talloc, reply, &out->arg0);
if (ret != EOK) {
goto done;
}
*_value = talloc_steal(mem_ctx, out->arg0)out->arg0;
ret = EOK;
done:
talloc_free(tmp_ctx);
return ret;
}
static errno_t
sbus_set_${input-signature}
(struct sbus_sync_connection *conn,
const char *bus,
const char *path,
const char *iface,
const char *property,
${input-type} value)
{
TALLOC_CTX *tmp_ctx;
struct _sbus_invoker_args_${input-signature} in;
DBusMessage *raw_message;
errno_t ret;
tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory!\n");
return ENOMEM;
}
in.arg0 = value;
raw_message = sbus_create_set_call(tmp_ctx,
(sbus_invoker_writer_fn)_sbus_invoker_write_${input-signature},
bus, path, iface, property,
"${dbus-type}", &in);
if (raw_message == NULL) {
ret = ENOMEM;
goto done;
}
ret = sbus_call_DBusProperties_Set(conn, raw_message);
if (ret != EOK) {
goto done;
}
ret = EOK;
done:
talloc_free(tmp_ctx);
return ret;
}
errno_t
sbus_get_${token}
(struct sbus_sync_connection *conn,
const char *busname,
const char *object_path,
${output-type} _value)
{
return sbus_get_${output-signature}(conn, busname, object_path,
"${iface}", "${property}", _value);
}
errno_t
sbus_get_${token}
(TALLOC_CTX *mem_ctx,
struct sbus_sync_connection *conn,
const char *busname,
const char *object_path,
${output-type} _value)
{
return sbus_get_${output-signature}(mem_ctx, conn, busname, object_path,
"${iface}", "${property}", _value);
}
errno_t
sbus_set_${token}
(struct sbus_sync_connection *conn,
const char *busname,
const char *object_path,
${input-type} value)
{
return sbus_set_${input-signature}(conn, busname, object_path,
"${iface}", "${property}", value);
}
errno_t
sbus_getall_${token}
(TALLOC_CTX *mem_ctx,
struct sbus_sync_connection *conn,
const char *busname,
const char *object_path,
struct sbus_all_${token} **_properties)
{
TALLOC_CTX *tmp_ctx;
struct sbus_all_${token} *properties;
DBusMessage *reply;
errno_t ret;
tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory!\n");
return ENOMEM;
}
properties = talloc_zero(tmp_ctx, struct sbus_all_${token});
if (properties == NULL) {
ret = ENOMEM;
goto done;
}
struct sbus_parse_getall_table table[] = {
{"${name}", (sbus_value_reader_fn)sbus_iterator_read_${output-signature}, NULL,
&properties->${name}.value, &properties->${name}.is_set},
{"${name}", NULL, (sbus_value_reader_talloc_fn)sbus_iterator_read_${output-signature},
&properties->${name}.value, &properties->${name}.is_set},
{NULL, NULL, NULL, NULL, NULL}
};
ret = sbus_call_DBusProperties_GetAll(tmp_ctx, conn,
busname, object_path, "${iface}", &reply);
if (ret != EOK) {
goto done;
}
ret = sbus_parse_getall_message(properties, table, reply);
if (ret != EOK) {
goto done;
}
*_properties = talloc_steal(mem_ctx, properties);
ret = EOK;
done:
talloc_free(tmp_ctx);
return ret;
}