• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //* Copyright 2019 The Dawn Authors
2 //*
3 //* Licensed under the Apache License, Version 2.0 (the "License");
4 //* you may not use this file except in compliance with the License.
5 //* You may obtain a copy of the License at
6 //*
7 //*     http://www.apache.org/licenses/LICENSE-2.0
8 //*
9 //* Unless required by applicable law or agreed to in writing, software
10 //* distributed under the License is distributed on an "AS IS" BASIS,
11 //* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //* See the License for the specific language governing permissions and
13 //* limitations under the License.
14 
15 #ifndef DAWNWIRE_CLIENT_CLIENTBASE_AUTOGEN_H_
16 #define DAWNWIRE_CLIENT_CLIENTBASE_AUTOGEN_H_
17 
18 #include "dawn_wire/ChunkedCommandHandler.h"
19 #include "dawn_wire/WireCmd_autogen.h"
20 #include "dawn_wire/client/ApiObjects.h"
21 #include "dawn_wire/client/ObjectAllocator.h"
22 
23 namespace dawn_wire { namespace client {
24 
25     class ClientBase : public ChunkedCommandHandler, public ObjectIdProvider {
26       public:
27         ClientBase() = default;
28         virtual ~ClientBase() = default;
29 
30         {% for type in by_category["object"] %}
31             const ObjectAllocator<{{type.name.CamelCase()}}>& {{type.name.CamelCase()}}Allocator() const {
32                 return m{{type.name.CamelCase()}}Allocator;
33             }
34             ObjectAllocator<{{type.name.CamelCase()}}>& {{type.name.CamelCase()}}Allocator() {
35                 return m{{type.name.CamelCase()}}Allocator;
36             }
37         {% endfor %}
38 
39         void FreeObject(ObjectType objectType, ObjectBase* obj) {
40             switch (objectType) {
41                 {% for type in by_category["object"] %}
42                     case ObjectType::{{type.name.CamelCase()}}:
43                         m{{type.name.CamelCase()}}Allocator.Free(static_cast<{{type.name.CamelCase()}}*>(obj));
44                         break;
45                 {% endfor %}
46             }
47         }
48 
49       private:
50         // Implementation of the ObjectIdProvider interface
51         {% for type in by_category["object"] %}
52             WireResult GetId({{as_cType(type.name)}} object, ObjectId* out) const final {
53                 ASSERT(out != nullptr);
54                 if (object == nullptr) {
55                     return WireResult::FatalError;
56                 }
57                 *out = reinterpret_cast<{{as_wireType(type)}}>(object)->id;
58                 return WireResult::Success;
59             }
60             WireResult GetOptionalId({{as_cType(type.name)}} object, ObjectId* out) const final {
61                 ASSERT(out != nullptr);
62                 *out = (object == nullptr ? 0 : reinterpret_cast<{{as_wireType(type)}}>(object)->id);
63                 return WireResult::Success;
64             }
65         {% endfor %}
66 
67         {% for type in by_category["object"] %}
68             ObjectAllocator<{{type.name.CamelCase()}}> m{{type.name.CamelCase()}}Allocator;
69         {% endfor %}
70     };
71 
72 }}  // namespace dawn_wire::client
73 
74 #endif  // DAWNWIRE_CLIENT_CLIENTBASE_AUTOGEN_H_
75