| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| // This file was auto-generated by the vanadium vdl tool. |
| // Source: speaker.vdl |
| |
| package sample |
| |
| import ( |
| // VDL system imports |
| "io" |
| "v.io/v23" |
| "v.io/v23/context" |
| "v.io/v23/rpc" |
| ) |
| |
| // SpeakerClientMethods is the client interface |
| // containing Speaker methods. |
| // |
| // Speaker allows clients to control the music being played. |
| type SpeakerClientMethods interface { |
| // Play starts or continues the current song. |
| Play(*context.T, ...rpc.CallOpt) error |
| // PlaySong plays back the given song title, if possible. |
| PlaySong(ctx *context.T, songName string, opts ...rpc.CallOpt) error |
| // PlayStream plays the given stream of music data. |
| PlayStream(*context.T, ...rpc.CallOpt) (SpeakerPlayStreamClientCall, error) |
| // GetSong retrieves the title of the Speaker's current song, if any. |
| GetSong(*context.T, ...rpc.CallOpt) (string, error) |
| // Pause playback of the Speaker's current song. |
| Pause(*context.T, ...rpc.CallOpt) error |
| // Stop playback of the Speaker's current song. |
| Stop(*context.T, ...rpc.CallOpt) error |
| // Volume adjusts the Speaker's volume. |
| Volume(ctx *context.T, volumeLevel uint16, opts ...rpc.CallOpt) error |
| // GetVolume retrieves the Speaker's volume. |
| GetVolume(*context.T, ...rpc.CallOpt) (uint16, error) |
| // AddSongs adds the list of given songs to the song library. |
| AddSongs(ctx *context.T, songs []string, opts ...rpc.CallOpt) error |
| // Delete removes the list of given songs from the song library. |
| Delete(ctx *context.T, songs []string, opts ...rpc.CallOpt) error |
| } |
| |
| // SpeakerClientStub adds universal methods to SpeakerClientMethods. |
| type SpeakerClientStub interface { |
| SpeakerClientMethods |
| rpc.UniversalServiceMethods |
| } |
| |
| // SpeakerClient returns a client stub for Speaker. |
| func SpeakerClient(name string) SpeakerClientStub { |
| return implSpeakerClientStub{name} |
| } |
| |
| type implSpeakerClientStub struct { |
| name string |
| } |
| |
| func (c implSpeakerClientStub) Play(ctx *context.T, opts ...rpc.CallOpt) (err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "Play", nil, nil, opts...) |
| return |
| } |
| |
| func (c implSpeakerClientStub) PlaySong(ctx *context.T, i0 string, opts ...rpc.CallOpt) (err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "PlaySong", []interface{}{i0}, nil, opts...) |
| return |
| } |
| |
| func (c implSpeakerClientStub) PlayStream(ctx *context.T, opts ...rpc.CallOpt) (ocall SpeakerPlayStreamClientCall, err error) { |
| var call rpc.ClientCall |
| if call, err = v23.GetClient(ctx).StartCall(ctx, c.name, "PlayStream", nil, opts...); err != nil { |
| return |
| } |
| ocall = &implSpeakerPlayStreamClientCall{ClientCall: call} |
| return |
| } |
| |
| func (c implSpeakerClientStub) GetSong(ctx *context.T, opts ...rpc.CallOpt) (o0 string, err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "GetSong", nil, []interface{}{&o0}, opts...) |
| return |
| } |
| |
| func (c implSpeakerClientStub) Pause(ctx *context.T, opts ...rpc.CallOpt) (err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "Pause", nil, nil, opts...) |
| return |
| } |
| |
| func (c implSpeakerClientStub) Stop(ctx *context.T, opts ...rpc.CallOpt) (err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "Stop", nil, nil, opts...) |
| return |
| } |
| |
| func (c implSpeakerClientStub) Volume(ctx *context.T, i0 uint16, opts ...rpc.CallOpt) (err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "Volume", []interface{}{i0}, nil, opts...) |
| return |
| } |
| |
| func (c implSpeakerClientStub) GetVolume(ctx *context.T, opts ...rpc.CallOpt) (o0 uint16, err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "GetVolume", nil, []interface{}{&o0}, opts...) |
| return |
| } |
| |
| func (c implSpeakerClientStub) AddSongs(ctx *context.T, i0 []string, opts ...rpc.CallOpt) (err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "AddSongs", []interface{}{i0}, nil, opts...) |
| return |
| } |
| |
| func (c implSpeakerClientStub) Delete(ctx *context.T, i0 []string, opts ...rpc.CallOpt) (err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "Delete", []interface{}{i0}, nil, opts...) |
| return |
| } |
| |
| // SpeakerPlayStreamClientStream is the client stream for Speaker.PlayStream. |
| type SpeakerPlayStreamClientStream interface { |
| // SendStream returns the send side of the Speaker.PlayStream client stream. |
| SendStream() interface { |
| // Send places the item onto the output stream. Returns errors |
| // encountered while sending, or if Send is called after Close or |
| // the stream has been canceled. Blocks if there is no buffer |
| // space; will unblock when buffer space is available or after |
| // the stream has been canceled. |
| Send(item []byte) error |
| // Close indicates to the server that no more items will be sent; |
| // server Recv calls will receive io.EOF after all sent items. |
| // This is an optional call - e.g. a client might call Close if it |
| // needs to continue receiving items from the server after it's |
| // done sending. Returns errors encountered while closing, or if |
| // Close is called after the stream has been canceled. Like Send, |
| // blocks if there is no buffer space available. |
| Close() error |
| } |
| } |
| |
| // SpeakerPlayStreamClientCall represents the call returned from Speaker.PlayStream. |
| type SpeakerPlayStreamClientCall interface { |
| SpeakerPlayStreamClientStream |
| // Finish performs the equivalent of SendStream().Close, then blocks until |
| // the server is done, and returns the positional return values for the call. |
| // |
| // Finish returns immediately if the call has been canceled; depending on the |
| // timing the output could either be an error signaling cancelation, or the |
| // valid positional return values from the server. |
| // |
| // Calling Finish is mandatory for releasing stream resources, unless the call |
| // has been canceled or any of the other methods return an error. Finish should |
| // be called at most once. |
| Finish() error |
| } |
| |
| type implSpeakerPlayStreamClientCall struct { |
| rpc.ClientCall |
| } |
| |
| func (c *implSpeakerPlayStreamClientCall) SendStream() interface { |
| Send(item []byte) error |
| Close() error |
| } { |
| return implSpeakerPlayStreamClientCallSend{c} |
| } |
| |
| type implSpeakerPlayStreamClientCallSend struct { |
| c *implSpeakerPlayStreamClientCall |
| } |
| |
| func (c implSpeakerPlayStreamClientCallSend) Send(item []byte) error { |
| return c.c.Send(item) |
| } |
| func (c implSpeakerPlayStreamClientCallSend) Close() error { |
| return c.c.CloseSend() |
| } |
| func (c *implSpeakerPlayStreamClientCall) Finish() (err error) { |
| err = c.ClientCall.Finish() |
| return |
| } |
| |
| // SpeakerServerMethods is the interface a server writer |
| // implements for Speaker. |
| // |
| // Speaker allows clients to control the music being played. |
| type SpeakerServerMethods interface { |
| // Play starts or continues the current song. |
| Play(*context.T, rpc.ServerCall) error |
| // PlaySong plays back the given song title, if possible. |
| PlaySong(ctx *context.T, call rpc.ServerCall, songName string) error |
| // PlayStream plays the given stream of music data. |
| PlayStream(*context.T, SpeakerPlayStreamServerCall) error |
| // GetSong retrieves the title of the Speaker's current song, if any. |
| GetSong(*context.T, rpc.ServerCall) (string, error) |
| // Pause playback of the Speaker's current song. |
| Pause(*context.T, rpc.ServerCall) error |
| // Stop playback of the Speaker's current song. |
| Stop(*context.T, rpc.ServerCall) error |
| // Volume adjusts the Speaker's volume. |
| Volume(ctx *context.T, call rpc.ServerCall, volumeLevel uint16) error |
| // GetVolume retrieves the Speaker's volume. |
| GetVolume(*context.T, rpc.ServerCall) (uint16, error) |
| // AddSongs adds the list of given songs to the song library. |
| AddSongs(ctx *context.T, call rpc.ServerCall, songs []string) error |
| // Delete removes the list of given songs from the song library. |
| Delete(ctx *context.T, call rpc.ServerCall, songs []string) error |
| } |
| |
| // SpeakerServerStubMethods is the server interface containing |
| // Speaker methods, as expected by rpc.Server. |
| // The only difference between this interface and SpeakerServerMethods |
| // is the streaming methods. |
| type SpeakerServerStubMethods interface { |
| // Play starts or continues the current song. |
| Play(*context.T, rpc.ServerCall) error |
| // PlaySong plays back the given song title, if possible. |
| PlaySong(ctx *context.T, call rpc.ServerCall, songName string) error |
| // PlayStream plays the given stream of music data. |
| PlayStream(*context.T, *SpeakerPlayStreamServerCallStub) error |
| // GetSong retrieves the title of the Speaker's current song, if any. |
| GetSong(*context.T, rpc.ServerCall) (string, error) |
| // Pause playback of the Speaker's current song. |
| Pause(*context.T, rpc.ServerCall) error |
| // Stop playback of the Speaker's current song. |
| Stop(*context.T, rpc.ServerCall) error |
| // Volume adjusts the Speaker's volume. |
| Volume(ctx *context.T, call rpc.ServerCall, volumeLevel uint16) error |
| // GetVolume retrieves the Speaker's volume. |
| GetVolume(*context.T, rpc.ServerCall) (uint16, error) |
| // AddSongs adds the list of given songs to the song library. |
| AddSongs(ctx *context.T, call rpc.ServerCall, songs []string) error |
| // Delete removes the list of given songs from the song library. |
| Delete(ctx *context.T, call rpc.ServerCall, songs []string) error |
| } |
| |
| // SpeakerServerStub adds universal methods to SpeakerServerStubMethods. |
| type SpeakerServerStub interface { |
| SpeakerServerStubMethods |
| // Describe the Speaker interfaces. |
| Describe__() []rpc.InterfaceDesc |
| } |
| |
| // SpeakerServer returns a server stub for Speaker. |
| // It converts an implementation of SpeakerServerMethods into |
| // an object that may be used by rpc.Server. |
| func SpeakerServer(impl SpeakerServerMethods) SpeakerServerStub { |
| stub := implSpeakerServerStub{ |
| impl: impl, |
| } |
| // Initialize GlobState; always check the stub itself first, to handle the |
| // case where the user has the Glob method defined in their VDL source. |
| if gs := rpc.NewGlobState(stub); gs != nil { |
| stub.gs = gs |
| } else if gs := rpc.NewGlobState(impl); gs != nil { |
| stub.gs = gs |
| } |
| return stub |
| } |
| |
| type implSpeakerServerStub struct { |
| impl SpeakerServerMethods |
| gs *rpc.GlobState |
| } |
| |
| func (s implSpeakerServerStub) Play(ctx *context.T, call rpc.ServerCall) error { |
| return s.impl.Play(ctx, call) |
| } |
| |
| func (s implSpeakerServerStub) PlaySong(ctx *context.T, call rpc.ServerCall, i0 string) error { |
| return s.impl.PlaySong(ctx, call, i0) |
| } |
| |
| func (s implSpeakerServerStub) PlayStream(ctx *context.T, call *SpeakerPlayStreamServerCallStub) error { |
| return s.impl.PlayStream(ctx, call) |
| } |
| |
| func (s implSpeakerServerStub) GetSong(ctx *context.T, call rpc.ServerCall) (string, error) { |
| return s.impl.GetSong(ctx, call) |
| } |
| |
| func (s implSpeakerServerStub) Pause(ctx *context.T, call rpc.ServerCall) error { |
| return s.impl.Pause(ctx, call) |
| } |
| |
| func (s implSpeakerServerStub) Stop(ctx *context.T, call rpc.ServerCall) error { |
| return s.impl.Stop(ctx, call) |
| } |
| |
| func (s implSpeakerServerStub) Volume(ctx *context.T, call rpc.ServerCall, i0 uint16) error { |
| return s.impl.Volume(ctx, call, i0) |
| } |
| |
| func (s implSpeakerServerStub) GetVolume(ctx *context.T, call rpc.ServerCall) (uint16, error) { |
| return s.impl.GetVolume(ctx, call) |
| } |
| |
| func (s implSpeakerServerStub) AddSongs(ctx *context.T, call rpc.ServerCall, i0 []string) error { |
| return s.impl.AddSongs(ctx, call, i0) |
| } |
| |
| func (s implSpeakerServerStub) Delete(ctx *context.T, call rpc.ServerCall, i0 []string) error { |
| return s.impl.Delete(ctx, call, i0) |
| } |
| |
| func (s implSpeakerServerStub) Globber() *rpc.GlobState { |
| return s.gs |
| } |
| |
| func (s implSpeakerServerStub) Describe__() []rpc.InterfaceDesc { |
| return []rpc.InterfaceDesc{SpeakerDesc} |
| } |
| |
| // SpeakerDesc describes the Speaker interface. |
| var SpeakerDesc rpc.InterfaceDesc = descSpeaker |
| |
| // descSpeaker hides the desc to keep godoc clean. |
| var descSpeaker = rpc.InterfaceDesc{ |
| Name: "Speaker", |
| PkgPath: "v.io/x/browser/sample", |
| Doc: "// Speaker allows clients to control the music being played.", |
| Methods: []rpc.MethodDesc{ |
| { |
| Name: "Play", |
| Doc: "// Play starts or continues the current song.", |
| }, |
| { |
| Name: "PlaySong", |
| Doc: "// PlaySong plays back the given song title, if possible.", |
| InArgs: []rpc.ArgDesc{ |
| {"songName", ``}, // string |
| }, |
| }, |
| { |
| Name: "PlayStream", |
| Doc: "// PlayStream plays the given stream of music data.", |
| }, |
| { |
| Name: "GetSong", |
| Doc: "// GetSong retrieves the title of the Speaker's current song, if any.", |
| OutArgs: []rpc.ArgDesc{ |
| {"", ``}, // string |
| }, |
| }, |
| { |
| Name: "Pause", |
| Doc: "// Pause playback of the Speaker's current song.", |
| }, |
| { |
| Name: "Stop", |
| Doc: "// Stop playback of the Speaker's current song.", |
| }, |
| { |
| Name: "Volume", |
| Doc: "// Volume adjusts the Speaker's volume.", |
| InArgs: []rpc.ArgDesc{ |
| {"volumeLevel", ``}, // uint16 |
| }, |
| }, |
| { |
| Name: "GetVolume", |
| Doc: "// GetVolume retrieves the Speaker's volume.", |
| OutArgs: []rpc.ArgDesc{ |
| {"", ``}, // uint16 |
| }, |
| }, |
| { |
| Name: "AddSongs", |
| Doc: "// AddSongs adds the list of given songs to the song library.", |
| InArgs: []rpc.ArgDesc{ |
| {"songs", ``}, // []string |
| }, |
| }, |
| { |
| Name: "Delete", |
| Doc: "// Delete removes the list of given songs from the song library.", |
| InArgs: []rpc.ArgDesc{ |
| {"songs", ``}, // []string |
| }, |
| }, |
| }, |
| } |
| |
| // SpeakerPlayStreamServerStream is the server stream for Speaker.PlayStream. |
| type SpeakerPlayStreamServerStream interface { |
| // RecvStream returns the receiver side of the Speaker.PlayStream server stream. |
| RecvStream() interface { |
| // Advance stages an item so that it may be retrieved via Value. Returns |
| // true iff there is an item to retrieve. Advance must be called before |
| // Value is called. May block if an item is not available. |
| Advance() bool |
| // Value returns the item that was staged by Advance. May panic if Advance |
| // returned false or was not called. Never blocks. |
| Value() []byte |
| // Err returns any error encountered by Advance. Never blocks. |
| Err() error |
| } |
| } |
| |
| // SpeakerPlayStreamServerCall represents the context passed to Speaker.PlayStream. |
| type SpeakerPlayStreamServerCall interface { |
| rpc.ServerCall |
| SpeakerPlayStreamServerStream |
| } |
| |
| // SpeakerPlayStreamServerCallStub is a wrapper that converts rpc.StreamServerCall into |
| // a typesafe stub that implements SpeakerPlayStreamServerCall. |
| type SpeakerPlayStreamServerCallStub struct { |
| rpc.StreamServerCall |
| valRecv []byte |
| errRecv error |
| } |
| |
| // Init initializes SpeakerPlayStreamServerCallStub from rpc.StreamServerCall. |
| func (s *SpeakerPlayStreamServerCallStub) Init(call rpc.StreamServerCall) { |
| s.StreamServerCall = call |
| } |
| |
| // RecvStream returns the receiver side of the Speaker.PlayStream server stream. |
| func (s *SpeakerPlayStreamServerCallStub) RecvStream() interface { |
| Advance() bool |
| Value() []byte |
| Err() error |
| } { |
| return implSpeakerPlayStreamServerCallRecv{s} |
| } |
| |
| type implSpeakerPlayStreamServerCallRecv struct { |
| s *SpeakerPlayStreamServerCallStub |
| } |
| |
| func (s implSpeakerPlayStreamServerCallRecv) Advance() bool { |
| s.s.errRecv = s.s.Recv(&s.s.valRecv) |
| return s.s.errRecv == nil |
| } |
| func (s implSpeakerPlayStreamServerCallRecv) Value() []byte { |
| return s.s.valRecv |
| } |
| func (s implSpeakerPlayStreamServerCallRecv) Err() error { |
| if s.s.errRecv == io.EOF { |
| return nil |
| } |
| return s.s.errRecv |
| } |