// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_ITEMS_H_ #define COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_ITEMS_H_ // Defines common templates that could be used to create device specific // capabilities and print tickets. #include <stddef.h> #include <optional> #include <utility> #include <vector> #include "base/check_op.h" #include "base/containers/contains.h" #include "components/cloud_devices/common/cloud_device_description.h" namespace cloud_devices { // All traits below specify how to serialize and validate capabilities and // ticket items. // Traits should have following methods: // // Returns true if capability semantically valid. // static bool IsValid(const Option&); // // // Returns json path relative to the root of CDD/CJT. // static std::string GetItemPath(); // // // Loads ticket item. Returns false if failed. // static bool Load(const base::Value::Dict& dict, ContentType* option); // // // Saves ticket item. // static void Save(ContentType option, base::Value::Dict* dict); // Represents a CDD capability that is stored as a JSON list // Ex: "<CAPABILITY_NAME>": [ {<VALUE>}, {<VALUE>}, {<VALUE>} ] // Option specifies data type for <VALUE>. // Traits specifies how <VALUE> is stored in JSON and semantic validation. template <class Option, class Traits> class ListCapability { … }; // Represents a CJT item that is stored as a JSON list. This works similarly to // ListCapability except it's used for ticket items instead of capabilities. template <class Option, class Traits> class ListTicketItem : public ListCapability<Option, Traits> { … }; // Represents CDD capability stored as JSON list with default_value value. // Ex: "<CAPABILITY_NAME>": { "option": [{ "is_default": true, <VALUE>}, // {<VALUE>} ]} // Option specifies data type for <VALUE>. // Traits specifies how <VALUE> is stored in JSON and semantic validation. template <class Option, class Traits> class SelectionCapability { … }; // Represents CDD capability that can be true or false. // Ex: "<CAPABILITY_NAME>": { "default_value": true } // Traits specifies how <VALUE> is stored in JSON and semantic validation. template <class Traits> class BooleanCapability { … }; // Represents CDD capability for which existence is only important. // Ex: "<CAPABILITY_NAME>": { } // Traits specifies how <VALUE> is stored in JSON and semantic validation. template <class Traits> class EmptyCapability { … }; // Represents an item that is of a specific value type. // Ex: "<CAPABILITY_NAME>": {<VALUE>} // Option specifies data type for <VALUE>. // Traits specifies how <VALUE> is stored in JSON and semantic validation. template <class Option, class Traits> class ValueCapability { … }; // Represents CJT items. // Ex: "<CAPABILITY_NAME>": {<VALUE>} // Option specifies data type for <VALUE>. // Traits specifies how <VALUE> is stored in JSON and semantic validation. template <class Option, class Traits> class TicketItem { … }; } // namespace cloud_devices #endif // COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_ITEMS_H_