Yavor Goulishev | 9c08e84 | 2020-04-29 14:03:33 -0700 | [diff] [blame^] | 1 | // This file is generated by Exported_h.template. |
Andrew Top | 286dd78 | 2018-10-02 16:52:45 -0700 | [diff] [blame] | 2 | |
| 3 | // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | |
| 7 | #ifndef {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_api_h |
| 8 | #define {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_api_h |
| 9 | |
| 10 | {% if config.exported.export_header %} |
| 11 | #include {{format_include(config.exported.export_header)}} |
| 12 | {% endif %} |
| 13 | #include {{format_include(config.exported.string_header)}} |
| 14 | |
| 15 | {% for namespace in config.protocol.namespace %} |
| 16 | namespace {{namespace}} { |
| 17 | {% endfor %} |
Yavor Goulishev | 9c08e84 | 2020-04-29 14:03:33 -0700 | [diff] [blame^] | 18 | |
| 19 | #ifndef {{"_".join(config.protocol.namespace)}}_exported_api_h |
| 20 | #define {{"_".join(config.protocol.namespace)}}_exported_api_h |
| 21 | class {{config.exported.export_macro}} Exported { |
| 22 | public: |
| 23 | virtual {{config.exported.string_out}} toJSONString() const = 0; |
| 24 | virtual void writeBinary(std::vector<uint8_t>* out) const = 0; |
| 25 | virtual ~Exported() { } |
| 26 | }; |
| 27 | #endif // !defined({{"_".join(config.protocol.namespace)}}_exported_api_h) |
| 28 | |
Andrew Top | 286dd78 | 2018-10-02 16:52:45 -0700 | [diff] [blame] | 29 | namespace {{domain.domain}} { |
| 30 | namespace API { |
| 31 | |
| 32 | // ------------- Enums. |
| 33 | {% for type in domain.types %} |
| 34 | {% if ("enum" in type) and protocol.is_exported(domain.domain, type.id) %} |
| 35 | |
| 36 | namespace {{type.id}}Enum { |
| 37 | {% for literal in type.enum %} |
| 38 | {{config.exported.export_macro}} extern const char* {{ literal | dash_to_camelcase}}; |
| 39 | {% endfor %} |
| 40 | } // {{type.id}}Enum |
| 41 | {% endif %} |
| 42 | {% endfor %} |
| 43 | {% for command in join_arrays(domain, ["commands", "events"]) %} |
| 44 | {% for param in join_arrays(command, ["parameters", "returns"]) %} |
| 45 | {% if ("enum" in param) and protocol.is_exported(domain.domain, command.name + "." + param.name) %} |
| 46 | |
| 47 | namespace {{command.name | to_title_case}} { |
| 48 | namespace {{param.name | to_title_case}}Enum { |
| 49 | {% for literal in param.enum %} |
| 50 | {{config.exported.export_macro}} extern const char* {{ literal | dash_to_camelcase}}; |
| 51 | {% endfor %} |
| 52 | } // {{param.name | to_title_case}}Enum |
| 53 | } // {{command.name | to_title_case }} |
| 54 | {% endif %} |
| 55 | {% endfor %} |
| 56 | {% endfor %} |
| 57 | |
| 58 | // ------------- Types. |
| 59 | {% for type in domain.types %} |
| 60 | {% if not (type.type == "object") or not ("properties" in type) or not protocol.is_exported(domain.domain, type.id) %}{% continue %}{% endif %} |
| 61 | |
Yavor Goulishev | 9c08e84 | 2020-04-29 14:03:33 -0700 | [diff] [blame^] | 62 | class {{config.exported.export_macro}} {{type.id}} : public Exported { |
Andrew Top | 286dd78 | 2018-10-02 16:52:45 -0700 | [diff] [blame] | 63 | public: |
Andrew Top | 286dd78 | 2018-10-02 16:52:45 -0700 | [diff] [blame] | 64 | static std::unique_ptr<protocol::{{domain.domain}}::API::{{type.id}}> fromJSONString(const {{config.exported.string_in}}& json); |
Yavor Goulishev | 9c08e84 | 2020-04-29 14:03:33 -0700 | [diff] [blame^] | 65 | static std::unique_ptr<protocol::{{domain.domain}}::API::{{type.id}}> fromBinary(const uint8_t* data, size_t length); |
Andrew Top | 286dd78 | 2018-10-02 16:52:45 -0700 | [diff] [blame] | 66 | }; |
| 67 | {% endfor %} |
| 68 | |
| 69 | } // namespace API |
| 70 | } // namespace {{domain.domain}} |
| 71 | {% for namespace in config.protocol.namespace %} |
| 72 | } // namespace {{namespace}} |
| 73 | {% endfor %} |
| 74 | |
| 75 | #endif // !defined({{"_".join(config.protocol.namespace)}}_{{domain.domain}}_api_h) |