1 /*
2  * Copyright (c) 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_HDI_MAP_DATA_H
17 #define OHOS_HDI_MAP_DATA_H
18 
19 #include <parcel.h>
20 #include <string>
21 #include <vector>
22 #include <any>
23 #include <map>
24 #include <mutex>
25 namespace OHOS {
26 namespace HDI {
27 namespace Camera {
28 namespace V1_0 {
29 using OHOS::Parcelable;
30 using OHOS::Parcel;
31 using OHOS::sptr;
32 
33 class MapDataSequenceable : public Parcelable {
34 public:
35     MapDataSequenceable() = default;
36     virtual ~MapDataSequenceable() = default;
37 
38     int32_t Get(const std::string &key, int32_t &value) const;
39     int32_t Get(const std::string &key, int64_t &value) const;
40     int32_t Get(const std::string &key, double &value) const;
41     int32_t Get(const std::string &key, std::string &value) const;
42     int32_t Set(const std::string &key, int32_t value);
43     int32_t Set(const std::string &key, int64_t value);
44     int32_t Set(const std::string &key, double value);
45     int32_t Set(const std::string &key, const std::string& value);
46 
47     bool Marshalling(Parcel &parcel) const override;
48 
49     static sptr<MapDataSequenceable> Unmarshalling(Parcel &parcel);
50 
51 private:
52     enum class MapDataType : int32_t {
53         I32,
54         I64,
55         F64,
56         STRING,
57     };
58     template<class T>
59     int32_t Get(const std::string &key, MapDataType type, T &value) const;
60     int32_t Set(const std::string &key, MapDataType type, const std::any& val);
61 
62     struct MapData {
63         std::any val;
64         MapDataType type;
65     };
66     std::map<std::string, struct MapData> datas_;
67     mutable std::mutex mtx_;
68 };
69 } // V1_0
70 } // Camera
71 } // HDI
72 } // OHOS
73 #endif // OHOS_HDI_MAP_DATA_H
74