diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2012-03-01 18:16:23 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2012-03-02 13:41:05 +0100 |
commit | 70e1dcbff0728ab19d741a77ecd5c9261c4922fe (patch) | |
tree | ec1c6a4be7dd88aafb2c9219c398c367ddb572fd /src/compositor/global | |
parent | 05eb5da1c80411242947a604fa41eaab7a0bd48f (diff) |
Improve wayland_cast and introduce resolve to simplify code.
Resolves the wl_resource by accessing the data member.
Change-Id: I10912acea0a3ca6abbc067d07d43a46ec65a77aa
Reviewed-by: Laszlo Agocs <laszlo.p.agocs@nokia.com>
Diffstat (limited to 'src/compositor/global')
-rw-r--r-- | src/compositor/global/waylandobject.h | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/compositor/global/waylandobject.h b/src/compositor/global/waylandobject.h index 32721df22..4cbe6da71 100644 --- a/src/compositor/global/waylandobject.h +++ b/src/compositor/global/waylandobject.h @@ -51,35 +51,45 @@ template <typename T> class Object { public: + typedef T Base; + Object() { memset(&m_waylandObject, 0, sizeof(T)); } const T *base() const { return &m_waylandObject; } T *base() { return &m_waylandObject; } + template <typename Implementation> + void addClientResource(wl_client *client, + wl_resource *resource, + int id, const struct wl_interface *interface, + Implementation implementation, + void (*destroy)(struct wl_resource *resource)) + { + resource->object.id = id; + resource->object.interface = interface; + resource->object.implementation = (void (**)(void))implementation; + resource->data = &m_waylandObject; + resource->destroy = destroy; + + wl_client_add_resource(client, resource); + } + private: T m_waylandObject; }; -template <typename To, typename From> -To wayland_cast(From *from) +template <typename T> +T *resolve(wl_resource *from) { - Object<From> *object = reinterpret_cast<Object<From> *>(from); - return static_cast<To>(object); + Object<typename T::Base> *object = reinterpret_cast<Object<typename T::Base> *>(from->data); + return static_cast<T *>(object); } -template <typename Implementation> -void addClientResource(struct wl_client *client, - struct wl_resource *resource, - int id, const struct wl_interface *interface, - Implementation implementation, - void (*destroy)(struct wl_resource *resource)) +template <typename T> +T *wayland_cast(typename T::Base *from) { - resource->object.id = id; - resource->object.interface = interface; - resource->object.implementation = (void (**)(void))implementation; - resource->destroy = destroy; - - wl_client_add_resource(client, resource); + Object<typename T::Base> *object = reinterpret_cast<Object<typename T::Base> *>(from); + return static_cast<T *>(object); } } |