handle_type.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2018-2019 SignalWire, Inc
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. #pragma once
  23. #define KS_BEGIN_EXTERN_C
  24. /* Define the handle types in swclient. We start at the user group start
  25. * id, libks owns all groups prior. so we get 10 groups to play with
  26. * but for now we only use one, KS_HANDLE_GROUP_SWCLT. */
  27. #define KS_HANDLE_GROUP_SWCLT KS_HANDLE_USER_GROUP_START
  28. #define KS_HANDLE_GROUP_SWCLT_SYS (KS_HANDLE_USER_GROUP_START + 1)
  29. typedef enum {
  30. /* CMD - Commands are request/reply wrappers for json rpc */
  31. SWCLT_HTYPE_CMD = KS_HANDLE_MAKE_TYPE(SWCLT_SYS, 1),
  32. /* SESS - A session is the highest level construct, and is the
  33. * primary means in which a client ineracts with this sdk. */
  34. SWCLT_HTYPE_SESS = KS_HANDLE_MAKE_TYPE(SWCLT_SYS, 2),
  35. /* SUB - A subscription holds the callback state for a subscription
  36. * and is a child of a session. */
  37. SWCLT_HTYPE_SUB = KS_HANDLE_MAKE_TYPE(SWCLT, 1),
  38. /* STORE - A node store contains the up to date state of
  39. * provider/protocols/channels and routes */
  40. SWCLT_HTYPE_STORE = KS_HANDLE_MAKE_TYPE(SWCLT, 2),
  41. /* HMON - A handle monitoring context, used for state change
  42. * detection on any swclient handle */
  43. SWCLT_HTYPE_HMON = KS_HANDLE_MAKE_TYPE(SWCLT, 3),
  44. /* TEST - Used for unit testing */
  45. SWCLT_HTYPE_TEST = KS_HANDLE_MAKE_TYPE(SWCLT, 4),
  46. } swclt_htype_t;
  47. static inline ks_bool_t swclt_htype_valid(swclt_htype_t type)
  48. {
  49. /* The type is valid if its group is our group */
  50. return KS_HANDLE_GROUP_FROM_TYPE(type) == KS_HANDLE_GROUP_SWCLT ||
  51. KS_HANDLE_GROUP_FROM_TYPE(type) == KS_HANDLE_GROUP_SWCLT_SYS;
  52. }
  53. static inline const char *swclt_htype_str(swclt_htype_t type)
  54. {
  55. switch(type) {
  56. case SWCLT_HTYPE_CMD:
  57. return "Command";
  58. case SWCLT_HTYPE_SESS:
  59. return "Session";
  60. case SWCLT_HTYPE_SUB:
  61. return "Subscription";
  62. case SWCLT_HTYPE_STORE:
  63. return "NodeStore";
  64. case SWCLT_HTYPE_HMON:
  65. return "HandleMonitor";
  66. default:
  67. ks_abort_fmt("Invalid handle type: %lu", type);
  68. }
  69. }
  70. #define KS_END_EXTERN_C
  71. /* For Emacs:
  72. * Local Variables:
  73. * mode:c
  74. * indent-tabs-mode:t
  75. * tab-width:4
  76. * c-basic-offset:4
  77. * End:
  78. * For VIM:
  79. * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
  80. */