Jiri Simsa | 67b8a26 | 2015-03-24 21:14:07 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Vanadium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Suharsh Sivakumar | a4ac50a | 2015-03-13 16:13:50 -0700 | [diff] [blame] | 5 | // This file was auto-generated by the vanadium vdl tool. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 6 | // Source: service.vdl |
| 7 | |
Todd Wang | 8c4e5cc | 2015-04-09 11:30:52 -0700 | [diff] [blame] | 8 | // Package rps defines interfaces for playing the game Rock-Paper-Scissors. It |
| 9 | // is an example of a simple Vanadium service. |
| 10 | // |
| 11 | // http://en.wikipedia.org/wiki/Rock-paper-scissors |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 12 | // |
| 13 | // There are three different roles in the game: |
| 14 | // |
Todd Wang | 8c4e5cc | 2015-04-09 11:30:52 -0700 | [diff] [blame] | 15 | // 1. Judge: A judge enforces the rules of the game and decides who the winner |
| 16 | // is. At the end of the game, the judge reports the final score to all the |
| 17 | // score keepers. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 18 | // |
Todd Wang | 8c4e5cc | 2015-04-09 11:30:52 -0700 | [diff] [blame] | 19 | // 2. Player: A player can ask a judge to start a new game, it can challenge |
| 20 | // another player, and it can play a game. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 21 | // |
Todd Wang | 8c4e5cc | 2015-04-09 11:30:52 -0700 | [diff] [blame] | 22 | // 3. ScoreKeeper: A score keeper receives the final score for a game after it |
| 23 | // ended. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 24 | package rps |
| 25 | |
| 26 | import ( |
Todd Wang | d1779a5 | 2015-02-05 11:46:12 -0800 | [diff] [blame] | 27 | // VDL system imports |
| 28 | "io" |
Jiri Simsa | 386ce3e | 2015-02-23 16:14:20 -0800 | [diff] [blame] | 29 | "v.io/v23" |
| 30 | "v.io/v23/context" |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 31 | "v.io/v23/rpc" |
Jiri Simsa | 386ce3e | 2015-02-23 16:14:20 -0800 | [diff] [blame] | 32 | "v.io/v23/vdl" |
Asim Shankar | 4794c93 | 2014-11-24 17:45:56 -0800 | [diff] [blame] | 33 | |
Todd Wang | d1779a5 | 2015-02-05 11:46:12 -0800 | [diff] [blame] | 34 | // VDL user imports |
Todd Wang | 07f1346 | 2015-03-13 15:54:15 -0700 | [diff] [blame] | 35 | "time" |
Todd Wang | 387d8a4 | 2015-03-30 17:09:05 -0700 | [diff] [blame] | 36 | "v.io/v23/security/access" |
Todd Wang | 07f1346 | 2015-03-13 15:54:15 -0700 | [diff] [blame] | 37 | _ "v.io/v23/vdlroot/time" |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 38 | ) |
| 39 | |
Benjamin Prosnitz | 2be28dc | 2015-03-11 13:33:22 -0700 | [diff] [blame] | 40 | // A GameId is used to uniquely identify a game within one Judge. |
| 41 | type GameId struct { |
| 42 | Id string |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Benjamin Prosnitz | 2be28dc | 2015-03-11 13:33:22 -0700 | [diff] [blame] | 45 | func (GameId) __VDLReflect(struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 46 | Name string `vdl:"v.io/x/ref/examples/rps.GameId"` |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 47 | }) { |
| 48 | } |
| 49 | |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 50 | // GameOptions specifies the parameters of a game. |
| 51 | type GameOptions struct { |
| 52 | NumRounds int32 // The number of rounds that a player must win to win the game. |
| 53 | GameType GameTypeTag // The type of game to play: Classic or LizardSpock. |
| 54 | } |
| 55 | |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 56 | func (GameOptions) __VDLReflect(struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 57 | Name string `vdl:"v.io/x/ref/examples/rps.GameOptions"` |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 58 | }) { |
| 59 | } |
| 60 | |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 61 | type GameTypeTag byte |
| 62 | |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 63 | func (GameTypeTag) __VDLReflect(struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 64 | Name string `vdl:"v.io/x/ref/examples/rps.GameTypeTag"` |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 65 | }) { |
| 66 | } |
| 67 | |
Robin Thellend | 636b360 | 2015-02-11 14:57:44 -0800 | [diff] [blame] | 68 | type ( |
| 69 | // PlayerAction represents any single field of the PlayerAction union type. |
| 70 | PlayerAction interface { |
| 71 | // Index returns the field index. |
| 72 | Index() int |
| 73 | // Interface returns the field value as an interface. |
| 74 | Interface() interface{} |
| 75 | // Name returns the field name. |
| 76 | Name() string |
| 77 | // __VDLReflect describes the PlayerAction union type. |
| 78 | __VDLReflect(__PlayerActionReflect) |
| 79 | } |
| 80 | // PlayerActionMove represents field Move of the PlayerAction union type. |
| 81 | PlayerActionMove struct{ Value string } // The move that the player wants to make. |
| 82 | // PlayerActionQuit represents field Quit of the PlayerAction union type. |
| 83 | PlayerActionQuit struct{ Value unused } // Indicates that the player is quitting the game. |
| 84 | // __PlayerActionReflect describes the PlayerAction union type. |
| 85 | __PlayerActionReflect struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 86 | Name string `vdl:"v.io/x/ref/examples/rps.PlayerAction"` |
Robin Thellend | 636b360 | 2015-02-11 14:57:44 -0800 | [diff] [blame] | 87 | Type PlayerAction |
| 88 | Union struct { |
| 89 | Move PlayerActionMove |
| 90 | Quit PlayerActionQuit |
| 91 | } |
| 92 | } |
| 93 | ) |
| 94 | |
| 95 | func (x PlayerActionMove) Index() int { return 0 } |
| 96 | func (x PlayerActionMove) Interface() interface{} { return x.Value } |
| 97 | func (x PlayerActionMove) Name() string { return "Move" } |
| 98 | func (x PlayerActionMove) __VDLReflect(__PlayerActionReflect) {} |
| 99 | |
| 100 | func (x PlayerActionQuit) Index() int { return 1 } |
| 101 | func (x PlayerActionQuit) Interface() interface{} { return x.Value } |
| 102 | func (x PlayerActionQuit) Name() string { return "Quit" } |
| 103 | func (x PlayerActionQuit) __VDLReflect(__PlayerActionReflect) {} |
| 104 | |
| 105 | type unused struct { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Robin Thellend | 636b360 | 2015-02-11 14:57:44 -0800 | [diff] [blame] | 108 | func (unused) __VDLReflect(struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 109 | Name string `vdl:"v.io/x/ref/examples/rps.unused"` |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 110 | }) { |
| 111 | } |
| 112 | |
Robin Thellend | 636b360 | 2015-02-11 14:57:44 -0800 | [diff] [blame] | 113 | type ( |
| 114 | // JudgeAction represents any single field of the JudgeAction union type. |
| 115 | JudgeAction interface { |
| 116 | // Index returns the field index. |
| 117 | Index() int |
| 118 | // Interface returns the field value as an interface. |
| 119 | Interface() interface{} |
| 120 | // Name returns the field name. |
| 121 | Name() string |
| 122 | // __VDLReflect describes the JudgeAction union type. |
| 123 | __VDLReflect(__JudgeActionReflect) |
| 124 | } |
| 125 | // JudgeActionPlayerNum represents field PlayerNum of the JudgeAction union type. |
| 126 | JudgeActionPlayerNum struct{ Value int32 } // The player's number. |
| 127 | // JudgeActionOpponentName represents field OpponentName of the JudgeAction union type. |
| 128 | JudgeActionOpponentName struct{ Value string } // The name of the opponent. |
| 129 | // JudgeActionMoveOptions represents field MoveOptions of the JudgeAction union type. |
| 130 | JudgeActionMoveOptions struct{ Value []string } // A list of allowed moves that the player must choose from. |
| 131 | // JudgeActionRoundResult represents field RoundResult of the JudgeAction union type. |
| 132 | JudgeActionRoundResult struct{ Value Round } // The result of the previous round. |
| 133 | // JudgeActionScore represents field Score of the JudgeAction union type. |
| 134 | JudgeActionScore struct{ Value ScoreCard } // The result of the game. |
| 135 | // __JudgeActionReflect describes the JudgeAction union type. |
| 136 | __JudgeActionReflect struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 137 | Name string `vdl:"v.io/x/ref/examples/rps.JudgeAction"` |
Robin Thellend | 636b360 | 2015-02-11 14:57:44 -0800 | [diff] [blame] | 138 | Type JudgeAction |
| 139 | Union struct { |
| 140 | PlayerNum JudgeActionPlayerNum |
| 141 | OpponentName JudgeActionOpponentName |
| 142 | MoveOptions JudgeActionMoveOptions |
| 143 | RoundResult JudgeActionRoundResult |
| 144 | Score JudgeActionScore |
| 145 | } |
| 146 | } |
| 147 | ) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 148 | |
Robin Thellend | 636b360 | 2015-02-11 14:57:44 -0800 | [diff] [blame] | 149 | func (x JudgeActionPlayerNum) Index() int { return 0 } |
| 150 | func (x JudgeActionPlayerNum) Interface() interface{} { return x.Value } |
| 151 | func (x JudgeActionPlayerNum) Name() string { return "PlayerNum" } |
| 152 | func (x JudgeActionPlayerNum) __VDLReflect(__JudgeActionReflect) {} |
| 153 | |
| 154 | func (x JudgeActionOpponentName) Index() int { return 1 } |
| 155 | func (x JudgeActionOpponentName) Interface() interface{} { return x.Value } |
| 156 | func (x JudgeActionOpponentName) Name() string { return "OpponentName" } |
| 157 | func (x JudgeActionOpponentName) __VDLReflect(__JudgeActionReflect) {} |
| 158 | |
| 159 | func (x JudgeActionMoveOptions) Index() int { return 2 } |
| 160 | func (x JudgeActionMoveOptions) Interface() interface{} { return x.Value } |
| 161 | func (x JudgeActionMoveOptions) Name() string { return "MoveOptions" } |
| 162 | func (x JudgeActionMoveOptions) __VDLReflect(__JudgeActionReflect) {} |
| 163 | |
| 164 | func (x JudgeActionRoundResult) Index() int { return 3 } |
| 165 | func (x JudgeActionRoundResult) Interface() interface{} { return x.Value } |
| 166 | func (x JudgeActionRoundResult) Name() string { return "RoundResult" } |
| 167 | func (x JudgeActionRoundResult) __VDLReflect(__JudgeActionReflect) {} |
| 168 | |
| 169 | func (x JudgeActionScore) Index() int { return 4 } |
| 170 | func (x JudgeActionScore) Interface() interface{} { return x.Value } |
| 171 | func (x JudgeActionScore) Name() string { return "Score" } |
| 172 | func (x JudgeActionScore) __VDLReflect(__JudgeActionReflect) {} |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 173 | |
Sergey Rogulenko | 2f64f98 | 2015-02-05 14:14:46 -0800 | [diff] [blame] | 174 | type PlayersMoves [2]string |
| 175 | |
| 176 | func (PlayersMoves) __VDLReflect(struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 177 | Name string `vdl:"v.io/x/ref/examples/rps.PlayersMoves"` |
Sergey Rogulenko | 2f64f98 | 2015-02-05 14:14:46 -0800 | [diff] [blame] | 178 | }) { |
| 179 | } |
| 180 | |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 181 | // Round represents the state of a round. |
| 182 | type Round struct { |
Todd Wang | 07f1346 | 2015-03-13 15:54:15 -0700 | [diff] [blame] | 183 | Moves PlayersMoves // Each player's move. |
| 184 | Comment string // A text comment from judge about the round. |
| 185 | Winner WinnerTag // Who won the round. |
| 186 | StartTime time.Time // The time at which the round started. |
| 187 | EndTime time.Time // The time at which the round ended. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 190 | func (Round) __VDLReflect(struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 191 | Name string `vdl:"v.io/x/ref/examples/rps.Round"` |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 192 | }) { |
| 193 | } |
| 194 | |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 195 | // WinnerTag is a type used to indicate whether a round or a game was a draw, |
| 196 | // was won by player 1 or was won by player 2. |
| 197 | type WinnerTag byte |
| 198 | |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 199 | func (WinnerTag) __VDLReflect(struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 200 | Name string `vdl:"v.io/x/ref/examples/rps.WinnerTag"` |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 201 | }) { |
| 202 | } |
| 203 | |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 204 | // PlayResult is the value returned by the Play method. It indicates the outcome of the game. |
| 205 | type PlayResult struct { |
| 206 | YouWon bool // True if the player receiving the result won the game. |
| 207 | } |
| 208 | |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 209 | func (PlayResult) __VDLReflect(struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 210 | Name string `vdl:"v.io/x/ref/examples/rps.PlayResult"` |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 211 | }) { |
| 212 | } |
| 213 | |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 214 | type ScoreCard struct { |
Todd Wang | 07f1346 | 2015-03-13 15:54:15 -0700 | [diff] [blame] | 215 | Opts GameOptions // The game options. |
| 216 | Judge string // The name of the judge. |
| 217 | Players []string // The name of the players. |
| 218 | Rounds []Round // The outcome of each round. |
| 219 | StartTime time.Time // The time at which the game started. |
| 220 | EndTime time.Time // The time at which the game ended. |
| 221 | Winner WinnerTag // Who won the game. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 224 | func (ScoreCard) __VDLReflect(struct { |
Suharsh Sivakumar | 071d1c8 | 2015-05-08 14:45:10 -0700 | [diff] [blame] | 225 | Name string `vdl:"v.io/x/ref/examples/rps.ScoreCard"` |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 226 | }) { |
| 227 | } |
| 228 | |
| 229 | func init() { |
Benjamin Prosnitz | 2be28dc | 2015-03-11 13:33:22 -0700 | [diff] [blame] | 230 | vdl.Register((*GameId)(nil)) |
Todd Wang | 83f63ba | 2015-02-09 13:30:43 -0800 | [diff] [blame] | 231 | vdl.Register((*GameOptions)(nil)) |
| 232 | vdl.Register((*GameTypeTag)(nil)) |
| 233 | vdl.Register((*PlayerAction)(nil)) |
Robin Thellend | 636b360 | 2015-02-11 14:57:44 -0800 | [diff] [blame] | 234 | vdl.Register((*unused)(nil)) |
Todd Wang | 83f63ba | 2015-02-09 13:30:43 -0800 | [diff] [blame] | 235 | vdl.Register((*JudgeAction)(nil)) |
| 236 | vdl.Register((*PlayersMoves)(nil)) |
| 237 | vdl.Register((*Round)(nil)) |
| 238 | vdl.Register((*WinnerTag)(nil)) |
| 239 | vdl.Register((*PlayResult)(nil)) |
| 240 | vdl.Register((*ScoreCard)(nil)) |
Todd Wang | 24983c7 | 2014-11-26 15:07:25 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 243 | const Classic = GameTypeTag(0) // Rock-Paper-Scissors |
| 244 | |
| 245 | const LizardSpock = GameTypeTag(1) // Rock-Paper-Scissors-Lizard-Spock |
| 246 | |
| 247 | const Draw = WinnerTag(0) |
| 248 | |
| 249 | const Player1 = WinnerTag(1) |
| 250 | |
| 251 | const Player2 = WinnerTag(2) |
| 252 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 253 | // JudgeClientMethods is the client interface |
| 254 | // containing Judge methods. |
| 255 | type JudgeClientMethods interface { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 256 | // CreateGame creates a new game with the given game options and returns a game |
| 257 | // identifier that can be used by the players to join the game. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 258 | CreateGame(ctx *context.T, Opts GameOptions, opts ...rpc.CallOpt) (GameId, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 259 | // Play lets a player join an existing game and play. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 260 | Play(ctx *context.T, Id GameId, opts ...rpc.CallOpt) (JudgePlayClientCall, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 263 | // JudgeClientStub adds universal methods to JudgeClientMethods. |
| 264 | type JudgeClientStub interface { |
| 265 | JudgeClientMethods |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 266 | rpc.UniversalServiceMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 269 | // JudgeClient returns a client stub for Judge. |
Asim Shankar | 69fa69f | 2015-04-01 11:34:32 -0700 | [diff] [blame] | 270 | func JudgeClient(name string) JudgeClientStub { |
| 271 | return implJudgeClientStub{name} |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | type implJudgeClientStub struct { |
Asim Shankar | 69fa69f | 2015-04-01 11:34:32 -0700 | [diff] [blame] | 275 | name string |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 278 | func (c implJudgeClientStub) CreateGame(ctx *context.T, i0 GameOptions, opts ...rpc.CallOpt) (o0 GameId, err error) { |
Suharsh Sivakumar | df2672a | 2015-04-09 19:26:43 -0700 | [diff] [blame] | 279 | err = v23.GetClient(ctx).Call(ctx, c.name, "CreateGame", []interface{}{i0}, []interface{}{&o0}, opts...) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 280 | return |
| 281 | } |
| 282 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 283 | func (c implJudgeClientStub) Play(ctx *context.T, i0 GameId, opts ...rpc.CallOpt) (ocall JudgePlayClientCall, err error) { |
| 284 | var call rpc.ClientCall |
Asim Shankar | 69fa69f | 2015-04-01 11:34:32 -0700 | [diff] [blame] | 285 | if call, err = v23.GetClient(ctx).StartCall(ctx, c.name, "Play", []interface{}{i0}, opts...); err != nil { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 286 | return |
| 287 | } |
Matt Rosencrantz | 72a1561 | 2015-02-27 22:22:41 -0800 | [diff] [blame] | 288 | ocall = &implJudgePlayClientCall{ClientCall: call} |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 289 | return |
| 290 | } |
| 291 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 292 | // JudgePlayClientStream is the client stream for Judge.Play. |
| 293 | type JudgePlayClientStream interface { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 294 | // RecvStream returns the receiver side of the Judge.Play client stream. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 295 | RecvStream() interface { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 296 | // Advance stages an item so that it may be retrieved via Value. Returns |
| 297 | // true iff there is an item to retrieve. Advance must be called before |
| 298 | // Value is called. May block if an item is not available. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 299 | Advance() bool |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 300 | // Value returns the item that was staged by Advance. May panic if Advance |
| 301 | // returned false or was not called. Never blocks. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 302 | Value() JudgeAction |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 303 | // Err returns any error encountered by Advance. Never blocks. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 304 | Err() error |
| 305 | } |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 306 | // SendStream returns the send side of the Judge.Play client stream. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 307 | SendStream() interface { |
Todd Wang | 04f97dd | 2014-12-18 18:52:07 -0800 | [diff] [blame] | 308 | // Send places the item onto the output stream. Returns errors |
| 309 | // encountered while sending, or if Send is called after Close or |
| 310 | // the stream has been canceled. Blocks if there is no buffer |
| 311 | // space; will unblock when buffer space is available or after |
| 312 | // the stream has been canceled. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 313 | Send(item PlayerAction) error |
Todd Wang | 04f97dd | 2014-12-18 18:52:07 -0800 | [diff] [blame] | 314 | // Close indicates to the server that no more items will be sent; |
| 315 | // server Recv calls will receive io.EOF after all sent items. |
| 316 | // This is an optional call - e.g. a client might call Close if it |
| 317 | // needs to continue receiving items from the server after it's |
| 318 | // done sending. Returns errors encountered while closing, or if |
| 319 | // Close is called after the stream has been canceled. Like Send, |
| 320 | // blocks if there is no buffer space available. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 321 | Close() error |
| 322 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 323 | } |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 324 | |
Matt Rosencrantz | 72a1561 | 2015-02-27 22:22:41 -0800 | [diff] [blame] | 325 | // JudgePlayClientCall represents the call returned from Judge.Play. |
| 326 | type JudgePlayClientCall interface { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 327 | JudgePlayClientStream |
| 328 | // Finish performs the equivalent of SendStream().Close, then blocks until |
| 329 | // the server is done, and returns the positional return values for the call. |
| 330 | // |
Todd Wang | 04f97dd | 2014-12-18 18:52:07 -0800 | [diff] [blame] | 331 | // Finish returns immediately if the call has been canceled; depending on the |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 332 | // timing the output could either be an error signaling cancelation, or the |
| 333 | // valid positional return values from the server. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 334 | // |
Todd Wang | 04f97dd | 2014-12-18 18:52:07 -0800 | [diff] [blame] | 335 | // Calling Finish is mandatory for releasing stream resources, unless the call |
| 336 | // has been canceled or any of the other methods return an error. Finish should |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 337 | // be called at most once. |
| 338 | Finish() (PlayResult, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Matt Rosencrantz | 72a1561 | 2015-02-27 22:22:41 -0800 | [diff] [blame] | 341 | type implJudgePlayClientCall struct { |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 342 | rpc.ClientCall |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 343 | valRecv JudgeAction |
| 344 | errRecv error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Matt Rosencrantz | 72a1561 | 2015-02-27 22:22:41 -0800 | [diff] [blame] | 347 | func (c *implJudgePlayClientCall) RecvStream() interface { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 348 | Advance() bool |
| 349 | Value() JudgeAction |
| 350 | Err() error |
| 351 | } { |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 352 | return implJudgePlayClientCallRecv{c} |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 355 | type implJudgePlayClientCallRecv struct { |
Matt Rosencrantz | 72a1561 | 2015-02-27 22:22:41 -0800 | [diff] [blame] | 356 | c *implJudgePlayClientCall |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 359 | func (c implJudgePlayClientCallRecv) Advance() bool { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 360 | c.c.errRecv = c.c.Recv(&c.c.valRecv) |
| 361 | return c.c.errRecv == nil |
| 362 | } |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 363 | func (c implJudgePlayClientCallRecv) Value() JudgeAction { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 364 | return c.c.valRecv |
| 365 | } |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 366 | func (c implJudgePlayClientCallRecv) Err() error { |
Todd Wang | d1779a5 | 2015-02-05 11:46:12 -0800 | [diff] [blame] | 367 | if c.c.errRecv == io.EOF { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 368 | return nil |
| 369 | } |
| 370 | return c.c.errRecv |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 371 | } |
Matt Rosencrantz | 72a1561 | 2015-02-27 22:22:41 -0800 | [diff] [blame] | 372 | func (c *implJudgePlayClientCall) SendStream() interface { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 373 | Send(item PlayerAction) error |
| 374 | Close() error |
| 375 | } { |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 376 | return implJudgePlayClientCallSend{c} |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 379 | type implJudgePlayClientCallSend struct { |
Matt Rosencrantz | 72a1561 | 2015-02-27 22:22:41 -0800 | [diff] [blame] | 380 | c *implJudgePlayClientCall |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 383 | func (c implJudgePlayClientCallSend) Send(item PlayerAction) error { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 384 | return c.c.Send(item) |
| 385 | } |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 386 | func (c implJudgePlayClientCallSend) Close() error { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 387 | return c.c.CloseSend() |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 388 | } |
Matt Rosencrantz | 72a1561 | 2015-02-27 22:22:41 -0800 | [diff] [blame] | 389 | func (c *implJudgePlayClientCall) Finish() (o0 PlayResult, err error) { |
| 390 | err = c.ClientCall.Finish(&o0) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 391 | return |
| 392 | } |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 393 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 394 | // JudgeServerMethods is the interface a server writer |
| 395 | // implements for Judge. |
| 396 | type JudgeServerMethods interface { |
| 397 | // CreateGame creates a new game with the given game options and returns a game |
| 398 | // identifier that can be used by the players to join the game. |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 399 | CreateGame(ctx *context.T, call rpc.ServerCall, Opts GameOptions) (GameId, error) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 400 | // Play lets a player join an existing game and play. |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 401 | Play(ctx *context.T, call JudgePlayServerCall, Id GameId) (PlayResult, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 404 | // JudgeServerStubMethods is the server interface containing |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 405 | // Judge methods, as expected by rpc.Server. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 406 | // The only difference between this interface and JudgeServerMethods |
| 407 | // is the streaming methods. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 408 | type JudgeServerStubMethods interface { |
| 409 | // CreateGame creates a new game with the given game options and returns a game |
| 410 | // identifier that can be used by the players to join the game. |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 411 | CreateGame(ctx *context.T, call rpc.ServerCall, Opts GameOptions) (GameId, error) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 412 | // Play lets a player join an existing game and play. |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 413 | Play(ctx *context.T, call *JudgePlayServerCallStub, Id GameId) (PlayResult, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 416 | // JudgeServerStub adds universal methods to JudgeServerStubMethods. |
| 417 | type JudgeServerStub interface { |
| 418 | JudgeServerStubMethods |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 419 | // Describe the Judge interfaces. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 420 | Describe__() []rpc.InterfaceDesc |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 423 | // JudgeServer returns a server stub for Judge. |
| 424 | // It converts an implementation of JudgeServerMethods into |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 425 | // an object that may be used by rpc.Server. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 426 | func JudgeServer(impl JudgeServerMethods) JudgeServerStub { |
| 427 | stub := implJudgeServerStub{ |
| 428 | impl: impl, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 429 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 430 | // Initialize GlobState; always check the stub itself first, to handle the |
| 431 | // case where the user has the Glob method defined in their VDL source. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 432 | if gs := rpc.NewGlobState(stub); gs != nil { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 433 | stub.gs = gs |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 434 | } else if gs := rpc.NewGlobState(impl); gs != nil { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 435 | stub.gs = gs |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 436 | } |
Robin Thellend | a754845 | 2014-11-05 18:10:24 -0800 | [diff] [blame] | 437 | return stub |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 440 | type implJudgeServerStub struct { |
| 441 | impl JudgeServerMethods |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 442 | gs *rpc.GlobState |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 445 | func (s implJudgeServerStub) CreateGame(ctx *context.T, call rpc.ServerCall, i0 GameOptions) (GameId, error) { |
| 446 | return s.impl.CreateGame(ctx, call, i0) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 449 | func (s implJudgeServerStub) Play(ctx *context.T, call *JudgePlayServerCallStub, i0 GameId) (PlayResult, error) { |
| 450 | return s.impl.Play(ctx, call, i0) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 453 | func (s implJudgeServerStub) Globber() *rpc.GlobState { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 454 | return s.gs |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 457 | func (s implJudgeServerStub) Describe__() []rpc.InterfaceDesc { |
| 458 | return []rpc.InterfaceDesc{JudgeDesc} |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | // JudgeDesc describes the Judge interface. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 462 | var JudgeDesc rpc.InterfaceDesc = descJudge |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 463 | |
| 464 | // descJudge hides the desc to keep godoc clean. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 465 | var descJudge = rpc.InterfaceDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 466 | Name: "Judge", |
Jiri Simsa | 3b91302 | 2015-02-27 15:19:25 -0800 | [diff] [blame] | 467 | PkgPath: "v.io/x/ref/examples/rps", |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 468 | Methods: []rpc.MethodDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 469 | { |
| 470 | Name: "CreateGame", |
| 471 | Doc: "// CreateGame creates a new game with the given game options and returns a game\n// identifier that can be used by the players to join the game.", |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 472 | InArgs: []rpc.ArgDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 473 | {"Opts", ``}, // GameOptions |
| 474 | }, |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 475 | OutArgs: []rpc.ArgDesc{ |
Benjamin Prosnitz | 2be28dc | 2015-03-11 13:33:22 -0700 | [diff] [blame] | 476 | {"", ``}, // GameId |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 477 | }, |
Todd Wang | cab990d | 2015-02-19 19:54:06 -0800 | [diff] [blame] | 478 | Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Write"))}, |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 479 | }, |
| 480 | { |
| 481 | Name: "Play", |
| 482 | Doc: "// Play lets a player join an existing game and play.", |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 483 | InArgs: []rpc.ArgDesc{ |
Benjamin Prosnitz | 2be28dc | 2015-03-11 13:33:22 -0700 | [diff] [blame] | 484 | {"Id", ``}, // GameId |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 485 | }, |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 486 | OutArgs: []rpc.ArgDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 487 | {"", ``}, // PlayResult |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 488 | }, |
Todd Wang | cab990d | 2015-02-19 19:54:06 -0800 | [diff] [blame] | 489 | Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Write"))}, |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 490 | }, |
| 491 | }, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 494 | // JudgePlayServerStream is the server stream for Judge.Play. |
| 495 | type JudgePlayServerStream interface { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 496 | // RecvStream returns the receiver side of the Judge.Play server stream. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 497 | RecvStream() interface { |
| 498 | // Advance stages an item so that it may be retrieved via Value. Returns |
| 499 | // true iff there is an item to retrieve. Advance must be called before |
| 500 | // Value is called. May block if an item is not available. |
| 501 | Advance() bool |
| 502 | // Value returns the item that was staged by Advance. May panic if Advance |
| 503 | // returned false or was not called. Never blocks. |
| 504 | Value() PlayerAction |
| 505 | // Err returns any error encountered by Advance. Never blocks. |
| 506 | Err() error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 507 | } |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 508 | // SendStream returns the send side of the Judge.Play server stream. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 509 | SendStream() interface { |
| 510 | // Send places the item onto the output stream. Returns errors encountered |
| 511 | // while sending. Blocks if there is no buffer space; will unblock when |
| 512 | // buffer space is available. |
| 513 | Send(item JudgeAction) error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 514 | } |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 517 | // JudgePlayServerCall represents the context passed to Judge.Play. |
| 518 | type JudgePlayServerCall interface { |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 519 | rpc.ServerCall |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 520 | JudgePlayServerStream |
Robin Thellend | a754845 | 2014-11-05 18:10:24 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 523 | // JudgePlayServerCallStub is a wrapper that converts rpc.StreamServerCall into |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 524 | // a typesafe stub that implements JudgePlayServerCall. |
| 525 | type JudgePlayServerCallStub struct { |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 526 | rpc.StreamServerCall |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 527 | valRecv PlayerAction |
| 528 | errRecv error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 531 | // Init initializes JudgePlayServerCallStub from rpc.StreamServerCall. |
| 532 | func (s *JudgePlayServerCallStub) Init(call rpc.StreamServerCall) { |
Matt Rosencrantz | 9ef0f2d | 2015-02-27 11:04:32 -0800 | [diff] [blame] | 533 | s.StreamServerCall = call |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 536 | // RecvStream returns the receiver side of the Judge.Play server stream. |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 537 | func (s *JudgePlayServerCallStub) RecvStream() interface { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 538 | Advance() bool |
| 539 | Value() PlayerAction |
| 540 | Err() error |
| 541 | } { |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 542 | return implJudgePlayServerCallRecv{s} |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 543 | } |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 544 | |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 545 | type implJudgePlayServerCallRecv struct { |
| 546 | s *JudgePlayServerCallStub |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 549 | func (s implJudgePlayServerCallRecv) Advance() bool { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 550 | s.s.errRecv = s.s.Recv(&s.s.valRecv) |
| 551 | return s.s.errRecv == nil |
| 552 | } |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 553 | func (s implJudgePlayServerCallRecv) Value() PlayerAction { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 554 | return s.s.valRecv |
| 555 | } |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 556 | func (s implJudgePlayServerCallRecv) Err() error { |
Todd Wang | d1779a5 | 2015-02-05 11:46:12 -0800 | [diff] [blame] | 557 | if s.s.errRecv == io.EOF { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 558 | return nil |
| 559 | } |
| 560 | return s.s.errRecv |
| 561 | } |
| 562 | |
| 563 | // SendStream returns the send side of the Judge.Play server stream. |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 564 | func (s *JudgePlayServerCallStub) SendStream() interface { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 565 | Send(item JudgeAction) error |
| 566 | } { |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 567 | return implJudgePlayServerCallSend{s} |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 568 | } |
| 569 | |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 570 | type implJudgePlayServerCallSend struct { |
| 571 | s *JudgePlayServerCallStub |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Suharsh Sivakumar | 31f4985 | 2015-03-03 16:13:20 -0800 | [diff] [blame] | 574 | func (s implJudgePlayServerCallSend) Send(item JudgeAction) error { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 575 | return s.s.Send(item) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | // PlayerClientMethods is the client interface |
| 579 | // containing Player methods. |
| 580 | // |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 581 | // Player can receive challenges from other players. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 582 | type PlayerClientMethods interface { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 583 | // Challenge is used by other players to challenge this player to a game. If |
| 584 | // the challenge is accepted, the method returns nil. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 585 | Challenge(ctx *context.T, Address string, Id GameId, Opts GameOptions, opts ...rpc.CallOpt) error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 588 | // PlayerClientStub adds universal methods to PlayerClientMethods. |
| 589 | type PlayerClientStub interface { |
| 590 | PlayerClientMethods |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 591 | rpc.UniversalServiceMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 594 | // PlayerClient returns a client stub for Player. |
Asim Shankar | 69fa69f | 2015-04-01 11:34:32 -0700 | [diff] [blame] | 595 | func PlayerClient(name string) PlayerClientStub { |
| 596 | return implPlayerClientStub{name} |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 599 | type implPlayerClientStub struct { |
Asim Shankar | 69fa69f | 2015-04-01 11:34:32 -0700 | [diff] [blame] | 600 | name string |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 603 | func (c implPlayerClientStub) Challenge(ctx *context.T, i0 string, i1 GameId, i2 GameOptions, opts ...rpc.CallOpt) (err error) { |
Suharsh Sivakumar | df2672a | 2015-04-09 19:26:43 -0700 | [diff] [blame] | 604 | err = v23.GetClient(ctx).Call(ctx, c.name, "Challenge", []interface{}{i0, i1, i2}, nil, opts...) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 605 | return |
| 606 | } |
| 607 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 608 | // PlayerServerMethods is the interface a server writer |
| 609 | // implements for Player. |
| 610 | // |
| 611 | // Player can receive challenges from other players. |
| 612 | type PlayerServerMethods interface { |
| 613 | // Challenge is used by other players to challenge this player to a game. If |
| 614 | // the challenge is accepted, the method returns nil. |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 615 | Challenge(ctx *context.T, call rpc.ServerCall, Address string, Id GameId, Opts GameOptions) error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 618 | // PlayerServerStubMethods is the server interface containing |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 619 | // Player methods, as expected by rpc.Server. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 620 | // There is no difference between this interface and PlayerServerMethods |
| 621 | // since there are no streaming methods. |
| 622 | type PlayerServerStubMethods PlayerServerMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 623 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 624 | // PlayerServerStub adds universal methods to PlayerServerStubMethods. |
| 625 | type PlayerServerStub interface { |
| 626 | PlayerServerStubMethods |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 627 | // Describe the Player interfaces. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 628 | Describe__() []rpc.InterfaceDesc |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | // PlayerServer returns a server stub for Player. |
| 632 | // It converts an implementation of PlayerServerMethods into |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 633 | // an object that may be used by rpc.Server. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 634 | func PlayerServer(impl PlayerServerMethods) PlayerServerStub { |
| 635 | stub := implPlayerServerStub{ |
| 636 | impl: impl, |
| 637 | } |
| 638 | // Initialize GlobState; always check the stub itself first, to handle the |
| 639 | // case where the user has the Glob method defined in their VDL source. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 640 | if gs := rpc.NewGlobState(stub); gs != nil { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 641 | stub.gs = gs |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 642 | } else if gs := rpc.NewGlobState(impl); gs != nil { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 643 | stub.gs = gs |
| 644 | } |
| 645 | return stub |
| 646 | } |
| 647 | |
| 648 | type implPlayerServerStub struct { |
| 649 | impl PlayerServerMethods |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 650 | gs *rpc.GlobState |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 653 | func (s implPlayerServerStub) Challenge(ctx *context.T, call rpc.ServerCall, i0 string, i1 GameId, i2 GameOptions) error { |
| 654 | return s.impl.Challenge(ctx, call, i0, i1, i2) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 655 | } |
| 656 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 657 | func (s implPlayerServerStub) Globber() *rpc.GlobState { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 658 | return s.gs |
| 659 | } |
| 660 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 661 | func (s implPlayerServerStub) Describe__() []rpc.InterfaceDesc { |
| 662 | return []rpc.InterfaceDesc{PlayerDesc} |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | // PlayerDesc describes the Player interface. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 666 | var PlayerDesc rpc.InterfaceDesc = descPlayer |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 667 | |
| 668 | // descPlayer hides the desc to keep godoc clean. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 669 | var descPlayer = rpc.InterfaceDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 670 | Name: "Player", |
Jiri Simsa | 3b91302 | 2015-02-27 15:19:25 -0800 | [diff] [blame] | 671 | PkgPath: "v.io/x/ref/examples/rps", |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 672 | Doc: "// Player can receive challenges from other players.", |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 673 | Methods: []rpc.MethodDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 674 | { |
| 675 | Name: "Challenge", |
| 676 | Doc: "// Challenge is used by other players to challenge this player to a game. If\n// the challenge is accepted, the method returns nil.", |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 677 | InArgs: []rpc.ArgDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 678 | {"Address", ``}, // string |
Benjamin Prosnitz | 2be28dc | 2015-03-11 13:33:22 -0700 | [diff] [blame] | 679 | {"Id", ``}, // GameId |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 680 | {"Opts", ``}, // GameOptions |
| 681 | }, |
Todd Wang | cab990d | 2015-02-19 19:54:06 -0800 | [diff] [blame] | 682 | Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Write"))}, |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 683 | }, |
| 684 | }, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 687 | // ScoreKeeperClientMethods is the client interface |
| 688 | // containing ScoreKeeper methods. |
| 689 | // |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 690 | // ScoreKeeper receives the outcome of games from Judges. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 691 | type ScoreKeeperClientMethods interface { |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 692 | Record(ctx *context.T, Score ScoreCard, opts ...rpc.CallOpt) error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 695 | // ScoreKeeperClientStub adds universal methods to ScoreKeeperClientMethods. |
| 696 | type ScoreKeeperClientStub interface { |
| 697 | ScoreKeeperClientMethods |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 698 | rpc.UniversalServiceMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 701 | // ScoreKeeperClient returns a client stub for ScoreKeeper. |
Asim Shankar | 69fa69f | 2015-04-01 11:34:32 -0700 | [diff] [blame] | 702 | func ScoreKeeperClient(name string) ScoreKeeperClientStub { |
| 703 | return implScoreKeeperClientStub{name} |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 706 | type implScoreKeeperClientStub struct { |
Asim Shankar | 69fa69f | 2015-04-01 11:34:32 -0700 | [diff] [blame] | 707 | name string |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 710 | func (c implScoreKeeperClientStub) Record(ctx *context.T, i0 ScoreCard, opts ...rpc.CallOpt) (err error) { |
Suharsh Sivakumar | df2672a | 2015-04-09 19:26:43 -0700 | [diff] [blame] | 711 | err = v23.GetClient(ctx).Call(ctx, c.name, "Record", []interface{}{i0}, nil, opts...) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 712 | return |
| 713 | } |
| 714 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 715 | // ScoreKeeperServerMethods is the interface a server writer |
| 716 | // implements for ScoreKeeper. |
| 717 | // |
| 718 | // ScoreKeeper receives the outcome of games from Judges. |
| 719 | type ScoreKeeperServerMethods interface { |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 720 | Record(ctx *context.T, call rpc.ServerCall, Score ScoreCard) error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 723 | // ScoreKeeperServerStubMethods is the server interface containing |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 724 | // ScoreKeeper methods, as expected by rpc.Server. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 725 | // There is no difference between this interface and ScoreKeeperServerMethods |
| 726 | // since there are no streaming methods. |
| 727 | type ScoreKeeperServerStubMethods ScoreKeeperServerMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 728 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 729 | // ScoreKeeperServerStub adds universal methods to ScoreKeeperServerStubMethods. |
| 730 | type ScoreKeeperServerStub interface { |
| 731 | ScoreKeeperServerStubMethods |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 732 | // Describe the ScoreKeeper interfaces. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 733 | Describe__() []rpc.InterfaceDesc |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | // ScoreKeeperServer returns a server stub for ScoreKeeper. |
| 737 | // It converts an implementation of ScoreKeeperServerMethods into |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 738 | // an object that may be used by rpc.Server. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 739 | func ScoreKeeperServer(impl ScoreKeeperServerMethods) ScoreKeeperServerStub { |
| 740 | stub := implScoreKeeperServerStub{ |
| 741 | impl: impl, |
| 742 | } |
| 743 | // Initialize GlobState; always check the stub itself first, to handle the |
| 744 | // case where the user has the Glob method defined in their VDL source. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 745 | if gs := rpc.NewGlobState(stub); gs != nil { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 746 | stub.gs = gs |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 747 | } else if gs := rpc.NewGlobState(impl); gs != nil { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 748 | stub.gs = gs |
| 749 | } |
| 750 | return stub |
| 751 | } |
| 752 | |
| 753 | type implScoreKeeperServerStub struct { |
| 754 | impl ScoreKeeperServerMethods |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 755 | gs *rpc.GlobState |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Todd Wang | 54feabe | 2015-04-15 23:38:26 -0700 | [diff] [blame] | 758 | func (s implScoreKeeperServerStub) Record(ctx *context.T, call rpc.ServerCall, i0 ScoreCard) error { |
| 759 | return s.impl.Record(ctx, call, i0) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 760 | } |
| 761 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 762 | func (s implScoreKeeperServerStub) Globber() *rpc.GlobState { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 763 | return s.gs |
| 764 | } |
| 765 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 766 | func (s implScoreKeeperServerStub) Describe__() []rpc.InterfaceDesc { |
| 767 | return []rpc.InterfaceDesc{ScoreKeeperDesc} |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | // ScoreKeeperDesc describes the ScoreKeeper interface. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 771 | var ScoreKeeperDesc rpc.InterfaceDesc = descScoreKeeper |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 772 | |
| 773 | // descScoreKeeper hides the desc to keep godoc clean. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 774 | var descScoreKeeper = rpc.InterfaceDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 775 | Name: "ScoreKeeper", |
Jiri Simsa | 3b91302 | 2015-02-27 15:19:25 -0800 | [diff] [blame] | 776 | PkgPath: "v.io/x/ref/examples/rps", |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 777 | Doc: "// ScoreKeeper receives the outcome of games from Judges.", |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 778 | Methods: []rpc.MethodDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 779 | { |
| 780 | Name: "Record", |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 781 | InArgs: []rpc.ArgDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 782 | {"Score", ``}, // ScoreCard |
| 783 | }, |
Todd Wang | cab990d | 2015-02-19 19:54:06 -0800 | [diff] [blame] | 784 | Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Write"))}, |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 785 | }, |
| 786 | }, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 789 | // RockPaperScissorsClientMethods is the client interface |
| 790 | // containing RockPaperScissors methods. |
| 791 | type RockPaperScissorsClientMethods interface { |
| 792 | JudgeClientMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 793 | // Player can receive challenges from other players. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 794 | PlayerClientMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 795 | // ScoreKeeper receives the outcome of games from Judges. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 796 | ScoreKeeperClientMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 799 | // RockPaperScissorsClientStub adds universal methods to RockPaperScissorsClientMethods. |
| 800 | type RockPaperScissorsClientStub interface { |
| 801 | RockPaperScissorsClientMethods |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 802 | rpc.UniversalServiceMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 805 | // RockPaperScissorsClient returns a client stub for RockPaperScissors. |
Asim Shankar | 69fa69f | 2015-04-01 11:34:32 -0700 | [diff] [blame] | 806 | func RockPaperScissorsClient(name string) RockPaperScissorsClientStub { |
| 807 | return implRockPaperScissorsClientStub{name, JudgeClient(name), PlayerClient(name), ScoreKeeperClient(name)} |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 810 | type implRockPaperScissorsClientStub struct { |
Asim Shankar | 69fa69f | 2015-04-01 11:34:32 -0700 | [diff] [blame] | 811 | name string |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 812 | |
| 813 | JudgeClientStub |
| 814 | PlayerClientStub |
| 815 | ScoreKeeperClientStub |
| 816 | } |
| 817 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 818 | // RockPaperScissorsServerMethods is the interface a server writer |
| 819 | // implements for RockPaperScissors. |
| 820 | type RockPaperScissorsServerMethods interface { |
| 821 | JudgeServerMethods |
| 822 | // Player can receive challenges from other players. |
| 823 | PlayerServerMethods |
| 824 | // ScoreKeeper receives the outcome of games from Judges. |
| 825 | ScoreKeeperServerMethods |
| 826 | } |
| 827 | |
| 828 | // RockPaperScissorsServerStubMethods is the server interface containing |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 829 | // RockPaperScissors methods, as expected by rpc.Server. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 830 | // The only difference between this interface and RockPaperScissorsServerMethods |
| 831 | // is the streaming methods. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 832 | type RockPaperScissorsServerStubMethods interface { |
| 833 | JudgeServerStubMethods |
| 834 | // Player can receive challenges from other players. |
| 835 | PlayerServerStubMethods |
| 836 | // ScoreKeeper receives the outcome of games from Judges. |
| 837 | ScoreKeeperServerStubMethods |
| 838 | } |
| 839 | |
| 840 | // RockPaperScissorsServerStub adds universal methods to RockPaperScissorsServerStubMethods. |
| 841 | type RockPaperScissorsServerStub interface { |
| 842 | RockPaperScissorsServerStubMethods |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 843 | // Describe the RockPaperScissors interfaces. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 844 | Describe__() []rpc.InterfaceDesc |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | // RockPaperScissorsServer returns a server stub for RockPaperScissors. |
| 848 | // It converts an implementation of RockPaperScissorsServerMethods into |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 849 | // an object that may be used by rpc.Server. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 850 | func RockPaperScissorsServer(impl RockPaperScissorsServerMethods) RockPaperScissorsServerStub { |
| 851 | stub := implRockPaperScissorsServerStub{ |
| 852 | impl: impl, |
| 853 | JudgeServerStub: JudgeServer(impl), |
| 854 | PlayerServerStub: PlayerServer(impl), |
| 855 | ScoreKeeperServerStub: ScoreKeeperServer(impl), |
| 856 | } |
| 857 | // Initialize GlobState; always check the stub itself first, to handle the |
| 858 | // case where the user has the Glob method defined in their VDL source. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 859 | if gs := rpc.NewGlobState(stub); gs != nil { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 860 | stub.gs = gs |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 861 | } else if gs := rpc.NewGlobState(impl); gs != nil { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 862 | stub.gs = gs |
| 863 | } |
Robin Thellend | a754845 | 2014-11-05 18:10:24 -0800 | [diff] [blame] | 864 | return stub |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 867 | type implRockPaperScissorsServerStub struct { |
| 868 | impl RockPaperScissorsServerMethods |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 869 | JudgeServerStub |
| 870 | PlayerServerStub |
| 871 | ScoreKeeperServerStub |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 872 | gs *rpc.GlobState |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 875 | func (s implRockPaperScissorsServerStub) Globber() *rpc.GlobState { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 876 | return s.gs |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 879 | func (s implRockPaperScissorsServerStub) Describe__() []rpc.InterfaceDesc { |
| 880 | return []rpc.InterfaceDesc{RockPaperScissorsDesc, JudgeDesc, PlayerDesc, ScoreKeeperDesc} |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | // RockPaperScissorsDesc describes the RockPaperScissors interface. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 884 | var RockPaperScissorsDesc rpc.InterfaceDesc = descRockPaperScissors |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 885 | |
| 886 | // descRockPaperScissors hides the desc to keep godoc clean. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 887 | var descRockPaperScissors = rpc.InterfaceDesc{ |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 888 | Name: "RockPaperScissors", |
Jiri Simsa | 3b91302 | 2015-02-27 15:19:25 -0800 | [diff] [blame] | 889 | PkgPath: "v.io/x/ref/examples/rps", |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 890 | Embeds: []rpc.EmbedDesc{ |
Jiri Simsa | 3b91302 | 2015-02-27 15:19:25 -0800 | [diff] [blame] | 891 | {"Judge", "v.io/x/ref/examples/rps", ``}, |
| 892 | {"Player", "v.io/x/ref/examples/rps", "// Player can receive challenges from other players."}, |
| 893 | {"ScoreKeeper", "v.io/x/ref/examples/rps", "// ScoreKeeper receives the outcome of games from Judges."}, |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame] | 894 | }, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 895 | } |