Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client methods to interfaceClient template #285

Merged
merged 11 commits into from
Aug 5, 2022
33 changes: 33 additions & 0 deletions capnpc-go/templates/interfaceClient
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,36 @@ func (c {{$.Node.Name}}) {{.Name|title}}(ctx {{$.G.Imports.Context}}.Context, pa
}
{{end}}

// String returns a string that identifies this capability for debugging
// purposes. Its format should not be depended on: in particular, it
// should not be used to compare clients. Use IsSame to compare clients
// for equality.
func (c {{$.Node.Name}}) String() string {
return capnp.Client(c).String()
lthibault marked this conversation as resolved.
Show resolved Hide resolved
}

// AddRef creates a new Client that refers to the same capability as c.
// If c is nil or has resolved to null, then AddRef returns nil.
func (c {{$.Node.Name}}) AddRef() {{$.Node.Name}} {
return {{$.Node.Name}}(capnp.Client(c).AddRef())
}

// Release releases a capability reference. If this is the last
// reference to the capability, then the underlying resources associated
// with the capability will be released.
//
// Release will panic if c has already been released, but not if c is
// nil or resolved to null.
func (c {{$.Node.Name}}) Release() {
capnp.Client(c).Release()
}

// Resolve blocks until the capability is fully resolved or the Context
// expires.
func (c {{$.Node.Name}}) Resolve(ctx context.Context) error {
return capnp.Client(c).Resolve(ctx)
}

func (c {{$.Node.Name}}) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr {
return capnp.Client(c).EncodeAsPtr(seg)
}
Expand All @@ -37,6 +59,17 @@ func ({{$.Node.Name}}) DecodeFromPtr(p capnp.Ptr) {{$.Node.Name}} {
return {{$.Node.Name}}(capnp.Client{}.DecodeFromPtr(p))
}

// IsValid reports whether c is a valid reference to a capability.
// A reference is invalid if it is nil, has resolved to null, or has
// been released.
func (c {{$.Node.Name}}) IsValid() bool {
return capnp.Client(c).IsValid()
}

// Update the flowcontrol.FlowLimiter used to manage flow control for
// this client. This affects all future calls, but not calls already
// waiting to send. Passing nil sets the value to flowcontrol.NopLimiter,
// which is also the default.
func (c {{$.Node.Name}}) SetFlowLimiter(lim flowcontrol.FlowLimiter) {
lthibault marked this conversation as resolved.
Show resolved Hide resolved
capnp.Client(c).SetFlowLimiter(lim)
}