// Code generated by wlturbo-scanner. DO NOT EDIT. // Protocol: drm_lease_v1 // Source: drm-lease-v1.xml // Upstream protocol copyright and license: // Copyright © 2018 NXP // Copyright © 2019 Status Research & Development GmbH. // Copyright © 2021 Xaver Hugl // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice (including the next // paragraph) shall be included in all copies or substantial portions of the // Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. package drmlease import ( "sync" "github.com/bnema/wlturbo/wl" ) // ERROR_WRONG_DEVICE is the error wrong_device value. const ERROR_WRONG_DEVICE = 0 // ERROR_DUPLICATE_CONNECTOR is the error duplicate_connector value. const ERROR_DUPLICATE_CONNECTOR = 1 // ERROR_EMPTY_LEASE is the error empty_lease value. const ERROR_EMPTY_LEASE = 2 // WpDrmLeaseDeviceInterface is the protocol interface name. const WpDrmLeaseDeviceInterface = "wp_drm_lease_device_v1" // WpDrmLeaseDevice is the generated binding for wp_drm_lease_device_v1 version 1. type WpDrmLeaseDevice struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onDrmFd []func(fd *wl.OwnedFD) onConnector []func(idObject *WpDrmLeaseConnector) onDone []func() onReleased []func() } // NewWpDrmLeaseDevice returns an unbound WpDrmLeaseDevice. func NewWpDrmLeaseDevice(ctx *wl.Context) *WpDrmLeaseDevice { obj := &WpDrmLeaseDevice{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Creates a lease request object. See the documentation for wp_drm_lease_request_v1 for details. func (o *WpDrmLeaseDevice) CreateLeaseRequest() (*WpDrmLeaseRequest, error) { child := &WpDrmLeaseRequest{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "wp_drm_lease_device_v1.create_lease_request", Child: child}, wl.ArgObject(child)); err != nil { return nil, err } return child, nil } // Indicates the client no longer wishes to use this object. In response the compositor will immediately send the released event and destroy this object. It can however not guarantee that the client won't receive connector events before the released event. The client must not send any requests after this one, doing so will raise a wl_display error. Existing connectors, lease request and leases will not be affected. func (o *WpDrmLeaseDevice) Release() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "wp_drm_lease_device_v1.release"}); err != nil { return err } return nil } // OnDrmFd registers a handler for the drm_fd event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLeaseDevice) OnDrmFd(handler func(fd *wl.OwnedFD)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDrmFd = append(o.onDrmFd, handler) } // handlersForDrmFd returns the handlers registered for drm_fd, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLeaseDevice) handlersForDrmFd() []func(fd *wl.OwnedFD) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDrmFd } // OnConnector registers a handler for the connector event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLeaseDevice) OnConnector(handler func(idObject *WpDrmLeaseConnector)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onConnector = append(o.onConnector, handler) } // handlersForConnector returns the handlers registered for connector, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLeaseDevice) handlersForConnector() []func(idObject *WpDrmLeaseConnector) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onConnector } // OnDone registers a handler for the done event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLeaseDevice) OnDone(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDone = append(o.onDone, handler) } // handlersForDone returns the handlers registered for done, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLeaseDevice) handlersForDone() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDone } // OnReleased registers a handler for the released event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLeaseDevice) OnReleased(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onReleased = append(o.onReleased, handler) } // handlersForReleased returns the handlers registered for released, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLeaseDevice) handlersForReleased() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onReleased } // EventSignature returns the declared event argument types in wire order. func (o *WpDrmLeaseDevice) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "fd,", true case 1: return "new_id,", true case 2: return "", true case 3: return "", true default: return "", false } } // Dispatch decodes one event on wp_drm_lease_device_v1 and calls the registered handlers. func (o *WpDrmLeaseDevice) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // drm_fd fd := event.FD() ownedfd := fd defer ownedfd.Close() for i, handler := range o.handlersForDrmFd() { if i > 0 { fd = nil } handler(fd) } case 1: // connector idID := event.Uint32() idObject := &WpDrmLeaseConnector{} idObject.SetContext(o.Context()) idObject.SetID(idID) idObject.SetVersion(o.Version()) o.Context().Register(idObject) for i, handler := range o.handlersForConnector() { _ = i handler(idObject) } case 2: // done for i, handler := range o.handlersForDone() { _ = i handler() } case 3: // released for i, handler := range o.handlersForReleased() { _ = i handler() } o.Context().Unregister(o) default: } } // WpDrmLeaseConnectorInterface is the protocol interface name. const WpDrmLeaseConnectorInterface = "wp_drm_lease_connector_v1" // WpDrmLeaseConnector is the generated binding for wp_drm_lease_connector_v1 version 1. type WpDrmLeaseConnector struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onName []func(name string) onDescription []func(description string) onConnectorId []func(connectorId uint32) onDone []func() onWithdrawn []func() } // NewWpDrmLeaseConnector returns an unbound WpDrmLeaseConnector. func NewWpDrmLeaseConnector(ctx *wl.Context) *WpDrmLeaseConnector { obj := &WpDrmLeaseConnector{} obj.SetContext(ctx) ctx.Register(obj) return obj } // The client may send this request to indicate that it will not use this connector. Clients are encouraged to send this after receiving the "withdrawn" event so that the server can release the resources associated with this connector offer. Neither existing lease requests nor leases will be affected. func (o *WpDrmLeaseConnector) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "wp_drm_lease_connector_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnName registers a handler for the name event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLeaseConnector) OnName(handler func(name string)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onName = append(o.onName, handler) } // handlersForName returns the handlers registered for name, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLeaseConnector) handlersForName() []func(name string) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onName } // OnDescription registers a handler for the description event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLeaseConnector) OnDescription(handler func(description string)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDescription = append(o.onDescription, handler) } // handlersForDescription returns the handlers registered for description, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLeaseConnector) handlersForDescription() []func(description string) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDescription } // OnConnectorId registers a handler for the connector_id event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLeaseConnector) OnConnectorId(handler func(connectorId uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onConnectorId = append(o.onConnectorId, handler) } // handlersForConnectorId returns the handlers registered for connector_id, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLeaseConnector) handlersForConnectorId() []func(connectorId uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onConnectorId } // OnDone registers a handler for the done event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLeaseConnector) OnDone(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDone = append(o.onDone, handler) } // handlersForDone returns the handlers registered for done, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLeaseConnector) handlersForDone() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDone } // OnWithdrawn registers a handler for the withdrawn event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLeaseConnector) OnWithdrawn(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onWithdrawn = append(o.onWithdrawn, handler) } // handlersForWithdrawn returns the handlers registered for withdrawn, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLeaseConnector) handlersForWithdrawn() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onWithdrawn } // EventSignature returns the declared event argument types in wire order. func (o *WpDrmLeaseConnector) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "string,", true case 1: return "string,", true case 2: return "uint,", true case 3: return "", true case 4: return "", true default: return "", false } } // Dispatch decodes one event on wp_drm_lease_connector_v1 and calls the registered handlers. func (o *WpDrmLeaseConnector) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // name name := event.String() for i, handler := range o.handlersForName() { _ = i handler(name) } case 1: // description description := event.String() for i, handler := range o.handlersForDescription() { _ = i handler(description) } case 2: // connector_id connectorId := event.Uint32() for i, handler := range o.handlersForConnectorId() { _ = i handler(connectorId) } case 3: // done for i, handler := range o.handlersForDone() { _ = i handler() } case 4: // withdrawn for i, handler := range o.handlersForWithdrawn() { _ = i handler() } default: } } // WpDrmLeaseRequestInterface is the protocol interface name. const WpDrmLeaseRequestInterface = "wp_drm_lease_request_v1" // WpDrmLeaseRequest is the generated binding for wp_drm_lease_request_v1 version 1. type WpDrmLeaseRequest struct { wl.BaseProxy } // NewWpDrmLeaseRequest returns an unbound WpDrmLeaseRequest. func NewWpDrmLeaseRequest(ctx *wl.Context) *WpDrmLeaseRequest { obj := &WpDrmLeaseRequest{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Indicates that the client would like to lease the given connector. This is only used as a suggestion, the compositor may choose to include any resources in the lease it issues, or change the set of leased resources at any time. Compositors are however encouraged to include the requested connector and other resources necessary to drive the connected output in the lease. Requesting a connector that was created from a different lease device than this lease request raises the wrong_device error. Requesting a connector twice will raise the duplicate_connector error. func (o *WpDrmLeaseRequest) RequestConnector(connector *WpDrmLeaseConnector) error { var arg0 wl.Object if connector != nil { arg0 = connector } if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "wp_drm_lease_request_v1.request_connector"}, wl.ArgObject(arg0)); err != nil { return err } return nil } // Submits the lease request and creates a new wp_drm_lease_v1 object. After calling submit the compositor will immediately destroy this object, issuing any more requests will cause a wl_display error. The compositor doesn't make any guarantees about the events of the lease object, clients cannot expect an immediate response. Not requesting any connectors before submitting the lease request will raise the empty_lease error. func (o *WpDrmLeaseRequest) Submit() (*WpDrmLease, error) { child := &WpDrmLease{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "wp_drm_lease_request_v1.submit", Destructor: true, Child: child}, wl.ArgObject(child)); err != nil { return nil, err } return child, nil } // EventSignature returns the declared event argument types in wire order. func (o *WpDrmLeaseRequest) EventSignature(opcode uint16) (string, bool) { switch opcode { default: return "", false } } // Dispatch decodes one event on wp_drm_lease_request_v1 and calls the registered handlers. func (o *WpDrmLeaseRequest) Dispatch(event *wl.Event) { switch event.Opcode { default: } } // WpDrmLeaseInterface is the protocol interface name. const WpDrmLeaseInterface = "wp_drm_lease_v1" // WpDrmLease is the generated binding for wp_drm_lease_v1 version 1. type WpDrmLease struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onLeaseFd []func(leasedFd *wl.OwnedFD) onFinished []func() } // NewWpDrmLease returns an unbound WpDrmLease. func NewWpDrmLease(ctx *wl.Context) *WpDrmLease { obj := &WpDrmLease{} obj.SetContext(ctx) ctx.Register(obj) return obj } // The client should send this to indicate that it no longer wishes to use this lease. The compositor should use drmModeRevokeLease on the appropriate file descriptor, if necessary. Upon destruction, the compositor should advertise the connector for leasing again by sending the connector event through the wp_drm_lease_device_v1 interface. func (o *WpDrmLease) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "wp_drm_lease_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnLeaseFd registers a handler for the lease_fd event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLease) OnLeaseFd(handler func(leasedFd *wl.OwnedFD)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onLeaseFd = append(o.onLeaseFd, handler) } // handlersForLeaseFd returns the handlers registered for lease_fd, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLease) handlersForLeaseFd() []func(leasedFd *wl.OwnedFD) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onLeaseFd } // OnFinished registers a handler for the finished event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *WpDrmLease) OnFinished(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onFinished = append(o.onFinished, handler) } // handlersForFinished returns the handlers registered for finished, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpDrmLease) handlersForFinished() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onFinished } // EventSignature returns the declared event argument types in wire order. func (o *WpDrmLease) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "fd,", true case 1: return "", true default: return "", false } } // Dispatch decodes one event on wp_drm_lease_v1 and calls the registered handlers. func (o *WpDrmLease) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // lease_fd leasedFd := event.FD() ownedleasedFd := leasedFd defer ownedleasedFd.Close() for i, handler := range o.handlersForLeaseFd() { if i > 0 { leasedFd = nil } handler(leasedFd) } case 1: // finished for i, handler := range o.handlersForFinished() { _ = i handler() } default: } }