2018-07-18 09:40:26 +00:00
|
|
|
//* Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//*
|
|
|
|
//* 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.
|
|
|
|
|
2018-07-26 13:07:57 +00:00
|
|
|
#ifndef DAWNWIRE_WIRECMD_AUTOGEN_H_
|
|
|
|
#define DAWNWIRE_WIRECMD_AUTOGEN_H_
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-26 13:07:57 +00:00
|
|
|
namespace dawn_wire {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-06-06 15:36:49 +00:00
|
|
|
using ObjectId = uint32_t;
|
|
|
|
using ObjectSerial = uint32_t;
|
|
|
|
|
|
|
|
enum class DeserializeResult {
|
|
|
|
Success,
|
|
|
|
FatalError,
|
|
|
|
ErrorObject,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Interface to allocate more space to deserialize pointed-to data.
|
|
|
|
// nullptr is treated as an error.
|
|
|
|
class DeserializeAllocator {
|
|
|
|
public:
|
|
|
|
virtual void* GetSpace(size_t size) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Interface to convert an ID to a server object, if possible.
|
|
|
|
// Methods return FatalError if the ID is for a non-existent object, ErrorObject if the
|
|
|
|
// object is an error value and Success otherwise.
|
|
|
|
class ObjectIdResolver {
|
|
|
|
public:
|
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
virtual DeserializeResult GetFromId(ObjectId id, {{as_cType(type.name)}}* out) const = 0;
|
2018-11-28 17:00:33 +00:00
|
|
|
virtual DeserializeResult GetOptionalFromId(ObjectId id, {{as_cType(type.name)}}* out) const = 0;
|
2018-06-06 15:36:49 +00:00
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Interface to convert a client object to its ID for the wiring.
|
|
|
|
class ObjectIdProvider {
|
|
|
|
public:
|
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
virtual ObjectId GetId({{as_cType(type.name)}} object) const = 0;
|
2018-11-28 17:00:33 +00:00
|
|
|
virtual ObjectId GetOptionalId({{as_cType(type.name)}} object) const = 0;
|
2018-06-06 15:36:49 +00:00
|
|
|
{% endfor %}
|
|
|
|
};
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
//* Enum used as a prefix to each command on the wire format.
|
|
|
|
enum class WireCmd : uint32_t {
|
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
{% for method in type.methods %}
|
|
|
|
{{as_MethodSuffix(type.name, method.name)}},
|
|
|
|
{% endfor %}
|
|
|
|
{{as_MethodSuffix(type.name, Name("destroy"))}},
|
|
|
|
{% endfor %}
|
2018-06-07 16:27:56 +00:00
|
|
|
BufferMapAsync,
|
|
|
|
BufferUpdateMappedDataCmd,
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
{% for method in type.methods %}
|
|
|
|
{% set Suffix = as_MethodSuffix(type.name, method.name) %}
|
2018-06-06 15:36:49 +00:00
|
|
|
{% set Cmd = Suffix + "Cmd" %}
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-18 13:28:38 +00:00
|
|
|
//* These are "structure" version of the list of arguments to the different Dawn methods.
|
2018-06-06 15:36:49 +00:00
|
|
|
//* They provide helpers to serialize/deserialize to/from a buffer.
|
|
|
|
struct {{Cmd}} {
|
|
|
|
//* From a filled structure, compute how much size will be used in the serialization buffer.
|
|
|
|
size_t GetRequiredSize() const;
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-06-06 15:36:49 +00:00
|
|
|
//* Serialize the structure and everything it points to into serializeBuffer which must be
|
|
|
|
//* big enough to contain all the data (as queried from GetRequiredSize).
|
|
|
|
void Serialize(char* serializeBuffer, const ObjectIdProvider& objectIdProvider) const;
|
|
|
|
|
|
|
|
//* Deserializes the structure from a buffer, consuming a maximum of *size bytes. When this
|
|
|
|
//* function returns, buffer and size will be updated by the number of bytes consumed to
|
|
|
|
//* deserialize the structure. Structures containing pointers will use allocator to get
|
|
|
|
//* scratch space to deserialize the pointed-to data.
|
|
|
|
//* Deserialize returns:
|
|
|
|
//* - Success if everything went well (yay!)
|
|
|
|
//* - FatalError is something bad happened (buffer too small for example)
|
|
|
|
//* - ErrorObject if one if the deserialized object is an error value, for the implementation
|
|
|
|
//* of the Maybe monad.
|
|
|
|
//* If the return value is not FatalError, selfId, resultId and resultSerial (if present) are
|
|
|
|
//* filled.
|
|
|
|
DeserializeResult Deserialize(const char** buffer, size_t* size, DeserializeAllocator* allocator, const ObjectIdResolver& resolver);
|
|
|
|
|
|
|
|
{{as_cType(type.name)}} self;
|
|
|
|
|
|
|
|
//* Command handlers want to know the object ID in addition to the backing object.
|
|
|
|
//* Doesn't need to be filled before Serialize, or GetRequiredSize.
|
|
|
|
ObjectId selfId;
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
//* Commands creating objects say which ID the created object will be referred as.
|
|
|
|
{% if method.return_type.category == "object" %}
|
2018-06-06 15:36:49 +00:00
|
|
|
ObjectId resultId;
|
|
|
|
ObjectSerial resultSerial;
|
2017-04-20 18:38:20 +00:00
|
|
|
{% endif %}
|
|
|
|
|
2018-06-06 15:36:49 +00:00
|
|
|
{% for arg in method.arguments %}
|
|
|
|
{{as_annotated_cType(arg)}};
|
2017-04-20 18:38:20 +00:00
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
//* The command structure used when sending that an ID is destroyed.
|
|
|
|
{% set Suffix = as_MethodSuffix(type.name, Name("destroy")) %}
|
|
|
|
struct {{Suffix}}Cmd {
|
2017-04-20 18:42:36 +00:00
|
|
|
WireCmd commandId = WireCmd::{{Suffix}};
|
2018-06-06 15:36:49 +00:00
|
|
|
ObjectId objectId;
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
2017-04-20 18:43:11 +00:00
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
{% endfor %}
|
|
|
|
|
2017-04-20 18:42:36 +00:00
|
|
|
//* Enum used as a prefix to each command on the return wire format.
|
|
|
|
enum class ReturnWireCmd : uint32_t {
|
|
|
|
DeviceErrorCallback,
|
2017-04-20 18:43:11 +00:00
|
|
|
{% for type in by_category["object"] if type.is_builder %}
|
|
|
|
{{type.name.CamelCase()}}ErrorCallback,
|
|
|
|
{% endfor %}
|
2017-06-09 14:51:55 +00:00
|
|
|
BufferMapReadAsyncCallback,
|
2018-06-07 16:27:56 +00:00
|
|
|
BufferMapWriteAsyncCallback,
|
2018-12-03 16:57:34 +00:00
|
|
|
FenceUpdateCompletedValue,
|
2017-04-20 18:42:36 +00:00
|
|
|
};
|
|
|
|
|
2018-06-06 15:36:49 +00:00
|
|
|
//* Command for the server calling a builder status callback.
|
2017-04-20 18:43:11 +00:00
|
|
|
{% for type in by_category["object"] if type.is_builder %}
|
|
|
|
struct Return{{type.name.CamelCase()}}ErrorCallbackCmd {
|
2018-07-26 13:07:57 +00:00
|
|
|
ReturnWireCmd commandId = ReturnWireCmd::{{type.name.CamelCase()}}ErrorCallback;
|
2017-04-20 18:43:11 +00:00
|
|
|
|
2018-06-06 15:36:49 +00:00
|
|
|
ObjectId builtObjectId;
|
|
|
|
ObjectSerial builtObjectSerial;
|
2017-04-20 18:43:11 +00:00
|
|
|
uint32_t status;
|
|
|
|
size_t messageStrlen;
|
|
|
|
};
|
|
|
|
{% endfor %}
|
|
|
|
|
2018-07-26 13:07:57 +00:00
|
|
|
} // namespace dawn_wire
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-26 13:07:57 +00:00
|
|
|
#endif // DAWNWIRE_WIRECMD_AUTOGEN_H_
|