test-cplusplus.cpp 858 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "libubus.h"
  2. // Ensure UBUS_* macros can be used from C++
  3. static int handler(ubus_context *, ubus_object *, ubus_request_data *, const char *, blob_attr *)
  4. {
  5. return 0;
  6. }
  7. enum {
  8. HELLO_ID,
  9. HELLO_MSG,
  10. };
  11. constexpr blobmsg_policy hello_policy[] = {
  12. [HELLO_ID] = { .name = "id", .type = BLOBMSG_TYPE_INT32 },
  13. [HELLO_MSG] = { .name = "msg", .type = BLOBMSG_TYPE_STRING },
  14. };
  15. constexpr ubus_method test_methods[] = {
  16. UBUS_METHOD("hello1", handler, hello_policy),
  17. UBUS_METHOD_TAG("hello2", handler, hello_policy, UBUS_TAG_ADMIN | UBUS_TAG_PRIVATE),
  18. UBUS_METHOD_MASK("hello3", handler, hello_policy, 0),
  19. UBUS_METHOD_NOARG("hello4", handler),
  20. UBUS_METHOD_TAG_NOARG("hello5", handler, UBUS_TAG_STATUS),
  21. };
  22. constexpr ubus_object_type test_object_type = UBUS_OBJECT_TYPE("test", test_methods);
  23. int main()
  24. {
  25. (void) test_object_type;
  26. return 0;
  27. }