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