b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter/*
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter Authors:
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter Stef Walter <stefw@redhat.com>
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter Copyright (C) 2014 Red Hat
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter This program is free software; you can redistribute it and/or modify
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter it under the terms of the GNU General Public License as published by
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter the Free Software Foundation; either version 3 of the License, or
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter (at your option) any later version.
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter This program is distributed in the hope that it will be useful,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter but WITHOUT ANY WARRANTY; without even the implied warranty of
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter GNU General Public License for more details.
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter You should have received a copy of the GNU General Public License
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter along with this program. If not, see <http://www.gnu.org/licenses/>.
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter*/
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#ifndef _SSSD_DBUS_META_H_
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#define _SSSD_DBUS_META_H_
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březina#include <dbus/dbus.h>
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březina
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter/*
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter * Interface metadata
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter *
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter * For arrays, the last item in each array will have a
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter * NULL .name field
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter *
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter * Typically these structs will be generated by sbus_codegen
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter * from canonical XML interface data:
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter *
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter * http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter */
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
886d29fced0bcc1668a3cb99a5bca66ea486b3a4Jakub Hrozek/* Looks up a vtable func, in a struct derived from struct sbus_vtable */
886d29fced0bcc1668a3cb99a5bca66ea486b3a4Jakub Hrozek#define VTABLE_FUNC(vtable, offset) \
0f495aa73529b06b0a8b4c39cfd098351c4f6760Michal Zidek (*(DISCARD_ALIGN((char *)(vtable) + (offset), void **)))
886d29fced0bcc1668a3cb99a5bca66ea486b3a4Jakub Hrozek
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterstruct sbus_arg_meta {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *name;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *type;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter};
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walterstruct sbus_request;
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walterstruct sbus_interface;
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březinatypedef int (* sbus_get_invoker_fn)(DBusMessageIter *iter,
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březina struct sbus_request *sbus_req,
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březina void *handler_fn);
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březina
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březinatypedef void (* sbus_get_all_invoker_fn)(struct sbus_request *sbus_req);
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březina
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březinatypedef int (* sbus_method_invoker_fn)(struct sbus_request *sbus_req,
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březina void *handler_fn);
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterstruct sbus_method_meta {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *name;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_arg_meta *in_args;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_arg_meta *out_args;
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter size_t vtable_offset;
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter sbus_method_invoker_fn invoker;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter};
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterenum {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter SBUS_PROPERTY_READABLE = 1 << 0,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter SBUS_PROPERTY_WRITABLE = 1 << 1
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter};
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterstruct sbus_property_meta {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *name;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *type;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter int flags;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek size_t vtable_offset_get;
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březina sbus_get_invoker_fn invoker_get;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter size_t vtable_offset_set;
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter sbus_method_invoker_fn invoker_set;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter};
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterstruct sbus_signal_meta {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *name;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_arg_meta *args;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter};
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterstruct sbus_interface_meta {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *name;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_method_meta *methods;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_signal_meta *signals;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_property_meta *properties;
df4e1db5d41c903ae57fd880acc76a0ad84aa7b2Pavel Březina sbus_get_all_invoker_fn invoker_get_all;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter};
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterconst struct sbus_method_meta *
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Waltersbus_meta_find_method (const struct sbus_interface_meta *interface,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *method_name);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterconst struct sbus_signal_meta *
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Waltersbus_meta_find_signal (const struct sbus_interface_meta *interface,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *signal_name);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterconst struct sbus_property_meta *
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Waltersbus_meta_find_property (const struct sbus_interface_meta *interface,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *property_name);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#endif /* _SSSD_DBUS_META_H_ */