client.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. *
  3. * Copyright 2015, 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. #include "src/core/surface/client.h"
  34. #include "src/core/surface/call.h"
  35. #include "src/core/surface/channel.h"
  36. #include "src/core/support/string.h"
  37. #include <grpc/support/alloc.h>
  38. #include <grpc/support/log.h>
  39. typedef struct { void *unused; } call_data;
  40. typedef struct { void *unused; } channel_data;
  41. static void client_start_transport_op(grpc_call_element *elem,
  42. grpc_transport_op *op) {
  43. GRPC_CALL_LOG_OP(GPR_INFO, elem, op);
  44. grpc_call_next_op(elem, op);
  45. }
  46. static void channel_op(grpc_channel_element *elem,
  47. grpc_channel_element *from_elem, grpc_channel_op *op) {
  48. switch (op->type) {
  49. case GRPC_ACCEPT_CALL:
  50. gpr_log(GPR_ERROR, "Client cannot accept new calls");
  51. break;
  52. case GRPC_TRANSPORT_CLOSED:
  53. grpc_client_channel_closed(elem);
  54. break;
  55. case GRPC_TRANSPORT_GOAWAY:
  56. gpr_slice_unref(op->data.goaway.message);
  57. break;
  58. default:
  59. GPR_ASSERT(op->dir == GRPC_CALL_DOWN);
  60. grpc_channel_next_op(elem, op);
  61. }
  62. }
  63. static void init_call_elem(grpc_call_element *elem,
  64. const void *transport_server_data,
  65. grpc_transport_op *initial_op) {}
  66. static void destroy_call_elem(grpc_call_element *elem) {}
  67. static void init_channel_elem(grpc_channel_element *elem,
  68. const grpc_channel_args *args, grpc_mdctx *mdctx,
  69. int is_first, int is_last) {
  70. GPR_ASSERT(is_first);
  71. GPR_ASSERT(!is_last);
  72. }
  73. static void destroy_channel_elem(grpc_channel_element *elem) {}
  74. const grpc_channel_filter grpc_client_surface_filter = {
  75. client_start_transport_op, channel_op, sizeof(call_data), init_call_elem,
  76. destroy_call_elem, sizeof(channel_data), init_channel_elem,
  77. destroy_channel_elem, "client",
  78. };