1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_CAMERA_DPS_METADATA_INFO_H
17 #define OHOS_CAMERA_DPS_METADATA_INFO_H
18 
19 #include <any>
20 #include <mutex>
21 #include <map>
22 #include "message_parcel.h"
23 
24 namespace OHOS {
25 namespace CameraStandard {
26 
27 enum DpsMetadataError {
28     DPS_METADATA_OK = 0,
29     DPS_METADATA_INTERNAL_ERROR,
30     DPS_METADATA_ERROR_NO_ENTRY,
31     DPS_METADATA_ERROR_TYPE_ERROR,
32     DPS_METADATA_ERROR_OUT_OF_RANGE
33 };
34 
35 const char* const DEFERRED_PROCESSING_TYPE_KEY = "deferredProcessingType";
36 
37 enum DeferredProcessingType {
38     DPS_BACKGROUND = 0,
39     DPS_OFFLINE,
40 };
41 
42 class DpsMetadata {
43 public:
44     DpsMetadataError ReadFromParcel(MessageParcel &parcel);
45     DpsMetadataError WriteToParcel(MessageParcel &parcel);
46     DpsMetadataError Get(const std::string &key, int32_t &value) const;
47     DpsMetadataError Get(const std::string &key, int64_t &value) const;
48     DpsMetadataError Get(const std::string &key, double &value) const;
49     DpsMetadataError Get(const std::string &key, std::string &value) const;
50     DpsMetadataError Set(const std::string &key, int32_t value);
51     DpsMetadataError Set(const std::string &key, int64_t value);
52     DpsMetadataError Set(const std::string &key, double value);
53     DpsMetadataError Set(const std::string &key, const std::string& value);
54 
55 private:
56     enum class DpsDataType : int32_t {
57         i32,
58         i64,
59         f64,
60         string,
61     };
62     template<class T>
63     DpsMetadataError Get(const std::string &key, DpsDataType type, T &value) const;
64     DpsMetadataError Set(const std::string &key, DpsDataType type, const std::any& val);
65 
66     struct DpsData {
67         std::any val;
68         DpsDataType type;
69     };
70 
71     std::map<std::string, struct DpsData> datas;
72 };
73 
74 } // namespace CameraStandard
75 } // namespace OHOS
76 #endif // OHOS_CAMERA_DPS_METADATA_INFO_H