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 | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 21 | // The non-user imports are prefixed with "__" to prevent collisions. |
| 22 | __io "io" |
| 23 | __veyron2 "veyron.io/veyron/veyron2" |
| 24 | __context "veyron.io/veyron/veyron2/context" |
| 25 | __ipc "veyron.io/veyron/veyron2/ipc" |
| 26 | __vdlutil "veyron.io/veyron/veyron2/vdl/vdlutil" |
| 27 | __wiretype "veyron.io/veyron/veyron2/wiretype" |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 30 | // TODO(toddw): Remove this line once the new signature support is done. |
| 31 | // It corrects a bug where __wiretype is unused in VDL pacakges where only |
| 32 | // bootstrap types are used on interfaces. |
| 33 | const _ = __wiretype.TypeIDInvalid |
| 34 | |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 35 | // A GameID is used to uniquely identify a game within one Judge. |
| 36 | type GameID struct { |
| 37 | ID string |
| 38 | } |
| 39 | |
| 40 | // GameOptions specifies the parameters of a game. |
| 41 | type GameOptions struct { |
| 42 | NumRounds int32 // The number of rounds that a player must win to win the game. |
| 43 | GameType GameTypeTag // The type of game to play: Classic or LizardSpock. |
| 44 | } |
| 45 | |
| 46 | type GameTypeTag byte |
| 47 | |
| 48 | type PlayerAction struct { |
| 49 | Move string // The move that the player wants to make. |
| 50 | Quit bool // Whether the player wants to quit the game. |
| 51 | } |
| 52 | |
| 53 | type JudgeAction struct { |
| 54 | PlayerNum int32 // The player's number. |
| 55 | OpponentName string // The name of the opponent. |
| 56 | MoveOptions []string // A list of allowed moves that the player must choose from. Not always present. |
| 57 | RoundResult Round // The result of the previous round. Not always present. |
| 58 | Score ScoreCard // The result of the game. Not always present. |
| 59 | } |
| 60 | |
| 61 | // Round represents the state of a round. |
| 62 | type Round struct { |
| 63 | Moves [2]string // Each player's move. |
| 64 | Comment string // A text comment from judge about the round. |
| 65 | Winner WinnerTag // Who won the round. |
| 66 | StartTimeNS int64 // The time at which the round started. |
| 67 | EndTimeNS int64 // The time at which the round ended. |
| 68 | } |
| 69 | |
| 70 | // WinnerTag is a type used to indicate whether a round or a game was a draw, |
| 71 | // was won by player 1 or was won by player 2. |
| 72 | type WinnerTag byte |
| 73 | |
| 74 | // PlayResult is the value returned by the Play method. It indicates the outcome of the game. |
| 75 | type PlayResult struct { |
| 76 | YouWon bool // True if the player receiving the result won the game. |
| 77 | } |
| 78 | |
| 79 | type ScoreCard struct { |
| 80 | Opts GameOptions // The game options. |
| 81 | Judge string // The name of the judge. |
| 82 | Players []string // The name of the players. |
| 83 | Rounds []Round // The outcome of each round. |
| 84 | StartTimeNS int64 // The time at which the game started. |
| 85 | EndTimeNS int64 // The time at which the game ended. |
| 86 | Winner WinnerTag // Who won the game. |
| 87 | } |
| 88 | |
| 89 | const Classic = GameTypeTag(0) // Rock-Paper-Scissors |
| 90 | |
| 91 | const LizardSpock = GameTypeTag(1) // Rock-Paper-Scissors-Lizard-Spock |
| 92 | |
| 93 | const Draw = WinnerTag(0) |
| 94 | |
| 95 | const Player1 = WinnerTag(1) |
| 96 | |
| 97 | const Player2 = WinnerTag(2) |
| 98 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 99 | // JudgeClientMethods is the client interface |
| 100 | // containing Judge methods. |
| 101 | type JudgeClientMethods interface { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 102 | // CreateGame creates a new game with the given game options and returns a game |
| 103 | // identifier that can be used by the players to join the game. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 104 | CreateGame(ctx __context.T, Opts GameOptions, opts ...__ipc.CallOpt) (GameID, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 105 | // Play lets a player join an existing game and play. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 106 | Play(ctx __context.T, ID GameID, opts ...__ipc.CallOpt) (JudgePlayCall, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 109 | // JudgeClientStub adds universal methods to JudgeClientMethods. |
| 110 | type JudgeClientStub interface { |
| 111 | JudgeClientMethods |
| 112 | __ipc.UniversalServiceMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 115 | // JudgeClient returns a client stub for Judge. |
| 116 | func JudgeClient(name string, opts ...__ipc.BindOpt) JudgeClientStub { |
| 117 | var client __ipc.Client |
| 118 | for _, opt := range opts { |
| 119 | if clientOpt, ok := opt.(__ipc.Client); ok { |
| 120 | client = clientOpt |
| 121 | } |
| 122 | } |
| 123 | return implJudgeClientStub{name, client} |
| 124 | } |
| 125 | |
| 126 | type implJudgeClientStub struct { |
| 127 | name string |
| 128 | client __ipc.Client |
| 129 | } |
| 130 | |
| 131 | func (c implJudgeClientStub) c(ctx __context.T) __ipc.Client { |
| 132 | if c.client != nil { |
| 133 | return c.client |
| 134 | } |
| 135 | return __veyron2.RuntimeFromContext(ctx).Client() |
| 136 | } |
| 137 | |
| 138 | func (c implJudgeClientStub) CreateGame(ctx __context.T, i0 GameOptions, opts ...__ipc.CallOpt) (o0 GameID, err error) { |
| 139 | var call __ipc.Call |
| 140 | if call, err = c.c(ctx).StartCall(ctx, c.name, "CreateGame", []interface{}{i0}, opts...); err != nil { |
| 141 | return |
| 142 | } |
| 143 | if ierr := call.Finish(&o0, &err); ierr != nil { |
| 144 | err = ierr |
| 145 | } |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | func (c implJudgeClientStub) Play(ctx __context.T, i0 GameID, opts ...__ipc.CallOpt) (ocall JudgePlayCall, err error) { |
| 150 | var call __ipc.Call |
| 151 | if call, err = c.c(ctx).StartCall(ctx, c.name, "Play", []interface{}{i0}, opts...); err != nil { |
| 152 | return |
| 153 | } |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 154 | ocall = &implJudgePlayCall{Call: call} |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 155 | return |
| 156 | } |
| 157 | |
| 158 | func (c implJudgeClientStub) Signature(ctx __context.T, opts ...__ipc.CallOpt) (o0 __ipc.ServiceSignature, err error) { |
| 159 | var call __ipc.Call |
| 160 | if call, err = c.c(ctx).StartCall(ctx, c.name, "Signature", nil, opts...); err != nil { |
| 161 | return |
| 162 | } |
| 163 | if ierr := call.Finish(&o0, &err); ierr != nil { |
| 164 | err = ierr |
| 165 | } |
| 166 | return |
| 167 | } |
| 168 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 169 | // JudgePlayClientStream is the client stream for Judge.Play. |
| 170 | type JudgePlayClientStream interface { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 171 | // RecvStream returns the receiver side of the Judge.Play client stream. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 172 | RecvStream() interface { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 173 | // Advance stages an item so that it may be retrieved via Value. Returns |
| 174 | // true iff there is an item to retrieve. Advance must be called before |
| 175 | // Value is called. May block if an item is not available. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 176 | Advance() bool |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 177 | // Value returns the item that was staged by Advance. May panic if Advance |
| 178 | // returned false or was not called. Never blocks. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 179 | Value() JudgeAction |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 180 | // Err returns any error encountered by Advance. Never blocks. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 181 | Err() error |
| 182 | } |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 183 | // SendStream returns the send side of the Judge.Play client stream. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 184 | SendStream() interface { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 185 | // Send places the item onto the output stream. Returns errors encountered |
| 186 | // while sending, or if Send is called after Close or Cancel. Blocks if |
| 187 | // there is no buffer space; will unblock when buffer space is available or |
| 188 | // after Cancel. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 189 | Send(item PlayerAction) error |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 190 | // Close indicates to the server that no more items will be sent; server |
| 191 | // Recv calls will receive io.EOF after all sent items. This is an optional |
| 192 | // call - e.g. a client might call Close if it needs to continue receiving |
| 193 | // items from the server after it's done sending. Returns errors |
| 194 | // encountered while closing, or if Close is called after Cancel. Like |
| 195 | // Send, blocks if there is no buffer space available. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 196 | Close() error |
| 197 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 198 | } |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 199 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 200 | // JudgePlayCall represents the call returned from Judge.Play. |
| 201 | type JudgePlayCall interface { |
| 202 | JudgePlayClientStream |
| 203 | // Finish performs the equivalent of SendStream().Close, then blocks until |
| 204 | // the server is done, and returns the positional return values for the call. |
| 205 | // |
| 206 | // Finish returns immediately if Cancel has been called; depending on the |
| 207 | // timing the output could either be an error signaling cancelation, or the |
| 208 | // valid positional return values from the server. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 209 | // |
| 210 | // Calling Finish is mandatory for releasing stream resources, unless Cancel |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 211 | // has been called or any of the other methods return an error. Finish should |
| 212 | // be called at most once. |
| 213 | Finish() (PlayResult, error) |
| 214 | // Cancel cancels the RPC, notifying the server to stop processing. It is |
| 215 | // safe to call Cancel concurrently with any of the other stream methods. |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 216 | // Calling Cancel after Finish has returned is a no-op. |
| 217 | Cancel() |
| 218 | } |
| 219 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 220 | type implJudgePlayCall struct { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 221 | __ipc.Call |
| 222 | valRecv JudgeAction |
| 223 | errRecv error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | func (c *implJudgePlayCall) RecvStream() interface { |
| 227 | Advance() bool |
| 228 | Value() JudgeAction |
| 229 | Err() error |
| 230 | } { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 231 | return implJudgePlayCallRecv{c} |
| 232 | } |
| 233 | |
| 234 | type implJudgePlayCallRecv struct { |
| 235 | c *implJudgePlayCall |
| 236 | } |
| 237 | |
| 238 | func (c implJudgePlayCallRecv) Advance() bool { |
| 239 | c.c.valRecv = JudgeAction{} |
| 240 | c.c.errRecv = c.c.Recv(&c.c.valRecv) |
| 241 | return c.c.errRecv == nil |
| 242 | } |
| 243 | func (c implJudgePlayCallRecv) Value() JudgeAction { |
| 244 | return c.c.valRecv |
| 245 | } |
| 246 | func (c implJudgePlayCallRecv) Err() error { |
| 247 | if c.c.errRecv == __io.EOF { |
| 248 | return nil |
| 249 | } |
| 250 | return c.c.errRecv |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 251 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 252 | func (c *implJudgePlayCall) SendStream() interface { |
| 253 | Send(item PlayerAction) error |
| 254 | Close() error |
| 255 | } { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 256 | return implJudgePlayCallSend{c} |
| 257 | } |
| 258 | |
| 259 | type implJudgePlayCallSend struct { |
| 260 | c *implJudgePlayCall |
| 261 | } |
| 262 | |
| 263 | func (c implJudgePlayCallSend) Send(item PlayerAction) error { |
| 264 | return c.c.Send(item) |
| 265 | } |
| 266 | func (c implJudgePlayCallSend) Close() error { |
| 267 | return c.c.CloseSend() |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 268 | } |
| 269 | func (c *implJudgePlayCall) Finish() (o0 PlayResult, err error) { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 270 | if ierr := c.Call.Finish(&o0, &err); ierr != nil { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 271 | err = ierr |
| 272 | } |
| 273 | return |
| 274 | } |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 275 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 276 | // JudgeServerMethods is the interface a server writer |
| 277 | // implements for Judge. |
| 278 | type JudgeServerMethods interface { |
| 279 | // CreateGame creates a new game with the given game options and returns a game |
| 280 | // identifier that can be used by the players to join the game. |
| 281 | CreateGame(ctx __ipc.ServerContext, Opts GameOptions) (GameID, error) |
| 282 | // Play lets a player join an existing game and play. |
| 283 | Play(ctx JudgePlayContext, ID GameID) (PlayResult, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 286 | // JudgeServerStubMethods is the server interface containing |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 287 | // Judge methods, as expected by ipc.Server. |
| 288 | // The only difference between this interface and JudgeServerMethods |
| 289 | // is the streaming methods. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 290 | type JudgeServerStubMethods interface { |
| 291 | // CreateGame creates a new game with the given game options and returns a game |
| 292 | // identifier that can be used by the players to join the game. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 293 | CreateGame(ctx __ipc.ServerContext, Opts GameOptions) (GameID, error) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 294 | // Play lets a player join an existing game and play. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 295 | Play(ctx *JudgePlayContextStub, ID GameID) (PlayResult, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 298 | // JudgeServerStub adds universal methods to JudgeServerStubMethods. |
| 299 | type JudgeServerStub interface { |
| 300 | JudgeServerStubMethods |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 301 | // Describe the Judge interfaces. |
| 302 | Describe__() []__ipc.InterfaceDesc |
| 303 | // Signature will be replaced with Describe__. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 304 | Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 307 | // JudgeServer returns a server stub for Judge. |
| 308 | // It converts an implementation of JudgeServerMethods into |
| 309 | // an object that may be used by ipc.Server. |
| 310 | func JudgeServer(impl JudgeServerMethods) JudgeServerStub { |
| 311 | stub := implJudgeServerStub{ |
| 312 | impl: impl, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 313 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 314 | // Initialize GlobState; always check the stub itself first, to handle the |
| 315 | // case where the user has the Glob method defined in their VDL source. |
| 316 | if gs := __ipc.NewGlobState(stub); gs != nil { |
| 317 | stub.gs = gs |
| 318 | } else if gs := __ipc.NewGlobState(impl); gs != nil { |
| 319 | stub.gs = gs |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 320 | } |
Robin Thellend | a754845 | 2014-11-05 18:10:24 -0800 | [diff] [blame] | 321 | return stub |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 324 | type implJudgeServerStub struct { |
| 325 | impl JudgeServerMethods |
| 326 | gs *__ipc.GlobState |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 329 | func (s implJudgeServerStub) CreateGame(ctx __ipc.ServerContext, i0 GameOptions) (GameID, error) { |
| 330 | return s.impl.CreateGame(ctx, i0) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 333 | func (s implJudgeServerStub) Play(ctx *JudgePlayContextStub, i0 GameID) (PlayResult, error) { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 334 | return s.impl.Play(ctx, i0) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 337 | func (s implJudgeServerStub) VGlob() *__ipc.GlobState { |
| 338 | return s.gs |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 341 | func (s implJudgeServerStub) Describe__() []__ipc.InterfaceDesc { |
| 342 | return []__ipc.InterfaceDesc{JudgeDesc} |
| 343 | } |
| 344 | |
| 345 | // JudgeDesc describes the Judge interface. |
| 346 | var JudgeDesc __ipc.InterfaceDesc = descJudge |
| 347 | |
| 348 | // descJudge hides the desc to keep godoc clean. |
| 349 | var descJudge = __ipc.InterfaceDesc{ |
| 350 | Name: "Judge", |
| 351 | PkgPath: "veyron.io/apps/rps", |
| 352 | Methods: []__ipc.MethodDesc{ |
| 353 | { |
| 354 | Name: "CreateGame", |
| 355 | Doc: "// CreateGame creates a new game with the given game options and returns a game\n// identifier that can be used by the players to join the game.", |
| 356 | InArgs: []__ipc.ArgDesc{ |
| 357 | {"Opts", ``}, // GameOptions |
| 358 | }, |
| 359 | OutArgs: []__ipc.ArgDesc{ |
| 360 | {"", ``}, // GameID |
| 361 | {"", ``}, // error |
| 362 | }, |
| 363 | }, |
| 364 | { |
| 365 | Name: "Play", |
| 366 | Doc: "// Play lets a player join an existing game and play.", |
| 367 | InArgs: []__ipc.ArgDesc{ |
| 368 | {"ID", ``}, // GameID |
| 369 | }, |
| 370 | OutArgs: []__ipc.ArgDesc{ |
| 371 | {"", ``}, // PlayResult |
| 372 | {"", ``}, // error |
| 373 | }, |
| 374 | }, |
| 375 | }, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 378 | func (s implJudgeServerStub) Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) { |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 379 | // TODO(toddw): Replace with new Describe__ implementation. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 380 | result := __ipc.ServiceSignature{Methods: make(map[string]__ipc.MethodSignature)} |
| 381 | result.Methods["CreateGame"] = __ipc.MethodSignature{ |
| 382 | InArgs: []__ipc.MethodArgument{ |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 383 | {Name: "Opts", Type: 66}, |
| 384 | }, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 385 | OutArgs: []__ipc.MethodArgument{ |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 386 | {Name: "", Type: 67}, |
| 387 | {Name: "", Type: 68}, |
| 388 | }, |
| 389 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 390 | result.Methods["Play"] = __ipc.MethodSignature{ |
| 391 | InArgs: []__ipc.MethodArgument{ |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 392 | {Name: "ID", Type: 67}, |
| 393 | }, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 394 | OutArgs: []__ipc.MethodArgument{ |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 395 | {Name: "", Type: 69}, |
| 396 | {Name: "", Type: 68}, |
| 397 | }, |
| 398 | InStream: 70, |
| 399 | OutStream: 76, |
| 400 | } |
| 401 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 402 | result.TypeDefs = []__vdlutil.Any{ |
| 403 | __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.GameTypeTag", Tags: []string(nil)}, __wiretype.StructType{ |
| 404 | []__wiretype.FieldType{ |
| 405 | __wiretype.FieldType{Type: 0x24, Name: "NumRounds"}, |
| 406 | __wiretype.FieldType{Type: 0x41, Name: "GameType"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 407 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 408 | "veyron.io/apps/rps.GameOptions", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 409 | __wiretype.StructType{ |
| 410 | []__wiretype.FieldType{ |
| 411 | __wiretype.FieldType{Type: 0x3, Name: "ID"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 412 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 413 | "veyron.io/apps/rps.GameID", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 414 | __wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}, __wiretype.StructType{ |
| 415 | []__wiretype.FieldType{ |
| 416 | __wiretype.FieldType{Type: 0x2, Name: "YouWon"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 417 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 418 | "veyron.io/apps/rps.PlayResult", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 419 | __wiretype.StructType{ |
| 420 | []__wiretype.FieldType{ |
| 421 | __wiretype.FieldType{Type: 0x3, Name: "Move"}, |
| 422 | __wiretype.FieldType{Type: 0x2, Name: "Quit"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 423 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 424 | "veyron.io/apps/rps.PlayerAction", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 425 | __wiretype.ArrayType{Elem: 0x3, Len: 0x2, Name: "", Tags: []string(nil)}, __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.WinnerTag", Tags: []string(nil)}, __wiretype.StructType{ |
| 426 | []__wiretype.FieldType{ |
| 427 | __wiretype.FieldType{Type: 0x47, Name: "Moves"}, |
| 428 | __wiretype.FieldType{Type: 0x3, Name: "Comment"}, |
| 429 | __wiretype.FieldType{Type: 0x48, Name: "Winner"}, |
| 430 | __wiretype.FieldType{Type: 0x25, Name: "StartTimeNS"}, |
| 431 | __wiretype.FieldType{Type: 0x25, Name: "EndTimeNS"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 432 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 433 | "veyron.io/apps/rps.Round", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 434 | __wiretype.SliceType{Elem: 0x49, Name: "", Tags: []string(nil)}, __wiretype.StructType{ |
| 435 | []__wiretype.FieldType{ |
| 436 | __wiretype.FieldType{Type: 0x42, Name: "Opts"}, |
| 437 | __wiretype.FieldType{Type: 0x3, Name: "Judge"}, |
| 438 | __wiretype.FieldType{Type: 0x3d, Name: "Players"}, |
| 439 | __wiretype.FieldType{Type: 0x4a, Name: "Rounds"}, |
| 440 | __wiretype.FieldType{Type: 0x25, Name: "StartTimeNS"}, |
| 441 | __wiretype.FieldType{Type: 0x25, Name: "EndTimeNS"}, |
| 442 | __wiretype.FieldType{Type: 0x48, Name: "Winner"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 443 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 444 | "veyron.io/apps/rps.ScoreCard", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 445 | __wiretype.StructType{ |
| 446 | []__wiretype.FieldType{ |
| 447 | __wiretype.FieldType{Type: 0x24, Name: "PlayerNum"}, |
| 448 | __wiretype.FieldType{Type: 0x3, Name: "OpponentName"}, |
| 449 | __wiretype.FieldType{Type: 0x3d, Name: "MoveOptions"}, |
| 450 | __wiretype.FieldType{Type: 0x49, Name: "RoundResult"}, |
| 451 | __wiretype.FieldType{Type: 0x4b, Name: "Score"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 452 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 453 | "veyron.io/apps/rps.JudgeAction", []string(nil)}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | return result, nil |
| 457 | } |
| 458 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 459 | // JudgePlayServerStream is the server stream for Judge.Play. |
| 460 | type JudgePlayServerStream interface { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 461 | // RecvStream returns the receiver side of the Judge.Play server stream. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 462 | RecvStream() interface { |
| 463 | // Advance stages an item so that it may be retrieved via Value. Returns |
| 464 | // true iff there is an item to retrieve. Advance must be called before |
| 465 | // Value is called. May block if an item is not available. |
| 466 | Advance() bool |
| 467 | // Value returns the item that was staged by Advance. May panic if Advance |
| 468 | // returned false or was not called. Never blocks. |
| 469 | Value() PlayerAction |
| 470 | // Err returns any error encountered by Advance. Never blocks. |
| 471 | Err() error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 472 | } |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 473 | // SendStream returns the send side of the Judge.Play server stream. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 474 | SendStream() interface { |
| 475 | // Send places the item onto the output stream. Returns errors encountered |
| 476 | // while sending. Blocks if there is no buffer space; will unblock when |
| 477 | // buffer space is available. |
| 478 | Send(item JudgeAction) error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 479 | } |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 482 | // JudgePlayContext represents the context passed to Judge.Play. |
| 483 | type JudgePlayContext interface { |
| 484 | __ipc.ServerContext |
| 485 | JudgePlayServerStream |
Robin Thellend | a754845 | 2014-11-05 18:10:24 -0800 | [diff] [blame] | 486 | } |
| 487 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 488 | // JudgePlayContextStub is a wrapper that converts ipc.ServerCall into |
| 489 | // a typesafe stub that implements JudgePlayContext. |
| 490 | type JudgePlayContextStub struct { |
| 491 | __ipc.ServerCall |
| 492 | valRecv PlayerAction |
| 493 | errRecv error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 496 | // Init initializes JudgePlayContextStub from ipc.ServerCall. |
| 497 | func (s *JudgePlayContextStub) Init(call __ipc.ServerCall) { |
| 498 | s.ServerCall = call |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 501 | // RecvStream returns the receiver side of the Judge.Play server stream. |
| 502 | func (s *JudgePlayContextStub) RecvStream() interface { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 503 | Advance() bool |
| 504 | Value() PlayerAction |
| 505 | Err() error |
| 506 | } { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 507 | return implJudgePlayContextRecv{s} |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 508 | } |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 509 | |
| 510 | type implJudgePlayContextRecv struct { |
| 511 | s *JudgePlayContextStub |
| 512 | } |
| 513 | |
| 514 | func (s implJudgePlayContextRecv) Advance() bool { |
| 515 | s.s.valRecv = PlayerAction{} |
| 516 | s.s.errRecv = s.s.Recv(&s.s.valRecv) |
| 517 | return s.s.errRecv == nil |
| 518 | } |
| 519 | func (s implJudgePlayContextRecv) Value() PlayerAction { |
| 520 | return s.s.valRecv |
| 521 | } |
| 522 | func (s implJudgePlayContextRecv) Err() error { |
| 523 | if s.s.errRecv == __io.EOF { |
| 524 | return nil |
| 525 | } |
| 526 | return s.s.errRecv |
| 527 | } |
| 528 | |
| 529 | // SendStream returns the send side of the Judge.Play server stream. |
| 530 | func (s *JudgePlayContextStub) SendStream() interface { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 531 | Send(item JudgeAction) error |
| 532 | } { |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 533 | return implJudgePlayContextSend{s} |
| 534 | } |
| 535 | |
| 536 | type implJudgePlayContextSend struct { |
| 537 | s *JudgePlayContextStub |
| 538 | } |
| 539 | |
| 540 | func (s implJudgePlayContextSend) Send(item JudgeAction) error { |
| 541 | return s.s.Send(item) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | // PlayerClientMethods is the client interface |
| 545 | // containing Player methods. |
| 546 | // |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 547 | // Player can receive challenges from other players. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 548 | type PlayerClientMethods interface { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 549 | // Challenge is used by other players to challenge this player to a game. If |
| 550 | // the challenge is accepted, the method returns nil. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 551 | 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] | 552 | } |
| 553 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 554 | // PlayerClientStub adds universal methods to PlayerClientMethods. |
| 555 | type PlayerClientStub interface { |
| 556 | PlayerClientMethods |
| 557 | __ipc.UniversalServiceMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 560 | // PlayerClient returns a client stub for Player. |
| 561 | func PlayerClient(name string, opts ...__ipc.BindOpt) PlayerClientStub { |
| 562 | var client __ipc.Client |
| 563 | for _, opt := range opts { |
| 564 | if clientOpt, ok := opt.(__ipc.Client); ok { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 565 | client = clientOpt |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 566 | } |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 567 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 568 | return implPlayerClientStub{name, client} |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 571 | type implPlayerClientStub struct { |
| 572 | name string |
| 573 | client __ipc.Client |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 576 | func (c implPlayerClientStub) c(ctx __context.T) __ipc.Client { |
| 577 | if c.client != nil { |
| 578 | return c.client |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 579 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 580 | return __veyron2.RuntimeFromContext(ctx).Client() |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 583 | func (c implPlayerClientStub) Challenge(ctx __context.T, i0 string, i1 GameID, i2 GameOptions, opts ...__ipc.CallOpt) (err error) { |
| 584 | var call __ipc.Call |
| 585 | if call, err = c.c(ctx).StartCall(ctx, c.name, "Challenge", []interface{}{i0, i1, i2}, opts...); err != nil { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 586 | return |
| 587 | } |
| 588 | if ierr := call.Finish(&err); ierr != nil { |
| 589 | err = ierr |
| 590 | } |
| 591 | return |
| 592 | } |
| 593 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 594 | func (c implPlayerClientStub) Signature(ctx __context.T, opts ...__ipc.CallOpt) (o0 __ipc.ServiceSignature, err error) { |
| 595 | var call __ipc.Call |
| 596 | if call, err = c.c(ctx).StartCall(ctx, c.name, "Signature", nil, opts...); err != nil { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 597 | return |
| 598 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 599 | if ierr := call.Finish(&o0, &err); ierr != nil { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 600 | err = ierr |
| 601 | } |
| 602 | return |
| 603 | } |
| 604 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 605 | // PlayerServerMethods is the interface a server writer |
| 606 | // implements for Player. |
| 607 | // |
| 608 | // Player can receive challenges from other players. |
| 609 | type PlayerServerMethods interface { |
| 610 | // Challenge is used by other players to challenge this player to a game. If |
| 611 | // the challenge is accepted, the method returns nil. |
| 612 | Challenge(ctx __ipc.ServerContext, Address string, ID GameID, Opts GameOptions) error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 615 | // PlayerServerStubMethods is the server interface containing |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 616 | // Player methods, as expected by ipc.Server. |
| 617 | // There is no difference between this interface and PlayerServerMethods |
| 618 | // since there are no streaming methods. |
| 619 | type PlayerServerStubMethods PlayerServerMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 620 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 621 | // PlayerServerStub adds universal methods to PlayerServerStubMethods. |
| 622 | type PlayerServerStub interface { |
| 623 | PlayerServerStubMethods |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 624 | // Describe the Player interfaces. |
| 625 | Describe__() []__ipc.InterfaceDesc |
| 626 | // Signature will be replaced with Describe__. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 627 | Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | // PlayerServer returns a server stub for Player. |
| 631 | // It converts an implementation of PlayerServerMethods into |
| 632 | // an object that may be used by ipc.Server. |
| 633 | func PlayerServer(impl PlayerServerMethods) PlayerServerStub { |
| 634 | stub := implPlayerServerStub{ |
| 635 | impl: impl, |
| 636 | } |
| 637 | // Initialize GlobState; always check the stub itself first, to handle the |
| 638 | // case where the user has the Glob method defined in their VDL source. |
| 639 | if gs := __ipc.NewGlobState(stub); gs != nil { |
| 640 | stub.gs = gs |
| 641 | } else if gs := __ipc.NewGlobState(impl); gs != nil { |
| 642 | stub.gs = gs |
| 643 | } |
| 644 | return stub |
| 645 | } |
| 646 | |
| 647 | type implPlayerServerStub struct { |
| 648 | impl PlayerServerMethods |
| 649 | gs *__ipc.GlobState |
| 650 | } |
| 651 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 652 | func (s implPlayerServerStub) Challenge(ctx __ipc.ServerContext, i0 string, i1 GameID, i2 GameOptions) error { |
| 653 | return s.impl.Challenge(ctx, i0, i1, i2) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | func (s implPlayerServerStub) VGlob() *__ipc.GlobState { |
| 657 | return s.gs |
| 658 | } |
| 659 | |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 660 | func (s implPlayerServerStub) Describe__() []__ipc.InterfaceDesc { |
| 661 | return []__ipc.InterfaceDesc{PlayerDesc} |
| 662 | } |
| 663 | |
| 664 | // PlayerDesc describes the Player interface. |
| 665 | var PlayerDesc __ipc.InterfaceDesc = descPlayer |
| 666 | |
| 667 | // descPlayer hides the desc to keep godoc clean. |
| 668 | var descPlayer = __ipc.InterfaceDesc{ |
| 669 | Name: "Player", |
| 670 | PkgPath: "veyron.io/apps/rps", |
| 671 | Doc: "// Player can receive challenges from other players.", |
| 672 | Methods: []__ipc.MethodDesc{ |
| 673 | { |
| 674 | Name: "Challenge", |
| 675 | Doc: "// Challenge is used by other players to challenge this player to a game. If\n// the challenge is accepted, the method returns nil.", |
| 676 | InArgs: []__ipc.ArgDesc{ |
| 677 | {"Address", ``}, // string |
| 678 | {"ID", ``}, // GameID |
| 679 | {"Opts", ``}, // GameOptions |
| 680 | }, |
| 681 | OutArgs: []__ipc.ArgDesc{ |
| 682 | {"", ``}, // error |
| 683 | }, |
| 684 | }, |
| 685 | }, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 688 | func (s implPlayerServerStub) Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) { |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 689 | // TODO(toddw): Replace with new Describe__ implementation. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 690 | result := __ipc.ServiceSignature{Methods: make(map[string]__ipc.MethodSignature)} |
| 691 | result.Methods["Challenge"] = __ipc.MethodSignature{ |
| 692 | InArgs: []__ipc.MethodArgument{ |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 693 | {Name: "Address", Type: 3}, |
| 694 | {Name: "ID", Type: 65}, |
| 695 | {Name: "Opts", Type: 67}, |
| 696 | }, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 697 | OutArgs: []__ipc.MethodArgument{ |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 698 | {Name: "", Type: 68}, |
| 699 | }, |
| 700 | } |
| 701 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 702 | result.TypeDefs = []__vdlutil.Any{ |
| 703 | __wiretype.StructType{ |
| 704 | []__wiretype.FieldType{ |
| 705 | __wiretype.FieldType{Type: 0x3, Name: "ID"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 706 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 707 | "veyron.io/apps/rps.GameID", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 708 | __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.GameTypeTag", Tags: []string(nil)}, __wiretype.StructType{ |
| 709 | []__wiretype.FieldType{ |
| 710 | __wiretype.FieldType{Type: 0x24, Name: "NumRounds"}, |
| 711 | __wiretype.FieldType{Type: 0x42, Name: "GameType"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 712 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 713 | "veyron.io/apps/rps.GameOptions", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 714 | __wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}} |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 715 | |
| 716 | return result, nil |
| 717 | } |
| 718 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 719 | // ScoreKeeperClientMethods is the client interface |
| 720 | // containing ScoreKeeper methods. |
| 721 | // |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 722 | // ScoreKeeper receives the outcome of games from Judges. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 723 | type ScoreKeeperClientMethods interface { |
| 724 | Record(ctx __context.T, Score ScoreCard, opts ...__ipc.CallOpt) error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 727 | // ScoreKeeperClientStub adds universal methods to ScoreKeeperClientMethods. |
| 728 | type ScoreKeeperClientStub interface { |
| 729 | ScoreKeeperClientMethods |
| 730 | __ipc.UniversalServiceMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 733 | // ScoreKeeperClient returns a client stub for ScoreKeeper. |
| 734 | func ScoreKeeperClient(name string, opts ...__ipc.BindOpt) ScoreKeeperClientStub { |
| 735 | var client __ipc.Client |
| 736 | for _, opt := range opts { |
| 737 | if clientOpt, ok := opt.(__ipc.Client); ok { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 738 | client = clientOpt |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 739 | } |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 740 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 741 | return implScoreKeeperClientStub{name, client} |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 744 | type implScoreKeeperClientStub struct { |
| 745 | name string |
| 746 | client __ipc.Client |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 749 | func (c implScoreKeeperClientStub) c(ctx __context.T) __ipc.Client { |
| 750 | if c.client != nil { |
| 751 | return c.client |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 752 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 753 | return __veyron2.RuntimeFromContext(ctx).Client() |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 756 | func (c implScoreKeeperClientStub) Record(ctx __context.T, i0 ScoreCard, opts ...__ipc.CallOpt) (err error) { |
| 757 | var call __ipc.Call |
| 758 | if call, err = c.c(ctx).StartCall(ctx, c.name, "Record", []interface{}{i0}, opts...); err != nil { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 759 | return |
| 760 | } |
| 761 | if ierr := call.Finish(&err); ierr != nil { |
| 762 | err = ierr |
| 763 | } |
| 764 | return |
| 765 | } |
| 766 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 767 | func (c implScoreKeeperClientStub) Signature(ctx __context.T, opts ...__ipc.CallOpt) (o0 __ipc.ServiceSignature, err error) { |
| 768 | var call __ipc.Call |
| 769 | if call, err = c.c(ctx).StartCall(ctx, c.name, "Signature", nil, opts...); err != nil { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 770 | return |
| 771 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 772 | if ierr := call.Finish(&o0, &err); ierr != nil { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 773 | err = ierr |
| 774 | } |
| 775 | return |
| 776 | } |
| 777 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 778 | // ScoreKeeperServerMethods is the interface a server writer |
| 779 | // implements for ScoreKeeper. |
| 780 | // |
| 781 | // ScoreKeeper receives the outcome of games from Judges. |
| 782 | type ScoreKeeperServerMethods interface { |
| 783 | Record(ctx __ipc.ServerContext, Score ScoreCard) error |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 786 | // ScoreKeeperServerStubMethods is the server interface containing |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 787 | // ScoreKeeper methods, as expected by ipc.Server. |
| 788 | // There is no difference between this interface and ScoreKeeperServerMethods |
| 789 | // since there are no streaming methods. |
| 790 | type ScoreKeeperServerStubMethods ScoreKeeperServerMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 791 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 792 | // ScoreKeeperServerStub adds universal methods to ScoreKeeperServerStubMethods. |
| 793 | type ScoreKeeperServerStub interface { |
| 794 | ScoreKeeperServerStubMethods |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 795 | // Describe the ScoreKeeper interfaces. |
| 796 | Describe__() []__ipc.InterfaceDesc |
| 797 | // Signature will be replaced with Describe__. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 798 | Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | // ScoreKeeperServer returns a server stub for ScoreKeeper. |
| 802 | // It converts an implementation of ScoreKeeperServerMethods into |
| 803 | // an object that may be used by ipc.Server. |
| 804 | func ScoreKeeperServer(impl ScoreKeeperServerMethods) ScoreKeeperServerStub { |
| 805 | stub := implScoreKeeperServerStub{ |
| 806 | impl: impl, |
| 807 | } |
| 808 | // Initialize GlobState; always check the stub itself first, to handle the |
| 809 | // case where the user has the Glob method defined in their VDL source. |
| 810 | if gs := __ipc.NewGlobState(stub); gs != nil { |
| 811 | stub.gs = gs |
| 812 | } else if gs := __ipc.NewGlobState(impl); gs != nil { |
| 813 | stub.gs = gs |
| 814 | } |
| 815 | return stub |
| 816 | } |
| 817 | |
| 818 | type implScoreKeeperServerStub struct { |
| 819 | impl ScoreKeeperServerMethods |
| 820 | gs *__ipc.GlobState |
| 821 | } |
| 822 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 823 | func (s implScoreKeeperServerStub) Record(ctx __ipc.ServerContext, i0 ScoreCard) error { |
| 824 | return s.impl.Record(ctx, i0) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | func (s implScoreKeeperServerStub) VGlob() *__ipc.GlobState { |
| 828 | return s.gs |
| 829 | } |
| 830 | |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 831 | func (s implScoreKeeperServerStub) Describe__() []__ipc.InterfaceDesc { |
| 832 | return []__ipc.InterfaceDesc{ScoreKeeperDesc} |
| 833 | } |
| 834 | |
| 835 | // ScoreKeeperDesc describes the ScoreKeeper interface. |
| 836 | var ScoreKeeperDesc __ipc.InterfaceDesc = descScoreKeeper |
| 837 | |
| 838 | // descScoreKeeper hides the desc to keep godoc clean. |
| 839 | var descScoreKeeper = __ipc.InterfaceDesc{ |
| 840 | Name: "ScoreKeeper", |
| 841 | PkgPath: "veyron.io/apps/rps", |
| 842 | Doc: "// ScoreKeeper receives the outcome of games from Judges.", |
| 843 | Methods: []__ipc.MethodDesc{ |
| 844 | { |
| 845 | Name: "Record", |
| 846 | InArgs: []__ipc.ArgDesc{ |
| 847 | {"Score", ``}, // ScoreCard |
| 848 | }, |
| 849 | OutArgs: []__ipc.ArgDesc{ |
| 850 | {"", ``}, // error |
| 851 | }, |
| 852 | }, |
| 853 | }, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 854 | } |
| 855 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 856 | func (s implScoreKeeperServerStub) Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) { |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 857 | // TODO(toddw): Replace with new Describe__ implementation. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 858 | result := __ipc.ServiceSignature{Methods: make(map[string]__ipc.MethodSignature)} |
| 859 | result.Methods["Record"] = __ipc.MethodSignature{ |
| 860 | InArgs: []__ipc.MethodArgument{ |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 861 | {Name: "Score", Type: 71}, |
| 862 | }, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 863 | OutArgs: []__ipc.MethodArgument{ |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 864 | {Name: "", Type: 72}, |
| 865 | }, |
| 866 | } |
| 867 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 868 | result.TypeDefs = []__vdlutil.Any{ |
| 869 | __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.GameTypeTag", Tags: []string(nil)}, __wiretype.StructType{ |
| 870 | []__wiretype.FieldType{ |
| 871 | __wiretype.FieldType{Type: 0x24, Name: "NumRounds"}, |
| 872 | __wiretype.FieldType{Type: 0x41, Name: "GameType"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 873 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 874 | "veyron.io/apps/rps.GameOptions", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 875 | __wiretype.ArrayType{Elem: 0x3, Len: 0x2, Name: "", Tags: []string(nil)}, __wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron.io/apps/rps.WinnerTag", Tags: []string(nil)}, __wiretype.StructType{ |
| 876 | []__wiretype.FieldType{ |
| 877 | __wiretype.FieldType{Type: 0x43, Name: "Moves"}, |
| 878 | __wiretype.FieldType{Type: 0x3, Name: "Comment"}, |
| 879 | __wiretype.FieldType{Type: 0x44, Name: "Winner"}, |
| 880 | __wiretype.FieldType{Type: 0x25, Name: "StartTimeNS"}, |
| 881 | __wiretype.FieldType{Type: 0x25, Name: "EndTimeNS"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 882 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 883 | "veyron.io/apps/rps.Round", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 884 | __wiretype.SliceType{Elem: 0x45, Name: "", Tags: []string(nil)}, __wiretype.StructType{ |
| 885 | []__wiretype.FieldType{ |
| 886 | __wiretype.FieldType{Type: 0x42, Name: "Opts"}, |
| 887 | __wiretype.FieldType{Type: 0x3, Name: "Judge"}, |
| 888 | __wiretype.FieldType{Type: 0x3d, Name: "Players"}, |
| 889 | __wiretype.FieldType{Type: 0x46, Name: "Rounds"}, |
| 890 | __wiretype.FieldType{Type: 0x25, Name: "StartTimeNS"}, |
| 891 | __wiretype.FieldType{Type: 0x25, Name: "EndTimeNS"}, |
| 892 | __wiretype.FieldType{Type: 0x44, Name: "Winner"}, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 893 | }, |
Ali Ghassemi | 85ed8fa | 2014-10-22 15:46:10 -0700 | [diff] [blame] | 894 | "veyron.io/apps/rps.ScoreCard", []string(nil)}, |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 895 | __wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}} |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 896 | |
| 897 | return result, nil |
| 898 | } |
| 899 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 900 | // RockPaperScissorsClientMethods is the client interface |
| 901 | // containing RockPaperScissors methods. |
| 902 | type RockPaperScissorsClientMethods interface { |
| 903 | JudgeClientMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 904 | // Player can receive challenges from other players. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 905 | PlayerClientMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 906 | // ScoreKeeper receives the outcome of games from Judges. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 907 | ScoreKeeperClientMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 910 | // RockPaperScissorsClientStub adds universal methods to RockPaperScissorsClientMethods. |
| 911 | type RockPaperScissorsClientStub interface { |
| 912 | RockPaperScissorsClientMethods |
| 913 | __ipc.UniversalServiceMethods |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 916 | // RockPaperScissorsClient returns a client stub for RockPaperScissors. |
| 917 | func RockPaperScissorsClient(name string, opts ...__ipc.BindOpt) RockPaperScissorsClientStub { |
| 918 | var client __ipc.Client |
| 919 | for _, opt := range opts { |
| 920 | if clientOpt, ok := opt.(__ipc.Client); ok { |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 921 | client = clientOpt |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 922 | } |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 923 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 924 | 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] | 925 | } |
| 926 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 927 | type implRockPaperScissorsClientStub struct { |
| 928 | name string |
| 929 | client __ipc.Client |
| 930 | |
| 931 | JudgeClientStub |
| 932 | PlayerClientStub |
| 933 | ScoreKeeperClientStub |
| 934 | } |
| 935 | |
| 936 | func (c implRockPaperScissorsClientStub) c(ctx __context.T) __ipc.Client { |
| 937 | if c.client != nil { |
| 938 | return c.client |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 939 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 940 | return __veyron2.RuntimeFromContext(ctx).Client() |
| 941 | } |
| 942 | |
| 943 | func (c implRockPaperScissorsClientStub) Signature(ctx __context.T, opts ...__ipc.CallOpt) (o0 __ipc.ServiceSignature, err error) { |
| 944 | var call __ipc.Call |
| 945 | if call, err = c.c(ctx).StartCall(ctx, c.name, "Signature", nil, opts...); err != nil { |
| 946 | return |
Robin Thellend | a754845 | 2014-11-05 18:10:24 -0800 | [diff] [blame] | 947 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 948 | if ierr := call.Finish(&o0, &err); ierr != nil { |
| 949 | err = ierr |
Robin Thellend | a754845 | 2014-11-05 18:10:24 -0800 | [diff] [blame] | 950 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 951 | return |
| 952 | } |
| 953 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 954 | // RockPaperScissorsServerMethods is the interface a server writer |
| 955 | // implements for RockPaperScissors. |
| 956 | type RockPaperScissorsServerMethods interface { |
| 957 | JudgeServerMethods |
| 958 | // Player can receive challenges from other players. |
| 959 | PlayerServerMethods |
| 960 | // ScoreKeeper receives the outcome of games from Judges. |
| 961 | ScoreKeeperServerMethods |
| 962 | } |
| 963 | |
| 964 | // RockPaperScissorsServerStubMethods is the server interface containing |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 965 | // RockPaperScissors methods, as expected by ipc.Server. |
| 966 | // The only difference between this interface and RockPaperScissorsServerMethods |
| 967 | // is the streaming methods. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 968 | type RockPaperScissorsServerStubMethods interface { |
| 969 | JudgeServerStubMethods |
| 970 | // Player can receive challenges from other players. |
| 971 | PlayerServerStubMethods |
| 972 | // ScoreKeeper receives the outcome of games from Judges. |
| 973 | ScoreKeeperServerStubMethods |
| 974 | } |
| 975 | |
| 976 | // RockPaperScissorsServerStub adds universal methods to RockPaperScissorsServerStubMethods. |
| 977 | type RockPaperScissorsServerStub interface { |
| 978 | RockPaperScissorsServerStubMethods |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 979 | // Describe the RockPaperScissors interfaces. |
| 980 | Describe__() []__ipc.InterfaceDesc |
| 981 | // Signature will be replaced with Describe__. |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 982 | Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | // RockPaperScissorsServer returns a server stub for RockPaperScissors. |
| 986 | // It converts an implementation of RockPaperScissorsServerMethods into |
| 987 | // an object that may be used by ipc.Server. |
| 988 | func RockPaperScissorsServer(impl RockPaperScissorsServerMethods) RockPaperScissorsServerStub { |
| 989 | stub := implRockPaperScissorsServerStub{ |
| 990 | impl: impl, |
| 991 | JudgeServerStub: JudgeServer(impl), |
| 992 | PlayerServerStub: PlayerServer(impl), |
| 993 | ScoreKeeperServerStub: ScoreKeeperServer(impl), |
| 994 | } |
| 995 | // Initialize GlobState; always check the stub itself first, to handle the |
| 996 | // case where the user has the Glob method defined in their VDL source. |
| 997 | if gs := __ipc.NewGlobState(stub); gs != nil { |
| 998 | stub.gs = gs |
| 999 | } else if gs := __ipc.NewGlobState(impl); gs != nil { |
| 1000 | stub.gs = gs |
| 1001 | } |
Robin Thellend | a754845 | 2014-11-05 18:10:24 -0800 | [diff] [blame] | 1002 | return stub |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1005 | type implRockPaperScissorsServerStub struct { |
| 1006 | impl RockPaperScissorsServerMethods |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1007 | JudgeServerStub |
| 1008 | PlayerServerStub |
| 1009 | ScoreKeeperServerStub |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 1010 | gs *__ipc.GlobState |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1013 | func (s implRockPaperScissorsServerStub) VGlob() *__ipc.GlobState { |
| 1014 | return s.gs |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 1017 | func (s implRockPaperScissorsServerStub) Describe__() []__ipc.InterfaceDesc { |
| 1018 | return []__ipc.InterfaceDesc{RockPaperScissorsDesc, JudgeDesc, PlayerDesc, ScoreKeeperDesc} |
| 1019 | } |
| 1020 | |
| 1021 | // RockPaperScissorsDesc describes the RockPaperScissors interface. |
| 1022 | var RockPaperScissorsDesc __ipc.InterfaceDesc = descRockPaperScissors |
| 1023 | |
| 1024 | // descRockPaperScissors hides the desc to keep godoc clean. |
| 1025 | var descRockPaperScissors = __ipc.InterfaceDesc{ |
| 1026 | Name: "RockPaperScissors", |
| 1027 | PkgPath: "veyron.io/apps/rps", |
| 1028 | Embeds: []__ipc.EmbedDesc{ |
| 1029 | {"Judge", "veyron.io/apps/rps", ``}, |
| 1030 | {"Player", "veyron.io/apps/rps", "// Player can receive challenges from other players."}, |
| 1031 | {"ScoreKeeper", "veyron.io/apps/rps", "// ScoreKeeper receives the outcome of games from Judges."}, |
| 1032 | }, |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 1035 | func (s implRockPaperScissorsServerStub) Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) { |
Todd Wang | dddc1fb | 2014-11-16 21:39:02 -0800 | [diff] [blame^] | 1036 | // TODO(toddw): Replace with new Describe__ implementation. |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1037 | result := __ipc.ServiceSignature{Methods: make(map[string]__ipc.MethodSignature)} |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1038 | |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1039 | result.TypeDefs = []__vdlutil.Any{} |
| 1040 | var ss __ipc.ServiceSignature |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1041 | var firstAdded int |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 1042 | ss, _ = s.JudgeServerStub.Signature(ctx) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1043 | firstAdded = len(result.TypeDefs) |
| 1044 | for k, v := range ss.Methods { |
| 1045 | for i, _ := range v.InArgs { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1046 | if v.InArgs[i].Type >= __wiretype.TypeIDFirst { |
| 1047 | v.InArgs[i].Type += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1048 | } |
| 1049 | } |
| 1050 | for i, _ := range v.OutArgs { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1051 | if v.OutArgs[i].Type >= __wiretype.TypeIDFirst { |
| 1052 | v.OutArgs[i].Type += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1053 | } |
| 1054 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1055 | if v.InStream >= __wiretype.TypeIDFirst { |
| 1056 | v.InStream += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1057 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1058 | if v.OutStream >= __wiretype.TypeIDFirst { |
| 1059 | v.OutStream += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1060 | } |
| 1061 | result.Methods[k] = v |
| 1062 | } |
| 1063 | //TODO(bprosnitz) combine type definitions from embeded interfaces in a way that doesn't cause duplication. |
| 1064 | for _, d := range ss.TypeDefs { |
| 1065 | switch wt := d.(type) { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1066 | case __wiretype.SliceType: |
| 1067 | if wt.Elem >= __wiretype.TypeIDFirst { |
| 1068 | wt.Elem += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1069 | } |
| 1070 | d = wt |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1071 | case __wiretype.ArrayType: |
| 1072 | if wt.Elem >= __wiretype.TypeIDFirst { |
| 1073 | wt.Elem += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1074 | } |
| 1075 | d = wt |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1076 | case __wiretype.MapType: |
| 1077 | if wt.Key >= __wiretype.TypeIDFirst { |
| 1078 | wt.Key += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1079 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1080 | if wt.Elem >= __wiretype.TypeIDFirst { |
| 1081 | wt.Elem += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1082 | } |
| 1083 | d = wt |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1084 | case __wiretype.StructType: |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1085 | for i, fld := range wt.Fields { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1086 | if fld.Type >= __wiretype.TypeIDFirst { |
| 1087 | wt.Fields[i].Type += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | d = wt |
| 1091 | // NOTE: other types are missing, but we are upgrading anyways. |
| 1092 | } |
| 1093 | result.TypeDefs = append(result.TypeDefs, d) |
| 1094 | } |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 1095 | ss, _ = s.PlayerServerStub.Signature(ctx) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1096 | firstAdded = len(result.TypeDefs) |
| 1097 | for k, v := range ss.Methods { |
| 1098 | for i, _ := range v.InArgs { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1099 | if v.InArgs[i].Type >= __wiretype.TypeIDFirst { |
| 1100 | v.InArgs[i].Type += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | for i, _ := range v.OutArgs { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1104 | if v.OutArgs[i].Type >= __wiretype.TypeIDFirst { |
| 1105 | v.OutArgs[i].Type += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1106 | } |
| 1107 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1108 | if v.InStream >= __wiretype.TypeIDFirst { |
| 1109 | v.InStream += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1110 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1111 | if v.OutStream >= __wiretype.TypeIDFirst { |
| 1112 | v.OutStream += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1113 | } |
| 1114 | result.Methods[k] = v |
| 1115 | } |
| 1116 | //TODO(bprosnitz) combine type definitions from embeded interfaces in a way that doesn't cause duplication. |
| 1117 | for _, d := range ss.TypeDefs { |
| 1118 | switch wt := d.(type) { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1119 | case __wiretype.SliceType: |
| 1120 | if wt.Elem >= __wiretype.TypeIDFirst { |
| 1121 | wt.Elem += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1122 | } |
| 1123 | d = wt |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1124 | case __wiretype.ArrayType: |
| 1125 | if wt.Elem >= __wiretype.TypeIDFirst { |
| 1126 | wt.Elem += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1127 | } |
| 1128 | d = wt |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1129 | case __wiretype.MapType: |
| 1130 | if wt.Key >= __wiretype.TypeIDFirst { |
| 1131 | wt.Key += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1132 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1133 | if wt.Elem >= __wiretype.TypeIDFirst { |
| 1134 | wt.Elem += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1135 | } |
| 1136 | d = wt |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1137 | case __wiretype.StructType: |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1138 | for i, fld := range wt.Fields { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1139 | if fld.Type >= __wiretype.TypeIDFirst { |
| 1140 | wt.Fields[i].Type += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | d = wt |
| 1144 | // NOTE: other types are missing, but we are upgrading anyways. |
| 1145 | } |
| 1146 | result.TypeDefs = append(result.TypeDefs, d) |
| 1147 | } |
Todd Wang | 5cd2735 | 2014-11-11 20:27:39 -0800 | [diff] [blame] | 1148 | ss, _ = s.ScoreKeeperServerStub.Signature(ctx) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1149 | firstAdded = len(result.TypeDefs) |
| 1150 | for k, v := range ss.Methods { |
| 1151 | for i, _ := range v.InArgs { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1152 | if v.InArgs[i].Type >= __wiretype.TypeIDFirst { |
| 1153 | v.InArgs[i].Type += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | for i, _ := range v.OutArgs { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1157 | if v.OutArgs[i].Type >= __wiretype.TypeIDFirst { |
| 1158 | v.OutArgs[i].Type += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1159 | } |
| 1160 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1161 | if v.InStream >= __wiretype.TypeIDFirst { |
| 1162 | v.InStream += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1163 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1164 | if v.OutStream >= __wiretype.TypeIDFirst { |
| 1165 | v.OutStream += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1166 | } |
| 1167 | result.Methods[k] = v |
| 1168 | } |
| 1169 | //TODO(bprosnitz) combine type definitions from embeded interfaces in a way that doesn't cause duplication. |
| 1170 | for _, d := range ss.TypeDefs { |
| 1171 | switch wt := d.(type) { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1172 | case __wiretype.SliceType: |
| 1173 | if wt.Elem >= __wiretype.TypeIDFirst { |
| 1174 | wt.Elem += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1175 | } |
| 1176 | d = wt |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1177 | case __wiretype.ArrayType: |
| 1178 | if wt.Elem >= __wiretype.TypeIDFirst { |
| 1179 | wt.Elem += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1180 | } |
| 1181 | d = wt |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1182 | case __wiretype.MapType: |
| 1183 | if wt.Key >= __wiretype.TypeIDFirst { |
| 1184 | wt.Key += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1185 | } |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1186 | if wt.Elem >= __wiretype.TypeIDFirst { |
| 1187 | wt.Elem += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1188 | } |
| 1189 | d = wt |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1190 | case __wiretype.StructType: |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1191 | for i, fld := range wt.Fields { |
Todd Wang | d8cb55b | 2014-11-07 00:58:32 -0800 | [diff] [blame] | 1192 | if fld.Type >= __wiretype.TypeIDFirst { |
| 1193 | wt.Fields[i].Type += __wiretype.TypeID(firstAdded) |
Jiri Simsa | 37cdfc0 | 2014-10-09 18:00:43 -0700 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | d = wt |
| 1197 | // NOTE: other types are missing, but we are upgrading anyways. |
| 1198 | } |
| 1199 | result.TypeDefs = append(result.TypeDefs, d) |
| 1200 | } |
| 1201 | |
| 1202 | return result, nil |
| 1203 | } |