dbus_new_helpers.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Alternatively, this software may be distributed under the terms of BSD
  11. * license.
  12. *
  13. * See README and COPYING for more details.
  14. */
  15. #ifndef WPA_DBUS_CTRL_H
  16. #define WPA_DBUS_CTRL_H
  17. #include <dbus/dbus.h>
  18. typedef DBusMessage * (* WPADBusMethodHandler)(DBusMessage *message,
  19. void *user_data);
  20. typedef void (* WPADBusArgumentFreeFunction)(void *handler_arg);
  21. typedef DBusMessage * (* WPADBusPropertyAccessor)(DBusMessage *message,
  22. const void *user_data);
  23. struct wpa_dbus_object_desc {
  24. DBusConnection *connection;
  25. /* list of methods, properties and signals registered with object */
  26. struct wpa_dbus_method_desc *methods;
  27. struct wpa_dbus_signal_desc *signals;
  28. struct wpa_dbus_property_desc *properties;
  29. /* argument for method handlers and properties
  30. * getter and setter functions */
  31. void *user_data;
  32. /* function used to free above argument */
  33. WPADBusArgumentFreeFunction user_data_free_func;
  34. };
  35. enum dbus_prop_access { R, W, RW };
  36. enum dbus_arg_direction { ARG_IN, ARG_OUT };
  37. struct wpa_dbus_argument {
  38. char *name;
  39. char *type;
  40. enum dbus_arg_direction dir;
  41. };
  42. #define END_ARGS { NULL, NULL, ARG_IN }
  43. /**
  44. * struct wpa_dbus_method_desc - DBus method description
  45. */
  46. struct wpa_dbus_method_desc {
  47. /* pointer to next description in list */
  48. struct wpa_dbus_method_desc *next;
  49. /* method interface */
  50. char *dbus_interface;
  51. /* method name */
  52. char *dbus_method;
  53. /* method handling function */
  54. WPADBusMethodHandler method_handler;
  55. /* number of method arguments */
  56. int args_num;
  57. /* array of arguments */
  58. struct wpa_dbus_argument args[];
  59. };
  60. /**
  61. * struct wpa_dbus_signal_desc - DBus signal description
  62. */
  63. struct wpa_dbus_signal_desc {
  64. /* pointer to next description in list */
  65. struct wpa_dbus_signal_desc *next;
  66. /* signal interface */
  67. char *dbus_interface;
  68. /* signal name */
  69. char *dbus_signal;
  70. /* number of signal arguments */
  71. int args_num;
  72. /* array of arguments */
  73. struct wpa_dbus_argument args[0];
  74. };
  75. /**
  76. * struct wpa_dbus_property_desc - DBus property description
  77. */
  78. struct wpa_dbus_property_desc {
  79. /* pointer to next description in list */
  80. struct wpa_dbus_property_desc *next;
  81. /* property interface */
  82. char *dbus_interface;
  83. /* property name */
  84. char *dbus_property;
  85. /* property type signature in DBus type notation */
  86. char *type;
  87. /* property access permissions */
  88. enum dbus_prop_access access;
  89. /* property getter function */
  90. WPADBusPropertyAccessor getter;
  91. /* property setter function */
  92. WPADBusPropertyAccessor setter;
  93. };
  94. #define WPAS_DBUS_OBJECT_PATH_MAX 150
  95. #define WPAS_DBUS_INTERFACE_MAX 150
  96. #define WPAS_DBUS_METHOD_SIGNAL_PROP_MAX 50
  97. #define WPA_DBUS_INTROSPECTION_INTERFACE "org.freedesktop.DBus.Introspectable"
  98. #define WPA_DBUS_INTROSPECTION_METHOD "Introspect"
  99. #define WPA_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
  100. #define WPA_DBUS_PROPERTIES_GET "Get"
  101. #define WPA_DBUS_PROPERTIES_SET "Set"
  102. #define WPA_DBUS_PROPERTIES_GETALL "GetAll"
  103. void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc);
  104. int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface, char *dbus_path,
  105. char *dbus_service,
  106. struct wpa_dbus_object_desc *obj_desc);
  107. int wpa_dbus_register_object_per_iface(
  108. struct wpas_dbus_priv *ctrl_iface,
  109. const char *path, const char *ifname,
  110. struct wpa_dbus_object_desc *obj_desc);
  111. int wpa_dbus_unregister_object_per_iface(
  112. struct wpas_dbus_priv *ctrl_iface,
  113. const char *path);
  114. int wpa_dbus_method_register(struct wpa_dbus_object_desc *obj_dsc,
  115. const char *dbus_interface,
  116. const char *dbus_method,
  117. WPADBusMethodHandler method_handler,
  118. const struct wpa_dbus_argument args[]);
  119. int wpa_dbus_signal_register(struct wpa_dbus_object_desc *obj_dsc,
  120. const char *dbus_interface,
  121. const char *dbus_signal,
  122. const struct wpa_dbus_argument args[]);
  123. int wpa_dbus_property_register(
  124. struct wpa_dbus_object_desc *obj_dsc,
  125. const char *dbus_interface, const char *dbus_property,
  126. const char *type,
  127. WPADBusPropertyAccessor getter,
  128. WPADBusPropertyAccessor setter,
  129. enum dbus_prop_access _access);
  130. void wpa_dbus_signal_property_changed(struct wpas_dbus_priv *iface,
  131. WPADBusPropertyAccessor property_getter,
  132. void *getter_arg,
  133. const char *path,
  134. const char *interface_name,
  135. const char *property_name);
  136. void wpa_dbus_get_object_properties(struct wpas_dbus_priv *iface,
  137. const char *path, const char *interface,
  138. DBusMessageIter *dict_iter);
  139. DBusMessage * wpa_dbus_introspect(DBusMessage *message,
  140. struct wpa_dbus_object_desc *obj_dsc);
  141. #endif /* WPA_DBUS_CTRL_H */