dbus_new_helpers.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * FOTA Supplicant / dbus-based control interface
  3. * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
  4. * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
  5. *
  6. * This software may be distributed under the terms of the BSD license.
  7. * See README for more details.
  8. */
  9. #ifndef _DBUS_NEW_HELPER_H_
  10. #define _DBUS_NEW_HELPER_H_
  11. #include <stdint.h>
  12. #include <dbus/dbus.h>
  13. #include <fota.h>
  14. typedef int (*method_function)(DBusMessage *message, fota_server_t *fota);
  15. typedef void (*FOTADBusArgumentFreeFunction)(void *handler_arg);
  16. struct fota_dbus_property_desc;
  17. typedef dbus_bool_t (*FOTADBusPropertyAccessor)(
  18. const struct fota_dbus_property_desc *property_desc,
  19. DBusMessageIter *iter, DBusError *error, void *user_data);
  20. #define DECLARE_ACCESSOR(f) \
  21. dbus_bool_t f(const struct fota_dbus_property_desc *property_desc, \
  22. DBusMessageIter *iter, DBusError *error, void *user_data)
  23. struct fota_dbus_object_desc {
  24. DBusConnection *connection;
  25. char *path;
  26. /* list of methods, properties and signals registered with object */
  27. const struct fota_dbus_method_desc *methods;
  28. const struct fota_dbus_signal_desc *signals;
  29. const struct fota_dbus_property_desc *properties;
  30. /* property changed flags */
  31. uint8_t *prop_changed_flags;
  32. /* argument for method handlers and properties
  33. * getter and setter functions */
  34. void *user_data;
  35. /* function used to free above argument */
  36. FOTADBusArgumentFreeFunction user_data_free_func;
  37. };
  38. enum dbus_arg_direction { ARG_IN, ARG_OUT };
  39. /**
  40. * type Definition:
  41. *
  42. * 'Auto': 'v'
  43. * String: 's'
  44. * Number: 'd'
  45. * Boolean: 'b'
  46. * Array: 'av'
  47. * Object: 'a{sv}'
  48. */
  49. struct fota_dbus_argument {
  50. char *name;
  51. char *type;
  52. enum dbus_arg_direction dir;
  53. };
  54. #define END_ARGS { NULL, NULL, ARG_IN }
  55. /**
  56. * struct fota_dbus_method_desc - DBus method description
  57. */
  58. struct fota_dbus_method_desc {
  59. /* method name */
  60. const char *dbus_method;
  61. /* method interface */
  62. const char *dbus_interface;
  63. /* method handling function */
  64. method_function function;
  65. /* array of arguments */
  66. struct fota_dbus_argument args[4];
  67. };
  68. /**
  69. * struct fota_dbus_signal_desc - DBus signal description
  70. */
  71. struct fota_dbus_signal_desc {
  72. /* signal name */
  73. const char *dbus_signal;
  74. /* signal interface */
  75. const char *dbus_interface;
  76. /* array of arguments */
  77. struct fota_dbus_argument args[4];
  78. };
  79. /**
  80. * struct fota_dbus_property_desc - DBus property description
  81. */
  82. struct fota_dbus_property_desc {
  83. /* property name */
  84. const char *dbus_property;
  85. /* property interface */
  86. const char *dbus_interface;
  87. /* property type signature in DBus type notation */
  88. const char *type;
  89. /* property getter function */
  90. FOTADBusPropertyAccessor getter;
  91. /* property setter function */
  92. FOTADBusPropertyAccessor setter;
  93. /* other data */
  94. const char *data;
  95. };
  96. #define FOTA_DBUS_INTROSPECTION_INTERFACE "org.freedesktop.DBus.Introspectable"
  97. #define FOTA_DBUS_INTROSPECTION_METHOD "Introspect"
  98. #define FOTA_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
  99. #define FOTA_DBUS_PROPERTIES_GET "Get"
  100. #define FOTA_DBUS_PROPERTIES_SET "Set"
  101. #define FOTA_DBUS_PROPERTIES_GETALL "GetAll"
  102. extern const struct fota_dbus_method_desc fota_dbus_global_methods[];
  103. DBusMessage *fota_dbus_introspect(DBusMessage *message,
  104. struct fota_dbus_object_desc *obj_dsc,
  105. fota_server_t *fota);
  106. #endif /* _DBUS_NEW_HELPER_H_ */