/*
 * AUTOGENERATED - DO NOT EDIT
 *
 * This file is generated from ext-workspace-v1.xml by mir_wayland_generator
 */

#include "ext-workspace-v1_wrapper.h"

#include <boost/exception/diagnostic_information.hpp>
#include <wayland-server-core.h>

#include "mir/wayland/protocol_error.h"
#include "mir/wayland/client.h"

namespace mir
{
namespace wayland
{
extern struct wl_interface const ext_workspace_group_handle_v1_interface_data;
extern struct wl_interface const ext_workspace_handle_v1_interface_data;
extern struct wl_interface const ext_workspace_manager_v1_interface_data;
extern struct wl_interface const wl_output_interface_data;
}
}

namespace mw = mir::wayland;

namespace
{
struct wl_interface const* all_null_types [] {
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr};
}

// ExtWorkspaceManagerV1

struct mw::ExtWorkspaceManagerV1::Thunks
{
    static int const supported_version;

    static void commit_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        try
        {
            auto me = static_cast<ExtWorkspaceManagerV1*>(wl_resource_get_user_data(resource));
            me->commit();
        }
        catch(ProtocolError const& err)
        {
            wl_resource_post_error(err.resource(), err.code(), "%s", err.message());
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceManagerV1::commit()");
        }
    }

    static void stop_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        try
        {
            auto me = static_cast<ExtWorkspaceManagerV1*>(wl_resource_get_user_data(resource));
            me->stop();
        }
        catch(ProtocolError const& err)
        {
            wl_resource_post_error(err.resource(), err.code(), "%s", err.message());
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceManagerV1::stop()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<ExtWorkspaceManagerV1*>(wl_resource_get_user_data(resource));
    }

    static void bind_thunk(struct wl_client* client, void* data, uint32_t version, uint32_t id)
    {
        auto me = static_cast<ExtWorkspaceManagerV1::Global*>(data);
        auto resource = wl_resource_create(
            client,
            &ext_workspace_manager_v1_interface_data,
            std::min((int)version, Thunks::supported_version),
            id);
        if (resource == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->bind(resource);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceManagerV1 global bind");
        }
    }

    static struct wl_interface const* workspace_group_types[];
    static struct wl_interface const* workspace_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::ExtWorkspaceManagerV1::Thunks::supported_version = 1;

mw::ExtWorkspaceManagerV1::ExtWorkspaceManagerV1(struct wl_resource* resource, Version<1>)
    : Resource{resource}
{
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

mw::ExtWorkspaceManagerV1::~ExtWorkspaceManagerV1()
{
    wl_resource_set_implementation(resource, nullptr, nullptr, nullptr);
}

void mw::ExtWorkspaceManagerV1::send_workspace_group_event(struct wl_resource* workspace_group) const
{
    wl_resource_post_event(resource, Opcode::workspace_group, workspace_group);
}

void mw::ExtWorkspaceManagerV1::send_workspace_event(struct wl_resource* workspace) const
{
    wl_resource_post_event(resource, Opcode::workspace, workspace);
}

void mw::ExtWorkspaceManagerV1::send_done_event() const
{
    wl_resource_post_event(resource, Opcode::done);
}

void mw::ExtWorkspaceManagerV1::send_finished_event() const
{
    wl_resource_post_event(resource, Opcode::finished);
}

bool mw::ExtWorkspaceManagerV1::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &ext_workspace_manager_v1_interface_data, Thunks::request_vtable);
}

void mw::ExtWorkspaceManagerV1::destroy_and_delete() const
{
    // Will result in this object being deleted
    wl_resource_destroy(resource);
}

mw::ExtWorkspaceManagerV1::Global::Global(wl_display* display, Version<1>)
    : wayland::Global{
          wl_global_create(
              display,
              &ext_workspace_manager_v1_interface_data,
              Thunks::supported_version,
              this,
              &Thunks::bind_thunk)}
{
}

auto mw::ExtWorkspaceManagerV1::Global::interface_name() const -> char const*
{
    return ExtWorkspaceManagerV1::interface_name;
}

struct wl_interface const* mw::ExtWorkspaceManagerV1::Thunks::workspace_group_types[] {
    &ext_workspace_group_handle_v1_interface_data};

struct wl_interface const* mw::ExtWorkspaceManagerV1::Thunks::workspace_types[] {
    &ext_workspace_handle_v1_interface_data};

struct wl_message const mw::ExtWorkspaceManagerV1::Thunks::request_messages[] {
    {"commit", "", all_null_types},
    {"stop", "", all_null_types}};

struct wl_message const mw::ExtWorkspaceManagerV1::Thunks::event_messages[] {
    {"workspace_group", "n", workspace_group_types},
    {"workspace", "n", workspace_types},
    {"done", "", all_null_types},
    {"finished", "", all_null_types}};

void const* mw::ExtWorkspaceManagerV1::Thunks::request_vtable[] {
    (void*)Thunks::commit_thunk,
    (void*)Thunks::stop_thunk};

mw::ExtWorkspaceManagerV1* mw::ExtWorkspaceManagerV1::from(struct wl_resource* resource)
{
    if (resource &&
        wl_resource_instance_of(resource, &ext_workspace_manager_v1_interface_data, ExtWorkspaceManagerV1::Thunks::request_vtable))
    {
        return static_cast<ExtWorkspaceManagerV1*>(wl_resource_get_user_data(resource));
    }
    else
    {
        return nullptr;
    }
}

// ExtWorkspaceGroupHandleV1

struct mw::ExtWorkspaceGroupHandleV1::Thunks
{
    static int const supported_version;

    static void create_workspace_thunk(struct wl_client* client, struct wl_resource* resource, char const* workspace)
    {
        try
        {
            auto me = static_cast<ExtWorkspaceGroupHandleV1*>(wl_resource_get_user_data(resource));
            me->create_workspace(workspace);
        }
        catch(ProtocolError const& err)
        {
            wl_resource_post_error(err.resource(), err.code(), "%s", err.message());
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceGroupHandleV1::create_workspace()");
        }
    }

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        try
        {
            auto me = static_cast<ExtWorkspaceGroupHandleV1*>(wl_resource_get_user_data(resource));
            me->destroy();
            wl_resource_destroy(resource);
        }
        catch(ProtocolError const& err)
        {
            wl_resource_post_error(err.resource(), err.code(), "%s", err.message());
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceGroupHandleV1::destroy()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<ExtWorkspaceGroupHandleV1*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* output_enter_types[];
    static struct wl_interface const* output_leave_types[];
    static struct wl_interface const* workspace_enter_types[];
    static struct wl_interface const* workspace_leave_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::ExtWorkspaceGroupHandleV1::Thunks::supported_version = 1;

mw::ExtWorkspaceGroupHandleV1::ExtWorkspaceGroupHandleV1(ExtWorkspaceManagerV1 const& parent)
    : Resource{wl_resource_create(
          wl_resource_get_client(parent.resource),
          &ext_workspace_group_handle_v1_interface_data,
          wl_resource_get_version(parent.resource), 0)}
{
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

mw::ExtWorkspaceGroupHandleV1::~ExtWorkspaceGroupHandleV1()
{
    wl_resource_set_implementation(resource, nullptr, nullptr, nullptr);
}

void mw::ExtWorkspaceGroupHandleV1::send_capabilities_event(uint32_t capabilities) const
{
    wl_resource_post_event(resource, Opcode::capabilities, capabilities);
}

void mw::ExtWorkspaceGroupHandleV1::send_output_enter_event(struct wl_resource* output) const
{
    wl_resource_post_event(resource, Opcode::output_enter, output);
}

void mw::ExtWorkspaceGroupHandleV1::send_output_leave_event(struct wl_resource* output) const
{
    wl_resource_post_event(resource, Opcode::output_leave, output);
}

void mw::ExtWorkspaceGroupHandleV1::send_workspace_enter_event(struct wl_resource* workspace) const
{
    wl_resource_post_event(resource, Opcode::workspace_enter, workspace);
}

void mw::ExtWorkspaceGroupHandleV1::send_workspace_leave_event(struct wl_resource* workspace) const
{
    wl_resource_post_event(resource, Opcode::workspace_leave, workspace);
}

void mw::ExtWorkspaceGroupHandleV1::send_removed_event() const
{
    wl_resource_post_event(resource, Opcode::removed);
}

bool mw::ExtWorkspaceGroupHandleV1::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &ext_workspace_group_handle_v1_interface_data, Thunks::request_vtable);
}

uint32_t const mw::ExtWorkspaceGroupHandleV1::GroupCapabilities::create_workspace;

struct wl_interface const* mw::ExtWorkspaceGroupHandleV1::Thunks::output_enter_types[] {
    &wl_output_interface_data};

struct wl_interface const* mw::ExtWorkspaceGroupHandleV1::Thunks::output_leave_types[] {
    &wl_output_interface_data};

struct wl_interface const* mw::ExtWorkspaceGroupHandleV1::Thunks::workspace_enter_types[] {
    &ext_workspace_handle_v1_interface_data};

struct wl_interface const* mw::ExtWorkspaceGroupHandleV1::Thunks::workspace_leave_types[] {
    &ext_workspace_handle_v1_interface_data};

struct wl_message const mw::ExtWorkspaceGroupHandleV1::Thunks::request_messages[] {
    {"create_workspace", "s", all_null_types},
    {"destroy", "", all_null_types}};

struct wl_message const mw::ExtWorkspaceGroupHandleV1::Thunks::event_messages[] {
    {"capabilities", "u", all_null_types},
    {"output_enter", "o", output_enter_types},
    {"output_leave", "o", output_leave_types},
    {"workspace_enter", "o", workspace_enter_types},
    {"workspace_leave", "o", workspace_leave_types},
    {"removed", "", all_null_types}};

void const* mw::ExtWorkspaceGroupHandleV1::Thunks::request_vtable[] {
    (void*)Thunks::create_workspace_thunk,
    (void*)Thunks::destroy_thunk};

mw::ExtWorkspaceGroupHandleV1* mw::ExtWorkspaceGroupHandleV1::from(struct wl_resource* resource)
{
    if (resource &&
        wl_resource_instance_of(resource, &ext_workspace_group_handle_v1_interface_data, ExtWorkspaceGroupHandleV1::Thunks::request_vtable))
    {
        return static_cast<ExtWorkspaceGroupHandleV1*>(wl_resource_get_user_data(resource));
    }
    else
    {
        return nullptr;
    }
}

// ExtWorkspaceHandleV1

struct mw::ExtWorkspaceHandleV1::Thunks
{
    static int const supported_version;

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        try
        {
            auto me = static_cast<ExtWorkspaceHandleV1*>(wl_resource_get_user_data(resource));
            me->destroy();
            wl_resource_destroy(resource);
        }
        catch(ProtocolError const& err)
        {
            wl_resource_post_error(err.resource(), err.code(), "%s", err.message());
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceHandleV1::destroy()");
        }
    }

    static void activate_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        try
        {
            auto me = static_cast<ExtWorkspaceHandleV1*>(wl_resource_get_user_data(resource));
            me->activate();
        }
        catch(ProtocolError const& err)
        {
            wl_resource_post_error(err.resource(), err.code(), "%s", err.message());
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceHandleV1::activate()");
        }
    }

    static void deactivate_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        try
        {
            auto me = static_cast<ExtWorkspaceHandleV1*>(wl_resource_get_user_data(resource));
            me->deactivate();
        }
        catch(ProtocolError const& err)
        {
            wl_resource_post_error(err.resource(), err.code(), "%s", err.message());
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceHandleV1::deactivate()");
        }
    }

    static void assign_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* workspace_group)
    {
        try
        {
            auto me = static_cast<ExtWorkspaceHandleV1*>(wl_resource_get_user_data(resource));
            me->assign(workspace_group);
        }
        catch(ProtocolError const& err)
        {
            wl_resource_post_error(err.resource(), err.code(), "%s", err.message());
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceHandleV1::assign()");
        }
    }

    static void remove_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        try
        {
            auto me = static_cast<ExtWorkspaceHandleV1*>(wl_resource_get_user_data(resource));
            me->remove();
        }
        catch(ProtocolError const& err)
        {
            wl_resource_post_error(err.resource(), err.code(), "%s", err.message());
        }
        catch(...)
        {
            internal_error_processing_request(client, "ExtWorkspaceHandleV1::remove()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<ExtWorkspaceHandleV1*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* assign_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::ExtWorkspaceHandleV1::Thunks::supported_version = 1;

mw::ExtWorkspaceHandleV1::ExtWorkspaceHandleV1(ExtWorkspaceManagerV1 const& parent)
    : Resource{wl_resource_create(
          wl_resource_get_client(parent.resource),
          &ext_workspace_handle_v1_interface_data,
          wl_resource_get_version(parent.resource), 0)}
{
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

mw::ExtWorkspaceHandleV1::~ExtWorkspaceHandleV1()
{
    wl_resource_set_implementation(resource, nullptr, nullptr, nullptr);
}

void mw::ExtWorkspaceHandleV1::send_id_event(std::string const& id) const
{
    const char* id_resolved = id.c_str();
    wl_resource_post_event(resource, Opcode::id, id_resolved);
}

void mw::ExtWorkspaceHandleV1::send_name_event(std::string const& name) const
{
    const char* name_resolved = name.c_str();
    wl_resource_post_event(resource, Opcode::name, name_resolved);
}

void mw::ExtWorkspaceHandleV1::send_coordinates_event(struct wl_array* coordinates) const
{
    wl_resource_post_event(resource, Opcode::coordinates, coordinates);
}

void mw::ExtWorkspaceHandleV1::send_state_event(uint32_t state) const
{
    wl_resource_post_event(resource, Opcode::state, state);
}

void mw::ExtWorkspaceHandleV1::send_capabilities_event(uint32_t capabilities) const
{
    wl_resource_post_event(resource, Opcode::capabilities, capabilities);
}

void mw::ExtWorkspaceHandleV1::send_removed_event() const
{
    wl_resource_post_event(resource, Opcode::removed);
}

bool mw::ExtWorkspaceHandleV1::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &ext_workspace_handle_v1_interface_data, Thunks::request_vtable);
}

uint32_t const mw::ExtWorkspaceHandleV1::State::active;
uint32_t const mw::ExtWorkspaceHandleV1::State::urgent;
uint32_t const mw::ExtWorkspaceHandleV1::State::hidden;
uint32_t const mw::ExtWorkspaceHandleV1::WorkspaceCapabilities::activate;
uint32_t const mw::ExtWorkspaceHandleV1::WorkspaceCapabilities::deactivate;
uint32_t const mw::ExtWorkspaceHandleV1::WorkspaceCapabilities::remove;
uint32_t const mw::ExtWorkspaceHandleV1::WorkspaceCapabilities::assign;

struct wl_interface const* mw::ExtWorkspaceHandleV1::Thunks::assign_types[] {
    &ext_workspace_group_handle_v1_interface_data};

struct wl_message const mw::ExtWorkspaceHandleV1::Thunks::request_messages[] {
    {"destroy", "", all_null_types},
    {"activate", "", all_null_types},
    {"deactivate", "", all_null_types},
    {"assign", "o", assign_types},
    {"remove", "", all_null_types}};

struct wl_message const mw::ExtWorkspaceHandleV1::Thunks::event_messages[] {
    {"id", "s", all_null_types},
    {"name", "s", all_null_types},
    {"coordinates", "a", all_null_types},
    {"state", "u", all_null_types},
    {"capabilities", "u", all_null_types},
    {"removed", "", all_null_types}};

void const* mw::ExtWorkspaceHandleV1::Thunks::request_vtable[] {
    (void*)Thunks::destroy_thunk,
    (void*)Thunks::activate_thunk,
    (void*)Thunks::deactivate_thunk,
    (void*)Thunks::assign_thunk,
    (void*)Thunks::remove_thunk};

mw::ExtWorkspaceHandleV1* mw::ExtWorkspaceHandleV1::from(struct wl_resource* resource)
{
    if (resource &&
        wl_resource_instance_of(resource, &ext_workspace_handle_v1_interface_data, ExtWorkspaceHandleV1::Thunks::request_vtable))
    {
        return static_cast<ExtWorkspaceHandleV1*>(wl_resource_get_user_data(resource));
    }
    else
    {
        return nullptr;
    }
}

namespace mir
{
namespace wayland
{

struct wl_interface const ext_workspace_manager_v1_interface_data {
    mw::ExtWorkspaceManagerV1::interface_name,
    mw::ExtWorkspaceManagerV1::Thunks::supported_version,
    2, mw::ExtWorkspaceManagerV1::Thunks::request_messages,
    4, mw::ExtWorkspaceManagerV1::Thunks::event_messages};

struct wl_interface const ext_workspace_group_handle_v1_interface_data {
    mw::ExtWorkspaceGroupHandleV1::interface_name,
    mw::ExtWorkspaceGroupHandleV1::Thunks::supported_version,
    2, mw::ExtWorkspaceGroupHandleV1::Thunks::request_messages,
    6, mw::ExtWorkspaceGroupHandleV1::Thunks::event_messages};

struct wl_interface const ext_workspace_handle_v1_interface_data {
    mw::ExtWorkspaceHandleV1::interface_name,
    mw::ExtWorkspaceHandleV1::Thunks::supported_version,
    5, mw::ExtWorkspaceHandleV1::Thunks::request_messages,
    6, mw::ExtWorkspaceHandleV1::Thunks::event_messages};

}
}
