blob: 62967d58980312c2693f2c600b41fe257ddbeb3a [file] [log] [blame]
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001// This file was auto-generated by the veyron vdl tool.
2// Source: service.vdl
3
4// Package rps is an example of veyron service for playing the game of
5// Rock-Paper-Scissors. (http://en.wikipedia.org/wiki/Rock-paper-scissors)
6//
7// There are three different roles in the game:
8//
9// 1. Judge: A judge enforces the rules of the game and decides who
10// the winner is. At the end of the game, the judge reports the
11// final score to all the score keepers.
12//
13// 2. Player: A player can ask a judge to start a new game, it can
14// challenge another player, and it can play a game.
15//
16// 3. ScoreKeeper: A score keeper receives the final score for a game
17// after it ended.
18package rps
19
20import (
Todd Wangd1779a52015-02-05 11:46:12 -080021 // VDL system imports
22 "io"
23 "v.io/core/veyron2"
24 "v.io/core/veyron2/context"
25 "v.io/core/veyron2/ipc"
26 "v.io/core/veyron2/vdl"
Asim Shankar4794c932014-11-24 17:45:56 -080027
Todd Wangd1779a52015-02-05 11:46:12 -080028 // VDL user imports
29 "v.io/core/veyron2/services/security/access"
Jiri Simsa37cdfc02014-10-09 18:00:43 -070030)
31
32// A GameID is used to uniquely identify a game within one Judge.
33type GameID struct {
34 ID string
35}
36
Todd Wang24983c72014-11-26 15:07:25 -080037func (GameID) __VDLReflect(struct {
Jiri Simsa5bcedc52014-12-25 15:36:40 -080038 Name string "v.io/apps/rps.GameID"
Todd Wang24983c72014-11-26 15:07:25 -080039}) {
40}
41
Jiri Simsa37cdfc02014-10-09 18:00:43 -070042// GameOptions specifies the parameters of a game.
43type GameOptions struct {
44 NumRounds int32 // The number of rounds that a player must win to win the game.
45 GameType GameTypeTag // The type of game to play: Classic or LizardSpock.
46}
47
Todd Wang24983c72014-11-26 15:07:25 -080048func (GameOptions) __VDLReflect(struct {
Jiri Simsa5bcedc52014-12-25 15:36:40 -080049 Name string "v.io/apps/rps.GameOptions"
Todd Wang24983c72014-11-26 15:07:25 -080050}) {
51}
52
Jiri Simsa37cdfc02014-10-09 18:00:43 -070053type GameTypeTag byte
54
Todd Wang24983c72014-11-26 15:07:25 -080055func (GameTypeTag) __VDLReflect(struct {
Jiri Simsa5bcedc52014-12-25 15:36:40 -080056 Name string "v.io/apps/rps.GameTypeTag"
Todd Wang24983c72014-11-26 15:07:25 -080057}) {
58}
59
Robin Thellend636b3602015-02-11 14:57:44 -080060type (
61 // PlayerAction represents any single field of the PlayerAction union type.
62 PlayerAction interface {
63 // Index returns the field index.
64 Index() int
65 // Interface returns the field value as an interface.
66 Interface() interface{}
67 // Name returns the field name.
68 Name() string
69 // __VDLReflect describes the PlayerAction union type.
70 __VDLReflect(__PlayerActionReflect)
71 }
72 // PlayerActionMove represents field Move of the PlayerAction union type.
73 PlayerActionMove struct{ Value string } // The move that the player wants to make.
74 // PlayerActionQuit represents field Quit of the PlayerAction union type.
75 PlayerActionQuit struct{ Value unused } // Indicates that the player is quitting the game.
76 // __PlayerActionReflect describes the PlayerAction union type.
77 __PlayerActionReflect struct {
78 Name string "v.io/apps/rps.PlayerAction"
79 Type PlayerAction
80 Union struct {
81 Move PlayerActionMove
82 Quit PlayerActionQuit
83 }
84 }
85)
86
87func (x PlayerActionMove) Index() int { return 0 }
88func (x PlayerActionMove) Interface() interface{} { return x.Value }
89func (x PlayerActionMove) Name() string { return "Move" }
90func (x PlayerActionMove) __VDLReflect(__PlayerActionReflect) {}
91
92func (x PlayerActionQuit) Index() int { return 1 }
93func (x PlayerActionQuit) Interface() interface{} { return x.Value }
94func (x PlayerActionQuit) Name() string { return "Quit" }
95func (x PlayerActionQuit) __VDLReflect(__PlayerActionReflect) {}
96
97type unused struct {
Jiri Simsa37cdfc02014-10-09 18:00:43 -070098}
99
Robin Thellend636b3602015-02-11 14:57:44 -0800100func (unused) __VDLReflect(struct {
101 Name string "v.io/apps/rps.unused"
Todd Wang24983c72014-11-26 15:07:25 -0800102}) {
103}
104
Robin Thellend636b3602015-02-11 14:57:44 -0800105type (
106 // JudgeAction represents any single field of the JudgeAction union type.
107 JudgeAction interface {
108 // Index returns the field index.
109 Index() int
110 // Interface returns the field value as an interface.
111 Interface() interface{}
112 // Name returns the field name.
113 Name() string
114 // __VDLReflect describes the JudgeAction union type.
115 __VDLReflect(__JudgeActionReflect)
116 }
117 // JudgeActionPlayerNum represents field PlayerNum of the JudgeAction union type.
118 JudgeActionPlayerNum struct{ Value int32 } // The player's number.
119 // JudgeActionOpponentName represents field OpponentName of the JudgeAction union type.
120 JudgeActionOpponentName struct{ Value string } // The name of the opponent.
121 // JudgeActionMoveOptions represents field MoveOptions of the JudgeAction union type.
122 JudgeActionMoveOptions struct{ Value []string } // A list of allowed moves that the player must choose from.
123 // JudgeActionRoundResult represents field RoundResult of the JudgeAction union type.
124 JudgeActionRoundResult struct{ Value Round } // The result of the previous round.
125 // JudgeActionScore represents field Score of the JudgeAction union type.
126 JudgeActionScore struct{ Value ScoreCard } // The result of the game.
127 // __JudgeActionReflect describes the JudgeAction union type.
128 __JudgeActionReflect struct {
129 Name string "v.io/apps/rps.JudgeAction"
130 Type JudgeAction
131 Union struct {
132 PlayerNum JudgeActionPlayerNum
133 OpponentName JudgeActionOpponentName
134 MoveOptions JudgeActionMoveOptions
135 RoundResult JudgeActionRoundResult
136 Score JudgeActionScore
137 }
138 }
139)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700140
Robin Thellend636b3602015-02-11 14:57:44 -0800141func (x JudgeActionPlayerNum) Index() int { return 0 }
142func (x JudgeActionPlayerNum) Interface() interface{} { return x.Value }
143func (x JudgeActionPlayerNum) Name() string { return "PlayerNum" }
144func (x JudgeActionPlayerNum) __VDLReflect(__JudgeActionReflect) {}
145
146func (x JudgeActionOpponentName) Index() int { return 1 }
147func (x JudgeActionOpponentName) Interface() interface{} { return x.Value }
148func (x JudgeActionOpponentName) Name() string { return "OpponentName" }
149func (x JudgeActionOpponentName) __VDLReflect(__JudgeActionReflect) {}
150
151func (x JudgeActionMoveOptions) Index() int { return 2 }
152func (x JudgeActionMoveOptions) Interface() interface{} { return x.Value }
153func (x JudgeActionMoveOptions) Name() string { return "MoveOptions" }
154func (x JudgeActionMoveOptions) __VDLReflect(__JudgeActionReflect) {}
155
156func (x JudgeActionRoundResult) Index() int { return 3 }
157func (x JudgeActionRoundResult) Interface() interface{} { return x.Value }
158func (x JudgeActionRoundResult) Name() string { return "RoundResult" }
159func (x JudgeActionRoundResult) __VDLReflect(__JudgeActionReflect) {}
160
161func (x JudgeActionScore) Index() int { return 4 }
162func (x JudgeActionScore) Interface() interface{} { return x.Value }
163func (x JudgeActionScore) Name() string { return "Score" }
164func (x JudgeActionScore) __VDLReflect(__JudgeActionReflect) {}
Todd Wang24983c72014-11-26 15:07:25 -0800165
Sergey Rogulenko2f64f982015-02-05 14:14:46 -0800166type PlayersMoves [2]string
167
168func (PlayersMoves) __VDLReflect(struct {
169 Name string "v.io/apps/rps.PlayersMoves"
170}) {
171}
172
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700173// Round represents the state of a round.
174type Round struct {
Sergey Rogulenko2f64f982015-02-05 14:14:46 -0800175 Moves PlayersMoves // Each player's move.
176 Comment string // A text comment from judge about the round.
177 Winner WinnerTag // Who won the round.
178 StartTimeNS int64 // The time at which the round started.
179 EndTimeNS int64 // The time at which the round ended.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700180}
181
Todd Wang24983c72014-11-26 15:07:25 -0800182func (Round) __VDLReflect(struct {
Jiri Simsa5bcedc52014-12-25 15:36:40 -0800183 Name string "v.io/apps/rps.Round"
Todd Wang24983c72014-11-26 15:07:25 -0800184}) {
185}
186
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700187// WinnerTag is a type used to indicate whether a round or a game was a draw,
188// was won by player 1 or was won by player 2.
189type WinnerTag byte
190
Todd Wang24983c72014-11-26 15:07:25 -0800191func (WinnerTag) __VDLReflect(struct {
Jiri Simsa5bcedc52014-12-25 15:36:40 -0800192 Name string "v.io/apps/rps.WinnerTag"
Todd Wang24983c72014-11-26 15:07:25 -0800193}) {
194}
195
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700196// PlayResult is the value returned by the Play method. It indicates the outcome of the game.
197type PlayResult struct {
198 YouWon bool // True if the player receiving the result won the game.
199}
200
Todd Wang24983c72014-11-26 15:07:25 -0800201func (PlayResult) __VDLReflect(struct {
Jiri Simsa5bcedc52014-12-25 15:36:40 -0800202 Name string "v.io/apps/rps.PlayResult"
Todd Wang24983c72014-11-26 15:07:25 -0800203}) {
204}
205
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700206type ScoreCard struct {
207 Opts GameOptions // The game options.
208 Judge string // The name of the judge.
209 Players []string // The name of the players.
210 Rounds []Round // The outcome of each round.
211 StartTimeNS int64 // The time at which the game started.
212 EndTimeNS int64 // The time at which the game ended.
213 Winner WinnerTag // Who won the game.
214}
215
Todd Wang24983c72014-11-26 15:07:25 -0800216func (ScoreCard) __VDLReflect(struct {
Jiri Simsa5bcedc52014-12-25 15:36:40 -0800217 Name string "v.io/apps/rps.ScoreCard"
Todd Wang24983c72014-11-26 15:07:25 -0800218}) {
219}
220
221func init() {
Todd Wang83f63ba2015-02-09 13:30:43 -0800222 vdl.Register((*GameID)(nil))
223 vdl.Register((*GameOptions)(nil))
224 vdl.Register((*GameTypeTag)(nil))
225 vdl.Register((*PlayerAction)(nil))
Robin Thellend636b3602015-02-11 14:57:44 -0800226 vdl.Register((*unused)(nil))
Todd Wang83f63ba2015-02-09 13:30:43 -0800227 vdl.Register((*JudgeAction)(nil))
228 vdl.Register((*PlayersMoves)(nil))
229 vdl.Register((*Round)(nil))
230 vdl.Register((*WinnerTag)(nil))
231 vdl.Register((*PlayResult)(nil))
232 vdl.Register((*ScoreCard)(nil))
Todd Wang24983c72014-11-26 15:07:25 -0800233}
234
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700235const Classic = GameTypeTag(0) // Rock-Paper-Scissors
236
237const LizardSpock = GameTypeTag(1) // Rock-Paper-Scissors-Lizard-Spock
238
239const Draw = WinnerTag(0)
240
241const Player1 = WinnerTag(1)
242
243const Player2 = WinnerTag(2)
244
Todd Wangd8cb55b2014-11-07 00:58:32 -0800245// JudgeClientMethods is the client interface
246// containing Judge methods.
247type JudgeClientMethods interface {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700248 // CreateGame creates a new game with the given game options and returns a game
249 // identifier that can be used by the players to join the game.
Todd Wangd1779a52015-02-05 11:46:12 -0800250 CreateGame(ctx *context.T, Opts GameOptions, opts ...ipc.CallOpt) (GameID, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700251 // Play lets a player join an existing game and play.
Todd Wangd1779a52015-02-05 11:46:12 -0800252 Play(ctx *context.T, ID GameID, opts ...ipc.CallOpt) (JudgePlayCall, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700253}
254
Todd Wangd8cb55b2014-11-07 00:58:32 -0800255// JudgeClientStub adds universal methods to JudgeClientMethods.
256type JudgeClientStub interface {
257 JudgeClientMethods
Todd Wangd1779a52015-02-05 11:46:12 -0800258 ipc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700259}
260
Todd Wangd8cb55b2014-11-07 00:58:32 -0800261// JudgeClient returns a client stub for Judge.
Todd Wangd1779a52015-02-05 11:46:12 -0800262func JudgeClient(name string, opts ...ipc.BindOpt) JudgeClientStub {
263 var client ipc.Client
Todd Wangd8cb55b2014-11-07 00:58:32 -0800264 for _, opt := range opts {
Todd Wangd1779a52015-02-05 11:46:12 -0800265 if clientOpt, ok := opt.(ipc.Client); ok {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800266 client = clientOpt
267 }
268 }
269 return implJudgeClientStub{name, client}
270}
271
272type implJudgeClientStub struct {
273 name string
Todd Wangd1779a52015-02-05 11:46:12 -0800274 client ipc.Client
Todd Wangd8cb55b2014-11-07 00:58:32 -0800275}
276
Todd Wangd1779a52015-02-05 11:46:12 -0800277func (c implJudgeClientStub) c(ctx *context.T) ipc.Client {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800278 if c.client != nil {
279 return c.client
280 }
Todd Wangd1779a52015-02-05 11:46:12 -0800281 return veyron2.GetClient(ctx)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800282}
283
Todd Wangd1779a52015-02-05 11:46:12 -0800284func (c implJudgeClientStub) CreateGame(ctx *context.T, i0 GameOptions, opts ...ipc.CallOpt) (o0 GameID, err error) {
285 var call ipc.Call
Todd Wangd8cb55b2014-11-07 00:58:32 -0800286 if call, err = c.c(ctx).StartCall(ctx, c.name, "CreateGame", []interface{}{i0}, opts...); err != nil {
287 return
288 }
289 if ierr := call.Finish(&o0, &err); ierr != nil {
290 err = ierr
291 }
292 return
293}
294
Todd Wangd1779a52015-02-05 11:46:12 -0800295func (c implJudgeClientStub) Play(ctx *context.T, i0 GameID, opts ...ipc.CallOpt) (ocall JudgePlayCall, err error) {
296 var call ipc.Call
Todd Wangd8cb55b2014-11-07 00:58:32 -0800297 if call, err = c.c(ctx).StartCall(ctx, c.name, "Play", []interface{}{i0}, opts...); err != nil {
298 return
299 }
Todd Wang5cd27352014-11-11 20:27:39 -0800300 ocall = &implJudgePlayCall{Call: call}
Todd Wangd8cb55b2014-11-07 00:58:32 -0800301 return
302}
303
Todd Wangd8cb55b2014-11-07 00:58:32 -0800304// JudgePlayClientStream is the client stream for Judge.Play.
305type JudgePlayClientStream interface {
Todd Wang5cd27352014-11-11 20:27:39 -0800306 // RecvStream returns the receiver side of the Judge.Play client stream.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700307 RecvStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800308 // Advance stages an item so that it may be retrieved via Value. Returns
309 // true iff there is an item to retrieve. Advance must be called before
310 // Value is called. May block if an item is not available.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700311 Advance() bool
Todd Wangd8cb55b2014-11-07 00:58:32 -0800312 // Value returns the item that was staged by Advance. May panic if Advance
313 // returned false or was not called. Never blocks.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700314 Value() JudgeAction
Todd Wangd8cb55b2014-11-07 00:58:32 -0800315 // Err returns any error encountered by Advance. Never blocks.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700316 Err() error
317 }
Todd Wang5cd27352014-11-11 20:27:39 -0800318 // SendStream returns the send side of the Judge.Play client stream.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700319 SendStream() interface {
Todd Wang04f97dd2014-12-18 18:52:07 -0800320 // Send places the item onto the output stream. Returns errors
321 // encountered while sending, or if Send is called after Close or
322 // the stream has been canceled. Blocks if there is no buffer
323 // space; will unblock when buffer space is available or after
324 // the stream has been canceled.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700325 Send(item PlayerAction) error
Todd Wang04f97dd2014-12-18 18:52:07 -0800326 // Close indicates to the server that no more items will be sent;
327 // server Recv calls will receive io.EOF after all sent items.
328 // This is an optional call - e.g. a client might call Close if it
329 // needs to continue receiving items from the server after it's
330 // done sending. Returns errors encountered while closing, or if
331 // Close is called after the stream has been canceled. Like Send,
332 // blocks if there is no buffer space available.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700333 Close() error
334 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800335}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700336
Todd Wangd8cb55b2014-11-07 00:58:32 -0800337// JudgePlayCall represents the call returned from Judge.Play.
338type JudgePlayCall interface {
339 JudgePlayClientStream
340 // Finish performs the equivalent of SendStream().Close, then blocks until
341 // the server is done, and returns the positional return values for the call.
342 //
Todd Wang04f97dd2014-12-18 18:52:07 -0800343 // Finish returns immediately if the call has been canceled; depending on the
Todd Wangd8cb55b2014-11-07 00:58:32 -0800344 // timing the output could either be an error signaling cancelation, or the
345 // valid positional return values from the server.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700346 //
Todd Wang04f97dd2014-12-18 18:52:07 -0800347 // Calling Finish is mandatory for releasing stream resources, unless the call
348 // has been canceled or any of the other methods return an error. Finish should
Todd Wangd8cb55b2014-11-07 00:58:32 -0800349 // be called at most once.
350 Finish() (PlayResult, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700351}
352
Todd Wangd8cb55b2014-11-07 00:58:32 -0800353type implJudgePlayCall struct {
Todd Wangd1779a52015-02-05 11:46:12 -0800354 ipc.Call
Todd Wang5cd27352014-11-11 20:27:39 -0800355 valRecv JudgeAction
356 errRecv error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700357}
358
359func (c *implJudgePlayCall) RecvStream() interface {
360 Advance() bool
361 Value() JudgeAction
362 Err() error
363} {
Todd Wang5cd27352014-11-11 20:27:39 -0800364 return implJudgePlayCallRecv{c}
365}
366
367type implJudgePlayCallRecv struct {
368 c *implJudgePlayCall
369}
370
371func (c implJudgePlayCallRecv) Advance() bool {
Todd Wang5cd27352014-11-11 20:27:39 -0800372 c.c.errRecv = c.c.Recv(&c.c.valRecv)
373 return c.c.errRecv == nil
374}
375func (c implJudgePlayCallRecv) Value() JudgeAction {
376 return c.c.valRecv
377}
378func (c implJudgePlayCallRecv) Err() error {
Todd Wangd1779a52015-02-05 11:46:12 -0800379 if c.c.errRecv == io.EOF {
Todd Wang5cd27352014-11-11 20:27:39 -0800380 return nil
381 }
382 return c.c.errRecv
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700383}
Todd Wangd8cb55b2014-11-07 00:58:32 -0800384func (c *implJudgePlayCall) SendStream() interface {
385 Send(item PlayerAction) error
386 Close() error
387} {
Todd Wang5cd27352014-11-11 20:27:39 -0800388 return implJudgePlayCallSend{c}
389}
390
391type implJudgePlayCallSend struct {
392 c *implJudgePlayCall
393}
394
395func (c implJudgePlayCallSend) Send(item PlayerAction) error {
396 return c.c.Send(item)
397}
398func (c implJudgePlayCallSend) Close() error {
399 return c.c.CloseSend()
Todd Wangd8cb55b2014-11-07 00:58:32 -0800400}
401func (c *implJudgePlayCall) Finish() (o0 PlayResult, err error) {
Todd Wang5cd27352014-11-11 20:27:39 -0800402 if ierr := c.Call.Finish(&o0, &err); ierr != nil {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700403 err = ierr
404 }
405 return
406}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700407
Todd Wangd8cb55b2014-11-07 00:58:32 -0800408// JudgeServerMethods is the interface a server writer
409// implements for Judge.
410type JudgeServerMethods interface {
411 // CreateGame creates a new game with the given game options and returns a game
412 // identifier that can be used by the players to join the game.
Todd Wangd1779a52015-02-05 11:46:12 -0800413 CreateGame(ctx ipc.ServerContext, Opts GameOptions) (GameID, error)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800414 // Play lets a player join an existing game and play.
415 Play(ctx JudgePlayContext, ID GameID) (PlayResult, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700416}
417
Todd Wangd8cb55b2014-11-07 00:58:32 -0800418// JudgeServerStubMethods is the server interface containing
Todd Wang5cd27352014-11-11 20:27:39 -0800419// Judge methods, as expected by ipc.Server.
420// The only difference between this interface and JudgeServerMethods
421// is the streaming methods.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800422type JudgeServerStubMethods interface {
423 // CreateGame creates a new game with the given game options and returns a game
424 // identifier that can be used by the players to join the game.
Todd Wangd1779a52015-02-05 11:46:12 -0800425 CreateGame(ctx ipc.ServerContext, Opts GameOptions) (GameID, error)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800426 // Play lets a player join an existing game and play.
Todd Wang5cd27352014-11-11 20:27:39 -0800427 Play(ctx *JudgePlayContextStub, ID GameID) (PlayResult, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700428}
429
Todd Wangd8cb55b2014-11-07 00:58:32 -0800430// JudgeServerStub adds universal methods to JudgeServerStubMethods.
431type JudgeServerStub interface {
432 JudgeServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800433 // Describe the Judge interfaces.
Todd Wangd1779a52015-02-05 11:46:12 -0800434 Describe__() []ipc.InterfaceDesc
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700435}
436
Todd Wangd8cb55b2014-11-07 00:58:32 -0800437// JudgeServer returns a server stub for Judge.
438// It converts an implementation of JudgeServerMethods into
439// an object that may be used by ipc.Server.
440func JudgeServer(impl JudgeServerMethods) JudgeServerStub {
441 stub := implJudgeServerStub{
442 impl: impl,
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700443 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800444 // Initialize GlobState; always check the stub itself first, to handle the
445 // case where the user has the Glob method defined in their VDL source.
Todd Wangd1779a52015-02-05 11:46:12 -0800446 if gs := ipc.NewGlobState(stub); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800447 stub.gs = gs
Todd Wangd1779a52015-02-05 11:46:12 -0800448 } else if gs := ipc.NewGlobState(impl); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800449 stub.gs = gs
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700450 }
Robin Thellenda7548452014-11-05 18:10:24 -0800451 return stub
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700452}
453
Todd Wangd8cb55b2014-11-07 00:58:32 -0800454type implJudgeServerStub struct {
455 impl JudgeServerMethods
Todd Wangd1779a52015-02-05 11:46:12 -0800456 gs *ipc.GlobState
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700457}
458
Todd Wangd1779a52015-02-05 11:46:12 -0800459func (s implJudgeServerStub) CreateGame(ctx ipc.ServerContext, i0 GameOptions) (GameID, error) {
Todd Wang5cd27352014-11-11 20:27:39 -0800460 return s.impl.CreateGame(ctx, i0)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700461}
462
Todd Wang5cd27352014-11-11 20:27:39 -0800463func (s implJudgeServerStub) Play(ctx *JudgePlayContextStub, i0 GameID) (PlayResult, error) {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800464 return s.impl.Play(ctx, i0)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700465}
466
Todd Wangd1779a52015-02-05 11:46:12 -0800467func (s implJudgeServerStub) Globber() *ipc.GlobState {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800468 return s.gs
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700469}
470
Todd Wangd1779a52015-02-05 11:46:12 -0800471func (s implJudgeServerStub) Describe__() []ipc.InterfaceDesc {
472 return []ipc.InterfaceDesc{JudgeDesc}
Todd Wangdddc1fb2014-11-16 21:39:02 -0800473}
474
475// JudgeDesc describes the Judge interface.
Todd Wangd1779a52015-02-05 11:46:12 -0800476var JudgeDesc ipc.InterfaceDesc = descJudge
Todd Wangdddc1fb2014-11-16 21:39:02 -0800477
478// descJudge hides the desc to keep godoc clean.
Todd Wangd1779a52015-02-05 11:46:12 -0800479var descJudge = ipc.InterfaceDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800480 Name: "Judge",
Jiri Simsa5bcedc52014-12-25 15:36:40 -0800481 PkgPath: "v.io/apps/rps",
Todd Wangd1779a52015-02-05 11:46:12 -0800482 Methods: []ipc.MethodDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800483 {
484 Name: "CreateGame",
485 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.",
Todd Wangd1779a52015-02-05 11:46:12 -0800486 InArgs: []ipc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800487 {"Opts", ``}, // GameOptions
488 },
Todd Wangd1779a52015-02-05 11:46:12 -0800489 OutArgs: []ipc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800490 {"", ``}, // GameID
491 {"", ``}, // error
492 },
Todd Wangd1779a52015-02-05 11:46:12 -0800493 Tags: []vdl.AnyRep{access.Tag("Write")},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800494 },
495 {
496 Name: "Play",
497 Doc: "// Play lets a player join an existing game and play.",
Todd Wangd1779a52015-02-05 11:46:12 -0800498 InArgs: []ipc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800499 {"ID", ``}, // GameID
500 },
Todd Wangd1779a52015-02-05 11:46:12 -0800501 OutArgs: []ipc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800502 {"", ``}, // PlayResult
503 {"", ``}, // error
504 },
Todd Wangd1779a52015-02-05 11:46:12 -0800505 Tags: []vdl.AnyRep{access.Tag("Write")},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800506 },
507 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700508}
509
Todd Wangd8cb55b2014-11-07 00:58:32 -0800510// JudgePlayServerStream is the server stream for Judge.Play.
511type JudgePlayServerStream interface {
Todd Wang5cd27352014-11-11 20:27:39 -0800512 // RecvStream returns the receiver side of the Judge.Play server stream.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800513 RecvStream() interface {
514 // Advance stages an item so that it may be retrieved via Value. Returns
515 // true iff there is an item to retrieve. Advance must be called before
516 // Value is called. May block if an item is not available.
517 Advance() bool
518 // Value returns the item that was staged by Advance. May panic if Advance
519 // returned false or was not called. Never blocks.
520 Value() PlayerAction
521 // Err returns any error encountered by Advance. Never blocks.
522 Err() error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700523 }
Todd Wang5cd27352014-11-11 20:27:39 -0800524 // SendStream returns the send side of the Judge.Play server stream.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800525 SendStream() interface {
526 // Send places the item onto the output stream. Returns errors encountered
527 // while sending. Blocks if there is no buffer space; will unblock when
528 // buffer space is available.
529 Send(item JudgeAction) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700530 }
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700531}
532
Todd Wangd8cb55b2014-11-07 00:58:32 -0800533// JudgePlayContext represents the context passed to Judge.Play.
534type JudgePlayContext interface {
Todd Wangd1779a52015-02-05 11:46:12 -0800535 ipc.ServerContext
Todd Wangd8cb55b2014-11-07 00:58:32 -0800536 JudgePlayServerStream
Robin Thellenda7548452014-11-05 18:10:24 -0800537}
538
Todd Wang5cd27352014-11-11 20:27:39 -0800539// JudgePlayContextStub is a wrapper that converts ipc.ServerCall into
540// a typesafe stub that implements JudgePlayContext.
541type JudgePlayContextStub struct {
Todd Wangd1779a52015-02-05 11:46:12 -0800542 ipc.ServerCall
Todd Wang5cd27352014-11-11 20:27:39 -0800543 valRecv PlayerAction
544 errRecv error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700545}
546
Todd Wang5cd27352014-11-11 20:27:39 -0800547// Init initializes JudgePlayContextStub from ipc.ServerCall.
Todd Wangd1779a52015-02-05 11:46:12 -0800548func (s *JudgePlayContextStub) Init(call ipc.ServerCall) {
Todd Wang5cd27352014-11-11 20:27:39 -0800549 s.ServerCall = call
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700550}
551
Todd Wang5cd27352014-11-11 20:27:39 -0800552// RecvStream returns the receiver side of the Judge.Play server stream.
553func (s *JudgePlayContextStub) RecvStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800554 Advance() bool
555 Value() PlayerAction
556 Err() error
557} {
Todd Wang5cd27352014-11-11 20:27:39 -0800558 return implJudgePlayContextRecv{s}
Todd Wangd8cb55b2014-11-07 00:58:32 -0800559}
Todd Wang5cd27352014-11-11 20:27:39 -0800560
561type implJudgePlayContextRecv struct {
562 s *JudgePlayContextStub
563}
564
565func (s implJudgePlayContextRecv) Advance() bool {
Todd Wang5cd27352014-11-11 20:27:39 -0800566 s.s.errRecv = s.s.Recv(&s.s.valRecv)
567 return s.s.errRecv == nil
568}
569func (s implJudgePlayContextRecv) Value() PlayerAction {
570 return s.s.valRecv
571}
572func (s implJudgePlayContextRecv) Err() error {
Todd Wangd1779a52015-02-05 11:46:12 -0800573 if s.s.errRecv == io.EOF {
Todd Wang5cd27352014-11-11 20:27:39 -0800574 return nil
575 }
576 return s.s.errRecv
577}
578
579// SendStream returns the send side of the Judge.Play server stream.
580func (s *JudgePlayContextStub) SendStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800581 Send(item JudgeAction) error
582} {
Todd Wang5cd27352014-11-11 20:27:39 -0800583 return implJudgePlayContextSend{s}
584}
585
586type implJudgePlayContextSend struct {
587 s *JudgePlayContextStub
588}
589
590func (s implJudgePlayContextSend) Send(item JudgeAction) error {
591 return s.s.Send(item)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800592}
593
594// PlayerClientMethods is the client interface
595// containing Player methods.
596//
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700597// Player can receive challenges from other players.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800598type PlayerClientMethods interface {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700599 // Challenge is used by other players to challenge this player to a game. If
600 // the challenge is accepted, the method returns nil.
Todd Wangd1779a52015-02-05 11:46:12 -0800601 Challenge(ctx *context.T, Address string, ID GameID, Opts GameOptions, opts ...ipc.CallOpt) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700602}
603
Todd Wangd8cb55b2014-11-07 00:58:32 -0800604// PlayerClientStub adds universal methods to PlayerClientMethods.
605type PlayerClientStub interface {
606 PlayerClientMethods
Todd Wangd1779a52015-02-05 11:46:12 -0800607 ipc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700608}
609
Todd Wangd8cb55b2014-11-07 00:58:32 -0800610// PlayerClient returns a client stub for Player.
Todd Wangd1779a52015-02-05 11:46:12 -0800611func PlayerClient(name string, opts ...ipc.BindOpt) PlayerClientStub {
612 var client ipc.Client
Todd Wangd8cb55b2014-11-07 00:58:32 -0800613 for _, opt := range opts {
Todd Wangd1779a52015-02-05 11:46:12 -0800614 if clientOpt, ok := opt.(ipc.Client); ok {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700615 client = clientOpt
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700616 }
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700617 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800618 return implPlayerClientStub{name, client}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700619}
620
Todd Wangd8cb55b2014-11-07 00:58:32 -0800621type implPlayerClientStub struct {
622 name string
Todd Wangd1779a52015-02-05 11:46:12 -0800623 client ipc.Client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700624}
625
Todd Wangd1779a52015-02-05 11:46:12 -0800626func (c implPlayerClientStub) c(ctx *context.T) ipc.Client {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800627 if c.client != nil {
628 return c.client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700629 }
Todd Wangd1779a52015-02-05 11:46:12 -0800630 return veyron2.GetClient(ctx)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700631}
632
Todd Wangd1779a52015-02-05 11:46:12 -0800633func (c implPlayerClientStub) Challenge(ctx *context.T, i0 string, i1 GameID, i2 GameOptions, opts ...ipc.CallOpt) (err error) {
634 var call ipc.Call
Todd Wangd8cb55b2014-11-07 00:58:32 -0800635 if call, err = c.c(ctx).StartCall(ctx, c.name, "Challenge", []interface{}{i0, i1, i2}, opts...); err != nil {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700636 return
637 }
638 if ierr := call.Finish(&err); ierr != nil {
639 err = ierr
640 }
641 return
642}
643
Todd Wangd8cb55b2014-11-07 00:58:32 -0800644// PlayerServerMethods is the interface a server writer
645// implements for Player.
646//
647// Player can receive challenges from other players.
648type PlayerServerMethods interface {
649 // Challenge is used by other players to challenge this player to a game. If
650 // the challenge is accepted, the method returns nil.
Todd Wangd1779a52015-02-05 11:46:12 -0800651 Challenge(ctx ipc.ServerContext, Address string, ID GameID, Opts GameOptions) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700652}
653
Todd Wangd8cb55b2014-11-07 00:58:32 -0800654// PlayerServerStubMethods is the server interface containing
Todd Wang5cd27352014-11-11 20:27:39 -0800655// Player methods, as expected by ipc.Server.
656// There is no difference between this interface and PlayerServerMethods
657// since there are no streaming methods.
658type PlayerServerStubMethods PlayerServerMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700659
Todd Wangd8cb55b2014-11-07 00:58:32 -0800660// PlayerServerStub adds universal methods to PlayerServerStubMethods.
661type PlayerServerStub interface {
662 PlayerServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800663 // Describe the Player interfaces.
Todd Wangd1779a52015-02-05 11:46:12 -0800664 Describe__() []ipc.InterfaceDesc
Todd Wangd8cb55b2014-11-07 00:58:32 -0800665}
666
667// PlayerServer returns a server stub for Player.
668// It converts an implementation of PlayerServerMethods into
669// an object that may be used by ipc.Server.
670func PlayerServer(impl PlayerServerMethods) PlayerServerStub {
671 stub := implPlayerServerStub{
672 impl: impl,
673 }
674 // Initialize GlobState; always check the stub itself first, to handle the
675 // case where the user has the Glob method defined in their VDL source.
Todd Wangd1779a52015-02-05 11:46:12 -0800676 if gs := ipc.NewGlobState(stub); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800677 stub.gs = gs
Todd Wangd1779a52015-02-05 11:46:12 -0800678 } else if gs := ipc.NewGlobState(impl); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800679 stub.gs = gs
680 }
681 return stub
682}
683
684type implPlayerServerStub struct {
685 impl PlayerServerMethods
Todd Wangd1779a52015-02-05 11:46:12 -0800686 gs *ipc.GlobState
Todd Wangd8cb55b2014-11-07 00:58:32 -0800687}
688
Todd Wangd1779a52015-02-05 11:46:12 -0800689func (s implPlayerServerStub) Challenge(ctx ipc.ServerContext, i0 string, i1 GameID, i2 GameOptions) error {
Todd Wang5cd27352014-11-11 20:27:39 -0800690 return s.impl.Challenge(ctx, i0, i1, i2)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800691}
692
Todd Wangd1779a52015-02-05 11:46:12 -0800693func (s implPlayerServerStub) Globber() *ipc.GlobState {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800694 return s.gs
695}
696
Todd Wangd1779a52015-02-05 11:46:12 -0800697func (s implPlayerServerStub) Describe__() []ipc.InterfaceDesc {
698 return []ipc.InterfaceDesc{PlayerDesc}
Todd Wangdddc1fb2014-11-16 21:39:02 -0800699}
700
701// PlayerDesc describes the Player interface.
Todd Wangd1779a52015-02-05 11:46:12 -0800702var PlayerDesc ipc.InterfaceDesc = descPlayer
Todd Wangdddc1fb2014-11-16 21:39:02 -0800703
704// descPlayer hides the desc to keep godoc clean.
Todd Wangd1779a52015-02-05 11:46:12 -0800705var descPlayer = ipc.InterfaceDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800706 Name: "Player",
Jiri Simsa5bcedc52014-12-25 15:36:40 -0800707 PkgPath: "v.io/apps/rps",
Todd Wangdddc1fb2014-11-16 21:39:02 -0800708 Doc: "// Player can receive challenges from other players.",
Todd Wangd1779a52015-02-05 11:46:12 -0800709 Methods: []ipc.MethodDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800710 {
711 Name: "Challenge",
712 Doc: "// Challenge is used by other players to challenge this player to a game. If\n// the challenge is accepted, the method returns nil.",
Todd Wangd1779a52015-02-05 11:46:12 -0800713 InArgs: []ipc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800714 {"Address", ``}, // string
715 {"ID", ``}, // GameID
716 {"Opts", ``}, // GameOptions
717 },
Todd Wangd1779a52015-02-05 11:46:12 -0800718 OutArgs: []ipc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800719 {"", ``}, // error
720 },
Todd Wangd1779a52015-02-05 11:46:12 -0800721 Tags: []vdl.AnyRep{access.Tag("Write")},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800722 },
723 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700724}
725
Todd Wangd8cb55b2014-11-07 00:58:32 -0800726// ScoreKeeperClientMethods is the client interface
727// containing ScoreKeeper methods.
728//
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700729// ScoreKeeper receives the outcome of games from Judges.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800730type ScoreKeeperClientMethods interface {
Todd Wangd1779a52015-02-05 11:46:12 -0800731 Record(ctx *context.T, Score ScoreCard, opts ...ipc.CallOpt) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700732}
733
Todd Wangd8cb55b2014-11-07 00:58:32 -0800734// ScoreKeeperClientStub adds universal methods to ScoreKeeperClientMethods.
735type ScoreKeeperClientStub interface {
736 ScoreKeeperClientMethods
Todd Wangd1779a52015-02-05 11:46:12 -0800737 ipc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700738}
739
Todd Wangd8cb55b2014-11-07 00:58:32 -0800740// ScoreKeeperClient returns a client stub for ScoreKeeper.
Todd Wangd1779a52015-02-05 11:46:12 -0800741func ScoreKeeperClient(name string, opts ...ipc.BindOpt) ScoreKeeperClientStub {
742 var client ipc.Client
Todd Wangd8cb55b2014-11-07 00:58:32 -0800743 for _, opt := range opts {
Todd Wangd1779a52015-02-05 11:46:12 -0800744 if clientOpt, ok := opt.(ipc.Client); ok {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700745 client = clientOpt
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700746 }
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700747 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800748 return implScoreKeeperClientStub{name, client}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700749}
750
Todd Wangd8cb55b2014-11-07 00:58:32 -0800751type implScoreKeeperClientStub struct {
752 name string
Todd Wangd1779a52015-02-05 11:46:12 -0800753 client ipc.Client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700754}
755
Todd Wangd1779a52015-02-05 11:46:12 -0800756func (c implScoreKeeperClientStub) c(ctx *context.T) ipc.Client {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800757 if c.client != nil {
758 return c.client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700759 }
Todd Wangd1779a52015-02-05 11:46:12 -0800760 return veyron2.GetClient(ctx)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700761}
762
Todd Wangd1779a52015-02-05 11:46:12 -0800763func (c implScoreKeeperClientStub) Record(ctx *context.T, i0 ScoreCard, opts ...ipc.CallOpt) (err error) {
764 var call ipc.Call
Todd Wangd8cb55b2014-11-07 00:58:32 -0800765 if call, err = c.c(ctx).StartCall(ctx, c.name, "Record", []interface{}{i0}, opts...); err != nil {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700766 return
767 }
768 if ierr := call.Finish(&err); ierr != nil {
769 err = ierr
770 }
771 return
772}
773
Todd Wangd8cb55b2014-11-07 00:58:32 -0800774// ScoreKeeperServerMethods is the interface a server writer
775// implements for ScoreKeeper.
776//
777// ScoreKeeper receives the outcome of games from Judges.
778type ScoreKeeperServerMethods interface {
Todd Wangd1779a52015-02-05 11:46:12 -0800779 Record(ctx ipc.ServerContext, Score ScoreCard) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700780}
781
Todd Wangd8cb55b2014-11-07 00:58:32 -0800782// ScoreKeeperServerStubMethods is the server interface containing
Todd Wang5cd27352014-11-11 20:27:39 -0800783// ScoreKeeper methods, as expected by ipc.Server.
784// There is no difference between this interface and ScoreKeeperServerMethods
785// since there are no streaming methods.
786type ScoreKeeperServerStubMethods ScoreKeeperServerMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700787
Todd Wangd8cb55b2014-11-07 00:58:32 -0800788// ScoreKeeperServerStub adds universal methods to ScoreKeeperServerStubMethods.
789type ScoreKeeperServerStub interface {
790 ScoreKeeperServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800791 // Describe the ScoreKeeper interfaces.
Todd Wangd1779a52015-02-05 11:46:12 -0800792 Describe__() []ipc.InterfaceDesc
Todd Wangd8cb55b2014-11-07 00:58:32 -0800793}
794
795// ScoreKeeperServer returns a server stub for ScoreKeeper.
796// It converts an implementation of ScoreKeeperServerMethods into
797// an object that may be used by ipc.Server.
798func ScoreKeeperServer(impl ScoreKeeperServerMethods) ScoreKeeperServerStub {
799 stub := implScoreKeeperServerStub{
800 impl: impl,
801 }
802 // Initialize GlobState; always check the stub itself first, to handle the
803 // case where the user has the Glob method defined in their VDL source.
Todd Wangd1779a52015-02-05 11:46:12 -0800804 if gs := ipc.NewGlobState(stub); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800805 stub.gs = gs
Todd Wangd1779a52015-02-05 11:46:12 -0800806 } else if gs := ipc.NewGlobState(impl); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800807 stub.gs = gs
808 }
809 return stub
810}
811
812type implScoreKeeperServerStub struct {
813 impl ScoreKeeperServerMethods
Todd Wangd1779a52015-02-05 11:46:12 -0800814 gs *ipc.GlobState
Todd Wangd8cb55b2014-11-07 00:58:32 -0800815}
816
Todd Wangd1779a52015-02-05 11:46:12 -0800817func (s implScoreKeeperServerStub) Record(ctx ipc.ServerContext, i0 ScoreCard) error {
Todd Wang5cd27352014-11-11 20:27:39 -0800818 return s.impl.Record(ctx, i0)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800819}
820
Todd Wangd1779a52015-02-05 11:46:12 -0800821func (s implScoreKeeperServerStub) Globber() *ipc.GlobState {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800822 return s.gs
823}
824
Todd Wangd1779a52015-02-05 11:46:12 -0800825func (s implScoreKeeperServerStub) Describe__() []ipc.InterfaceDesc {
826 return []ipc.InterfaceDesc{ScoreKeeperDesc}
Todd Wangdddc1fb2014-11-16 21:39:02 -0800827}
828
829// ScoreKeeperDesc describes the ScoreKeeper interface.
Todd Wangd1779a52015-02-05 11:46:12 -0800830var ScoreKeeperDesc ipc.InterfaceDesc = descScoreKeeper
Todd Wangdddc1fb2014-11-16 21:39:02 -0800831
832// descScoreKeeper hides the desc to keep godoc clean.
Todd Wangd1779a52015-02-05 11:46:12 -0800833var descScoreKeeper = ipc.InterfaceDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800834 Name: "ScoreKeeper",
Jiri Simsa5bcedc52014-12-25 15:36:40 -0800835 PkgPath: "v.io/apps/rps",
Todd Wangdddc1fb2014-11-16 21:39:02 -0800836 Doc: "// ScoreKeeper receives the outcome of games from Judges.",
Todd Wangd1779a52015-02-05 11:46:12 -0800837 Methods: []ipc.MethodDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800838 {
839 Name: "Record",
Todd Wangd1779a52015-02-05 11:46:12 -0800840 InArgs: []ipc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800841 {"Score", ``}, // ScoreCard
842 },
Todd Wangd1779a52015-02-05 11:46:12 -0800843 OutArgs: []ipc.ArgDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800844 {"", ``}, // error
845 },
Todd Wangd1779a52015-02-05 11:46:12 -0800846 Tags: []vdl.AnyRep{access.Tag("Write")},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800847 },
848 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700849}
850
Todd Wangd8cb55b2014-11-07 00:58:32 -0800851// RockPaperScissorsClientMethods is the client interface
852// containing RockPaperScissors methods.
853type RockPaperScissorsClientMethods interface {
854 JudgeClientMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700855 // Player can receive challenges from other players.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800856 PlayerClientMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700857 // ScoreKeeper receives the outcome of games from Judges.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800858 ScoreKeeperClientMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700859}
860
Todd Wangd8cb55b2014-11-07 00:58:32 -0800861// RockPaperScissorsClientStub adds universal methods to RockPaperScissorsClientMethods.
862type RockPaperScissorsClientStub interface {
863 RockPaperScissorsClientMethods
Todd Wangd1779a52015-02-05 11:46:12 -0800864 ipc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700865}
866
Todd Wangd8cb55b2014-11-07 00:58:32 -0800867// RockPaperScissorsClient returns a client stub for RockPaperScissors.
Todd Wangd1779a52015-02-05 11:46:12 -0800868func RockPaperScissorsClient(name string, opts ...ipc.BindOpt) RockPaperScissorsClientStub {
869 var client ipc.Client
Todd Wangd8cb55b2014-11-07 00:58:32 -0800870 for _, opt := range opts {
Todd Wangd1779a52015-02-05 11:46:12 -0800871 if clientOpt, ok := opt.(ipc.Client); ok {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700872 client = clientOpt
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700873 }
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700874 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800875 return implRockPaperScissorsClientStub{name, client, JudgeClient(name, client), PlayerClient(name, client), ScoreKeeperClient(name, client)}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700876}
877
Todd Wangd8cb55b2014-11-07 00:58:32 -0800878type implRockPaperScissorsClientStub struct {
879 name string
Todd Wangd1779a52015-02-05 11:46:12 -0800880 client ipc.Client
Todd Wangd8cb55b2014-11-07 00:58:32 -0800881
882 JudgeClientStub
883 PlayerClientStub
884 ScoreKeeperClientStub
885}
886
Todd Wangd1779a52015-02-05 11:46:12 -0800887func (c implRockPaperScissorsClientStub) c(ctx *context.T) ipc.Client {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800888 if c.client != nil {
889 return c.client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700890 }
Todd Wangd1779a52015-02-05 11:46:12 -0800891 return veyron2.GetClient(ctx)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800892}
893
Todd Wangd8cb55b2014-11-07 00:58:32 -0800894// RockPaperScissorsServerMethods is the interface a server writer
895// implements for RockPaperScissors.
896type RockPaperScissorsServerMethods interface {
897 JudgeServerMethods
898 // Player can receive challenges from other players.
899 PlayerServerMethods
900 // ScoreKeeper receives the outcome of games from Judges.
901 ScoreKeeperServerMethods
902}
903
904// RockPaperScissorsServerStubMethods is the server interface containing
Todd Wang5cd27352014-11-11 20:27:39 -0800905// RockPaperScissors methods, as expected by ipc.Server.
906// The only difference between this interface and RockPaperScissorsServerMethods
907// is the streaming methods.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800908type RockPaperScissorsServerStubMethods interface {
909 JudgeServerStubMethods
910 // Player can receive challenges from other players.
911 PlayerServerStubMethods
912 // ScoreKeeper receives the outcome of games from Judges.
913 ScoreKeeperServerStubMethods
914}
915
916// RockPaperScissorsServerStub adds universal methods to RockPaperScissorsServerStubMethods.
917type RockPaperScissorsServerStub interface {
918 RockPaperScissorsServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800919 // Describe the RockPaperScissors interfaces.
Todd Wangd1779a52015-02-05 11:46:12 -0800920 Describe__() []ipc.InterfaceDesc
Todd Wangd8cb55b2014-11-07 00:58:32 -0800921}
922
923// RockPaperScissorsServer returns a server stub for RockPaperScissors.
924// It converts an implementation of RockPaperScissorsServerMethods into
925// an object that may be used by ipc.Server.
926func RockPaperScissorsServer(impl RockPaperScissorsServerMethods) RockPaperScissorsServerStub {
927 stub := implRockPaperScissorsServerStub{
928 impl: impl,
929 JudgeServerStub: JudgeServer(impl),
930 PlayerServerStub: PlayerServer(impl),
931 ScoreKeeperServerStub: ScoreKeeperServer(impl),
932 }
933 // Initialize GlobState; always check the stub itself first, to handle the
934 // case where the user has the Glob method defined in their VDL source.
Todd Wangd1779a52015-02-05 11:46:12 -0800935 if gs := ipc.NewGlobState(stub); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800936 stub.gs = gs
Todd Wangd1779a52015-02-05 11:46:12 -0800937 } else if gs := ipc.NewGlobState(impl); gs != nil {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800938 stub.gs = gs
939 }
Robin Thellenda7548452014-11-05 18:10:24 -0800940 return stub
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700941}
942
Todd Wangd8cb55b2014-11-07 00:58:32 -0800943type implRockPaperScissorsServerStub struct {
944 impl RockPaperScissorsServerMethods
Todd Wangd8cb55b2014-11-07 00:58:32 -0800945 JudgeServerStub
946 PlayerServerStub
947 ScoreKeeperServerStub
Todd Wangd1779a52015-02-05 11:46:12 -0800948 gs *ipc.GlobState
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700949}
950
Todd Wangd1779a52015-02-05 11:46:12 -0800951func (s implRockPaperScissorsServerStub) Globber() *ipc.GlobState {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800952 return s.gs
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700953}
954
Todd Wangd1779a52015-02-05 11:46:12 -0800955func (s implRockPaperScissorsServerStub) Describe__() []ipc.InterfaceDesc {
956 return []ipc.InterfaceDesc{RockPaperScissorsDesc, JudgeDesc, PlayerDesc, ScoreKeeperDesc}
Todd Wangdddc1fb2014-11-16 21:39:02 -0800957}
958
959// RockPaperScissorsDesc describes the RockPaperScissors interface.
Todd Wangd1779a52015-02-05 11:46:12 -0800960var RockPaperScissorsDesc ipc.InterfaceDesc = descRockPaperScissors
Todd Wangdddc1fb2014-11-16 21:39:02 -0800961
962// descRockPaperScissors hides the desc to keep godoc clean.
Todd Wangd1779a52015-02-05 11:46:12 -0800963var descRockPaperScissors = ipc.InterfaceDesc{
Todd Wangdddc1fb2014-11-16 21:39:02 -0800964 Name: "RockPaperScissors",
Jiri Simsa5bcedc52014-12-25 15:36:40 -0800965 PkgPath: "v.io/apps/rps",
Todd Wangd1779a52015-02-05 11:46:12 -0800966 Embeds: []ipc.EmbedDesc{
Jiri Simsa5bcedc52014-12-25 15:36:40 -0800967 {"Judge", "v.io/apps/rps", ``},
968 {"Player", "v.io/apps/rps", "// Player can receive challenges from other players."},
969 {"ScoreKeeper", "v.io/apps/rps", "// ScoreKeeper receives the outcome of games from Judges."},
Todd Wangdddc1fb2014-11-16 21:39:02 -0800970 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700971}