NCDRequestClient.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. void *user;
  53. NCDRequestClient_handler_error handler_error;
  54. NCDRequestClient_handler_connected handler_connected;
  55. BConnector connector;
  56. BConnection con;
  57. PacketPassFifoQueue send_queue;
  58. PacketStreamSender send_sender;
  59. PacketProtoDecoder recv_decoder;
  60. PacketPassInterface recv_if;
  61. BAVL reqs_tree;
  62. uint32_t next_request_id;
  63. int state;
  64. int is_error;
  65. DebugCounter d_reqests_ctr;
  66. DebugError d_err;
  67. DebugObject d_obj;
  68. } NCDRequestClient;
  69. typedef struct {
  70. NCDRequestClient *client;
  71. void *user;
  72. NCDRequestClientRequest_handler_sent handler_sent;
  73. NCDRequestClientRequest_handler_reply handler_reply;
  74. NCDRequestClientRequest_handler_finished handler_finished;
  75. struct NCDRequestClient_req *req;
  76. DebugError d_err;
  77. DebugObject d_obj;
  78. } NCDRequestClientRequest;
  79. struct NCDRequestClient_req {
  80. NCDRequestClientRequest *creq;
  81. NCDRequestClient *client;
  82. BAVLNode reqs_tree_node;
  83. uint32_t request_id;
  84. uint8_t *request_data;
  85. int request_len;
  86. PacketPassInterface *send_qflow_iface;
  87. PacketPassFifoQueueFlow send_qflow;
  88. int state;
  89. };
  90. int NCDRequestClient_Init (NCDRequestClient *o, struct BConnection_addr addr, BReactor *reactor, void *user,
  91. NCDRequestClient_handler_error handler_error,
  92. NCDRequestClient_handler_connected handler_connected) WARN_UNUSED;
  93. void NCDRequestClient_Free (NCDRequestClient *o);
  94. int NCDRequestClientRequest_Init (NCDRequestClientRequest *o, NCDRequestClient *client, NCDValRef payload_value, void *user,
  95. NCDRequestClientRequest_handler_sent handler_sent,
  96. NCDRequestClientRequest_handler_reply handler_reply,
  97. NCDRequestClientRequest_handler_finished handler_finished) WARN_UNUSED;
  98. void NCDRequestClientRequest_Free (NCDRequestClientRequest *o);
  99. void NCDRequestClientRequest_Abort (NCDRequestClientRequest *o);
  100. #endif