Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 1 | // This file was auto-generated by the veyron vdl tool. |
| 2 | // Source: lightswitch.vdl |
| 3 | |
| 4 | package sample |
| 5 | |
| 6 | import ( |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 7 | // The non-user imports are prefixed with "__" to prevent collisions. |
| 8 | __veyron2 "veyron.io/veyron/veyron2" |
| 9 | __context "veyron.io/veyron/veyron2/context" |
| 10 | __ipc "veyron.io/veyron/veyron2/ipc" |
| 11 | __vdlutil "veyron.io/veyron/veyron2/vdl/vdlutil" |
| 12 | __wiretype "veyron.io/veyron/veyron2/wiretype" |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 13 | ) |
| 14 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 15 | // TODO(toddw): Remove this line once the new signature support is done. |
| 16 | // It corrects a bug where __wiretype is unused in VDL pacakges where only |
| 17 | // bootstrap types are used on interfaces. |
| 18 | const _ = __wiretype.TypeIDInvalid |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 19 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 20 | // LightSwitchClientMethods is the client interface |
| 21 | // containing LightSwitch methods. |
| 22 | // |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 23 | // LightSwitch allows clients to manipulate a virtual light switch. |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 24 | type LightSwitchClientMethods interface { |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 25 | // Status indicates whether the light is on or off. |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 26 | Status(__context.T, ...__ipc.CallOpt) (string, error) |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 27 | // FlipSwitch sets the light to on or off, depending on the input. |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 28 | FlipSwitch(ctx __context.T, toOn bool, opts ...__ipc.CallOpt) error |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 31 | // LightSwitchClientStub adds universal methods to LightSwitchClientMethods. |
| 32 | type LightSwitchClientStub interface { |
| 33 | LightSwitchClientMethods |
| 34 | __ipc.UniversalServiceMethods |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 37 | // LightSwitchClient returns a client stub for LightSwitch. |
| 38 | func LightSwitchClient(name string, opts ...__ipc.BindOpt) LightSwitchClientStub { |
| 39 | var client __ipc.Client |
| 40 | for _, opt := range opts { |
| 41 | if clientOpt, ok := opt.(__ipc.Client); ok { |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 42 | client = clientOpt |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 43 | } |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 44 | } |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 45 | return implLightSwitchClientStub{name, client} |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 48 | type implLightSwitchClientStub struct { |
| 49 | name string |
| 50 | client __ipc.Client |
| 51 | } |
| 52 | |
| 53 | func (c implLightSwitchClientStub) c(ctx __context.T) __ipc.Client { |
| 54 | if c.client != nil { |
| 55 | return c.client |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 56 | } |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 57 | return __veyron2.RuntimeFromContext(ctx).Client() |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 60 | func (c implLightSwitchClientStub) Status(ctx __context.T, opts ...__ipc.CallOpt) (o0 string, err error) { |
| 61 | var call __ipc.Call |
| 62 | if call, err = c.c(ctx).StartCall(ctx, c.name, "Status", nil, opts...); err != nil { |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 63 | return |
| 64 | } |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 65 | if ierr := call.Finish(&o0, &err); ierr != nil { |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 66 | err = ierr |
| 67 | } |
| 68 | return |
| 69 | } |
| 70 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 71 | func (c implLightSwitchClientStub) FlipSwitch(ctx __context.T, i0 bool, opts ...__ipc.CallOpt) (err error) { |
| 72 | var call __ipc.Call |
| 73 | if call, err = c.c(ctx).StartCall(ctx, c.name, "FlipSwitch", []interface{}{i0}, opts...); err != nil { |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 74 | return |
| 75 | } |
| 76 | if ierr := call.Finish(&err); ierr != nil { |
| 77 | err = ierr |
| 78 | } |
| 79 | return |
| 80 | } |
| 81 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 82 | func (c implLightSwitchClientStub) Signature(ctx __context.T, opts ...__ipc.CallOpt) (o0 __ipc.ServiceSignature, err error) { |
| 83 | var call __ipc.Call |
| 84 | if call, err = c.c(ctx).StartCall(ctx, c.name, "Signature", nil, opts...); err != nil { |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 85 | return |
| 86 | } |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 87 | if ierr := call.Finish(&o0, &err); ierr != nil { |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 88 | err = ierr |
| 89 | } |
| 90 | return |
| 91 | } |
| 92 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 93 | // LightSwitchServerMethods is the interface a server writer |
| 94 | // implements for LightSwitch. |
| 95 | // |
| 96 | // LightSwitch allows clients to manipulate a virtual light switch. |
| 97 | type LightSwitchServerMethods interface { |
| 98 | // Status indicates whether the light is on or off. |
| 99 | Status(__ipc.ServerContext) (string, error) |
| 100 | // FlipSwitch sets the light to on or off, depending on the input. |
| 101 | FlipSwitch(ctx __ipc.ServerContext, toOn bool) error |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 104 | // LightSwitchServerStubMethods is the server interface containing |
Todd Wang | 52500a5 | 2014-11-11 20:26:05 -0800 | [diff] [blame] | 105 | // LightSwitch methods, as expected by ipc.Server. |
| 106 | // There is no difference between this interface and LightSwitchServerMethods |
| 107 | // since there are no streaming methods. |
| 108 | type LightSwitchServerStubMethods LightSwitchServerMethods |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 109 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 110 | // LightSwitchServerStub adds universal methods to LightSwitchServerStubMethods. |
| 111 | type LightSwitchServerStub interface { |
| 112 | LightSwitchServerStubMethods |
Todd Wang | 09f71db | 2014-11-16 21:41:47 -0800 | [diff] [blame] | 113 | // Describe the LightSwitch interfaces. |
| 114 | Describe__() []__ipc.InterfaceDesc |
| 115 | // Signature will be replaced with Describe__. |
Todd Wang | 52500a5 | 2014-11-11 20:26:05 -0800 | [diff] [blame] | 116 | Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | // LightSwitchServer returns a server stub for LightSwitch. |
| 120 | // It converts an implementation of LightSwitchServerMethods into |
| 121 | // an object that may be used by ipc.Server. |
| 122 | func LightSwitchServer(impl LightSwitchServerMethods) LightSwitchServerStub { |
| 123 | stub := implLightSwitchServerStub{ |
| 124 | impl: impl, |
| 125 | } |
| 126 | // Initialize GlobState; always check the stub itself first, to handle the |
| 127 | // case where the user has the Glob method defined in their VDL source. |
| 128 | if gs := __ipc.NewGlobState(stub); gs != nil { |
| 129 | stub.gs = gs |
| 130 | } else if gs := __ipc.NewGlobState(impl); gs != nil { |
| 131 | stub.gs = gs |
| 132 | } |
| 133 | return stub |
| 134 | } |
| 135 | |
| 136 | type implLightSwitchServerStub struct { |
| 137 | impl LightSwitchServerMethods |
| 138 | gs *__ipc.GlobState |
| 139 | } |
| 140 | |
Todd Wang | 52500a5 | 2014-11-11 20:26:05 -0800 | [diff] [blame] | 141 | func (s implLightSwitchServerStub) Status(ctx __ipc.ServerContext) (string, error) { |
| 142 | return s.impl.Status(ctx) |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Todd Wang | 52500a5 | 2014-11-11 20:26:05 -0800 | [diff] [blame] | 145 | func (s implLightSwitchServerStub) FlipSwitch(ctx __ipc.ServerContext, i0 bool) error { |
| 146 | return s.impl.FlipSwitch(ctx, i0) |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | func (s implLightSwitchServerStub) VGlob() *__ipc.GlobState { |
| 150 | return s.gs |
| 151 | } |
| 152 | |
Todd Wang | 09f71db | 2014-11-16 21:41:47 -0800 | [diff] [blame] | 153 | func (s implLightSwitchServerStub) Describe__() []__ipc.InterfaceDesc { |
| 154 | return []__ipc.InterfaceDesc{LightSwitchDesc} |
| 155 | } |
| 156 | |
| 157 | // LightSwitchDesc describes the LightSwitch interface. |
| 158 | var LightSwitchDesc __ipc.InterfaceDesc = descLightSwitch |
| 159 | |
| 160 | // descLightSwitch hides the desc to keep godoc clean. |
| 161 | var descLightSwitch = __ipc.InterfaceDesc{ |
| 162 | Name: "LightSwitch", |
| 163 | PkgPath: "sample", |
| 164 | Doc: "// LightSwitch allows clients to manipulate a virtual light switch.", |
| 165 | Methods: []__ipc.MethodDesc{ |
| 166 | { |
| 167 | Name: "Status", |
| 168 | Doc: "// Status indicates whether the light is on or off.", |
| 169 | OutArgs: []__ipc.ArgDesc{ |
| 170 | {"", ``}, // string |
| 171 | {"", ``}, // error |
| 172 | }, |
| 173 | }, |
| 174 | { |
| 175 | Name: "FlipSwitch", |
| 176 | Doc: "// FlipSwitch sets the light to on or off, depending on the input.", |
| 177 | InArgs: []__ipc.ArgDesc{ |
| 178 | {"toOn", ``}, // bool |
| 179 | }, |
| 180 | OutArgs: []__ipc.ArgDesc{ |
| 181 | {"", ``}, // error |
| 182 | }, |
| 183 | }, |
| 184 | }, |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Todd Wang | 52500a5 | 2014-11-11 20:26:05 -0800 | [diff] [blame] | 187 | func (s implLightSwitchServerStub) Signature(ctx __ipc.ServerContext) (__ipc.ServiceSignature, error) { |
Todd Wang | 09f71db | 2014-11-16 21:41:47 -0800 | [diff] [blame] | 188 | // TODO(toddw): Replace with new Describe__ implementation. |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 189 | result := __ipc.ServiceSignature{Methods: make(map[string]__ipc.MethodSignature)} |
| 190 | result.Methods["FlipSwitch"] = __ipc.MethodSignature{ |
| 191 | InArgs: []__ipc.MethodArgument{ |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 192 | {Name: "toOn", Type: 2}, |
| 193 | }, |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 194 | OutArgs: []__ipc.MethodArgument{ |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 195 | {Name: "", Type: 65}, |
| 196 | }, |
| 197 | } |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 198 | result.Methods["Status"] = __ipc.MethodSignature{ |
| 199 | InArgs: []__ipc.MethodArgument{}, |
| 200 | OutArgs: []__ipc.MethodArgument{ |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 201 | {Name: "", Type: 3}, |
| 202 | {Name: "", Type: 65}, |
| 203 | }, |
| 204 | } |
| 205 | |
Todd Wang | e987f9f | 2014-11-07 00:36:04 -0800 | [diff] [blame] | 206 | result.TypeDefs = []__vdlutil.Any{ |
| 207 | __wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}} |
Alex Fandrianto | 4204a88 | 2014-09-19 13:34:32 -0700 | [diff] [blame] | 208 | |
| 209 | return result, nil |
| 210 | } |