Exported_h.template 2.6 KB

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