internal.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. *
  3. * Copyright 2016, Google Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. #ifndef cgrpc_internal_h
  34. #define cgrpc_internal_h
  35. #include <grpc/grpc.h>
  36. #include <grpc/grpc_security.h>
  37. #include <grpc/byte_buffer_reader.h>
  38. #include <grpc/impl/codegen/alloc.h>
  39. typedef struct {
  40. grpc_call *call; // owned
  41. } cgrpc_call;
  42. typedef struct {
  43. grpc_op *ops; // owned
  44. int ops_count;
  45. } cgrpc_operations;
  46. typedef struct {
  47. grpc_channel *client; // owned
  48. grpc_completion_queue *completion_queue; // owned
  49. } cgrpc_client;
  50. typedef struct {
  51. grpc_server *server; // owned
  52. grpc_completion_queue *completion_queue; // owned
  53. int port;
  54. } cgrpc_server;
  55. typedef struct {
  56. cgrpc_server *server; // reference
  57. grpc_completion_queue *completion_queue; // owned; handlers have dedicated completion queues
  58. grpc_metadata_array request_metadata_recv;
  59. grpc_call_details call_details;
  60. grpc_call *server_call; // owned
  61. } cgrpc_handler;
  62. typedef grpc_byte_buffer cgrpc_byte_buffer;
  63. typedef grpc_completion_queue cgrpc_completion_queue;
  64. typedef grpc_metadata cgrpc_metadata;
  65. typedef grpc_metadata_array cgrpc_metadata_array;
  66. typedef gpr_mu cgrpc_mutex;
  67. // OPERATIONS
  68. typedef struct {
  69. grpc_op_type op_type;
  70. } cgrpc_observer;
  71. typedef struct {
  72. grpc_op_type op_type;
  73. grpc_metadata_array initial_metadata;
  74. } cgrpc_observer_send_initial_metadata;
  75. typedef struct {
  76. grpc_op_type op_type;
  77. grpc_byte_buffer *request_payload;
  78. } cgrpc_observer_send_message;
  79. typedef struct {
  80. grpc_op_type op_type;
  81. } cgrpc_observer_send_close_from_client;
  82. typedef struct {
  83. grpc_op_type op_type;
  84. grpc_metadata_array trailing_metadata;
  85. grpc_status_code status;
  86. char *status_details;
  87. } cgrpc_observer_send_status_from_server;
  88. typedef struct {
  89. grpc_op_type op_type;
  90. grpc_metadata_array initial_metadata_recv;
  91. } cgrpc_observer_recv_initial_metadata;
  92. typedef struct {
  93. grpc_op_type op_type;
  94. grpc_byte_buffer *response_payload_recv;
  95. } cgrpc_observer_recv_message;
  96. typedef struct {
  97. grpc_op_type op_type;
  98. grpc_metadata_array trailing_metadata_recv;
  99. grpc_status_code server_status;
  100. char *server_details;
  101. size_t server_details_capacity;
  102. } cgrpc_observer_recv_status_on_client;
  103. typedef struct {
  104. grpc_op_type op_type;
  105. int was_cancelled;
  106. } cgrpc_observer_recv_close_on_server;
  107. // internal utilities
  108. void *cgrpc_create_tag(intptr_t t);
  109. gpr_timespec cgrpc_deadline_in_seconds_from_now(float seconds);
  110. void cgrpc_observer_apply(cgrpc_observer *observer, grpc_op *op);
  111. #endif /* cgrpc_internal_h */