sd-bus-vtable.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef foosdbusvtablehfoo
  2. #define foosdbusvtablehfoo
  3. /***
  4. This file is part of systemd.
  5. Copyright 2013 Lennart Poettering
  6. systemd is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published by
  8. the Free Software Foundation; either version 2.1 of the License, or
  9. (at your option) any later version.
  10. systemd is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with systemd; If not, see <http://www.gnu.org/licenses/>.
  16. ***/
  17. #include "_sd-common.h"
  18. _SD_BEGIN_DECLARATIONS;
  19. typedef struct sd_bus_vtable sd_bus_vtable;
  20. #include "sd-bus.h"
  21. enum {
  22. _SD_BUS_VTABLE_START = '<',
  23. _SD_BUS_VTABLE_END = '>',
  24. _SD_BUS_VTABLE_METHOD = 'M',
  25. _SD_BUS_VTABLE_SIGNAL = 'S',
  26. _SD_BUS_VTABLE_PROPERTY = 'P',
  27. _SD_BUS_VTABLE_WRITABLE_PROPERTY = 'W'
  28. };
  29. enum {
  30. SD_BUS_VTABLE_DEPRECATED = 1ULL << 0,
  31. SD_BUS_VTABLE_HIDDEN = 1ULL << 1,
  32. SD_BUS_VTABLE_UNPRIVILEGED = 1ULL << 2,
  33. SD_BUS_VTABLE_METHOD_NO_REPLY = 1ULL << 3,
  34. SD_BUS_VTABLE_PROPERTY_CONST = 1ULL << 4,
  35. SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE = 1ULL << 5,
  36. SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION = 1ULL << 6,
  37. SD_BUS_VTABLE_PROPERTY_EXPLICIT = 1ULL << 7,
  38. _SD_BUS_VTABLE_CAPABILITY_MASK = 0xFFFFULL << 40
  39. };
  40. #define SD_BUS_VTABLE_CAPABILITY(x) ((uint64_t) (((x)+1) & 0xFFFF) << 40)
  41. struct sd_bus_vtable {
  42. /* Please do not initialize this structure directly, use the
  43. * macros below instead */
  44. uint8_t type:8;
  45. uint64_t flags:56;
  46. union {
  47. struct {
  48. size_t element_size;
  49. } start;
  50. struct {
  51. const char *member;
  52. const char *signature;
  53. const char *result;
  54. sd_bus_message_handler_t handler;
  55. size_t offset;
  56. } method;
  57. struct {
  58. const char *member;
  59. const char *signature;
  60. } signal;
  61. struct {
  62. const char *member;
  63. const char *signature;
  64. sd_bus_property_get_t get;
  65. sd_bus_property_set_t set;
  66. size_t offset;
  67. } property;
  68. } x;
  69. };
  70. #define SD_BUS_VTABLE_START(_flags) \
  71. { \
  72. .type = _SD_BUS_VTABLE_START, \
  73. .flags = _flags, \
  74. .x.start.element_size = sizeof(sd_bus_vtable), \
  75. }
  76. #define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags) \
  77. { \
  78. .type = _SD_BUS_VTABLE_METHOD, \
  79. .flags = _flags, \
  80. .x.method.member = _member, \
  81. .x.method.signature = _signature, \
  82. .x.method.result = _result, \
  83. .x.method.handler = _handler, \
  84. .x.method.offset = _offset, \
  85. }
  86. #define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags) \
  87. SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, 0, _flags)
  88. #define SD_BUS_SIGNAL(_member, _signature, _flags) \
  89. { \
  90. .type = _SD_BUS_VTABLE_SIGNAL, \
  91. .flags = _flags, \
  92. .x.signal.member = _member, \
  93. .x.signal.signature = _signature, \
  94. }
  95. #define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \
  96. { \
  97. .type = _SD_BUS_VTABLE_PROPERTY, \
  98. .flags = _flags, \
  99. .x.property.member = _member, \
  100. .x.property.signature = _signature, \
  101. .x.property.get = _get, \
  102. .x.property.offset = _offset, \
  103. }
  104. #define SD_BUS_WRITABLE_PROPERTY(_member, _signature, _get, _set, _offset, _flags) \
  105. { \
  106. .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, \
  107. .flags = _flags, \
  108. .x.property.member = _member, \
  109. .x.property.signature = _signature, \
  110. .x.property.get = _get, \
  111. .x.property.set = _set, \
  112. .x.property.offset = _offset, \
  113. }
  114. #define SD_BUS_VTABLE_END \
  115. { \
  116. .type = _SD_BUS_VTABLE_END, \
  117. }
  118. _SD_END_DECLARATIONS;
  119. #endif