// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_CLOUD_DEVICES_CAPABILITY_INTERFACES_H_ #define COMPONENTS_CLOUD_DEVICES_CAPABILITY_INTERFACES_H_ // Defines common templates that could be used to create device specific // capabilities and print tickets. #include #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "components/cloud_devices/cloud_device_description.h" namespace base { class DictionaryValue; } 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::DictionaryValue& dict, ContentType* option); // // // Saves ticket item. // static void Save(ContentType option, base::DictionaryValue* dict); // Represents a CDD capability that is stored as a JSON list // Ex: "": [ {}, {}, {} ] // Option specifies data type for . // Traits specifies how is stored in JSON and semantic validation. template class ListCapability { public: ListCapability(); ~ListCapability(); bool LoadFrom(const CloudDeviceDescription& description); void SaveTo(CloudDeviceDescription* description) const; void Reset() { options_.clear(); } bool IsValid() const; bool empty() const { return options_.empty(); } size_t size() const { return options_.size(); } const Option& operator[](size_t i) const { return options_[i]; } bool Contains(const Option& option) const{ return std::find(options_.begin(), options_.end(), option) != options_.end(); } void AddOption(const Option& option) { options_.push_back(option); } private: typedef std::vector