blob: 9bc1711110686cdb45a5b5dcecfafd4a4fbd538b [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()) {
murgatroid999140a062015-03-26 11:27:58 -070072 $call = new UnaryCall($this->channel, $method, $deserialize);
73 $call->start($argument, $metadata);
74 return $call;
mlumishb892a272014-12-09 16:28:23 -080075 }
76
77 /**
78 * Call a remote method that takes a stream of arguments and has a single
79 * output
80 *
81 * @param string $method The name of the method to call
82 * @param $arguments An array or Traversable of arguments to stream to the
83 * server
84 * @param callable $deserialize A function that deserializes the response
85 * @param array $metadata A metadata map to send to the server
86 * @return ClientStreamingSurfaceActiveCall The active call object
87 */
murgatroid9914d2ce22015-01-30 15:36:23 -080088 public function _clientStreamRequest($method,
89 $arguments,
90 callable $deserialize,
91 $metadata = array()) {
murgatroid999140a062015-03-26 11:27:58 -070092 $call = new ClientStreamingCall($this->channel, $method, $deserialize);
93 $call->start($arguments, $metadata);
94 return $call;
mlumishb892a272014-12-09 16:28:23 -080095 }
96
97 /**
98 * Call a remote method that takes a single argument and returns a stream of
99 * responses
100 *
101 * @param string $method The name of the method to call
102 * @param $argument The argument to the method
103 * @param callable $deserialize A function that deserializes the responses
104 * @param array $metadata A metadata map to send to the server
105 * @return ServerStreamingSurfaceActiveCall The active call object
106 */
murgatroid9914d2ce22015-01-30 15:36:23 -0800107 public function _serverStreamRequest($method,
108 $argument,
109 callable $deserialize,
110 $metadata = array()) {
murgatroid999140a062015-03-26 11:27:58 -0700111 $call = new ServerStreamingCall($this->channel, $method, $deserialize);
112 $call->start($argument, $metadata);
113 return $call;
mlumishb892a272014-12-09 16:28:23 -0800114 }
115
116 /**
117 * Call a remote method with messages streaming in both directions
118 *
119 * @param string $method The name of the method to call
120 * @param callable $deserialize A function that deserializes the responses
121 * @param array $metadata A metadata map to send to the server
122 * @return BidiStreamingSurfaceActiveCall The active call object
123 */
murgatroid9914d2ce22015-01-30 15:36:23 -0800124 public function _bidiRequest($method,
125 callable $deserialize,
126 $metadata = array()) {
murgatroid999140a062015-03-26 11:27:58 -0700127 $call = new BidiStreamingCall($this->channel, $method, $deserialize);
128 $call->start($metadata);
129 return $call;
mlumishb892a272014-12-09 16:28:23 -0800130 }
131}