blob: a263e2601e2b3051274cb5bf722fb76ec3a1411c [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 Wangd8cb55b2014-11-07 00:58:32 -080021 // The non-user imports are prefixed with "__" to prevent collisions.
22 __io "io"
23 __veyron2 "veyron.io/veyron/veyron2"
24 __context "veyron.io/veyron/veyron2/context"
25 __ipc "veyron.io/veyron/veyron2/ipc"
26 __vdlutil "veyron.io/veyron/veyron2/vdl/vdlutil"
27 __wiretype "veyron.io/veyron/veyron2/wiretype"
Jiri Simsa37cdfc02014-10-09 18:00:43 -070028)
29
Todd Wangd8cb55b2014-11-07 00:58:32 -080030// TODO(toddw): Remove this line once the new signature support is done.
31// It corrects a bug where __wiretype is unused in VDL pacakges where only
32// bootstrap types are used on interfaces.
33const _ = __wiretype.TypeIDInvalid
34
Jiri Simsa37cdfc02014-10-09 18:00:43 -070035// A GameID is used to uniquely identify a game within one Judge.
36type GameID struct {
37 ID string
38}
39
40// GameOptions specifies the parameters of a game.
41type GameOptions struct {
42 NumRounds int32 // The number of rounds that a player must win to win the game.
43 GameType GameTypeTag // The type of game to play: Classic or LizardSpock.
44}
45
46type GameTypeTag byte
47
48type PlayerAction struct {
49 Move string // The move that the player wants to make.
50 Quit bool // Whether the player wants to quit the game.
51}
52
53type JudgeAction struct {
54 PlayerNum int32 // The player's number.
55 OpponentName string // The name of the opponent.
56 MoveOptions []string // A list of allowed moves that the player must choose from. Not always present.
57 RoundResult Round // The result of the previous round. Not always present.
58 Score ScoreCard // The result of the game. Not always present.
59}
60
61// Round represents the state of a round.
62type Round struct {
63 Moves [2]string // Each player's move.
64 Comment string // A text comment from judge about the round.
65 Winner WinnerTag // Who won the round.
66 StartTimeNS int64 // The time at which the round started.
67 EndTimeNS int64 // The time at which the round ended.
68}
69
70// WinnerTag is a type used to indicate whether a round or a game was a draw,
71// was won by player 1 or was won by player 2.
72type WinnerTag byte
73
74// PlayResult is the value returned by the Play method. It indicates the outcome of the game.
75type PlayResult struct {
76 YouWon bool // True if the player receiving the result won the game.
77}
78
79type ScoreCard struct {
80 Opts GameOptions // The game options.
81 Judge string // The name of the judge.
82 Players []string // The name of the players.
83 Rounds []Round // The outcome of each round.
84 StartTimeNS int64 // The time at which the game started.
85 EndTimeNS int64 // The time at which the game ended.
86 Winner WinnerTag // Who won the game.
87}
88
89const Classic = GameTypeTag(0) // Rock-Paper-Scissors
90
91const LizardSpock = GameTypeTag(1) // Rock-Paper-Scissors-Lizard-Spock
92
93const Draw = WinnerTag(0)
94
95const Player1 = WinnerTag(1)
96
97const Player2 = WinnerTag(2)
98
Todd Wangd8cb55b2014-11-07 00:58:32 -080099// JudgeClientMethods is the client interface
100// containing Judge methods.
101type JudgeClientMethods interface {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700102 // CreateGame creates a new game with the given game options and returns a game
103 // identifier that can be used by the players to join the game.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800104 CreateGame(ctx __context.T, Opts GameOptions, opts ...__ipc.CallOpt) (GameID, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700105 // Play lets a player join an existing game and play.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800106 Play(ctx __context.T, ID GameID, opts ...__ipc.CallOpt) (JudgePlayCall, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700107}
108
Todd Wangd8cb55b2014-11-07 00:58:32 -0800109// JudgeClientStub adds universal methods to JudgeClientMethods.
110type JudgeClientStub interface {
111 JudgeClientMethods
112 __ipc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700113}
114
Todd Wangd8cb55b2014-11-07 00:58:32 -0800115// JudgeClient returns a client stub for Judge.
116func JudgeClient(name string, opts ...__ipc.BindOpt) JudgeClientStub {
117 var client __ipc.Client
118 for _, opt := range opts {
119 if clientOpt, ok := opt.(__ipc.Client); ok {
120 client = clientOpt
121 }
122 }
123 return implJudgeClientStub{name, client}
124}
125
126type implJudgeClientStub struct {
127 name string
128 client __ipc.Client
129}
130
131func (c implJudgeClientStub) c(ctx __context.T) __ipc.Client {
132 if c.client != nil {
133 return c.client
134 }
135 return __veyron2.RuntimeFromContext(ctx).Client()
136}
137
138func (c implJudgeClientStub) CreateGame(ctx __context.T, i0 GameOptions, opts ...__ipc.CallOpt) (o0 GameID, err error) {
139 var call __ipc.Call
140 if call, err = c.c(ctx).StartCall(ctx, c.name, "CreateGame", []interface{}{i0}, opts...); err != nil {
141 return
142 }
143 if ierr := call.Finish(&o0, &err); ierr != nil {
144 err = ierr
145 }
146 return
147}
148
149func (c implJudgeClientStub) Play(ctx __context.T, i0 GameID, opts ...__ipc.CallOpt) (ocall JudgePlayCall, err error) {
150 var call __ipc.Call
151 if call, err = c.c(ctx).StartCall(ctx, c.name, "Play", []interface{}{i0}, opts...); err != nil {
152 return
153 }
Todd Wang5cd27352014-11-11 20:27:39 -0800154 ocall = &implJudgePlayCall{Call: call}
Todd Wangd8cb55b2014-11-07 00:58:32 -0800155 return
156}
157
158func (c implJudgeClientStub) Signature(ctx __context.T, opts ...__ipc.CallOpt) (o0 __ipc.ServiceSignature, err error) {
159 var call __ipc.Call
160 if call, err = c.c(ctx).StartCall(ctx, c.name, "Signature", nil, opts...); err != nil {
161 return
162 }
163 if ierr := call.Finish(&o0, &err); ierr != nil {
164 err = ierr
165 }
166 return
167}
168
Todd Wangd8cb55b2014-11-07 00:58:32 -0800169// JudgePlayClientStream is the client stream for Judge.Play.
170type JudgePlayClientStream interface {
Todd Wang5cd27352014-11-11 20:27:39 -0800171 // RecvStream returns the receiver side of the Judge.Play client stream.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700172 RecvStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800173 // Advance stages an item so that it may be retrieved via Value. Returns
174 // true iff there is an item to retrieve. Advance must be called before
175 // Value is called. May block if an item is not available.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700176 Advance() bool
Todd Wangd8cb55b2014-11-07 00:58:32 -0800177 // Value returns the item that was staged by Advance. May panic if Advance
178 // returned false or was not called. Never blocks.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700179 Value() JudgeAction
Todd Wangd8cb55b2014-11-07 00:58:32 -0800180 // Err returns any error encountered by Advance. Never blocks.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700181 Err() error
182 }
Todd Wang5cd27352014-11-11 20:27:39 -0800183 // SendStream returns the send side of the Judge.Play client stream.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700184 SendStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800185 // Send places the item onto the output stream. Returns errors encountered
186 // while sending, or if Send is called after Close or Cancel. Blocks if
187 // there is no buffer space; will unblock when buffer space is available or
188 // after Cancel.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700189 Send(item PlayerAction) error
Todd Wangd8cb55b2014-11-07 00:58:32 -0800190 // Close indicates to the server that no more items will be sent; server
191 // Recv calls will receive io.EOF after all sent items. This is an optional
192 // call - e.g. a client might call Close if it needs to continue receiving
193 // items from the server after it's done sending. Returns errors
194 // encountered while closing, or if Close is called after Cancel. Like
195 // Send, blocks if there is no buffer space available.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700196 Close() error
197 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800198}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700199
Todd Wangd8cb55b2014-11-07 00:58:32 -0800200// JudgePlayCall represents the call returned from Judge.Play.
201type JudgePlayCall interface {
202 JudgePlayClientStream
203 // Finish performs the equivalent of SendStream().Close, then blocks until
204 // the server is done, and returns the positional return values for the call.
205 //
206 // Finish returns immediately if Cancel has been called; depending on the
207 // timing the output could either be an error signaling cancelation, or the
208 // valid positional return values from the server.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700209 //
210 // Calling Finish is mandatory for releasing stream resources, unless Cancel
Todd Wangd8cb55b2014-11-07 00:58:32 -0800211 // has been called or any of the other methods return an error. Finish should
212 // be called at most once.
213 Finish() (PlayResult, error)
214 // Cancel cancels the RPC, notifying the server to stop processing. It is
215 // safe to call Cancel concurrently with any of the other stream methods.
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700216 // Calling Cancel after Finish has returned is a no-op.
217 Cancel()
218}
219
Todd Wangd8cb55b2014-11-07 00:58:32 -0800220type implJudgePlayCall struct {
Todd Wang5cd27352014-11-11 20:27:39 -0800221 __ipc.Call
222 valRecv JudgeAction
223 errRecv error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700224}
225
226func (c *implJudgePlayCall) RecvStream() interface {
227 Advance() bool
228 Value() JudgeAction
229 Err() error
230} {
Todd Wang5cd27352014-11-11 20:27:39 -0800231 return implJudgePlayCallRecv{c}
232}
233
234type implJudgePlayCallRecv struct {
235 c *implJudgePlayCall
236}
237
238func (c implJudgePlayCallRecv) Advance() bool {
239 c.c.valRecv = JudgeAction{}
240 c.c.errRecv = c.c.Recv(&c.c.valRecv)
241 return c.c.errRecv == nil
242}
243func (c implJudgePlayCallRecv) Value() JudgeAction {
244 return c.c.valRecv
245}
246func (c implJudgePlayCallRecv) Err() error {
247 if c.c.errRecv == __io.EOF {
248 return nil
249 }
250 return c.c.errRecv
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700251}
Todd Wangd8cb55b2014-11-07 00:58:32 -0800252func (c *implJudgePlayCall) SendStream() interface {
253 Send(item PlayerAction) error
254 Close() error
255} {
Todd Wang5cd27352014-11-11 20:27:39 -0800256 return implJudgePlayCallSend{c}
257}
258
259type implJudgePlayCallSend struct {
260 c *implJudgePlayCall
261}
262
263func (c implJudgePlayCallSend) Send(item PlayerAction) error {
264 return c.c.Send(item)
265}
266func (c implJudgePlayCallSend) Close() error {
267 return c.c.CloseSend()
Todd Wangd8cb55b2014-11-07 00:58:32 -0800268}
269func (c *implJudgePlayCall) Finish() (o0 PlayResult, err error) {
Todd Wang5cd27352014-11-11 20:27:39 -0800270 if ierr := c.Call.Finish(&o0, &err); ierr != nil {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700271 err = ierr
272 }
273 return
274}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700275
Todd Wangd8cb55b2014-11-07 00:58:32 -0800276// JudgeServerMethods is the interface a server writer
277// implements for Judge.
278type JudgeServerMethods interface {
279 // CreateGame creates a new game with the given game options and returns a game
280 // identifier that can be used by the players to join the game.
281 CreateGame(ctx __ipc.ServerContext, Opts GameOptions) (GameID, error)
282 // Play lets a player join an existing game and play.
283 Play(ctx JudgePlayContext, ID GameID) (PlayResult, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700284}
285
Todd Wangd8cb55b2014-11-07 00:58:32 -0800286// JudgeServerStubMethods is the server interface containing
Todd Wang5cd27352014-11-11 20:27:39 -0800287// Judge methods, as expected by ipc.Server.
288// The only difference between this interface and JudgeServerMethods
289// is the streaming methods.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800290type JudgeServerStubMethods interface {
291 // CreateGame creates a new game with the given game options and returns a game
292 // identifier that can be used by the players to join the game.
Todd Wang5cd27352014-11-11 20:27:39 -0800293 CreateGame(ctx __ipc.ServerContext, Opts GameOptions) (GameID, error)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800294 // Play lets a player join an existing game and play.
Todd Wang5cd27352014-11-11 20:27:39 -0800295 Play(ctx *JudgePlayContextStub, ID GameID) (PlayResult, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700296}
297
Todd Wangd8cb55b2014-11-07 00:58:32 -0800298// JudgeServerStub adds universal methods to JudgeServerStubMethods.
299type JudgeServerStub interface {
300 JudgeServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800301 // Describe the Judge interfaces.
302 Describe__() []__ipc.InterfaceDesc
303 // Signature will be replaced with Describe__.
Todd Wang5cd27352014-11-11 20:27:39 -0800304 Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700305}
306
Todd Wangd8cb55b2014-11-07 00:58:32 -0800307// JudgeServer returns a server stub for Judge.
308// It converts an implementation of JudgeServerMethods into
309// an object that may be used by ipc.Server.
310func JudgeServer(impl JudgeServerMethods) JudgeServerStub {
311 stub := implJudgeServerStub{
312 impl: impl,
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700313 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800314 // Initialize GlobState; always check the stub itself first, to handle the
315 // case where the user has the Glob method defined in their VDL source.
316 if gs := __ipc.NewGlobState(stub); gs != nil {
317 stub.gs = gs
318 } else if gs := __ipc.NewGlobState(impl); gs != nil {
319 stub.gs = gs
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700320 }
Robin Thellenda7548452014-11-05 18:10:24 -0800321 return stub
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700322}
323
Todd Wangd8cb55b2014-11-07 00:58:32 -0800324type implJudgeServerStub struct {
325 impl JudgeServerMethods
326 gs *__ipc.GlobState
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700327}
328
Todd Wang5cd27352014-11-11 20:27:39 -0800329func (s implJudgeServerStub) CreateGame(ctx __ipc.ServerContext, i0 GameOptions) (GameID, error) {
330 return s.impl.CreateGame(ctx, i0)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700331}
332
Todd Wang5cd27352014-11-11 20:27:39 -0800333func (s implJudgeServerStub) Play(ctx *JudgePlayContextStub, i0 GameID) (PlayResult, error) {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800334 return s.impl.Play(ctx, i0)
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700335}
336
Todd Wangd8cb55b2014-11-07 00:58:32 -0800337func (s implJudgeServerStub) VGlob() *__ipc.GlobState {
338 return s.gs
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700339}
340
Todd Wangdddc1fb2014-11-16 21:39:02 -0800341func (s implJudgeServerStub) Describe__() []__ipc.InterfaceDesc {
342 return []__ipc.InterfaceDesc{JudgeDesc}
343}
344
345// JudgeDesc describes the Judge interface.
346var JudgeDesc __ipc.InterfaceDesc = descJudge
347
348// descJudge hides the desc to keep godoc clean.
349var descJudge = __ipc.InterfaceDesc{
350 Name: "Judge",
351 PkgPath: "veyron.io/apps/rps",
352 Methods: []__ipc.MethodDesc{
353 {
354 Name: "CreateGame",
355 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.",
356 InArgs: []__ipc.ArgDesc{
357 {"Opts", ``}, // GameOptions
358 },
359 OutArgs: []__ipc.ArgDesc{
360 {"", ``}, // GameID
361 {"", ``}, // error
362 },
363 },
364 {
365 Name: "Play",
366 Doc: "// Play lets a player join an existing game and play.",
367 InArgs: []__ipc.ArgDesc{
368 {"ID", ``}, // GameID
369 },
370 OutArgs: []__ipc.ArgDesc{
371 {"", ``}, // PlayResult
372 {"", ``}, // error
373 },
374 },
375 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700376}
377
Todd Wang5cd27352014-11-11 20:27:39 -0800378func (s implJudgeServerStub) Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) {
Todd Wangdddc1fb2014-11-16 21:39:02 -0800379 // TODO(toddw): Replace with new Describe__ implementation.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800380 result := __ipc.ServiceSignature{Methods: make(map[string]__ipc.MethodSignature)}
381 result.Methods["CreateGame"] = __ipc.MethodSignature{
382 InArgs: []__ipc.MethodArgument{
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700383 {Name: "Opts", Type: 66},
384 },
Todd Wangd8cb55b2014-11-07 00:58:32 -0800385 OutArgs: []__ipc.MethodArgument{
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700386 {Name: "", Type: 67},
387 {Name: "", Type: 68},
388 },
389 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800390 result.Methods["Play"] = __ipc.MethodSignature{
391 InArgs: []__ipc.MethodArgument{
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700392 {Name: "ID", Type: 67},
393 },
Todd Wangd8cb55b2014-11-07 00:58:32 -0800394 OutArgs: []__ipc.MethodArgument{
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700395 {Name: "", Type: 69},
396 {Name: "", Type: 68},
397 },
398 InStream: 70,
399 OutStream: 76,
400 }
401
Todd Wangd8cb55b2014-11-07 00:58:32 -0800402 result.TypeDefs = []__vdlutil.Any{
403 __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.GameTypeTag", Tags: []string(nil)}, __wiretype.StructType{
404 []__wiretype.FieldType{
405 __wiretype.FieldType{Type: 0x24, Name: "NumRounds"},
406 __wiretype.FieldType{Type: 0x41, Name: "GameType"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700407 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700408 "veyron.io/apps/rps.GameOptions", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800409 __wiretype.StructType{
410 []__wiretype.FieldType{
411 __wiretype.FieldType{Type: 0x3, Name: "ID"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700412 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700413 "veyron.io/apps/rps.GameID", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800414 __wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}, __wiretype.StructType{
415 []__wiretype.FieldType{
416 __wiretype.FieldType{Type: 0x2, Name: "YouWon"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700417 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700418 "veyron.io/apps/rps.PlayResult", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800419 __wiretype.StructType{
420 []__wiretype.FieldType{
421 __wiretype.FieldType{Type: 0x3, Name: "Move"},
422 __wiretype.FieldType{Type: 0x2, Name: "Quit"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700423 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700424 "veyron.io/apps/rps.PlayerAction", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800425 __wiretype.ArrayType{Elem: 0x3, Len: 0x2, Name: "", Tags: []string(nil)}, __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.WinnerTag", Tags: []string(nil)}, __wiretype.StructType{
426 []__wiretype.FieldType{
427 __wiretype.FieldType{Type: 0x47, Name: "Moves"},
428 __wiretype.FieldType{Type: 0x3, Name: "Comment"},
429 __wiretype.FieldType{Type: 0x48, Name: "Winner"},
430 __wiretype.FieldType{Type: 0x25, Name: "StartTimeNS"},
431 __wiretype.FieldType{Type: 0x25, Name: "EndTimeNS"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700432 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700433 "veyron.io/apps/rps.Round", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800434 __wiretype.SliceType{Elem: 0x49, Name: "", Tags: []string(nil)}, __wiretype.StructType{
435 []__wiretype.FieldType{
436 __wiretype.FieldType{Type: 0x42, Name: "Opts"},
437 __wiretype.FieldType{Type: 0x3, Name: "Judge"},
438 __wiretype.FieldType{Type: 0x3d, Name: "Players"},
439 __wiretype.FieldType{Type: 0x4a, Name: "Rounds"},
440 __wiretype.FieldType{Type: 0x25, Name: "StartTimeNS"},
441 __wiretype.FieldType{Type: 0x25, Name: "EndTimeNS"},
442 __wiretype.FieldType{Type: 0x48, Name: "Winner"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700443 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700444 "veyron.io/apps/rps.ScoreCard", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800445 __wiretype.StructType{
446 []__wiretype.FieldType{
447 __wiretype.FieldType{Type: 0x24, Name: "PlayerNum"},
448 __wiretype.FieldType{Type: 0x3, Name: "OpponentName"},
449 __wiretype.FieldType{Type: 0x3d, Name: "MoveOptions"},
450 __wiretype.FieldType{Type: 0x49, Name: "RoundResult"},
451 __wiretype.FieldType{Type: 0x4b, Name: "Score"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700452 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700453 "veyron.io/apps/rps.JudgeAction", []string(nil)},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700454 }
455
456 return result, nil
457}
458
Todd Wangd8cb55b2014-11-07 00:58:32 -0800459// JudgePlayServerStream is the server stream for Judge.Play.
460type JudgePlayServerStream interface {
Todd Wang5cd27352014-11-11 20:27:39 -0800461 // RecvStream returns the receiver side of the Judge.Play server stream.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800462 RecvStream() interface {
463 // Advance stages an item so that it may be retrieved via Value. Returns
464 // true iff there is an item to retrieve. Advance must be called before
465 // Value is called. May block if an item is not available.
466 Advance() bool
467 // Value returns the item that was staged by Advance. May panic if Advance
468 // returned false or was not called. Never blocks.
469 Value() PlayerAction
470 // Err returns any error encountered by Advance. Never blocks.
471 Err() error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700472 }
Todd Wang5cd27352014-11-11 20:27:39 -0800473 // SendStream returns the send side of the Judge.Play server stream.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800474 SendStream() interface {
475 // Send places the item onto the output stream. Returns errors encountered
476 // while sending. Blocks if there is no buffer space; will unblock when
477 // buffer space is available.
478 Send(item JudgeAction) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700479 }
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700480}
481
Todd Wangd8cb55b2014-11-07 00:58:32 -0800482// JudgePlayContext represents the context passed to Judge.Play.
483type JudgePlayContext interface {
484 __ipc.ServerContext
485 JudgePlayServerStream
Robin Thellenda7548452014-11-05 18:10:24 -0800486}
487
Todd Wang5cd27352014-11-11 20:27:39 -0800488// JudgePlayContextStub is a wrapper that converts ipc.ServerCall into
489// a typesafe stub that implements JudgePlayContext.
490type JudgePlayContextStub struct {
491 __ipc.ServerCall
492 valRecv PlayerAction
493 errRecv error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700494}
495
Todd Wang5cd27352014-11-11 20:27:39 -0800496// Init initializes JudgePlayContextStub from ipc.ServerCall.
497func (s *JudgePlayContextStub) Init(call __ipc.ServerCall) {
498 s.ServerCall = call
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700499}
500
Todd Wang5cd27352014-11-11 20:27:39 -0800501// RecvStream returns the receiver side of the Judge.Play server stream.
502func (s *JudgePlayContextStub) RecvStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800503 Advance() bool
504 Value() PlayerAction
505 Err() error
506} {
Todd Wang5cd27352014-11-11 20:27:39 -0800507 return implJudgePlayContextRecv{s}
Todd Wangd8cb55b2014-11-07 00:58:32 -0800508}
Todd Wang5cd27352014-11-11 20:27:39 -0800509
510type implJudgePlayContextRecv struct {
511 s *JudgePlayContextStub
512}
513
514func (s implJudgePlayContextRecv) Advance() bool {
515 s.s.valRecv = PlayerAction{}
516 s.s.errRecv = s.s.Recv(&s.s.valRecv)
517 return s.s.errRecv == nil
518}
519func (s implJudgePlayContextRecv) Value() PlayerAction {
520 return s.s.valRecv
521}
522func (s implJudgePlayContextRecv) Err() error {
523 if s.s.errRecv == __io.EOF {
524 return nil
525 }
526 return s.s.errRecv
527}
528
529// SendStream returns the send side of the Judge.Play server stream.
530func (s *JudgePlayContextStub) SendStream() interface {
Todd Wangd8cb55b2014-11-07 00:58:32 -0800531 Send(item JudgeAction) error
532} {
Todd Wang5cd27352014-11-11 20:27:39 -0800533 return implJudgePlayContextSend{s}
534}
535
536type implJudgePlayContextSend struct {
537 s *JudgePlayContextStub
538}
539
540func (s implJudgePlayContextSend) Send(item JudgeAction) error {
541 return s.s.Send(item)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800542}
543
544// PlayerClientMethods is the client interface
545// containing Player methods.
546//
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700547// Player can receive challenges from other players.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800548type PlayerClientMethods interface {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700549 // Challenge is used by other players to challenge this player to a game. If
550 // the challenge is accepted, the method returns nil.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800551 Challenge(ctx __context.T, Address string, ID GameID, Opts GameOptions, opts ...__ipc.CallOpt) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700552}
553
Todd Wangd8cb55b2014-11-07 00:58:32 -0800554// PlayerClientStub adds universal methods to PlayerClientMethods.
555type PlayerClientStub interface {
556 PlayerClientMethods
557 __ipc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700558}
559
Todd Wangd8cb55b2014-11-07 00:58:32 -0800560// PlayerClient returns a client stub for Player.
561func PlayerClient(name string, opts ...__ipc.BindOpt) PlayerClientStub {
562 var client __ipc.Client
563 for _, opt := range opts {
564 if clientOpt, ok := opt.(__ipc.Client); ok {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700565 client = clientOpt
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700566 }
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700567 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800568 return implPlayerClientStub{name, client}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700569}
570
Todd Wangd8cb55b2014-11-07 00:58:32 -0800571type implPlayerClientStub struct {
572 name string
573 client __ipc.Client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700574}
575
Todd Wangd8cb55b2014-11-07 00:58:32 -0800576func (c implPlayerClientStub) c(ctx __context.T) __ipc.Client {
577 if c.client != nil {
578 return c.client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700579 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800580 return __veyron2.RuntimeFromContext(ctx).Client()
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700581}
582
Todd Wangd8cb55b2014-11-07 00:58:32 -0800583func (c implPlayerClientStub) Challenge(ctx __context.T, i0 string, i1 GameID, i2 GameOptions, opts ...__ipc.CallOpt) (err error) {
584 var call __ipc.Call
585 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 -0700586 return
587 }
588 if ierr := call.Finish(&err); ierr != nil {
589 err = ierr
590 }
591 return
592}
593
Todd Wangd8cb55b2014-11-07 00:58:32 -0800594func (c implPlayerClientStub) Signature(ctx __context.T, opts ...__ipc.CallOpt) (o0 __ipc.ServiceSignature, err error) {
595 var call __ipc.Call
596 if call, err = c.c(ctx).StartCall(ctx, c.name, "Signature", nil, opts...); err != nil {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700597 return
598 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800599 if ierr := call.Finish(&o0, &err); ierr != nil {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700600 err = ierr
601 }
602 return
603}
604
Todd Wangd8cb55b2014-11-07 00:58:32 -0800605// PlayerServerMethods is the interface a server writer
606// implements for Player.
607//
608// Player can receive challenges from other players.
609type PlayerServerMethods interface {
610 // Challenge is used by other players to challenge this player to a game. If
611 // the challenge is accepted, the method returns nil.
612 Challenge(ctx __ipc.ServerContext, Address string, ID GameID, Opts GameOptions) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700613}
614
Todd Wangd8cb55b2014-11-07 00:58:32 -0800615// PlayerServerStubMethods is the server interface containing
Todd Wang5cd27352014-11-11 20:27:39 -0800616// Player methods, as expected by ipc.Server.
617// There is no difference between this interface and PlayerServerMethods
618// since there are no streaming methods.
619type PlayerServerStubMethods PlayerServerMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700620
Todd Wangd8cb55b2014-11-07 00:58:32 -0800621// PlayerServerStub adds universal methods to PlayerServerStubMethods.
622type PlayerServerStub interface {
623 PlayerServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800624 // Describe the Player interfaces.
625 Describe__() []__ipc.InterfaceDesc
626 // Signature will be replaced with Describe__.
Todd Wang5cd27352014-11-11 20:27:39 -0800627 Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800628}
629
630// PlayerServer returns a server stub for Player.
631// It converts an implementation of PlayerServerMethods into
632// an object that may be used by ipc.Server.
633func PlayerServer(impl PlayerServerMethods) PlayerServerStub {
634 stub := implPlayerServerStub{
635 impl: impl,
636 }
637 // Initialize GlobState; always check the stub itself first, to handle the
638 // case where the user has the Glob method defined in their VDL source.
639 if gs := __ipc.NewGlobState(stub); gs != nil {
640 stub.gs = gs
641 } else if gs := __ipc.NewGlobState(impl); gs != nil {
642 stub.gs = gs
643 }
644 return stub
645}
646
647type implPlayerServerStub struct {
648 impl PlayerServerMethods
649 gs *__ipc.GlobState
650}
651
Todd Wang5cd27352014-11-11 20:27:39 -0800652func (s implPlayerServerStub) Challenge(ctx __ipc.ServerContext, i0 string, i1 GameID, i2 GameOptions) error {
653 return s.impl.Challenge(ctx, i0, i1, i2)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800654}
655
656func (s implPlayerServerStub) VGlob() *__ipc.GlobState {
657 return s.gs
658}
659
Todd Wangdddc1fb2014-11-16 21:39:02 -0800660func (s implPlayerServerStub) Describe__() []__ipc.InterfaceDesc {
661 return []__ipc.InterfaceDesc{PlayerDesc}
662}
663
664// PlayerDesc describes the Player interface.
665var PlayerDesc __ipc.InterfaceDesc = descPlayer
666
667// descPlayer hides the desc to keep godoc clean.
668var descPlayer = __ipc.InterfaceDesc{
669 Name: "Player",
670 PkgPath: "veyron.io/apps/rps",
671 Doc: "// Player can receive challenges from other players.",
672 Methods: []__ipc.MethodDesc{
673 {
674 Name: "Challenge",
675 Doc: "// Challenge is used by other players to challenge this player to a game. If\n// the challenge is accepted, the method returns nil.",
676 InArgs: []__ipc.ArgDesc{
677 {"Address", ``}, // string
678 {"ID", ``}, // GameID
679 {"Opts", ``}, // GameOptions
680 },
681 OutArgs: []__ipc.ArgDesc{
682 {"", ``}, // error
683 },
684 },
685 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700686}
687
Todd Wang5cd27352014-11-11 20:27:39 -0800688func (s implPlayerServerStub) Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) {
Todd Wangdddc1fb2014-11-16 21:39:02 -0800689 // TODO(toddw): Replace with new Describe__ implementation.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800690 result := __ipc.ServiceSignature{Methods: make(map[string]__ipc.MethodSignature)}
691 result.Methods["Challenge"] = __ipc.MethodSignature{
692 InArgs: []__ipc.MethodArgument{
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700693 {Name: "Address", Type: 3},
694 {Name: "ID", Type: 65},
695 {Name: "Opts", Type: 67},
696 },
Todd Wangd8cb55b2014-11-07 00:58:32 -0800697 OutArgs: []__ipc.MethodArgument{
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700698 {Name: "", Type: 68},
699 },
700 }
701
Todd Wangd8cb55b2014-11-07 00:58:32 -0800702 result.TypeDefs = []__vdlutil.Any{
703 __wiretype.StructType{
704 []__wiretype.FieldType{
705 __wiretype.FieldType{Type: 0x3, Name: "ID"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700706 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700707 "veyron.io/apps/rps.GameID", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800708 __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.GameTypeTag", Tags: []string(nil)}, __wiretype.StructType{
709 []__wiretype.FieldType{
710 __wiretype.FieldType{Type: 0x24, Name: "NumRounds"},
711 __wiretype.FieldType{Type: 0x42, Name: "GameType"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700712 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700713 "veyron.io/apps/rps.GameOptions", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800714 __wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700715
716 return result, nil
717}
718
Todd Wangd8cb55b2014-11-07 00:58:32 -0800719// ScoreKeeperClientMethods is the client interface
720// containing ScoreKeeper methods.
721//
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700722// ScoreKeeper receives the outcome of games from Judges.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800723type ScoreKeeperClientMethods interface {
724 Record(ctx __context.T, Score ScoreCard, opts ...__ipc.CallOpt) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700725}
726
Todd Wangd8cb55b2014-11-07 00:58:32 -0800727// ScoreKeeperClientStub adds universal methods to ScoreKeeperClientMethods.
728type ScoreKeeperClientStub interface {
729 ScoreKeeperClientMethods
730 __ipc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700731}
732
Todd Wangd8cb55b2014-11-07 00:58:32 -0800733// ScoreKeeperClient returns a client stub for ScoreKeeper.
734func ScoreKeeperClient(name string, opts ...__ipc.BindOpt) ScoreKeeperClientStub {
735 var client __ipc.Client
736 for _, opt := range opts {
737 if clientOpt, ok := opt.(__ipc.Client); ok {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700738 client = clientOpt
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700739 }
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700740 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800741 return implScoreKeeperClientStub{name, client}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700742}
743
Todd Wangd8cb55b2014-11-07 00:58:32 -0800744type implScoreKeeperClientStub struct {
745 name string
746 client __ipc.Client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700747}
748
Todd Wangd8cb55b2014-11-07 00:58:32 -0800749func (c implScoreKeeperClientStub) c(ctx __context.T) __ipc.Client {
750 if c.client != nil {
751 return c.client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700752 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800753 return __veyron2.RuntimeFromContext(ctx).Client()
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700754}
755
Todd Wangd8cb55b2014-11-07 00:58:32 -0800756func (c implScoreKeeperClientStub) Record(ctx __context.T, i0 ScoreCard, opts ...__ipc.CallOpt) (err error) {
757 var call __ipc.Call
758 if call, err = c.c(ctx).StartCall(ctx, c.name, "Record", []interface{}{i0}, opts...); err != nil {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700759 return
760 }
761 if ierr := call.Finish(&err); ierr != nil {
762 err = ierr
763 }
764 return
765}
766
Todd Wangd8cb55b2014-11-07 00:58:32 -0800767func (c implScoreKeeperClientStub) Signature(ctx __context.T, opts ...__ipc.CallOpt) (o0 __ipc.ServiceSignature, err error) {
768 var call __ipc.Call
769 if call, err = c.c(ctx).StartCall(ctx, c.name, "Signature", nil, opts...); err != nil {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700770 return
771 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800772 if ierr := call.Finish(&o0, &err); ierr != nil {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700773 err = ierr
774 }
775 return
776}
777
Todd Wangd8cb55b2014-11-07 00:58:32 -0800778// ScoreKeeperServerMethods is the interface a server writer
779// implements for ScoreKeeper.
780//
781// ScoreKeeper receives the outcome of games from Judges.
782type ScoreKeeperServerMethods interface {
783 Record(ctx __ipc.ServerContext, Score ScoreCard) error
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700784}
785
Todd Wangd8cb55b2014-11-07 00:58:32 -0800786// ScoreKeeperServerStubMethods is the server interface containing
Todd Wang5cd27352014-11-11 20:27:39 -0800787// ScoreKeeper methods, as expected by ipc.Server.
788// There is no difference between this interface and ScoreKeeperServerMethods
789// since there are no streaming methods.
790type ScoreKeeperServerStubMethods ScoreKeeperServerMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700791
Todd Wangd8cb55b2014-11-07 00:58:32 -0800792// ScoreKeeperServerStub adds universal methods to ScoreKeeperServerStubMethods.
793type ScoreKeeperServerStub interface {
794 ScoreKeeperServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800795 // Describe the ScoreKeeper interfaces.
796 Describe__() []__ipc.InterfaceDesc
797 // Signature will be replaced with Describe__.
Todd Wang5cd27352014-11-11 20:27:39 -0800798 Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800799}
800
801// ScoreKeeperServer returns a server stub for ScoreKeeper.
802// It converts an implementation of ScoreKeeperServerMethods into
803// an object that may be used by ipc.Server.
804func ScoreKeeperServer(impl ScoreKeeperServerMethods) ScoreKeeperServerStub {
805 stub := implScoreKeeperServerStub{
806 impl: impl,
807 }
808 // Initialize GlobState; always check the stub itself first, to handle the
809 // case where the user has the Glob method defined in their VDL source.
810 if gs := __ipc.NewGlobState(stub); gs != nil {
811 stub.gs = gs
812 } else if gs := __ipc.NewGlobState(impl); gs != nil {
813 stub.gs = gs
814 }
815 return stub
816}
817
818type implScoreKeeperServerStub struct {
819 impl ScoreKeeperServerMethods
820 gs *__ipc.GlobState
821}
822
Todd Wang5cd27352014-11-11 20:27:39 -0800823func (s implScoreKeeperServerStub) Record(ctx __ipc.ServerContext, i0 ScoreCard) error {
824 return s.impl.Record(ctx, i0)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800825}
826
827func (s implScoreKeeperServerStub) VGlob() *__ipc.GlobState {
828 return s.gs
829}
830
Todd Wangdddc1fb2014-11-16 21:39:02 -0800831func (s implScoreKeeperServerStub) Describe__() []__ipc.InterfaceDesc {
832 return []__ipc.InterfaceDesc{ScoreKeeperDesc}
833}
834
835// ScoreKeeperDesc describes the ScoreKeeper interface.
836var ScoreKeeperDesc __ipc.InterfaceDesc = descScoreKeeper
837
838// descScoreKeeper hides the desc to keep godoc clean.
839var descScoreKeeper = __ipc.InterfaceDesc{
840 Name: "ScoreKeeper",
841 PkgPath: "veyron.io/apps/rps",
842 Doc: "// ScoreKeeper receives the outcome of games from Judges.",
843 Methods: []__ipc.MethodDesc{
844 {
845 Name: "Record",
846 InArgs: []__ipc.ArgDesc{
847 {"Score", ``}, // ScoreCard
848 },
849 OutArgs: []__ipc.ArgDesc{
850 {"", ``}, // error
851 },
852 },
853 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700854}
855
Todd Wang5cd27352014-11-11 20:27:39 -0800856func (s implScoreKeeperServerStub) Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) {
Todd Wangdddc1fb2014-11-16 21:39:02 -0800857 // TODO(toddw): Replace with new Describe__ implementation.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800858 result := __ipc.ServiceSignature{Methods: make(map[string]__ipc.MethodSignature)}
859 result.Methods["Record"] = __ipc.MethodSignature{
860 InArgs: []__ipc.MethodArgument{
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700861 {Name: "Score", Type: 71},
862 },
Todd Wangd8cb55b2014-11-07 00:58:32 -0800863 OutArgs: []__ipc.MethodArgument{
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700864 {Name: "", Type: 72},
865 },
866 }
867
Todd Wangd8cb55b2014-11-07 00:58:32 -0800868 result.TypeDefs = []__vdlutil.Any{
869 __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.GameTypeTag", Tags: []string(nil)}, __wiretype.StructType{
870 []__wiretype.FieldType{
871 __wiretype.FieldType{Type: 0x24, Name: "NumRounds"},
872 __wiretype.FieldType{Type: 0x41, Name: "GameType"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700873 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700874 "veyron.io/apps/rps.GameOptions", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800875 __wiretype.ArrayType{Elem: 0x3, Len: 0x2, Name: "", Tags: []string(nil)}, __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.WinnerTag", Tags: []string(nil)}, __wiretype.StructType{
876 []__wiretype.FieldType{
877 __wiretype.FieldType{Type: 0x43, Name: "Moves"},
878 __wiretype.FieldType{Type: 0x3, Name: "Comment"},
879 __wiretype.FieldType{Type: 0x44, Name: "Winner"},
880 __wiretype.FieldType{Type: 0x25, Name: "StartTimeNS"},
881 __wiretype.FieldType{Type: 0x25, Name: "EndTimeNS"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700882 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700883 "veyron.io/apps/rps.Round", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800884 __wiretype.SliceType{Elem: 0x45, Name: "", Tags: []string(nil)}, __wiretype.StructType{
885 []__wiretype.FieldType{
886 __wiretype.FieldType{Type: 0x42, Name: "Opts"},
887 __wiretype.FieldType{Type: 0x3, Name: "Judge"},
888 __wiretype.FieldType{Type: 0x3d, Name: "Players"},
889 __wiretype.FieldType{Type: 0x46, Name: "Rounds"},
890 __wiretype.FieldType{Type: 0x25, Name: "StartTimeNS"},
891 __wiretype.FieldType{Type: 0x25, Name: "EndTimeNS"},
892 __wiretype.FieldType{Type: 0x44, Name: "Winner"},
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700893 },
Ali Ghassemi85ed8fa2014-10-22 15:46:10 -0700894 "veyron.io/apps/rps.ScoreCard", []string(nil)},
Todd Wangd8cb55b2014-11-07 00:58:32 -0800895 __wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700896
897 return result, nil
898}
899
Todd Wangd8cb55b2014-11-07 00:58:32 -0800900// RockPaperScissorsClientMethods is the client interface
901// containing RockPaperScissors methods.
902type RockPaperScissorsClientMethods interface {
903 JudgeClientMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700904 // Player can receive challenges from other players.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800905 PlayerClientMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700906 // ScoreKeeper receives the outcome of games from Judges.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800907 ScoreKeeperClientMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700908}
909
Todd Wangd8cb55b2014-11-07 00:58:32 -0800910// RockPaperScissorsClientStub adds universal methods to RockPaperScissorsClientMethods.
911type RockPaperScissorsClientStub interface {
912 RockPaperScissorsClientMethods
913 __ipc.UniversalServiceMethods
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700914}
915
Todd Wangd8cb55b2014-11-07 00:58:32 -0800916// RockPaperScissorsClient returns a client stub for RockPaperScissors.
917func RockPaperScissorsClient(name string, opts ...__ipc.BindOpt) RockPaperScissorsClientStub {
918 var client __ipc.Client
919 for _, opt := range opts {
920 if clientOpt, ok := opt.(__ipc.Client); ok {
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700921 client = clientOpt
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700922 }
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700923 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800924 return implRockPaperScissorsClientStub{name, client, JudgeClient(name, client), PlayerClient(name, client), ScoreKeeperClient(name, client)}
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700925}
926
Todd Wangd8cb55b2014-11-07 00:58:32 -0800927type implRockPaperScissorsClientStub struct {
928 name string
929 client __ipc.Client
930
931 JudgeClientStub
932 PlayerClientStub
933 ScoreKeeperClientStub
934}
935
936func (c implRockPaperScissorsClientStub) c(ctx __context.T) __ipc.Client {
937 if c.client != nil {
938 return c.client
Jiri Simsa37cdfc02014-10-09 18:00:43 -0700939 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800940 return __veyron2.RuntimeFromContext(ctx).Client()
941}
942
943func (c implRockPaperScissorsClientStub) Signature(ctx __context.T, opts ...__ipc.CallOpt) (o0 __ipc.ServiceSignature, err error) {
944 var call __ipc.Call
945 if call, err = c.c(ctx).StartCall(ctx, c.name, "Signature", nil, opts...); err != nil {
946 return
Robin Thellenda7548452014-11-05 18:10:24 -0800947 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800948 if ierr := call.Finish(&o0, &err); ierr != nil {
949 err = ierr
Robin Thellenda7548452014-11-05 18:10:24 -0800950 }
Todd Wangd8cb55b2014-11-07 00:58:32 -0800951 return
952}
953
Todd Wangd8cb55b2014-11-07 00:58:32 -0800954// RockPaperScissorsServerMethods is the interface a server writer
955// implements for RockPaperScissors.
956type RockPaperScissorsServerMethods interface {
957 JudgeServerMethods
958 // Player can receive challenges from other players.
959 PlayerServerMethods
960 // ScoreKeeper receives the outcome of games from Judges.
961 ScoreKeeperServerMethods
962}
963
964// RockPaperScissorsServerStubMethods is the server interface containing
Todd Wang5cd27352014-11-11 20:27:39 -0800965// RockPaperScissors methods, as expected by ipc.Server.
966// The only difference between this interface and RockPaperScissorsServerMethods
967// is the streaming methods.
Todd Wangd8cb55b2014-11-07 00:58:32 -0800968type RockPaperScissorsServerStubMethods interface {
969 JudgeServerStubMethods
970 // Player can receive challenges from other players.
971 PlayerServerStubMethods
972 // ScoreKeeper receives the outcome of games from Judges.
973 ScoreKeeperServerStubMethods
974}
975
976// RockPaperScissorsServerStub adds universal methods to RockPaperScissorsServerStubMethods.
977type RockPaperScissorsServerStub interface {
978 RockPaperScissorsServerStubMethods
Todd Wangdddc1fb2014-11-16 21:39:02 -0800979 // Describe the RockPaperScissors interfaces.
980 Describe__() []__ipc.InterfaceDesc
981 // Signature will be replaced with Describe__.
Todd Wang5cd27352014-11-11 20:27:39 -0800982 Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error)
Todd Wangd8cb55b2014-11-07 00:58:32 -0800983}
984
985// RockPaperScissorsServer returns a server stub for RockPaperScissors.
986// It converts an implementation of RockPaperScissorsServerMethods into
987// an object that may be used by ipc.Server.
988func RockPaperScissorsServer(impl RockPaperScissorsServerMethods) RockPaperScissorsServerStub {
989 stub := implRockPaperScissorsServerStub{
990 impl: impl,
991 JudgeServerStub: JudgeServer(impl),
992 PlayerServerStub: PlayerServer(impl),
993 ScoreKeeperServerStub: ScoreKeeperServer(impl),
994 }
995 // Initialize GlobState; always check the stub itself first, to handle the
996 // case where the user has the Glob method defined in their VDL source.
997 if gs := __ipc.NewGlobState(stub); gs != nil {
998 stub.gs = gs
999 } else if gs := __ipc.NewGlobState(impl); gs != nil {
1000 stub.gs = gs
1001 }
Robin Thellenda7548452014-11-05 18:10:24 -08001002 return stub
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001003}
1004
Todd Wangd8cb55b2014-11-07 00:58:32 -08001005type implRockPaperScissorsServerStub struct {
1006 impl RockPaperScissorsServerMethods
Todd Wangd8cb55b2014-11-07 00:58:32 -08001007 JudgeServerStub
1008 PlayerServerStub
1009 ScoreKeeperServerStub
Todd Wang5cd27352014-11-11 20:27:39 -08001010 gs *__ipc.GlobState
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001011}
1012
Todd Wangd8cb55b2014-11-07 00:58:32 -08001013func (s implRockPaperScissorsServerStub) VGlob() *__ipc.GlobState {
1014 return s.gs
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001015}
1016
Todd Wangdddc1fb2014-11-16 21:39:02 -08001017func (s implRockPaperScissorsServerStub) Describe__() []__ipc.InterfaceDesc {
1018 return []__ipc.InterfaceDesc{RockPaperScissorsDesc, JudgeDesc, PlayerDesc, ScoreKeeperDesc}
1019}
1020
1021// RockPaperScissorsDesc describes the RockPaperScissors interface.
1022var RockPaperScissorsDesc __ipc.InterfaceDesc = descRockPaperScissors
1023
1024// descRockPaperScissors hides the desc to keep godoc clean.
1025var descRockPaperScissors = __ipc.InterfaceDesc{
1026 Name: "RockPaperScissors",
1027 PkgPath: "veyron.io/apps/rps",
1028 Embeds: []__ipc.EmbedDesc{
1029 {"Judge", "veyron.io/apps/rps", ``},
1030 {"Player", "veyron.io/apps/rps", "// Player can receive challenges from other players."},
1031 {"ScoreKeeper", "veyron.io/apps/rps", "// ScoreKeeper receives the outcome of games from Judges."},
1032 },
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001033}
1034
Todd Wang5cd27352014-11-11 20:27:39 -08001035func (s implRockPaperScissorsServerStub) Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) {
Todd Wangdddc1fb2014-11-16 21:39:02 -08001036 // TODO(toddw): Replace with new Describe__ implementation.
Todd Wangd8cb55b2014-11-07 00:58:32 -08001037 result := __ipc.ServiceSignature{Methods: make(map[string]__ipc.MethodSignature)}
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001038
Todd Wangd8cb55b2014-11-07 00:58:32 -08001039 result.TypeDefs = []__vdlutil.Any{}
1040 var ss __ipc.ServiceSignature
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001041 var firstAdded int
Todd Wang5cd27352014-11-11 20:27:39 -08001042 ss, _ = s.JudgeServerStub.Signature(ctx)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001043 firstAdded = len(result.TypeDefs)
1044 for k, v := range ss.Methods {
1045 for i, _ := range v.InArgs {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001046 if v.InArgs[i].Type >= __wiretype.TypeIDFirst {
1047 v.InArgs[i].Type += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001048 }
1049 }
1050 for i, _ := range v.OutArgs {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001051 if v.OutArgs[i].Type >= __wiretype.TypeIDFirst {
1052 v.OutArgs[i].Type += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001053 }
1054 }
Todd Wangd8cb55b2014-11-07 00:58:32 -08001055 if v.InStream >= __wiretype.TypeIDFirst {
1056 v.InStream += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001057 }
Todd Wangd8cb55b2014-11-07 00:58:32 -08001058 if v.OutStream >= __wiretype.TypeIDFirst {
1059 v.OutStream += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001060 }
1061 result.Methods[k] = v
1062 }
1063 //TODO(bprosnitz) combine type definitions from embeded interfaces in a way that doesn't cause duplication.
1064 for _, d := range ss.TypeDefs {
1065 switch wt := d.(type) {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001066 case __wiretype.SliceType:
1067 if wt.Elem >= __wiretype.TypeIDFirst {
1068 wt.Elem += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001069 }
1070 d = wt
Todd Wangd8cb55b2014-11-07 00:58:32 -08001071 case __wiretype.ArrayType:
1072 if wt.Elem >= __wiretype.TypeIDFirst {
1073 wt.Elem += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001074 }
1075 d = wt
Todd Wangd8cb55b2014-11-07 00:58:32 -08001076 case __wiretype.MapType:
1077 if wt.Key >= __wiretype.TypeIDFirst {
1078 wt.Key += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001079 }
Todd Wangd8cb55b2014-11-07 00:58:32 -08001080 if wt.Elem >= __wiretype.TypeIDFirst {
1081 wt.Elem += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001082 }
1083 d = wt
Todd Wangd8cb55b2014-11-07 00:58:32 -08001084 case __wiretype.StructType:
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001085 for i, fld := range wt.Fields {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001086 if fld.Type >= __wiretype.TypeIDFirst {
1087 wt.Fields[i].Type += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001088 }
1089 }
1090 d = wt
1091 // NOTE: other types are missing, but we are upgrading anyways.
1092 }
1093 result.TypeDefs = append(result.TypeDefs, d)
1094 }
Todd Wang5cd27352014-11-11 20:27:39 -08001095 ss, _ = s.PlayerServerStub.Signature(ctx)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001096 firstAdded = len(result.TypeDefs)
1097 for k, v := range ss.Methods {
1098 for i, _ := range v.InArgs {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001099 if v.InArgs[i].Type >= __wiretype.TypeIDFirst {
1100 v.InArgs[i].Type += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001101 }
1102 }
1103 for i, _ := range v.OutArgs {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001104 if v.OutArgs[i].Type >= __wiretype.TypeIDFirst {
1105 v.OutArgs[i].Type += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001106 }
1107 }
Todd Wangd8cb55b2014-11-07 00:58:32 -08001108 if v.InStream >= __wiretype.TypeIDFirst {
1109 v.InStream += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001110 }
Todd Wangd8cb55b2014-11-07 00:58:32 -08001111 if v.OutStream >= __wiretype.TypeIDFirst {
1112 v.OutStream += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001113 }
1114 result.Methods[k] = v
1115 }
1116 //TODO(bprosnitz) combine type definitions from embeded interfaces in a way that doesn't cause duplication.
1117 for _, d := range ss.TypeDefs {
1118 switch wt := d.(type) {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001119 case __wiretype.SliceType:
1120 if wt.Elem >= __wiretype.TypeIDFirst {
1121 wt.Elem += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001122 }
1123 d = wt
Todd Wangd8cb55b2014-11-07 00:58:32 -08001124 case __wiretype.ArrayType:
1125 if wt.Elem >= __wiretype.TypeIDFirst {
1126 wt.Elem += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001127 }
1128 d = wt
Todd Wangd8cb55b2014-11-07 00:58:32 -08001129 case __wiretype.MapType:
1130 if wt.Key >= __wiretype.TypeIDFirst {
1131 wt.Key += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001132 }
Todd Wangd8cb55b2014-11-07 00:58:32 -08001133 if wt.Elem >= __wiretype.TypeIDFirst {
1134 wt.Elem += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001135 }
1136 d = wt
Todd Wangd8cb55b2014-11-07 00:58:32 -08001137 case __wiretype.StructType:
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001138 for i, fld := range wt.Fields {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001139 if fld.Type >= __wiretype.TypeIDFirst {
1140 wt.Fields[i].Type += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001141 }
1142 }
1143 d = wt
1144 // NOTE: other types are missing, but we are upgrading anyways.
1145 }
1146 result.TypeDefs = append(result.TypeDefs, d)
1147 }
Todd Wang5cd27352014-11-11 20:27:39 -08001148 ss, _ = s.ScoreKeeperServerStub.Signature(ctx)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001149 firstAdded = len(result.TypeDefs)
1150 for k, v := range ss.Methods {
1151 for i, _ := range v.InArgs {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001152 if v.InArgs[i].Type >= __wiretype.TypeIDFirst {
1153 v.InArgs[i].Type += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001154 }
1155 }
1156 for i, _ := range v.OutArgs {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001157 if v.OutArgs[i].Type >= __wiretype.TypeIDFirst {
1158 v.OutArgs[i].Type += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001159 }
1160 }
Todd Wangd8cb55b2014-11-07 00:58:32 -08001161 if v.InStream >= __wiretype.TypeIDFirst {
1162 v.InStream += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001163 }
Todd Wangd8cb55b2014-11-07 00:58:32 -08001164 if v.OutStream >= __wiretype.TypeIDFirst {
1165 v.OutStream += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001166 }
1167 result.Methods[k] = v
1168 }
1169 //TODO(bprosnitz) combine type definitions from embeded interfaces in a way that doesn't cause duplication.
1170 for _, d := range ss.TypeDefs {
1171 switch wt := d.(type) {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001172 case __wiretype.SliceType:
1173 if wt.Elem >= __wiretype.TypeIDFirst {
1174 wt.Elem += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001175 }
1176 d = wt
Todd Wangd8cb55b2014-11-07 00:58:32 -08001177 case __wiretype.ArrayType:
1178 if wt.Elem >= __wiretype.TypeIDFirst {
1179 wt.Elem += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001180 }
1181 d = wt
Todd Wangd8cb55b2014-11-07 00:58:32 -08001182 case __wiretype.MapType:
1183 if wt.Key >= __wiretype.TypeIDFirst {
1184 wt.Key += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001185 }
Todd Wangd8cb55b2014-11-07 00:58:32 -08001186 if wt.Elem >= __wiretype.TypeIDFirst {
1187 wt.Elem += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001188 }
1189 d = wt
Todd Wangd8cb55b2014-11-07 00:58:32 -08001190 case __wiretype.StructType:
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001191 for i, fld := range wt.Fields {
Todd Wangd8cb55b2014-11-07 00:58:32 -08001192 if fld.Type >= __wiretype.TypeIDFirst {
1193 wt.Fields[i].Type += __wiretype.TypeID(firstAdded)
Jiri Simsa37cdfc02014-10-09 18:00:43 -07001194 }
1195 }
1196 d = wt
1197 // NOTE: other types are missing, but we are upgrading anyways.
1198 }
1199 result.TypeDefs = append(result.TypeDefs, d)
1200 }
1201
1202 return result, nil
1203}