• 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 #ifndef OHOS_DISTRIBUTEDWANT_WANT_PARAMS_H
16 #define OHOS_DISTRIBUTEDWANT_WANT_PARAMS_H
17 
18 #include <iostream>
19 #include <map>
20 #include <set>
21 #include <vector>
22 #include "base_interfaces.h"
23 #include "parcel.h"
24 #include "refbase.h"
25 #include "want_params.h"
26 
27 namespace OHOS {
28 namespace DistributedSchedule {
29 class DistributedUnsupportedData {
30 public:
31     std::u16string key;
32     int type = 0;
33     int size = 0;
34     uint8_t *buffer = nullptr;
35 
36     ~DistributedUnsupportedData();
37 
38     DistributedUnsupportedData();
39     DistributedUnsupportedData(const DistributedUnsupportedData& other);
40     DistributedUnsupportedData(DistributedUnsupportedData&& other);
41 
42     DistributedUnsupportedData& operator=(const DistributedUnsupportedData& other);
43     DistributedUnsupportedData& operator=(DistributedUnsupportedData&& other);
44 };
45 
46 class DistributedWantParams final : public Parcelable {
47 public:
48     DistributedWantParams() = default;
49     DistributedWantParams(const DistributedWantParams& wantParams);
~DistributedWantParams()50     inline ~DistributedWantParams()
51     {}
52     DistributedWantParams& operator=(const DistributedWantParams& other);
53 
54     bool operator==(const DistributedWantParams& other);
55 
56     static sptr<AAFwk::IInterface> GetInterfaceByType(int typeId, const std::string& value);
57 
58     static bool CompareInterface(const sptr<AAFwk::IInterface> iIt1, const sptr<AAFwk::IInterface> iIt2, int typeId);
59 
60     static bool CompareNumberInterface(const sptr<AAFwk::IInterface> iIt1,
61         const sptr<AAFwk::IInterface> iIt2, int typeId);
62 
63     static int GetDataType(const sptr<AAFwk::IInterface> iIt);
64 
65     static int GetNumberDataType(const sptr<AAFwk::IInterface> iIt);
66 
67     static std::string GetStringByType(const sptr<AAFwk::IInterface> iIt, int typeId);
68 
69     void SetParam(const std::string& key, AAFwk::IInterface* value);
70 
71     sptr<AAFwk::IInterface> GetParam(const std::string& key) const;
72 
73     const std::map<std::string, sptr<AAFwk::IInterface>>& GetParams() const;
74 
75     const std::set<std::string> KeySet() const;
76 
77     void Remove(const std::string& key);
78 
79     bool HasParam(const std::string& key) const;
80 
81     int Size() const;
82 
83     bool IsEmpty() const;
84 
85     virtual bool Marshalling(Parcel& parcel) const;
86 
87     static DistributedWantParams* Unmarshalling(Parcel& parcel);
88 
89     AAFwk::WantParams ToWantParams();
90 
91 private:
92     enum {
93         VALUE_TYPE_NULL = -1,
94         VALUE_TYPE_BOOLEAN = 1,
95         VALUE_TYPE_BYTE = 2,
96         VALUE_TYPE_CHAR = 3,
97         VALUE_TYPE_SHORT = 4,
98         VALUE_TYPE_INT = 5,
99         VALUE_TYPE_LONG = 6,
100         VALUE_TYPE_FLOAT = 7,
101         VALUE_TYPE_DOUBLE = 8,
102         VALUE_TYPE_STRING = 9,
103         VALUE_TYPE_CHARSEQUENCE = 10,
104         VALUE_TYPE_BOOLEANARRAY = 11,
105         VALUE_TYPE_BYTEARRAY = 12,
106         VALUE_TYPE_CHARARRAY = 13,
107         VALUE_TYPE_SHORTARRAY = 14,
108         VALUE_TYPE_INTARRAY = 15,
109         VALUE_TYPE_LONGARRAY = 16,
110         VALUE_TYPE_FLOATARRAY = 17,
111         VALUE_TYPE_DOUBLEARRAY = 18,
112         VALUE_TYPE_STRINGARRAY = 19,
113         VALUE_TYPE_CHARSEQUENCEARRAY = 20,
114 
115         VALUE_TYPE_PARCELABLE = 21,
116         VALUE_TYPE_PARCELABLEARRAY = 22,
117         VALUE_TYPE_SERIALIZABLE = 23,
118         VALUE_TYPE_LIST = 50,
119 
120         VALUE_TYPE_WANTPARAMS = 101,
121         VALUE_TYPE_ARRAY = 102,
122         VALUE_TYPE_FD = 103,
123         VALUE_TYPE_REMOTE_OBJECT = 104
124     };
125 
126     bool WriteArrayToParcel(Parcel& parcel, AAFwk::IArray* ao) const;
127     bool ReadArrayToParcel(Parcel& parcel, int type, sptr<AAFwk::IArray>& ao);
128     bool ReadFromParcel(Parcel& parcel);
129     bool ReadFromParcelParam(Parcel& parcel, const std::string& key, int type);
130     bool ReadFromParcelString(Parcel& parcel, const std::string& key);
131     bool ReadFromParcelBool(Parcel& parcel, const std::string& key);
132     bool ReadFromParcelInt8(Parcel& parcel, const std::string& key);
133     bool ReadFromParcelChar(Parcel& parcel, const std::string& key);
134     bool ReadFromParcelShort(Parcel& parcel, const std::string& key);
135     bool ReadFromParcelInt(Parcel& parcel, const std::string& key);
136     bool ReadFromParcelLong(Parcel& parcel, const std::string& key);
137     bool ReadFromParcelFloat(Parcel& parcel, const std::string& key);
138     bool ReadFromParcelDouble(Parcel& parcel, const std::string& key);
139 
140     bool ReadFromParcelArrayString(Parcel& parcel, sptr<AAFwk::IArray>& ao);
141     bool ReadFromParcelArrayBool(Parcel& parcel, sptr<AAFwk::IArray>& ao);
142     bool ReadFromParcelArrayByte(Parcel& parcel, sptr<AAFwk::IArray>& ao);
143     bool ReadFromParcelArrayChar(Parcel& parcel, sptr<AAFwk::IArray>& ao);
144     bool ReadFromParcelArrayShort(Parcel& parcel, sptr<AAFwk::IArray>& ao);
145 
146     bool ReadFromParcelArrayInt(Parcel& parcel, sptr<AAFwk::IArray>& ao);
147     bool ReadFromParcelArrayLong(Parcel& parcel, sptr<AAFwk::IArray>& ao);
148     bool ReadFromParcelArrayFloat(Parcel& parcel, sptr<AAFwk::IArray>& ao);
149     bool ReadFromParcelArrayDouble(Parcel& parcel, sptr<AAFwk::IArray>& ao);
150     bool ReadFromParcelWantParamWrapper(Parcel& parcel, const std::string& key, int type);
151     bool ReadFromParcelFD(Parcel& parcel, const std::string& key);
152     bool ReadFromParcelRemoteObject(Parcel& parcel, const std::string& key);
153 
154     bool WriteArrayToParcelString(Parcel& parcel, AAFwk::IArray* ao) const;
155     bool WriteArrayToParcelBool(Parcel& parcel, AAFwk::IArray* ao) const;
156     bool WriteArrayToParcelByte(Parcel& parcel, AAFwk::IArray* ao) const;
157     bool WriteArrayToParcelChar(Parcel& parcel, AAFwk::IArray* ao) const;
158     bool WriteArrayToParcelShort(Parcel& parcel, AAFwk::IArray* ao) const;
159     bool WriteArrayToParcelInt(Parcel& parcel, AAFwk::IArray* ao) const;
160     bool WriteArrayToParcelLong(Parcel& parcel, AAFwk::IArray* ao) const;
161     bool WriteArrayToParcelFloat(Parcel& parcel, AAFwk::IArray* ao) const;
162     bool WriteArrayToParcelDouble(Parcel& parcel, AAFwk::IArray* ao) const;
163 
164     bool WriteMarshalling(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
165     bool WriteToParcelString(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
166     bool WriteToParcelBool(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
167     bool WriteToParcelByte(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
168     bool WriteToParcelChar(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
169     bool WriteToParcelShort(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
170     bool WriteToParcelInt(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
171     bool WriteToParcelLong(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
172     bool WriteToParcelFloat(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
173     bool WriteToParcelDouble(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
174     bool WriteToParcelWantParams(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
175     bool WriteToParcelFD(Parcel& parcel, const DistributedWantParams& value) const;
176     bool WriteToParcelRemoteObject(Parcel& parcel, const DistributedWantParams& value) const;
177 
178     bool DoMarshalling(Parcel& parcel) const;
179     bool ReadUnsupportedData(Parcel& parcel, const std::string& key, int type);
180 
181     friend class DistributedWantParamWrapper;
182     friend class DistributedWant;
183     // inner use function
184     bool NewArrayData(AAFwk::IArray* source, sptr<AAFwk::IArray>& dest);
185     bool NewParams(const DistributedWantParams& source, DistributedWantParams& dest);
186     std::map<std::string, sptr<AAFwk::IInterface>> params_;
187     std::map<std::string, int> fds_;
188     std::vector<DistributedUnsupportedData> cachedUnsupportedData_;
189 };
190 } // namespace DistributedSchedule
191 } // namespace OHOS
192 #endif // OHOS_DISTRIBUTEDWANT_WANT_PARAMS_H