dbus_new_helpers.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * WPA 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 WPA_DBUS_CTRL_H
  10. #define WPA_DBUS_CTRL_H
  11. #include <dbus/dbus.h>
  12. typedef DBusMessage * (*WPADBusMethodHandler)(DBusMessage *message,
  13. void *user_data);
  14. typedef void (*WPADBusArgumentFreeFunction)(void *handler_arg);
  15. struct wpa_dbus_property_desc;
  16. typedef dbus_bool_t (*WPADBusPropertyAccessor)(
  17. const struct wpa_dbus_property_desc *property_desc,
  18. DBusMessageIter *iter, DBusError *error, void *user_data);
  19. #define DECLARE_ACCESSOR(f) \
  20. dbus_bool_t f(const struct wpa_dbus_property_desc *property_desc, \
  21. DBusMessageIter *iter, DBusError *error, void *user_data)
  22. struct wpa_dbus_object_desc {
  23. DBusConnection *connection;
  24. char *path;
  25. /* list of methods, properties and signals registered with object */
  26. const struct wpa_dbus_method_desc *methods;
  27. const struct wpa_dbus_signal_desc *signals;
  28. const struct wpa_dbus_property_desc *properties;
  29. /* property changed flags */
  30. u8 *prop_changed_flags;
  31. /* argument for method handlers and properties
  32. * getter and setter functions */
  33. void *user_data;
  34. /* function used to free above argument */
  35. WPADBusArgumentFreeFunction user_data_free_func;
  36. };
  37. enum dbus_arg_direction { ARG_IN, ARG_OUT };
  38. struct wpa_dbus_argument {
  39. char *name;
  40. char *type;
  41. enum dbus_arg_direction dir;
  42. };
  43. #define END_ARGS { NULL, NULL, ARG_IN }
  44. /**
  45. * struct wpa_dbus_method_desc - DBus method description
  46. */
  47. struct wpa_dbus_method_desc {
  48. /* method name */
  49. const char *dbus_method;
  50. /* method interface */
  51. const char *dbus_interface;
  52. /* method handling function */
  53. WPADBusMethodHandler method_handler;
  54. /* array of arguments */
  55. struct wpa_dbus_argument args[4];
  56. };
  57. /**
  58. * struct wpa_dbus_signal_desc - DBus signal description
  59. */
  60. struct wpa_dbus_signal_desc {
  61. /* signal name */
  62. const char *dbus_signal;
  63. /* signal interface */
  64. const char *dbus_interface;
  65. /* array of arguments */
  66. struct wpa_dbus_argument args[4];
  67. };
  68. /**
  69. * struct wpa_dbus_property_desc - DBus property description
  70. */
  71. struct wpa_dbus_property_desc {
  72. /* property name */
  73. const char *dbus_property;
  74. /* property interface */
  75. const char *dbus_interface;
  76. /* property type signature in DBus type notation */
  77. const char *type;
  78. /* property getter function */
  79. WPADBusPropertyAccessor getter;
  80. /* property setter function */
  81. WPADBusPropertyAccessor setter;
  82. /* other data */
  83. const char *data;
  84. };
  85. #define WPAS_DBUS_OBJECT_PATH_MAX 150
  86. #define WPAS_DBUS_INTERFACE_MAX 150
  87. #define WPAS_DBUS_METHOD_SIGNAL_PROP_MAX 50
  88. #define WPAS_DBUS_AUTH_MODE_MAX 64
  89. #define WPA_DBUS_INTROSPECTION_INTERFACE "org.freedesktop.DBus.Introspectable"
  90. #define WPA_DBUS_INTROSPECTION_METHOD "Introspect"
  91. #define WPA_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
  92. #define WPA_DBUS_PROPERTIES_GET "Get"
  93. #define WPA_DBUS_PROPERTIES_SET "Set"
  94. #define WPA_DBUS_PROPERTIES_GETALL "GetAll"
  95. void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc);
  96. int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface, char *dbus_path,
  97. char *dbus_service,
  98. struct wpa_dbus_object_desc *obj_desc);
  99. int wpa_dbus_register_object_per_iface(
  100. struct wpas_dbus_priv *ctrl_iface,
  101. const char *path, const char *ifname,
  102. struct wpa_dbus_object_desc *obj_desc);
  103. int wpa_dbus_unregister_object_per_iface(
  104. struct wpas_dbus_priv *ctrl_iface,
  105. const char *path);
  106. dbus_bool_t wpa_dbus_get_object_properties(struct wpas_dbus_priv *iface,
  107. const char *path,
  108. const char *interface,
  109. DBusMessageIter *iter);
  110. void wpa_dbus_flush_all_changed_properties(DBusConnection *con);
  111. void wpa_dbus_flush_object_changed_properties(DBusConnection *con,
  112. const char *path);
  113. void wpa_dbus_mark_property_changed(struct wpas_dbus_priv *iface,
  114. const char *path, const char *interface,
  115. const char *property);
  116. DBusMessage * wpa_dbus_introspect(DBusMessage *message,
  117. struct wpa_dbus_object_desc *obj_dsc);
  118. char * wpas_dbus_new_decompose_object_path(const char *path, const char *sep,
  119. char **item);
  120. DBusMessage *wpas_dbus_reply_new_from_error(DBusMessage *message,
  121. DBusError *error,
  122. const char *fallback_name,
  123. const char *fallback_string);
  124. #endif /* WPA_DBUS_CTRL_H */