NCDRequestClient.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @file NCDRequestClient.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef BADVPN_NCDREQUESTCLIENT_H
  30. #define BADVPN_NCDREQUESTCLIENT_H
  31. #include <stdint.h>
  32. #include <misc/debug.h>
  33. #include <misc/debugerror.h>
  34. #include <misc/debugcounter.h>
  35. #include <structure/BAVL.h>
  36. #include <base/DebugObject.h>
  37. #include <system/BConnection.h>
  38. #include <system/BConnectionGeneric.h>
  39. #include <flow/PacketProtoDecoder.h>
  40. #include <flow/PacketStreamSender.h>
  41. #include <flow/PacketPassFifoQueue.h>
  42. #include <ncd/NCDValGenerator.h>
  43. #include <ncd/NCDValParser.h>
  44. struct NCDRequestClient_req;
  45. typedef void (*NCDRequestClient_handler_error) (void *user);
  46. typedef void (*NCDRequestClient_handler_connected) (void *user);
  47. typedef void (*NCDRequestClientRequest_handler_sent) (void *user);
  48. typedef void (*NCDRequestClientRequest_handler_reply) (void *user, NCDValMem reply_mem, NCDValRef reply_value);
  49. typedef void (*NCDRequestClientRequest_handler_finished) (void *user, int is_error);
  50. typedef struct {
  51. BReactor *reactor;
  52. NCDStringIndex *string_index;
  53. void *user;
  54. NCDRequestClient_handler_error handler_error;
  55. NCDRequestClient_handler_connected handler_connected;
  56. BConnector connector;
  57. BConnection con;
  58. PacketPassFifoQueue send_queue;
  59. PacketStreamSender send_sender;
  60. PacketProtoDecoder recv_decoder;
  61. PacketPassInterface recv_if;
  62. BAVL reqs_tree;
  63. uint32_t next_request_id;
  64. int state;
  65. int is_error;
  66. DebugCounter d_reqests_ctr;
  67. DebugError d_err;
  68. DebugObject d_obj;
  69. } NCDRequestClient;
  70. typedef struct {
  71. NCDRequestClient *client;
  72. void *user;
  73. NCDRequestClientRequest_handler_sent handler_sent;
  74. NCDRequestClientRequest_handler_reply handler_reply;
  75. NCDRequestClientRequest_handler_finished handler_finished;
  76. struct NCDRequestClient_req *req;
  77. DebugError d_err;
  78. DebugObject d_obj;
  79. } NCDRequestClientRequest;
  80. struct NCDRequestClient_req {
  81. NCDRequestClientRequest *creq;
  82. NCDRequestClient *client;
  83. BAVLNode reqs_tree_node;
  84. uint32_t request_id;
  85. uint8_t *request_data;
  86. int request_len;
  87. PacketPassInterface *send_qflow_iface;
  88. PacketPassFifoQueueFlow send_qflow;
  89. int state;
  90. };
  91. int NCDRequestClient_Init (NCDRequestClient *o, struct BConnection_addr addr, BReactor *reactor, NCDStringIndex *string_index,
  92. void *user,
  93. NCDRequestClient_handler_error handler_error,
  94. NCDRequestClient_handler_connected handler_connected) WARN_UNUSED;
  95. void NCDRequestClient_Free (NCDRequestClient *o);
  96. int NCDRequestClientRequest_Init (NCDRequestClientRequest *o, NCDRequestClient *client, NCDValRef payload_value, void *user,
  97. NCDRequestClientRequest_handler_sent handler_sent,
  98. NCDRequestClientRequest_handler_reply handler_reply,
  99. NCDRequestClientRequest_handler_finished handler_finished) WARN_UNUSED;
  100. void NCDRequestClientRequest_Free (NCDRequestClientRequest *o);
  101. void NCDRequestClientRequest_Abort (NCDRequestClientRequest *o);
  102. #endif