• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <map>
20 #include <optional>
21 
22 #include <json/json.h>
23 
24 namespace cuttlefish {
25 namespace webrtc_streaming {
26 
27 class ValidationResult {
28  public:
29   ValidationResult() = default;
ValidationResult(const std::string & error)30   ValidationResult(const std::string &error) : error_(error) {}
31 
32   // Helper method to ensure a json object has the required fields convertible
33   // to the appropriate types.
34   static ValidationResult ValidateJsonObject(
35       const Json::Value &obj, const std::string &type,
36       const std::map<std::string, Json::ValueType> &required_fields,
37       const std::map<std::string, Json::ValueType> &optional_fields = {});
38 
ok()39   bool ok() const { return !error_.has_value(); }
error()40   std::string error() const { return error_.value_or(""); }
41 
42  private:
43   std::optional<std::string> error_;
44 };
45 
46 }  // namespace webrtc_streaming
47 }  // namespace cuttlefish
48