• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, uint32_t &value) const;
40     int32_t Get(const std::string &key, int64_t &value) const;
41     int32_t Get(const std::string &key, double &value) const;
42     int32_t Get(const std::string &key, std::string &value) const;
43     int32_t Set(const std::string &key, int32_t value);
44     int32_t Set(const std::string &key, uint32_t value);
45     int32_t Set(const std::string &key, int64_t value);
46     int32_t Set(const std::string &key, double value);
47     int32_t Set(const std::string &key, const std::string& value);
48 
49     bool Marshalling(Parcel &parcel) const override;
50 
51     static sptr<MapDataSequenceable> Unmarshalling(Parcel &parcel);
52 
53 private:
54     enum class MapDataType : int32_t {
55         I32,
56         I64,
57         F64,
58         STRING,
59         U32,
60     };
61     template<class T>
62     int32_t Get(const std::string &key, MapDataType type, T &value) const;
63     int32_t Set(const std::string &key, MapDataType type, const std::any& val);
64 
65     struct MapData {
66         std::any val;
67         MapDataType type;
68     };
69     std::map<std::string, struct MapData> datas_;
70     mutable std::mutex mtx_;
71 };
72 } // V1_0
73 } // Camera
74 } // HDI
75 } // OHOS
76 #endif // OHOS_HDI_MAP_DATA_H
77