blob: fc83dace20552b7838487a1b3688e2d210068136 [file] [log] [blame]
mlumishb892a272014-12-09 16:28:23 -08001<?php
Craig Tiller2e498aa2015-02-16 12:09:31 -08002/*
3 *
4 * Copyright 2015, Google Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following disclaimer
15 * in the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Google Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
mlumishb892a272014-12-09 16:28:23 -080034namespace Grpc;
mlumishb892a272014-12-09 16:28:23 -080035
36/**
37 * Base class for generated client stubs. Stub methods are expected to call
38 * _simpleRequest or _streamRequest and return the result.
39 */
40class BaseStub {
41
42 private $channel;
43
murgatroid99f21eb252015-01-30 13:47:41 -080044 public function __construct($hostname, $opts) {
45 $this->channel = new Channel($hostname, $opts);
mlumishb892a272014-12-09 16:28:23 -080046 }
47
48 /**
49 * Close the communication channel associated with this stub
50 */
51 public function close() {
52 $channel->close();
53 }
54
55 /* This class is intended to be subclassed by generated code, so all functions
56 begin with "_" to avoid name collisions. */
57
58 /**
59 * Call a remote method that takes a single argument and has a single output
60 *
61 * @param string $method The name of the method to call
62 * @param $argument The argument to the method
63 * @param callable $deserialize A function that deserializes the response
64 * @param array $metadata A metadata map to send to the server
65 * @return SimpleSurfaceActiveCall The active call object
66 */
murgatroid9914d2ce22015-01-30 15:36:23 -080067 public function _simpleRequest($method,
68 $argument,
69 callable $deserialize,
70 $metadata = array()) {
murgatroid999140a062015-03-26 11:27:58 -070071 $call = new UnaryCall($this->channel, $method, $deserialize);
72 $call->start($argument, $metadata);
73 return $call;
mlumishb892a272014-12-09 16:28:23 -080074 }
75
76 /**
77 * Call a remote method that takes a stream of arguments and has a single
78 * output
79 *
80 * @param string $method The name of the method to call
81 * @param $arguments An array or Traversable of arguments to stream to the
82 * server
83 * @param callable $deserialize A function that deserializes the response
84 * @param array $metadata A metadata map to send to the server
85 * @return ClientStreamingSurfaceActiveCall The active call object
86 */
murgatroid9914d2ce22015-01-30 15:36:23 -080087 public function _clientStreamRequest($method,
88 $arguments,
89 callable $deserialize,
90 $metadata = array()) {
murgatroid999140a062015-03-26 11:27:58 -070091 $call = new ClientStreamingCall($this->channel, $method, $deserialize);
92 $call->start($arguments, $metadata);
93 return $call;
mlumishb892a272014-12-09 16:28:23 -080094 }
95
96 /**
97 * Call a remote method that takes a single argument and returns a stream of
98 * responses
99 *
100 * @param string $method The name of the method to call
101 * @param $argument The argument to the method
102 * @param callable $deserialize A function that deserializes the responses
103 * @param array $metadata A metadata map to send to the server
104 * @return ServerStreamingSurfaceActiveCall The active call object
105 */
murgatroid9914d2ce22015-01-30 15:36:23 -0800106 public function _serverStreamRequest($method,
107 $argument,
108 callable $deserialize,
109 $metadata = array()) {
murgatroid999140a062015-03-26 11:27:58 -0700110 $call = new ServerStreamingCall($this->channel, $method, $deserialize);
111 $call->start($argument, $metadata);
112 return $call;
mlumishb892a272014-12-09 16:28:23 -0800113 }
114
115 /**
116 * Call a remote method with messages streaming in both directions
117 *
118 * @param string $method The name of the method to call
119 * @param callable $deserialize A function that deserializes the responses
120 * @param array $metadata A metadata map to send to the server
121 * @return BidiStreamingSurfaceActiveCall The active call object
122 */
murgatroid9914d2ce22015-01-30 15:36:23 -0800123 public function _bidiRequest($method,
124 callable $deserialize,
125 $metadata = array()) {
murgatroid999140a062015-03-26 11:27:58 -0700126 $call = new BidiStreamingCall($this->channel, $method, $deserialize);
127 $call->start($metadata);
128 return $call;
mlumishb892a272014-12-09 16:28:23 -0800129 }
130}