blob: 3f86372d07fc6d490694d8b0161dff8e769c83dc [file] [log] [blame]
Jiri Simsa67b8a262015-03-24 21:14:07 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Suharsh Sivakumara4ac50a2015-03-13 16:13:50 -07005// This file was auto-generated by the vanadium vdl tool.
Jiri Simsa37cdfc02014-10-09 18:00:43 -07006// Source: service.vdl
7
Todd Wang8c4e5cc2015-04-09 11:30:52 -07008// Package rps defines interfaces for playing the game Rock-Paper-Scissors. It
9// is an example of a simple Vanadium service.
10//
11// http://en.wikipedia.org/wiki/Rock-paper-scissors
Jiri Simsa37cdfc02014-10-09 18:00:43 -070012//
13// There are three different roles in the game:
14//
Todd Wang8c4e5cc2015-04-09 11:30:52 -070015// 1. Judge: A judge enforces the rules of the game and decides who the winner
16// is. At the end of the game, the judge reports the final score to all the
17// score keepers.
Jiri Simsa37cdfc02014-10-09 18:00:43 -070018//
Todd Wang8c4e5cc2015-04-09 11:30:52 -070019// 2. Player: A player can ask a judge to start a new game, it can challenge
20// another player, and it can play a game.
Jiri Simsa37cdfc02014-10-09 18:00:43 -070021//
Todd Wang8c4e5cc2015-04-09 11:30:52 -070022// 3. ScoreKeeper: A score keeper receives the final score for a game after it
23// ended.
Jiri Simsa37cdfc02014-10-09 18:00:43 -070024package rps
25
26import (
Todd Wangd1779a52015-02-05 11:46:12 -080027 // VDL system imports
28 "io"
Jiri Simsa386ce3e2015-02-23 16:14:20 -080029 "v.io/v23"
30 "v.io/v23/context"
Matt Rosencrantz94502cf2015-03-18 09:43:44 -070031 "v.io/v23/rpc"
Jiri Simsa386ce3e2015-02-23 16:14:20 -080032 "v.io/v23/vdl"
Asim Shankar4794c932014-11-24 17:45:56 -080033
Todd Wangd1779a52015-02-05 11:46:12 -080034 // VDL user imports
Todd Wang07f13462015-03-13 15:54:15 -070035 "time"
Todd Wang387d8a42015-03-30 17:09:05 -070036 "v.io/v23/security/access"
Todd Wang07f13462015-03-13 15:54:15 -070037 _ "v.io/v23/vdlroot/time"
Jiri Simsa37cdfc02014-10-09 18:00:43 -070038)
39
Benjamin Prosnitz2be28dc2015-03-11 13:33:22 -070040// A GameId is used to uniquely identify a game within one Judge.
41type GameId struct {
42 Id string
Jiri Simsa37cdfc02014-10-09 18:00:43 -070043}
44
Benjamin Prosnitz2be28dc2015-03-11 13:33:22 -070045func (GameId) __VDLReflect(struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -070046 Name string `vdl:"v.io/x/ref/examples/rps.GameId"`
Todd Wang24983c72014-11-26 15:07:25 -080047}) {
48}
49
Jiri Simsa37cdfc02014-10-09 18:00:43 -070050// GameOptions specifies the parameters of a game.
51type GameOptions struct {
52 NumRounds int32 // The number of rounds that a player must win to win the game.
53 GameType GameTypeTag // The type of game to play: Classic or LizardSpock.
54}
55
Todd Wang24983c72014-11-26 15:07:25 -080056func (GameOptions) __VDLReflect(struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -070057 Name string `vdl:"v.io/x/ref/examples/rps.GameOptions"`
Todd Wang24983c72014-11-26 15:07:25 -080058}) {
59}
60
Jiri Simsa37cdfc02014-10-09 18:00:43 -070061type GameTypeTag byte
62
Todd Wang24983c72014-11-26 15:07:25 -080063func (GameTypeTag) __VDLReflect(struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -070064 Name string `vdl:"v.io/x/ref/examples/rps.GameTypeTag"`
Todd Wang24983c72014-11-26 15:07:25 -080065}) {
66}
67
Robin Thellend636b3602015-02-11 14:57:44 -080068type (
69 // PlayerAction represents any single field of the PlayerAction union type.
70 PlayerAction interface {
71 // Index returns the field index.
72 Index() int
73 // Interface returns the field value as an interface.
74 Interface() interface{}
75 // Name returns the field name.
76 Name() string
77 // __VDLReflect describes the PlayerAction union type.
78 __VDLReflect(__PlayerActionReflect)
79 }
80 // PlayerActionMove represents field Move of the PlayerAction union type.
81 PlayerActionMove struct{ Value string } // The move that the player wants to make.
82 // PlayerActionQuit represents field Quit of the PlayerAction union type.
83 PlayerActionQuit struct{ Value unused } // Indicates that the player is quitting the game.
84 // __PlayerActionReflect describes the PlayerAction union type.
85 __PlayerActionReflect struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -070086 Name string `vdl:"v.io/x/ref/examples/rps.PlayerAction"`
Robin Thellend636b3602015-02-11 14:57:44 -080087 Type PlayerAction
88 Union struct {
89 Move PlayerActionMove
90 Quit PlayerActionQuit
91 }
92 }
93)
94
95func (x PlayerActionMove) Index() int { return 0 }
96func (x PlayerActionMove) Interface() interface{} { return x.Value }
97func (x PlayerActionMove) Name() string { return "Move" }
98func (x PlayerActionMove) __VDLReflect(__PlayerActionReflect) {}
99
100func (x PlayerActionQuit) Index() int { return 1 }
101func (x PlayerActionQuit) Interface() interface{} { return x.Value }
102func (x PlayerActionQuit) Name() string { return "Quit" }
103func (x PlayerActionQuit) __VDLReflect(__PlayerActionReflect) {}
104
105type unused struct {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700106}
107
Robin Thellend636b3602015-02-11 14:57:44 -0800108func (unused) __VDLReflect(struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -0700109 Name string `vdl:"v.io/x/ref/examples/rps.unused"`
Todd Wang24983c72014-11-26 15:07:25 -0800110}) {
111}
112
Robin Thellend636b3602015-02-11 14:57:44 -0800113type (
114 // JudgeAction represents any single field of the JudgeAction union type.
115 JudgeAction interface {
116 // Index returns the field index.
117 Index() int
118 // Interface returns the field value as an interface.
119 Interface() interface{}
120 // Name returns the field name.
121 Name() string
122 // __VDLReflect describes the JudgeAction union type.
123 __VDLReflect(__JudgeActionReflect)
124 }
125 // JudgeActionPlayerNum represents field PlayerNum of the JudgeAction union type.
126 JudgeActionPlayerNum struct{ Value int32 } // The player's number.
127 // JudgeActionOpponentName represents field OpponentName of the JudgeAction union type.
128 JudgeActionOpponentName struct{ Value string } // The name of the opponent.
129 // JudgeActionMoveOptions represents field MoveOptions of the JudgeAction union type.
130 JudgeActionMoveOptions struct{ Value []string } // A list of allowed moves that the player must choose from.
131 // JudgeActionRoundResult represents field RoundResult of the JudgeAction union type.
132 JudgeActionRoundResult struct{ Value Round } // The result of the previous round.
133 // JudgeActionScore represents field Score of the JudgeAction union type.
134 JudgeActionScore struct{ Value ScoreCard } // The result of the game.
135 // __JudgeActionReflect describes the JudgeAction union type.
136 __JudgeActionReflect struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -0700137 Name string `vdl:"v.io/x/ref/examples/rps.JudgeAction"`
Robin Thellend636b3602015-02-11 14:57:44 -0800138 Type JudgeAction
139 Union struct {
140 PlayerNum JudgeActionPlayerNum
141 OpponentName JudgeActionOpponentName
142 MoveOptions JudgeActionMoveOptions
143 RoundResult JudgeActionRoundResult
144 Score JudgeActionScore
145 }
146 }
147)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700148
Robin Thellend636b3602015-02-11 14:57:44 -0800149func (x JudgeActionPlayerNum) Index() int { return 0 }
150func (x JudgeActionPlayerNum) Interface() interface{} { return x.Value }
151func (x JudgeActionPlayerNum) Name() string { return "PlayerNum" }
152func (x JudgeActionPlayerNum) __VDLReflect(__JudgeActionReflect) {}
153
154func (x JudgeActionOpponentName) Index() int { return 1 }
155func (x JudgeActionOpponentName) Interface() interface{} { return x.Value }
156func (x JudgeActionOpponentName) Name() string { return "OpponentName" }
157func (x JudgeActionOpponentName) __VDLReflect(__JudgeActionReflect) {}
158
159func (x JudgeActionMoveOptions) Index() int { return 2 }
160func (x JudgeActionMoveOptions) Interface() interface{} { return x.Value }
161func (x JudgeActionMoveOptions) Name() string { return "MoveOptions" }
162func (x JudgeActionMoveOptions) __VDLReflect(__JudgeActionReflect) {}
163
164func (x JudgeActionRoundResult) Index() int { return 3 }
165func (x JudgeActionRoundResult) Interface() interface{} { return x.Value }
166func (x JudgeActionRoundResult) Name() string { return "RoundResult" }
167func (x JudgeActionRoundResult) __VDLReflect(__JudgeActionReflect) {}
168
169func (x JudgeActionScore) Index() int { return 4 }
170func (x JudgeActionScore) Interface() interface{} { return x.Value }
171func (x JudgeActionScore) Name() string { return "Score" }
172func (x JudgeActionScore) __VDLReflect(__JudgeActionReflect) {}
Todd Wang24983c72014-11-26 15:07:25 -0800173
Sergey Rogulenko2f64f982015-02-05 14:14:46 -0800174type PlayersMoves [2]string
175
176func (PlayersMoves) __VDLReflect(struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -0700177 Name string `vdl:"v.io/x/ref/examples/rps.PlayersMoves"`
Sergey Rogulenko2f64f982015-02-05 14:14:46 -0800178}) {
179}
180
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700181// Round represents the state of a round.
182type Round struct {
Todd Wang07f13462015-03-13 15:54:15 -0700183 Moves PlayersMoves // Each player's move.
184 Comment string // A text comment from judge about the round.
185 Winner WinnerTag // Who won the round.
186 StartTime time.Time // The time at which the round started.
187 EndTime time.Time // The time at which the round ended.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700188}
189
Todd Wang24983c72014-11-26 15:07:25 -0800190func (Round) __VDLReflect(struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -0700191 Name string `vdl:"v.io/x/ref/examples/rps.Round"`
Todd Wang24983c72014-11-26 15:07:25 -0800192}) {
193}
194
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700195// WinnerTag is a type used to indicate whether a round or a game was a draw,
196// was won by player 1 or was won by player 2.
197type WinnerTag byte
198
Todd Wang24983c72014-11-26 15:07:25 -0800199func (WinnerTag) __VDLReflect(struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -0700200 Name string `vdl:"v.io/x/ref/examples/rps.WinnerTag"`
Todd Wang24983c72014-11-26 15:07:25 -0800201}) {
202}
203
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700204// PlayResult is the value returned by the Play method. It indicates the outcome of the game.
205type PlayResult struct {
206 YouWon bool // True if the player receiving the result won the game.
207}
208
Todd Wang24983c72014-11-26 15:07:25 -0800209func (PlayResult) __VDLReflect(struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -0700210 Name string `vdl:"v.io/x/ref/examples/rps.PlayResult"`
Todd Wang24983c72014-11-26 15:07:25 -0800211}) {
212}
213
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700214type ScoreCard struct {
Todd Wang07f13462015-03-13 15:54:15 -0700215 Opts GameOptions // The game options.
216 Judge string // The name of the judge.
217 Players []string // The name of the players.
218 Rounds []Round // The outcome of each round.
219 StartTime time.Time // The time at which the game started.
220 EndTime time.Time // The time at which the game ended.
221 Winner WinnerTag // Who won the game.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700222}
223
Todd Wang24983c72014-11-26 15:07:25 -0800224func (ScoreCard) __VDLReflect(struct {
Suharsh Sivakumar071d1c82015-05-08 14:45:10 -0700225 Name string `vdl:"v.io/x/ref/examples/rps.ScoreCard"`
Todd Wang24983c72014-11-26 15:07:25 -0800226}) {
227}
228
229func init() {
Benjamin Prosnitz2be28dc2015-03-11 13:33:22 -0700230 vdl.Register((*GameId)(nil))
Todd Wang83f63ba2015-02-09 13:30:43 -0800231 vdl.Register((*GameOptions)(nil))
232 vdl.Register((*GameTypeTag)(nil))
233 vdl.Register((*PlayerAction)(nil))
Robin Thellend636b3602015-02-11 14:57:44 -0800234 vdl.Register((*unused)(nil))
Todd Wang83f63ba2015-02-09 13:30:43 -0800235 vdl.Register((*JudgeAction)(nil))
236 vdl.Register((*PlayersMoves)(nil))
237 vdl.Register((*Round)(nil))
238 vdl.Register((*WinnerTag)(nil))
239 vdl.Register((*PlayResult)(nil))
240 vdl.Register((*ScoreCard)(nil))
Todd Wang24983c72014-11-26 15:07:25 -0800241}
242
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700243const Classic = GameTypeTag(0) // Rock-Paper-Scissors
244
245const LizardSpock = GameTypeTag(1) // Rock-Paper-Scissors-Lizard-Spock
246
247const Draw = WinnerTag(0)
248
249const Player1 = WinnerTag(1)
250
251const Player2 = WinnerTag(2)
252
Todd Wangd8cb55b2014-11-07 00:58:32 -0800253// JudgeClientMethods is the client interface
254// containing Judge methods.
255type JudgeClientMethods interface {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700256 // CreateGame creates a new game with the given game options and returns a game
257 // identifier that can be used by the players to join the game.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700258 CreateGame(ctx *context.T, Opts GameOptions, opts ...rpc.CallOpt) (GameId, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700259 // Play lets a player join an existing game and play.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700260 Play(ctx *context.T, Id GameId, opts ...rpc.CallOpt) (JudgePlayClientCall, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700261}
262
Todd Wangd8cb55b2014-11-07 00:58:32 -0800263// JudgeClientStub adds universal methods to JudgeClientMethods.
264type JudgeClientStub interface {
265 JudgeClientMethods
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700266 rpc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700267}
268
Todd Wangd8cb55b2014-11-07 00:58:32 -0800269// JudgeClient returns a client stub for Judge.
Asim Shankar69fa69f2015-04-01 11:34:32 -0700270func JudgeClient(name string) JudgeClientStub {
271 return implJudgeClientStub{name}
Todd Wangd8cb55b2014-11-07 00:58:32 -0800272}
273
274type implJudgeClientStub struct {
Asim Shankar69fa69f2015-04-01 11:34:32 -0700275 name string
Todd Wangd8cb55b2014-11-07 00:58:32 -0800276}
277
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700278func (c implJudgeClientStub) CreateGame(ctx *context.T, i0 GameOptions, opts ...rpc.CallOpt) (o0 GameId, err error) {
Suharsh Sivakumardf2672a2015-04-09 19:26:43 -0700279 err = v23.GetClient(ctx).Call(ctx, c.name, "CreateGame", []interface{}{i0}, []interface{}{&o0}, opts...)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800280 return
281}
282
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700283func (c implJudgeClientStub) Play(ctx *context.T, i0 GameId, opts ...rpc.CallOpt) (ocall JudgePlayClientCall, err error) {
284 var call rpc.ClientCall
Asim Shankar69fa69f2015-04-01 11:34:32 -0700285 if call, err = v23.GetClient(ctx).StartCall(ctx, c.name, "Play", []interface{}{i0}, opts...); err != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800286 return
287 }
Matt Rosencrantz72a15612015-02-27 22:22:41 -0800288 ocall = &implJudgePlayClientCall{ClientCall: call}
Todd Wangd8cb55b2014-11-07 00:58:32 -0800289 return
290}
291
Todd Wangd8cb55b2014-11-07 00:58:32 -0800292// JudgePlayClientStream is the client stream for Judge.Play.
293type JudgePlayClientStream interface {
Todd Wang5cd27352014-11-11 20:27:39 -0800294 // RecvStream returns the receiver side of the Judge.Play client stream.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700295 RecvStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800296 // Advance stages an item so that it may be retrieved via Value. Returns
297 // true iff there is an item to retrieve. Advance must be called before
298 // Value is called. May block if an item is not available.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700299 Advance() bool
Todd Wangd8cb55b2014-11-07 00:58:32 -0800300 // Value returns the item that was staged by Advance. May panic if Advance
301 // returned false or was not called. Never blocks.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700302 Value() JudgeAction
Todd Wangd8cb55b2014-11-07 00:58:32 -0800303 // Err returns any error encountered by Advance. Never blocks.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700304 Err() error
305 }
Todd Wang5cd27352014-11-11 20:27:39 -0800306 // SendStream returns the send side of the Judge.Play client stream.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700307 SendStream() interface {
Todd Wang04f97dd2014-12-18 18:52:07 -0800308 // Send places the item onto the output stream. Returns errors
309 // encountered while sending, or if Send is called after Close or
310 // the stream has been canceled. Blocks if there is no buffer
311 // space; will unblock when buffer space is available or after
312 // the stream has been canceled.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700313 Send(item PlayerAction) error
Todd Wang04f97dd2014-12-18 18:52:07 -0800314 // Close indicates to the server that no more items will be sent;
315 // server Recv calls will receive io.EOF after all sent items.
316 // This is an optional call - e.g. a client might call Close if it
317 // needs to continue receiving items from the server after it's
318 // done sending. Returns errors encountered while closing, or if
319 // Close is called after the stream has been canceled. Like Send,
320 // blocks if there is no buffer space available.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700321 Close() error
322 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800323}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700324
Matt Rosencrantz72a15612015-02-27 22:22:41 -0800325// JudgePlayClientCall represents the call returned from Judge.Play.
326type JudgePlayClientCall interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800327 JudgePlayClientStream
328 // Finish performs the equivalent of SendStream().Close, then blocks until
329 // the server is done, and returns the positional return values for the call.
330 //
Todd Wang04f97dd2014-12-18 18:52:07 -0800331 // Finish returns immediately if the call has been canceled; depending on the
Todd Wangd8cb55b2014-11-07 00:58:32 -0800332 // timing the output could either be an error signaling cancelation, or the
333 // valid positional return values from the server.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700334 //
Todd Wang04f97dd2014-12-18 18:52:07 -0800335 // Calling Finish is mandatory for releasing stream resources, unless the call
336 // has been canceled or any of the other methods return an error. Finish should
Todd Wangd8cb55b2014-11-07 00:58:32 -0800337 // be called at most once.
338 Finish() (PlayResult, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700339}
340
Matt Rosencrantz72a15612015-02-27 22:22:41 -0800341type implJudgePlayClientCall struct {
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700342 rpc.ClientCall
Todd Wang5cd27352014-11-11 20:27:39 -0800343 valRecv JudgeAction
344 errRecv error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700345}
346
Matt Rosencrantz72a15612015-02-27 22:22:41 -0800347func (c *implJudgePlayClientCall) RecvStream() interface {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700348 Advance() bool
349 Value() JudgeAction
350 Err() error
351} {
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800352 return implJudgePlayClientCallRecv{c}
Todd Wang5cd27352014-11-11 20:27:39 -0800353}
354
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800355type implJudgePlayClientCallRecv struct {
Matt Rosencrantz72a15612015-02-27 22:22:41 -0800356 c *implJudgePlayClientCall
Todd Wang5cd27352014-11-11 20:27:39 -0800357}
358
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800359func (c implJudgePlayClientCallRecv) Advance() bool {
Todd Wang5cd27352014-11-11 20:27:39 -0800360 c.c.errRecv = c.c.Recv(&c.c.valRecv)
361 return c.c.errRecv == nil
362}
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800363func (c implJudgePlayClientCallRecv) Value() JudgeAction {
Todd Wang5cd27352014-11-11 20:27:39 -0800364 return c.c.valRecv
365}
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800366func (c implJudgePlayClientCallRecv) Err() error {
Todd Wangd1779a52015-02-05 11:46:12 -0800367 if c.c.errRecv == io.EOF {
Todd Wang5cd27352014-11-11 20:27:39 -0800368 return nil
369 }
370 return c.c.errRecv
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700371}
Matt Rosencrantz72a15612015-02-27 22:22:41 -0800372func (c *implJudgePlayClientCall) SendStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800373 Send(item PlayerAction) error
374 Close() error
375} {
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800376 return implJudgePlayClientCallSend{c}
Todd Wang5cd27352014-11-11 20:27:39 -0800377}
378
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800379type implJudgePlayClientCallSend struct {
Matt Rosencrantz72a15612015-02-27 22:22:41 -0800380 c *implJudgePlayClientCall
Todd Wang5cd27352014-11-11 20:27:39 -0800381}
382
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800383func (c implJudgePlayClientCallSend) Send(item PlayerAction) error {
Todd Wang5cd27352014-11-11 20:27:39 -0800384 return c.c.Send(item)
385}
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800386func (c implJudgePlayClientCallSend) Close() error {
Todd Wang5cd27352014-11-11 20:27:39 -0800387 return c.c.CloseSend()
Todd Wangd8cb55b2014-11-07 00:58:32 -0800388}
Matt Rosencrantz72a15612015-02-27 22:22:41 -0800389func (c *implJudgePlayClientCall) Finish() (o0 PlayResult, err error) {
390 err = c.ClientCall.Finish(&o0)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700391 return
392}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700393
Todd Wangd8cb55b2014-11-07 00:58:32 -0800394// JudgeServerMethods is the interface a server writer
395// implements for Judge.
396type JudgeServerMethods interface {
397 // CreateGame creates a new game with the given game options and returns a game
398 // identifier that can be used by the players to join the game.
Todd Wang54feabe2015-04-15 23:38:26 -0700399 CreateGame(ctx *context.T, call rpc.ServerCall, Opts GameOptions) (GameId, error)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800400 // Play lets a player join an existing game and play.
Todd Wang54feabe2015-04-15 23:38:26 -0700401 Play(ctx *context.T, call JudgePlayServerCall, Id GameId) (PlayResult, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700402}
403
Todd Wangd8cb55b2014-11-07 00:58:32 -0800404// JudgeServerStubMethods is the server interface containing
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700405// Judge methods, as expected by rpc.Server.
Todd Wang5cd27352014-11-11 20:27:39 -0800406// The only difference between this interface and JudgeServerMethods
407// is the streaming methods.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800408type JudgeServerStubMethods interface {
409 // CreateGame creates a new game with the given game options and returns a game
410 // identifier that can be used by the players to join the game.
Todd Wang54feabe2015-04-15 23:38:26 -0700411 CreateGame(ctx *context.T, call rpc.ServerCall, Opts GameOptions) (GameId, error)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800412 // Play lets a player join an existing game and play.
Todd Wang54feabe2015-04-15 23:38:26 -0700413 Play(ctx *context.T, call *JudgePlayServerCallStub, Id GameId) (PlayResult, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700414}
415
Todd Wangd8cb55b2014-11-07 00:58:32 -0800416// JudgeServerStub adds universal methods to JudgeServerStubMethods.
417type JudgeServerStub interface {
418 JudgeServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800419 // Describe the Judge interfaces.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700420 Describe__() []rpc.InterfaceDesc
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700421}
422
Todd Wangd8cb55b2014-11-07 00:58:32 -0800423// JudgeServer returns a server stub for Judge.
424// It converts an implementation of JudgeServerMethods into
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700425// an object that may be used by rpc.Server.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800426func JudgeServer(impl JudgeServerMethods) JudgeServerStub {
427 stub := implJudgeServerStub{
428 impl: impl,
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700429 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800430 // Initialize GlobState; always check the stub itself first, to handle the
431 // case where the user has the Glob method defined in their VDL source.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700432 if gs := rpc.NewGlobState(stub); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800433 stub.gs = gs
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700434 } else if gs := rpc.NewGlobState(impl); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800435 stub.gs = gs
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700436 }
Robin Thellenda7548452014-11-05 18:10:24 -0800437 return stub
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700438}
439
Todd Wangd8cb55b2014-11-07 00:58:32 -0800440type implJudgeServerStub struct {
441 impl JudgeServerMethods
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700442 gs *rpc.GlobState
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700443}
444
Todd Wang54feabe2015-04-15 23:38:26 -0700445func (s implJudgeServerStub) CreateGame(ctx *context.T, call rpc.ServerCall, i0 GameOptions) (GameId, error) {
446 return s.impl.CreateGame(ctx, call, i0)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700447}
448
Todd Wang54feabe2015-04-15 23:38:26 -0700449func (s implJudgeServerStub) Play(ctx *context.T, call *JudgePlayServerCallStub, i0 GameId) (PlayResult, error) {
450 return s.impl.Play(ctx, call, i0)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700451}
452
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700453func (s implJudgeServerStub) Globber() *rpc.GlobState {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800454 return s.gs
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700455}
456
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700457func (s implJudgeServerStub) Describe__() []rpc.InterfaceDesc {
458 return []rpc.InterfaceDesc{JudgeDesc}
Todd Wangdddc1fb2014-11-16 21:39:02 -0800459}
460
461// JudgeDesc describes the Judge interface.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700462var JudgeDesc rpc.InterfaceDesc = descJudge
Todd Wangdddc1fb2014-11-16 21:39:02 -0800463
464// descJudge hides the desc to keep godoc clean.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700465var descJudge = rpc.InterfaceDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800466 Name: "Judge",
Jiri Simsa3b913022015-02-27 15:19:25 -0800467 PkgPath: "v.io/x/ref/examples/rps",
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700468 Methods: []rpc.MethodDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800469 {
470 Name: "CreateGame",
471 Doc: "// CreateGame creates a new game with the given game options and returns a game\n// identifier that can be used by the players to join the game.",
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700472 InArgs: []rpc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800473 {"Opts", ``}, // GameOptions
474 },
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700475 OutArgs: []rpc.ArgDesc{
Benjamin Prosnitz2be28dc2015-03-11 13:33:22 -0700476 {"", ``}, // GameId
Todd Wangdddc1fb2014-11-16 21:39:02 -0800477 },
Todd Wangcab990d2015-02-19 19:54:06 -0800478 Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Write"))},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800479 },
480 {
481 Name: "Play",
482 Doc: "// Play lets a player join an existing game and play.",
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700483 InArgs: []rpc.ArgDesc{
Benjamin Prosnitz2be28dc2015-03-11 13:33:22 -0700484 {"Id", ``}, // GameId
Todd Wangdddc1fb2014-11-16 21:39:02 -0800485 },
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700486 OutArgs: []rpc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800487 {"", ``}, // PlayResult
Todd Wangdddc1fb2014-11-16 21:39:02 -0800488 },
Todd Wangcab990d2015-02-19 19:54:06 -0800489 Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Write"))},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800490 },
491 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700492}
493
Todd Wangd8cb55b2014-11-07 00:58:32 -0800494// JudgePlayServerStream is the server stream for Judge.Play.
495type JudgePlayServerStream interface {
Todd Wang5cd27352014-11-11 20:27:39 -0800496 // RecvStream returns the receiver side of the Judge.Play server stream.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800497 RecvStream() interface {
498 // Advance stages an item so that it may be retrieved via Value. Returns
499 // true iff there is an item to retrieve. Advance must be called before
500 // Value is called. May block if an item is not available.
501 Advance() bool
502 // Value returns the item that was staged by Advance. May panic if Advance
503 // returned false or was not called. Never blocks.
504 Value() PlayerAction
505 // Err returns any error encountered by Advance. Never blocks.
506 Err() error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700507 }
Todd Wang5cd27352014-11-11 20:27:39 -0800508 // SendStream returns the send side of the Judge.Play server stream.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800509 SendStream() interface {
510 // Send places the item onto the output stream. Returns errors encountered
511 // while sending. Blocks if there is no buffer space; will unblock when
512 // buffer space is available.
513 Send(item JudgeAction) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700514 }
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700515}
516
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800517// JudgePlayServerCall represents the context passed to Judge.Play.
518type JudgePlayServerCall interface {
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700519 rpc.ServerCall
Todd Wangd8cb55b2014-11-07 00:58:32 -0800520 JudgePlayServerStream
Robin Thellenda7548452014-11-05 18:10:24 -0800521}
522
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700523// JudgePlayServerCallStub is a wrapper that converts rpc.StreamServerCall into
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800524// a typesafe stub that implements JudgePlayServerCall.
525type JudgePlayServerCallStub struct {
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700526 rpc.StreamServerCall
Todd Wang5cd27352014-11-11 20:27:39 -0800527 valRecv PlayerAction
528 errRecv error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700529}
530
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700531// Init initializes JudgePlayServerCallStub from rpc.StreamServerCall.
532func (s *JudgePlayServerCallStub) Init(call rpc.StreamServerCall) {
Matt Rosencrantz9ef0f2d2015-02-27 11:04:32 -0800533 s.StreamServerCall = call
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700534}
535
Todd Wang5cd27352014-11-11 20:27:39 -0800536// RecvStream returns the receiver side of the Judge.Play server stream.
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800537func (s *JudgePlayServerCallStub) RecvStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800538 Advance() bool
539 Value() PlayerAction
540 Err() error
541} {
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800542 return implJudgePlayServerCallRecv{s}
Todd Wangd8cb55b2014-11-07 00:58:32 -0800543}
Todd Wang5cd27352014-11-11 20:27:39 -0800544
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800545type implJudgePlayServerCallRecv struct {
546 s *JudgePlayServerCallStub
Todd Wang5cd27352014-11-11 20:27:39 -0800547}
548
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800549func (s implJudgePlayServerCallRecv) Advance() bool {
Todd Wang5cd27352014-11-11 20:27:39 -0800550 s.s.errRecv = s.s.Recv(&s.s.valRecv)
551 return s.s.errRecv == nil
552}
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800553func (s implJudgePlayServerCallRecv) Value() PlayerAction {
Todd Wang5cd27352014-11-11 20:27:39 -0800554 return s.s.valRecv
555}
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800556func (s implJudgePlayServerCallRecv) Err() error {
Todd Wangd1779a52015-02-05 11:46:12 -0800557 if s.s.errRecv == io.EOF {
Todd Wang5cd27352014-11-11 20:27:39 -0800558 return nil
559 }
560 return s.s.errRecv
561}
562
563// SendStream returns the send side of the Judge.Play server stream.
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800564func (s *JudgePlayServerCallStub) SendStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800565 Send(item JudgeAction) error
566} {
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800567 return implJudgePlayServerCallSend{s}
Todd Wang5cd27352014-11-11 20:27:39 -0800568}
569
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800570type implJudgePlayServerCallSend struct {
571 s *JudgePlayServerCallStub
Todd Wang5cd27352014-11-11 20:27:39 -0800572}
573
Suharsh Sivakumar31f49852015-03-03 16:13:20 -0800574func (s implJudgePlayServerCallSend) Send(item JudgeAction) error {
Todd Wang5cd27352014-11-11 20:27:39 -0800575 return s.s.Send(item)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800576}
577
578// PlayerClientMethods is the client interface
579// containing Player methods.
580//
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700581// Player can receive challenges from other players.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800582type PlayerClientMethods interface {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700583 // Challenge is used by other players to challenge this player to a game. If
584 // the challenge is accepted, the method returns nil.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700585 Challenge(ctx *context.T, Address string, Id GameId, Opts GameOptions, opts ...rpc.CallOpt) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700586}
587
Todd Wangd8cb55b2014-11-07 00:58:32 -0800588// PlayerClientStub adds universal methods to PlayerClientMethods.
589type PlayerClientStub interface {
590 PlayerClientMethods
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700591 rpc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700592}
593
Todd Wangd8cb55b2014-11-07 00:58:32 -0800594// PlayerClient returns a client stub for Player.
Asim Shankar69fa69f2015-04-01 11:34:32 -0700595func PlayerClient(name string) PlayerClientStub {
596 return implPlayerClientStub{name}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700597}
598
Todd Wangd8cb55b2014-11-07 00:58:32 -0800599type implPlayerClientStub struct {
Asim Shankar69fa69f2015-04-01 11:34:32 -0700600 name string
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700601}
602
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700603func (c implPlayerClientStub) Challenge(ctx *context.T, i0 string, i1 GameId, i2 GameOptions, opts ...rpc.CallOpt) (err error) {
Suharsh Sivakumardf2672a2015-04-09 19:26:43 -0700604 err = v23.GetClient(ctx).Call(ctx, c.name, "Challenge", []interface{}{i0, i1, i2}, nil, opts...)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700605 return
606}
607
Todd Wangd8cb55b2014-11-07 00:58:32 -0800608// PlayerServerMethods is the interface a server writer
609// implements for Player.
610//
611// Player can receive challenges from other players.
612type PlayerServerMethods interface {
613 // Challenge is used by other players to challenge this player to a game. If
614 // the challenge is accepted, the method returns nil.
Todd Wang54feabe2015-04-15 23:38:26 -0700615 Challenge(ctx *context.T, call rpc.ServerCall, Address string, Id GameId, Opts GameOptions) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700616}
617
Todd Wangd8cb55b2014-11-07 00:58:32 -0800618// PlayerServerStubMethods is the server interface containing
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700619// Player methods, as expected by rpc.Server.
Todd Wang5cd27352014-11-11 20:27:39 -0800620// There is no difference between this interface and PlayerServerMethods
621// since there are no streaming methods.
622type PlayerServerStubMethods PlayerServerMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700623
Todd Wangd8cb55b2014-11-07 00:58:32 -0800624// PlayerServerStub adds universal methods to PlayerServerStubMethods.
625type PlayerServerStub interface {
626 PlayerServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800627 // Describe the Player interfaces.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700628 Describe__() []rpc.InterfaceDesc
Todd Wangd8cb55b2014-11-07 00:58:32 -0800629}
630
631// PlayerServer returns a server stub for Player.
632// It converts an implementation of PlayerServerMethods into
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700633// an object that may be used by rpc.Server.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800634func PlayerServer(impl PlayerServerMethods) PlayerServerStub {
635 stub := implPlayerServerStub{
636 impl: impl,
637 }
638 // Initialize GlobState; always check the stub itself first, to handle the
639 // case where the user has the Glob method defined in their VDL source.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700640 if gs := rpc.NewGlobState(stub); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800641 stub.gs = gs
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700642 } else if gs := rpc.NewGlobState(impl); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800643 stub.gs = gs
644 }
645 return stub
646}
647
648type implPlayerServerStub struct {
649 impl PlayerServerMethods
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700650 gs *rpc.GlobState
Todd Wangd8cb55b2014-11-07 00:58:32 -0800651}
652
Todd Wang54feabe2015-04-15 23:38:26 -0700653func (s implPlayerServerStub) Challenge(ctx *context.T, call rpc.ServerCall, i0 string, i1 GameId, i2 GameOptions) error {
654 return s.impl.Challenge(ctx, call, i0, i1, i2)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800655}
656
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700657func (s implPlayerServerStub) Globber() *rpc.GlobState {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800658 return s.gs
659}
660
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700661func (s implPlayerServerStub) Describe__() []rpc.InterfaceDesc {
662 return []rpc.InterfaceDesc{PlayerDesc}
Todd Wangdddc1fb2014-11-16 21:39:02 -0800663}
664
665// PlayerDesc describes the Player interface.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700666var PlayerDesc rpc.InterfaceDesc = descPlayer
Todd Wangdddc1fb2014-11-16 21:39:02 -0800667
668// descPlayer hides the desc to keep godoc clean.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700669var descPlayer = rpc.InterfaceDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800670 Name: "Player",
Jiri Simsa3b913022015-02-27 15:19:25 -0800671 PkgPath: "v.io/x/ref/examples/rps",
Todd Wangdddc1fb2014-11-16 21:39:02 -0800672 Doc: "// Player can receive challenges from other players.",
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700673 Methods: []rpc.MethodDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800674 {
675 Name: "Challenge",
676 Doc: "// Challenge is used by other players to challenge this player to a game. If\n// the challenge is accepted, the method returns nil.",
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700677 InArgs: []rpc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800678 {"Address", ``}, // string
Benjamin Prosnitz2be28dc2015-03-11 13:33:22 -0700679 {"Id", ``}, // GameId
Todd Wangdddc1fb2014-11-16 21:39:02 -0800680 {"Opts", ``}, // GameOptions
681 },
Todd Wangcab990d2015-02-19 19:54:06 -0800682 Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Write"))},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800683 },
684 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700685}
686
Todd Wangd8cb55b2014-11-07 00:58:32 -0800687// ScoreKeeperClientMethods is the client interface
688// containing ScoreKeeper methods.
689//
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700690// ScoreKeeper receives the outcome of games from Judges.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800691type ScoreKeeperClientMethods interface {
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700692 Record(ctx *context.T, Score ScoreCard, opts ...rpc.CallOpt) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700693}
694
Todd Wangd8cb55b2014-11-07 00:58:32 -0800695// ScoreKeeperClientStub adds universal methods to ScoreKeeperClientMethods.
696type ScoreKeeperClientStub interface {
697 ScoreKeeperClientMethods
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700698 rpc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700699}
700
Todd Wangd8cb55b2014-11-07 00:58:32 -0800701// ScoreKeeperClient returns a client stub for ScoreKeeper.
Asim Shankar69fa69f2015-04-01 11:34:32 -0700702func ScoreKeeperClient(name string) ScoreKeeperClientStub {
703 return implScoreKeeperClientStub{name}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700704}
705
Todd Wangd8cb55b2014-11-07 00:58:32 -0800706type implScoreKeeperClientStub struct {
Asim Shankar69fa69f2015-04-01 11:34:32 -0700707 name string
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700708}
709
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700710func (c implScoreKeeperClientStub) Record(ctx *context.T, i0 ScoreCard, opts ...rpc.CallOpt) (err error) {
Suharsh Sivakumardf2672a2015-04-09 19:26:43 -0700711 err = v23.GetClient(ctx).Call(ctx, c.name, "Record", []interface{}{i0}, nil, opts...)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700712 return
713}
714
Todd Wangd8cb55b2014-11-07 00:58:32 -0800715// ScoreKeeperServerMethods is the interface a server writer
716// implements for ScoreKeeper.
717//
718// ScoreKeeper receives the outcome of games from Judges.
719type ScoreKeeperServerMethods interface {
Todd Wang54feabe2015-04-15 23:38:26 -0700720 Record(ctx *context.T, call rpc.ServerCall, Score ScoreCard) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700721}
722
Todd Wangd8cb55b2014-11-07 00:58:32 -0800723// ScoreKeeperServerStubMethods is the server interface containing
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700724// ScoreKeeper methods, as expected by rpc.Server.
Todd Wang5cd27352014-11-11 20:27:39 -0800725// There is no difference between this interface and ScoreKeeperServerMethods
726// since there are no streaming methods.
727type ScoreKeeperServerStubMethods ScoreKeeperServerMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700728
Todd Wangd8cb55b2014-11-07 00:58:32 -0800729// ScoreKeeperServerStub adds universal methods to ScoreKeeperServerStubMethods.
730type ScoreKeeperServerStub interface {
731 ScoreKeeperServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800732 // Describe the ScoreKeeper interfaces.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700733 Describe__() []rpc.InterfaceDesc
Todd Wangd8cb55b2014-11-07 00:58:32 -0800734}
735
736// ScoreKeeperServer returns a server stub for ScoreKeeper.
737// It converts an implementation of ScoreKeeperServerMethods into
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700738// an object that may be used by rpc.Server.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800739func ScoreKeeperServer(impl ScoreKeeperServerMethods) ScoreKeeperServerStub {
740 stub := implScoreKeeperServerStub{
741 impl: impl,
742 }
743 // Initialize GlobState; always check the stub itself first, to handle the
744 // case where the user has the Glob method defined in their VDL source.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700745 if gs := rpc.NewGlobState(stub); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800746 stub.gs = gs
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700747 } else if gs := rpc.NewGlobState(impl); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800748 stub.gs = gs
749 }
750 return stub
751}
752
753type implScoreKeeperServerStub struct {
754 impl ScoreKeeperServerMethods
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700755 gs *rpc.GlobState
Todd Wangd8cb55b2014-11-07 00:58:32 -0800756}
757
Todd Wang54feabe2015-04-15 23:38:26 -0700758func (s implScoreKeeperServerStub) Record(ctx *context.T, call rpc.ServerCall, i0 ScoreCard) error {
759 return s.impl.Record(ctx, call, i0)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800760}
761
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700762func (s implScoreKeeperServerStub) Globber() *rpc.GlobState {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800763 return s.gs
764}
765
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700766func (s implScoreKeeperServerStub) Describe__() []rpc.InterfaceDesc {
767 return []rpc.InterfaceDesc{ScoreKeeperDesc}
Todd Wangdddc1fb2014-11-16 21:39:02 -0800768}
769
770// ScoreKeeperDesc describes the ScoreKeeper interface.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700771var ScoreKeeperDesc rpc.InterfaceDesc = descScoreKeeper
Todd Wangdddc1fb2014-11-16 21:39:02 -0800772
773// descScoreKeeper hides the desc to keep godoc clean.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700774var descScoreKeeper = rpc.InterfaceDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800775 Name: "ScoreKeeper",
Jiri Simsa3b913022015-02-27 15:19:25 -0800776 PkgPath: "v.io/x/ref/examples/rps",
Todd Wangdddc1fb2014-11-16 21:39:02 -0800777 Doc: "// ScoreKeeper receives the outcome of games from Judges.",
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700778 Methods: []rpc.MethodDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800779 {
780 Name: "Record",
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700781 InArgs: []rpc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800782 {"Score", ``}, // ScoreCard
783 },
Todd Wangcab990d2015-02-19 19:54:06 -0800784 Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Write"))},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800785 },
786 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700787}
788
Todd Wangd8cb55b2014-11-07 00:58:32 -0800789// RockPaperScissorsClientMethods is the client interface
790// containing RockPaperScissors methods.
791type RockPaperScissorsClientMethods interface {
792 JudgeClientMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700793 // Player can receive challenges from other players.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800794 PlayerClientMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700795 // ScoreKeeper receives the outcome of games from Judges.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800796 ScoreKeeperClientMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700797}
798
Todd Wangd8cb55b2014-11-07 00:58:32 -0800799// RockPaperScissorsClientStub adds universal methods to RockPaperScissorsClientMethods.
800type RockPaperScissorsClientStub interface {
801 RockPaperScissorsClientMethods
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700802 rpc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700803}
804
Todd Wangd8cb55b2014-11-07 00:58:32 -0800805// RockPaperScissorsClient returns a client stub for RockPaperScissors.
Asim Shankar69fa69f2015-04-01 11:34:32 -0700806func RockPaperScissorsClient(name string) RockPaperScissorsClientStub {
807 return implRockPaperScissorsClientStub{name, JudgeClient(name), PlayerClient(name), ScoreKeeperClient(name)}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700808}
809
Todd Wangd8cb55b2014-11-07 00:58:32 -0800810type implRockPaperScissorsClientStub struct {
Asim Shankar69fa69f2015-04-01 11:34:32 -0700811 name string
Todd Wangd8cb55b2014-11-07 00:58:32 -0800812
813 JudgeClientStub
814 PlayerClientStub
815 ScoreKeeperClientStub
816}
817
Todd Wangd8cb55b2014-11-07 00:58:32 -0800818// RockPaperScissorsServerMethods is the interface a server writer
819// implements for RockPaperScissors.
820type RockPaperScissorsServerMethods interface {
821 JudgeServerMethods
822 // Player can receive challenges from other players.
823 PlayerServerMethods
824 // ScoreKeeper receives the outcome of games from Judges.
825 ScoreKeeperServerMethods
826}
827
828// RockPaperScissorsServerStubMethods is the server interface containing
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700829// RockPaperScissors methods, as expected by rpc.Server.
Todd Wang5cd27352014-11-11 20:27:39 -0800830// The only difference between this interface and RockPaperScissorsServerMethods
831// is the streaming methods.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800832type RockPaperScissorsServerStubMethods interface {
833 JudgeServerStubMethods
834 // Player can receive challenges from other players.
835 PlayerServerStubMethods
836 // ScoreKeeper receives the outcome of games from Judges.
837 ScoreKeeperServerStubMethods
838}
839
840// RockPaperScissorsServerStub adds universal methods to RockPaperScissorsServerStubMethods.
841type RockPaperScissorsServerStub interface {
842 RockPaperScissorsServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800843 // Describe the RockPaperScissors interfaces.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700844 Describe__() []rpc.InterfaceDesc
Todd Wangd8cb55b2014-11-07 00:58:32 -0800845}
846
847// RockPaperScissorsServer returns a server stub for RockPaperScissors.
848// It converts an implementation of RockPaperScissorsServerMethods into
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700849// an object that may be used by rpc.Server.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800850func RockPaperScissorsServer(impl RockPaperScissorsServerMethods) RockPaperScissorsServerStub {
851 stub := implRockPaperScissorsServerStub{
852 impl: impl,
853 JudgeServerStub: JudgeServer(impl),
854 PlayerServerStub: PlayerServer(impl),
855 ScoreKeeperServerStub: ScoreKeeperServer(impl),
856 }
857 // Initialize GlobState; always check the stub itself first, to handle the
858 // case where the user has the Glob method defined in their VDL source.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700859 if gs := rpc.NewGlobState(stub); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800860 stub.gs = gs
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700861 } else if gs := rpc.NewGlobState(impl); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800862 stub.gs = gs
863 }
Robin Thellenda7548452014-11-05 18:10:24 -0800864 return stub
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700865}
866
Todd Wangd8cb55b2014-11-07 00:58:32 -0800867type implRockPaperScissorsServerStub struct {
868 impl RockPaperScissorsServerMethods
Todd Wangd8cb55b2014-11-07 00:58:32 -0800869 JudgeServerStub
870 PlayerServerStub
871 ScoreKeeperServerStub
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700872 gs *rpc.GlobState
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700873}
874
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700875func (s implRockPaperScissorsServerStub) Globber() *rpc.GlobState {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800876 return s.gs
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700877}
878
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700879func (s implRockPaperScissorsServerStub) Describe__() []rpc.InterfaceDesc {
880 return []rpc.InterfaceDesc{RockPaperScissorsDesc, JudgeDesc, PlayerDesc, ScoreKeeperDesc}
Todd Wangdddc1fb2014-11-16 21:39:02 -0800881}
882
883// RockPaperScissorsDesc describes the RockPaperScissors interface.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700884var RockPaperScissorsDesc rpc.InterfaceDesc = descRockPaperScissors
Todd Wangdddc1fb2014-11-16 21:39:02 -0800885
886// descRockPaperScissors hides the desc to keep godoc clean.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700887var descRockPaperScissors = rpc.InterfaceDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800888 Name: "RockPaperScissors",
Jiri Simsa3b913022015-02-27 15:19:25 -0800889 PkgPath: "v.io/x/ref/examples/rps",
Matt Rosencrantz94502cf2015-03-18 09:43:44 -0700890 Embeds: []rpc.EmbedDesc{
Jiri Simsa3b913022015-02-27 15:19:25 -0800891 {"Judge", "v.io/x/ref/examples/rps", ``},
892 {"Player", "v.io/x/ref/examples/rps", "// Player can receive challenges from other players."},
893 {"ScoreKeeper", "v.io/x/ref/examples/rps", "// ScoreKeeper receives the outcome of games from Judges."},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800894 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700895}