chromium/ui/ozone/platform/wayland/test/server_object.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_SERVER_OBJECT_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_SERVER_OBJECT_H_

#include <memory>
#include <type_traits>
#include <utility>

#include <wayland-server-core.h>

#include "base/memory/raw_ptr.h"

struct wl_client;
struct wl_resource;

namespace wl {

// Base class for managing the life cycle of server objects.
class ServerObject {};

template <class T>
T* GetUserDataAs(wl_resource* resource) {}

template <class T>
std::unique_ptr<T> TakeUserDataAs(wl_resource* resource) {}

template <class T>
void DestroyUserData(wl_resource* resource) {}

template <class T>
void SetImplementation(wl_resource* resource,
                       const void* implementation,
                       std::unique_ptr<T> user_data) {}

template <typename ImplClass, typename... ImplArgs>
wl_resource* CreateResourceWithImpl(wl_client* client,
                                    const struct wl_interface* interface,
                                    int version,
                                    const void* implementation,
                                    uint32_t id,
                                    ImplArgs&&... impl_args) {}

// Does not transfer ownership of the user_data.  Use with caution.  The only
// legitimate purpose is setting more than one implementation to the same user
// data.
template <class T>
void SetImplementationUnretained(wl_resource* resource,
                                 const void* implementation,
                                 T* user_data) {}

bool ResourceHasImplementation(wl_resource* resource,
                               const wl_interface* interface,
                               const void* impl);

void DestroyResource(wl_client* client, wl_resource* resource);

}  // namespace wl

#endif  // UI_OZONE_PLATFORM_WAYLAND_TEST_SERVER_OBJECT_H_