2019-01-30 02:20:58 +00:00
|
|
|
//* Copyright 2019 The Dawn Authors
|
|
|
|
//*
|
|
|
|
//* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
//* you may not use this file except in compliance with the License.
|
|
|
|
//* You may obtain a copy of the License at
|
|
|
|
//*
|
|
|
|
//* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//*
|
|
|
|
//* Unless required by applicable law or agreed to in writing, software
|
|
|
|
//* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//* See the License for the specific language governing permissions and
|
|
|
|
//* limitations under the License.
|
|
|
|
|
|
|
|
#ifndef DAWNWIRE_SERVER_SERVERBASE_H_
|
|
|
|
#define DAWNWIRE_SERVER_SERVERBASE_H_
|
|
|
|
|
2019-10-15 11:44:38 +00:00
|
|
|
#include "dawn/dawn_proc_table.h"
|
2020-10-13 22:35:34 +00:00
|
|
|
#include "dawn_wire/ChunkedCommandHandler.h"
|
2019-01-30 02:20:58 +00:00
|
|
|
#include "dawn_wire/Wire.h"
|
|
|
|
#include "dawn_wire/WireCmd_autogen.h"
|
|
|
|
#include "dawn_wire/WireDeserializeAllocator.h"
|
|
|
|
#include "dawn_wire/server/ObjectStorage.h"
|
|
|
|
|
2022-01-11 09:57:33 +00:00
|
|
|
namespace dawn::wire::server {
|
2019-01-30 02:20:58 +00:00
|
|
|
|
2020-10-13 22:35:34 +00:00
|
|
|
class ServerBase : public ChunkedCommandHandler, public ObjectIdResolver {
|
2019-01-30 02:20:58 +00:00
|
|
|
public:
|
2019-01-30 17:37:28 +00:00
|
|
|
ServerBase() = default;
|
|
|
|
virtual ~ServerBase() = default;
|
2019-01-30 02:20:58 +00:00
|
|
|
|
2019-01-30 17:37:28 +00:00
|
|
|
protected:
|
2019-03-11 16:52:42 +00:00
|
|
|
void DestroyAllObjects(const DawnProcTable& procs) {
|
2019-04-01 21:04:17 +00:00
|
|
|
//* Free all objects when the server is destroyed
|
2021-01-13 20:58:18 +00:00
|
|
|
{% for type in by_category["object"] if type.name.get() != "device" %}
|
2019-01-30 02:20:58 +00:00
|
|
|
{
|
|
|
|
std::vector<{{as_cType(type.name)}}> handles = mKnown{{type.name.CamelCase()}}.AcquireAllHandles();
|
|
|
|
for ({{as_cType(type.name)}} handle : handles) {
|
2019-01-30 17:37:28 +00:00
|
|
|
procs.{{as_varName(type.name, Name("release"))}}(handle);
|
2019-01-30 02:20:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{% endfor %}
|
2021-01-13 20:58:18 +00:00
|
|
|
//* Release devices last because dawn_native requires this.
|
|
|
|
{
|
|
|
|
std::vector<WGPUDevice> handles = mKnownDevice.AcquireAllHandles();
|
|
|
|
for (WGPUDevice handle : handles) {
|
|
|
|
procs.deviceRelease(handle);
|
|
|
|
}
|
|
|
|
}
|
2019-01-30 02:20:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 17:37:28 +00:00
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
const KnownObjects<{{as_cType(type.name)}}>& {{type.name.CamelCase()}}Objects() const {
|
|
|
|
return mKnown{{type.name.CamelCase()}};
|
|
|
|
}
|
|
|
|
KnownObjects<{{as_cType(type.name)}}>& {{type.name.CamelCase()}}Objects() {
|
|
|
|
return mKnown{{type.name.CamelCase()}};
|
|
|
|
}
|
|
|
|
{% endfor %}
|
2019-01-30 02:20:58 +00:00
|
|
|
|
2019-01-30 17:37:28 +00:00
|
|
|
{% for type in by_category["object"] if type.name.CamelCase() in server_reverse_lookup_objects %}
|
|
|
|
const ObjectIdLookupTable<{{as_cType(type.name)}}>& {{type.name.CamelCase()}}ObjectIdTable() const {
|
|
|
|
return m{{type.name.CamelCase()}}IdTable;
|
|
|
|
}
|
|
|
|
ObjectIdLookupTable<{{as_cType(type.name)}}>& {{type.name.CamelCase()}}ObjectIdTable() {
|
|
|
|
return m{{type.name.CamelCase()}}IdTable;
|
|
|
|
}
|
|
|
|
{% endfor %}
|
2019-01-30 02:20:58 +00:00
|
|
|
|
2019-01-30 17:37:28 +00:00
|
|
|
private:
|
2019-01-30 02:20:58 +00:00
|
|
|
// Implementation of the ObjectIdResolver interface
|
|
|
|
{% for type in by_category["object"] %}
|
2021-02-25 20:21:25 +00:00
|
|
|
WireResult GetFromId(ObjectId id, {{as_cType(type.name)}}* out) const final {
|
2019-01-30 02:20:58 +00:00
|
|
|
auto data = mKnown{{type.name.CamelCase()}}.Get(id);
|
|
|
|
if (data == nullptr) {
|
2021-02-25 20:21:25 +00:00
|
|
|
return WireResult::FatalError;
|
2019-01-30 02:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*out = data->handle;
|
2021-02-25 20:21:25 +00:00
|
|
|
return WireResult::Success;
|
2019-01-30 02:20:58 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 20:21:25 +00:00
|
|
|
WireResult GetOptionalFromId(ObjectId id, {{as_cType(type.name)}}* out) const final {
|
2019-01-30 02:20:58 +00:00
|
|
|
if (id == 0) {
|
|
|
|
*out = nullptr;
|
2021-02-25 20:21:25 +00:00
|
|
|
return WireResult::Success;
|
2019-01-30 02:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GetFromId(id, out);
|
|
|
|
}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
//* The list of known IDs for each object type.
|
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
KnownObjects<{{as_cType(type.name)}}> mKnown{{type.name.CamelCase()}};
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% for type in by_category["object"] if type.name.CamelCase() in server_reverse_lookup_objects %}
|
|
|
|
ObjectIdLookupTable<{{as_cType(type.name)}}> m{{type.name.CamelCase()}}IdTable;
|
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
|
2022-01-11 09:57:33 +00:00
|
|
|
} // namespace dawn::wire::server
|
2019-01-30 02:20:58 +00:00
|
|
|
|
|
|
|
#endif // DAWNWIRE_SERVER_SERVERBASE_H_
|