sp_ses.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef SP_SES_H
  2. #define SP_SES_H
  3. #pragma once
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include "refcnt.h"
  8. #include "y2k_time.h"
  9. typedef struct sp_svc_t sp_svc_t;
  10. typedef struct iobuffer_t iobuffer_t;
  11. typedef struct sp_ses_mgr_t sp_ses_mgr_t;
  12. typedef struct sp_ses_uac_t sp_ses_uac_t;
  13. typedef struct sp_ses_uas_t sp_ses_uas_t;
  14. typedef struct sp_tsx_uac_t sp_tsx_uac_t;
  15. typedef struct sp_tsx_uas_t sp_tsx_uas_t;
  16. /** session mgr (both client session and server session ) */
  17. typedef struct sp_ses_mgr_callback_t {
  18. int (*on_accept)(sp_ses_mgr_t *mgr, int epid, int svc_id, int conn_id, iobuffer_t **conn_pkt, int *redirect_target, void *user_data);
  19. void (*on_destroy)(sp_ses_mgr_t *mgr, void *user_data);
  20. void *user_data;
  21. }sp_ses_mgr_callback_t;
  22. int sp_ses_mgr_create(sp_svc_t *svc, sp_ses_mgr_callback_t *cb, sp_ses_mgr_t **p_mgr);
  23. void sp_ses_mgr_destroy(sp_ses_mgr_t *mgr);
  24. int sp_ses_mgr_cancel_all(sp_ses_mgr_t *mgr);
  25. int sp_ses_mgr_get_conn_cnt(sp_ses_mgr_t *mgr);
  26. int sp_ses_mgr_start(sp_ses_mgr_t *mgr);
  27. int sp_ses_mgr_stop(sp_ses_mgr_t *mgr);
  28. sp_svc_t *sp_ses_mgr_get_svc(sp_ses_mgr_t *mgr);
  29. typedef struct sp_ses_info_t
  30. {
  31. int from_svc_id;
  32. int to_svc_id;
  33. y2k_time_t begin_time;
  34. int state;
  35. y2k_time_t state_begin_time;
  36. }sp_ses_info_t;
  37. sp_ses_info_t* sp_ses_mgr_get_ses_info(sp_ses_mgr_t *mgr, int *cnt);
  38. #define SP_SES_STATE_INIT 1
  39. #define SP_SES_STATE_CONNECTING 2
  40. #define SP_SES_STATE_CONNECTED 3
  41. #define SP_SES_STATE_TERM 4
  42. #define SP_SES_STATE_ERROR 5
  43. /** client session */
  44. typedef struct sp_ses_uac_callback {
  45. void (*on_connect)(sp_ses_uac_t *uac, int error, void *user_data);
  46. void (*on_close)(sp_ses_uac_t *uac, int error, void *user_data);
  47. void (*on_destroy)(sp_ses_uac_t *uac, void *user_data);
  48. void *user_data;
  49. }sp_ses_uac_callback;
  50. int sp_ses_uac_create(sp_ses_mgr_t *mgr, int remote_epid, int remote_svc_id, sp_ses_uac_callback *cb, sp_ses_uac_t **p_ses);
  51. void sp_ses_uac_destroy(sp_ses_uac_t *uac);
  52. int sp_ses_uac_async_connect(sp_ses_uac_t *uac, int timeout, iobuffer_t **conn_pkt);
  53. int sp_ses_uac_close(sp_ses_uac_t *uac);
  54. int sp_ses_uac_get_state(sp_ses_uac_t *uac);
  55. int sp_ses_uac_send_info(sp_ses_uac_t *uac, int method_id, int method_sig, iobuffer_t **info_pkt);
  56. int sp_ses_uac_get_remote_epid(sp_ses_uac_t *uac);
  57. int sp_ses_uac_get_remote_svc_id(sp_ses_uac_t *uac);
  58. int sp_ses_uac_get_conn_id(sp_ses_uac_t *uac);
  59. sp_ses_mgr_t *sp_ses_uac_get_mgr(sp_ses_uac_t *uac);
  60. int sp_ses_uac_get_tsx_cnt(sp_ses_uac_t *uac);
  61. /** server session */
  62. typedef struct sp_ses_uas_callback {
  63. int (*get_method_attr)(sp_ses_uas_t *uas, int method_id, int method_sig, int *overlap, void *user_data);
  64. void (*on_req)(sp_ses_uas_t *uas, int tsx_id, int method_id, int method_sig, int timeout, iobuffer_t **req_pkt, void *user_data);
  65. void (*on_info)(sp_ses_uas_t *uas, int method_id, int method_sig, iobuffer_t **info_pkt, void *user_data);
  66. void (*on_close)(sp_ses_uas_t *uas, int error, void *user_data);
  67. void (*on_destroy)(sp_ses_uas_t *uas, void *user_data);
  68. void *user_data;
  69. }sp_ses_uas_callback;
  70. int sp_ses_uas_create(sp_ses_mgr_t *mgr, int remote_epid, int remote_svc_id, int conn_id, int overlap, sp_ses_uas_callback *cb, sp_ses_uas_t **p_uas);
  71. void sp_ses_uas_destroy(sp_ses_uas_t *uas);
  72. int sp_ses_uas_close(sp_ses_uas_t *uas);
  73. int sp_ses_uas_get_remote_epid(sp_ses_uas_t *uas);
  74. int sp_ses_uas_get_remote_svc_id(sp_ses_uas_t *uas);
  75. int sp_ses_uas_get_conn_id(sp_ses_uas_t *uas);
  76. sp_ses_mgr_t *sp_ses_uas_get_mgr(sp_ses_uas_t *uas);
  77. int sp_ses_uas_get_state(sp_ses_uas_t *uas);
  78. int sp_ses_uas_get_tsx_cnt(sp_ses_uas_t *uas);
  79. int sp_ses_uas_accept(sp_ses_uas_t *uas);
  80. /* transaction */
  81. /* client side transaction */
  82. /*
  83. create +----------+ req +----------+ on_ans +----------+ on_ans +----------+ close +----------+
  84. --------> | INIT | --------> | REQ | --------> | TMPANS | --------> | ANS | --------> | TERM |
  85. +----------+ +----------+ +----------+ +----------+ +----------+
  86. */
  87. #define SP_TSX_UAC_STATE_INIT 1
  88. #define SP_TSX_UAC_STATE_TERM 2
  89. #define SP_TSX_UAC_STATE_REQ 3
  90. #define SP_TSX_UAC_STATE_ANS 4
  91. #define SP_TSX_UAC_STATE_TMPANS 5
  92. #define SP_TSX_UAC_STATE_ERROR 6
  93. typedef struct sp_tsx_uac_callback {
  94. void (*on_ans)(sp_tsx_uac_t *tsx, int error, int end, iobuffer_t **ans_pkt, void *user_data);
  95. void (*on_destroy)(sp_tsx_uac_t *tsx, void *user_data);
  96. void *user_data;
  97. }sp_tsx_uac_callback;
  98. int sp_tsx_uac_create(sp_ses_uac_t *uac, int tsx_id, int method_id, int method_sig, sp_tsx_uac_callback *cb, sp_tsx_uac_t **p_tsx);
  99. void sp_tsx_uac_destroy(sp_tsx_uac_t *tsx);
  100. int sp_tsx_uac_async_req(sp_tsx_uac_t *tsx, int timeout, iobuffer_t **req_pkt);
  101. int sp_tsx_uac_close(sp_tsx_uac_t *tsx);
  102. sp_ses_uac_t *sp_tsx_uac_get_session(sp_tsx_uac_t *tsx);
  103. int sp_tsx_uac_get_state(sp_tsx_uac_t *tsx);
  104. int sp_tsx_uac_get_id(sp_tsx_uac_t *tsx);
  105. /* server side transaction */
  106. /*
  107. create +----------+ answer +----------+ answer +----------+ close +----------+
  108. -------->| INIT | --------> | TMPANS | --------> | ANS | --------> | TERM |
  109. +----------+ +----------+ +----------+ +----------+
  110. */
  111. #define SP_TSX_UAS_STATE_INIT 1
  112. #define SP_TSX_UAS_STATE_TMPANS 2
  113. #define SP_TSX_UAS_STATE_ANS 3
  114. #define SP_TSX_UAS_STATE_TERM 4
  115. #define SP_TSX_UAS_STATE_ERROR 5
  116. typedef struct sp_tsx_uas_callback {
  117. void (*on_destroy)(sp_tsx_uas_t *tsx, void *user_data);
  118. void *user_data;
  119. }sp_tsx_uas_callback;
  120. int sp_tsx_uas_create(sp_ses_uas_t *uas, int tsx_id, sp_tsx_uas_callback *cb, sp_tsx_uas_t **p_tsx);
  121. void sp_tsx_uas_destroy(sp_tsx_uas_t *tsx);
  122. sp_ses_uas_t *sp_tsx_uas_get_session(sp_tsx_uas_t *tsx);
  123. int sp_tsx_uas_get_state(sp_tsx_uas_t *tsx);
  124. int sp_tsx_uas_get_id(sp_tsx_uas_t *tsx);
  125. int sp_tsx_uas_close(sp_tsx_uas_t *tsx);
  126. int sp_tsx_uas_answer(sp_tsx_uas_t *tsx, int end, iobuffer_t **ans_pkt);
  127. #ifdef __cplusplus
  128. } // extern "C" {
  129. #endif
  130. #endif // SP_SES_H