blob: fde055a3b327a979e3bff0ef443b052fca5617d1 [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;
mlumish156e67d2015-01-02 14:59:16 -080035require_once realpath(dirname(__FILE__) . '/../autoload.php');
mlumishb892a272014-12-09 16:28:23 -080036
37/**
38 * Base class for generated client stubs. Stub methods are expected to call
39 * _simpleRequest or _streamRequest and return the result.
40 */
41class BaseStub {
42
43 private $channel;
44
murgatroid99f21eb252015-01-30 13:47:41 -080045 public function __construct($hostname, $opts) {
46 $this->channel = new Channel($hostname, $opts);
mlumishb892a272014-12-09 16:28:23 -080047 }
48
49 /**
50 * Close the communication channel associated with this stub
51 */
52 public function close() {
53 $channel->close();
54 }
55
56 /* This class is intended to be subclassed by generated code, so all functions
57 begin with "_" to avoid name collisions. */
58
59 /**
60 * Call a remote method that takes a single argument and has a single output
61 *
62 * @param string $method The name of the method to call
63 * @param $argument The argument to the method
64 * @param callable $deserialize A function that deserializes the response
65 * @param array $metadata A metadata map to send to the server
66 * @return SimpleSurfaceActiveCall The active call object
67 */
murgatroid9914d2ce22015-01-30 15:36:23 -080068 public function _simpleRequest($method,
69 $argument,
70 callable $deserialize,
71 $metadata = array()) {
mlumishb892a272014-12-09 16:28:23 -080072 return new SimpleSurfaceActiveCall($this->channel,
73 $method,
74 $deserialize,
75 $argument,
76 $metadata);
77 }
78
79 /**
80 * Call a remote method that takes a stream of arguments and has a single
81 * output
82 *
83 * @param string $method The name of the method to call
84 * @param $arguments An array or Traversable of arguments to stream to the
85 * server
86 * @param callable $deserialize A function that deserializes the response
87 * @param array $metadata A metadata map to send to the server
88 * @return ClientStreamingSurfaceActiveCall The active call object
89 */
murgatroid9914d2ce22015-01-30 15:36:23 -080090 public function _clientStreamRequest($method,
91 $arguments,
92 callable $deserialize,
93 $metadata = array()) {
mlumishb892a272014-12-09 16:28:23 -080094 return new ClientStreamingSurfaceActiveCall($this->channel,
95 $method,
96 $deserialize,
97 $arguments,
98 $metadata);
99 }
100
101 /**
102 * Call a remote method that takes a single argument and returns a stream of
103 * responses
104 *
105 * @param string $method The name of the method to call
106 * @param $argument The argument to the method
107 * @param callable $deserialize A function that deserializes the responses
108 * @param array $metadata A metadata map to send to the server
109 * @return ServerStreamingSurfaceActiveCall The active call object
110 */
murgatroid9914d2ce22015-01-30 15:36:23 -0800111 public function _serverStreamRequest($method,
112 $argument,
113 callable $deserialize,
114 $metadata = array()) {
mlumishb892a272014-12-09 16:28:23 -0800115 return new ServerStreamingSurfaceActiveCall($this->channel,
116 $method,
117 $deserialize,
118 $argument,
119 $metadata);
120 }
121
122 /**
123 * Call a remote method with messages streaming in both directions
124 *
125 * @param string $method The name of the method to call
126 * @param callable $deserialize A function that deserializes the responses
127 * @param array $metadata A metadata map to send to the server
128 * @return BidiStreamingSurfaceActiveCall The active call object
129 */
murgatroid9914d2ce22015-01-30 15:36:23 -0800130 public function _bidiRequest($method,
131 callable $deserialize,
132 $metadata = array()) {
mlumishb892a272014-12-09 16:28:23 -0800133 return new BidiStreamingSurfaceActiveCall($this->channel,
134 $method,
135 $deserialize,
136 $metadata);
137 }
138}