1686862fbSopenharmony_ci/*
2686862fbSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4686862fbSopenharmony_ci * you may not use this file except in compliance with the License.
5686862fbSopenharmony_ci * You may obtain a copy of the License at
6686862fbSopenharmony_ci *
7686862fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8686862fbSopenharmony_ci *
9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12686862fbSopenharmony_ci * See the License for the specific language governing permissions and
13686862fbSopenharmony_ci * limitations under the License.
14686862fbSopenharmony_ci */
15686862fbSopenharmony_ci#ifndef OHOS_DISTRIBUTEDWANT_WANT_PARAMS_H
16686862fbSopenharmony_ci#define OHOS_DISTRIBUTEDWANT_WANT_PARAMS_H
17686862fbSopenharmony_ci
18686862fbSopenharmony_ci#include <iostream>
19686862fbSopenharmony_ci#include <map>
20686862fbSopenharmony_ci#include <set>
21686862fbSopenharmony_ci#include <vector>
22686862fbSopenharmony_ci
23686862fbSopenharmony_ci#include "base_interfaces.h"
24686862fbSopenharmony_ci#include "parcel.h"
25686862fbSopenharmony_ci#include "refbase.h"
26686862fbSopenharmony_ci#include "want_params.h"
27686862fbSopenharmony_ci
28686862fbSopenharmony_cinamespace OHOS {
29686862fbSopenharmony_cinamespace DistributedSchedule {
30686862fbSopenharmony_ciclass DistributedUnsupportedData {
31686862fbSopenharmony_cipublic:
32686862fbSopenharmony_ci    std::u16string key;
33686862fbSopenharmony_ci    int type = 0;
34686862fbSopenharmony_ci    int size = 0;
35686862fbSopenharmony_ci    uint8_t *buffer = nullptr;
36686862fbSopenharmony_ci
37686862fbSopenharmony_ci    ~DistributedUnsupportedData();
38686862fbSopenharmony_ci
39686862fbSopenharmony_ci    DistributedUnsupportedData();
40686862fbSopenharmony_ci    DistributedUnsupportedData(const DistributedUnsupportedData& other);
41686862fbSopenharmony_ci    DistributedUnsupportedData(DistributedUnsupportedData&& other);
42686862fbSopenharmony_ci
43686862fbSopenharmony_ci    DistributedUnsupportedData& operator=(const DistributedUnsupportedData& other);
44686862fbSopenharmony_ci    DistributedUnsupportedData& operator=(DistributedUnsupportedData&& other);
45686862fbSopenharmony_ci};
46686862fbSopenharmony_ci
47686862fbSopenharmony_ciclass DistributedWantParams final : public Parcelable {
48686862fbSopenharmony_cipublic:
49686862fbSopenharmony_ci    DistributedWantParams() = default;
50686862fbSopenharmony_ci    DistributedWantParams(const DistributedWantParams& wantParams);
51686862fbSopenharmony_ci    inline ~DistributedWantParams()
52686862fbSopenharmony_ci    {}
53686862fbSopenharmony_ci    DistributedWantParams& operator=(const DistributedWantParams& other);
54686862fbSopenharmony_ci
55686862fbSopenharmony_ci    bool operator==(const DistributedWantParams& other);
56686862fbSopenharmony_ci
57686862fbSopenharmony_ci    static sptr<AAFwk::IInterface> GetInterfaceByType(int typeId, const std::string& value);
58686862fbSopenharmony_ci
59686862fbSopenharmony_ci    static bool CompareInterface(const sptr<AAFwk::IInterface> iIt1, const sptr<AAFwk::IInterface> iIt2, int typeId);
60686862fbSopenharmony_ci
61686862fbSopenharmony_ci    static int GetDataType(const sptr<AAFwk::IInterface> iIt);
62686862fbSopenharmony_ci
63686862fbSopenharmony_ci    static int GetNumberDataType(const sptr<AAFwk::IInterface> iIt);
64686862fbSopenharmony_ci
65686862fbSopenharmony_ci    static std::string GetStringByType(const sptr<AAFwk::IInterface> iIt, int typeId);
66686862fbSopenharmony_ci
67686862fbSopenharmony_ci    void SetParam(const std::string& key, AAFwk::IInterface* value);
68686862fbSopenharmony_ci
69686862fbSopenharmony_ci    sptr<AAFwk::IInterface> GetParam(const std::string& key) const;
70686862fbSopenharmony_ci
71686862fbSopenharmony_ci    const std::map<std::string, sptr<AAFwk::IInterface>>& GetParams() const;
72686862fbSopenharmony_ci
73686862fbSopenharmony_ci    const std::set<std::string> KeySet() const;
74686862fbSopenharmony_ci
75686862fbSopenharmony_ci    void Remove(const std::string& key);
76686862fbSopenharmony_ci
77686862fbSopenharmony_ci    bool HasParam(const std::string& key) const;
78686862fbSopenharmony_ci
79686862fbSopenharmony_ci    int Size() const;
80686862fbSopenharmony_ci
81686862fbSopenharmony_ci    bool IsEmpty() const;
82686862fbSopenharmony_ci
83686862fbSopenharmony_ci    virtual bool Marshalling(Parcel& parcel) const;
84686862fbSopenharmony_ci
85686862fbSopenharmony_ci    static DistributedWantParams* Unmarshalling(Parcel& parcel);
86686862fbSopenharmony_ci
87686862fbSopenharmony_ci    AAFwk::WantParams ToWantParams();
88686862fbSopenharmony_ci
89686862fbSopenharmony_ciprivate:
90686862fbSopenharmony_ci    static std::string BooleanQueryToStr(const sptr<AAFwk::IInterface> iIt);
91686862fbSopenharmony_ci    static std::string ByteQueryToStr(const sptr<AAFwk::IInterface> iIt);
92686862fbSopenharmony_ci    static std::string CharQueryToStr(const sptr<AAFwk::IInterface> iIt);
93686862fbSopenharmony_ci    static std::string ShortQueryToStr(const sptr<AAFwk::IInterface> iIt);
94686862fbSopenharmony_ci    static std::string IntegerQueryToStr(const sptr<AAFwk::IInterface> iIt);
95686862fbSopenharmony_ci    static std::string LongQueryToStr(const sptr<AAFwk::IInterface> iIt);
96686862fbSopenharmony_ci    static std::string FloatQueryToStr(const sptr<AAFwk::IInterface> iIt);
97686862fbSopenharmony_ci    static std::string DoubleQueryToStr(const sptr<AAFwk::IInterface> iIt);
98686862fbSopenharmony_ci    static std::string StringQueryToStr(const sptr<AAFwk::IInterface> iIt);
99686862fbSopenharmony_ci    static std::string ArrayQueryToStr(const sptr<AAFwk::IInterface> iIt);
100686862fbSopenharmony_ci    static std::string DistributedWantParamsQueryToStr(const sptr<AAFwk::IInterface> iIt);
101686862fbSopenharmony_ci
102686862fbSopenharmony_ci    static bool BooleanQueryEquals(const sptr<AAFwk::IInterface> iIt);
103686862fbSopenharmony_ci    static bool ByteQueryEquals(const sptr<AAFwk::IInterface> iIt);
104686862fbSopenharmony_ci    static bool CharQueryEquals(const sptr<AAFwk::IInterface> iIt);
105686862fbSopenharmony_ci    static bool StringQueryEquals(const sptr<AAFwk::IInterface> iIt);
106686862fbSopenharmony_ci    static bool ArrayQueryEquals(const sptr<AAFwk::IInterface> iIt);
107686862fbSopenharmony_ci    static bool DistributedWantParamsQueryEquals(const sptr<AAFwk::IInterface> iIt);
108686862fbSopenharmony_ci    static bool ShortQueryEquals(const sptr<AAFwk::IInterface> iIt);
109686862fbSopenharmony_ci    static bool IntegerQueryEquals(const sptr<AAFwk::IInterface> iIt);
110686862fbSopenharmony_ci    static bool LongQueryEquals(const sptr<AAFwk::IInterface> iIt);
111686862fbSopenharmony_ci    static bool FloatQueryEquals(const sptr<AAFwk::IInterface> iIt);
112686862fbSopenharmony_ci    static bool DoubleQueryEquals(const sptr<AAFwk::IInterface> iIt);
113686862fbSopenharmony_ci
114686862fbSopenharmony_ci    bool WriteArrayToParcel(Parcel& parcel, AAFwk::IArray* ao) const;
115686862fbSopenharmony_ci    bool ReadArrayToParcel(Parcel& parcel, int type, sptr<AAFwk::IArray>& ao);
116686862fbSopenharmony_ci    bool ReadFromParcel(Parcel& parcel);
117686862fbSopenharmony_ci    bool ReadFromParcelParam(Parcel& parcel, const std::string& key, int type);
118686862fbSopenharmony_ci    bool ReadFromParcelString(Parcel& parcel, const std::string& key);
119686862fbSopenharmony_ci    bool ReadFromParcelBool(Parcel& parcel, const std::string& key);
120686862fbSopenharmony_ci    bool ReadFromParcelInt8(Parcel& parcel, const std::string& key);
121686862fbSopenharmony_ci    bool ReadFromParcelChar(Parcel& parcel, const std::string& key);
122686862fbSopenharmony_ci    bool ReadFromParcelShort(Parcel& parcel, const std::string& key);
123686862fbSopenharmony_ci    bool ReadFromParcelInt(Parcel& parcel, const std::string& key);
124686862fbSopenharmony_ci    bool ReadFromParcelLong(Parcel& parcel, const std::string& key);
125686862fbSopenharmony_ci    bool ReadFromParcelFloat(Parcel& parcel, const std::string& key);
126686862fbSopenharmony_ci    bool ReadFromParcelDouble(Parcel& parcel, const std::string& key);
127686862fbSopenharmony_ci
128686862fbSopenharmony_ci    bool ReadFromParcelArrayString(Parcel& parcel, sptr<AAFwk::IArray>& ao);
129686862fbSopenharmony_ci    bool ReadFromParcelArrayBool(Parcel& parcel, sptr<AAFwk::IArray>& ao);
130686862fbSopenharmony_ci    bool ReadFromParcelArrayByte(Parcel& parcel, sptr<AAFwk::IArray>& ao);
131686862fbSopenharmony_ci    bool ReadFromParcelArrayChar(Parcel& parcel, sptr<AAFwk::IArray>& ao);
132686862fbSopenharmony_ci    bool ReadFromParcelArrayShort(Parcel& parcel, sptr<AAFwk::IArray>& ao);
133686862fbSopenharmony_ci
134686862fbSopenharmony_ci    bool ReadFromParcelArrayInt(Parcel& parcel, sptr<AAFwk::IArray>& ao);
135686862fbSopenharmony_ci    bool ReadFromParcelArrayLong(Parcel& parcel, sptr<AAFwk::IArray>& ao);
136686862fbSopenharmony_ci    bool ReadFromParcelArrayFloat(Parcel& parcel, sptr<AAFwk::IArray>& ao);
137686862fbSopenharmony_ci    bool ReadFromParcelArrayDouble(Parcel& parcel, sptr<AAFwk::IArray>& ao);
138686862fbSopenharmony_ci    bool ReadFromParcelWantParamWrapper(Parcel& parcel, const std::string& key, int type);
139686862fbSopenharmony_ci    bool ReadFromParcelFD(Parcel& parcel, const std::string& key);
140686862fbSopenharmony_ci    bool ReadFromParcelRemoteObject(Parcel& parcel, const std::string& key);
141686862fbSopenharmony_ci
142686862fbSopenharmony_ci    bool WriteArrayToParcelString(Parcel& parcel, AAFwk::IArray* ao) const;
143686862fbSopenharmony_ci    bool WriteArrayToParcelBool(Parcel& parcel, AAFwk::IArray* ao) const;
144686862fbSopenharmony_ci    bool WriteArrayToParcelByte(Parcel& parcel, AAFwk::IArray* ao) const;
145686862fbSopenharmony_ci    bool WriteArrayToParcelChar(Parcel& parcel, AAFwk::IArray* ao) const;
146686862fbSopenharmony_ci    bool WriteArrayToParcelShort(Parcel& parcel, AAFwk::IArray* ao) const;
147686862fbSopenharmony_ci    bool WriteArrayToParcelInt(Parcel& parcel, AAFwk::IArray* ao) const;
148686862fbSopenharmony_ci    bool WriteArrayToParcelLong(Parcel& parcel, AAFwk::IArray* ao) const;
149686862fbSopenharmony_ci    bool WriteArrayToParcelFloat(Parcel& parcel, AAFwk::IArray* ao) const;
150686862fbSopenharmony_ci    bool WriteArrayToParcelDouble(Parcel& parcel, AAFwk::IArray* ao) const;
151686862fbSopenharmony_ci
152686862fbSopenharmony_ci    bool WriteMarshalling(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
153686862fbSopenharmony_ci    bool WriteToParcelString(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
154686862fbSopenharmony_ci    bool WriteToParcelBool(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
155686862fbSopenharmony_ci    bool WriteToParcelByte(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
156686862fbSopenharmony_ci    bool WriteToParcelChar(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
157686862fbSopenharmony_ci    bool WriteToParcelShort(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
158686862fbSopenharmony_ci    bool WriteToParcelInt(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
159686862fbSopenharmony_ci    bool WriteToParcelLong(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
160686862fbSopenharmony_ci    bool WriteToParcelFloat(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
161686862fbSopenharmony_ci    bool WriteToParcelDouble(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
162686862fbSopenharmony_ci    bool WriteToParcelWantParams(Parcel& parcel, sptr<AAFwk::IInterface>& o) const;
163686862fbSopenharmony_ci    bool WriteToParcelFD(Parcel& parcel, const DistributedWantParams& value) const;
164686862fbSopenharmony_ci    bool WriteToParcelRemoteObject(Parcel& parcel, const DistributedWantParams& value) const;
165686862fbSopenharmony_ci
166686862fbSopenharmony_ci    bool DoMarshalling(Parcel& parcel) const;
167686862fbSopenharmony_ci    bool ReadUnsupportedData(Parcel& parcel, const std::string& key, int type);
168686862fbSopenharmony_ci
169686862fbSopenharmony_ci    bool NewArrayData(AAFwk::IArray* source, sptr<AAFwk::IArray>& dest);
170686862fbSopenharmony_ci    bool NewParams(const DistributedWantParams& source, DistributedWantParams& dest);
171686862fbSopenharmony_ci
172686862fbSopenharmony_ciprivate:
173686862fbSopenharmony_ci    enum {
174686862fbSopenharmony_ci        VALUE_TYPE_NULL = -1,
175686862fbSopenharmony_ci        VALUE_TYPE_BOOLEAN = 1,
176686862fbSopenharmony_ci        VALUE_TYPE_BYTE = 2,
177686862fbSopenharmony_ci        VALUE_TYPE_CHAR = 3,
178686862fbSopenharmony_ci        VALUE_TYPE_SHORT = 4,
179686862fbSopenharmony_ci        VALUE_TYPE_INT = 5,
180686862fbSopenharmony_ci        VALUE_TYPE_LONG = 6,
181686862fbSopenharmony_ci        VALUE_TYPE_FLOAT = 7,
182686862fbSopenharmony_ci        VALUE_TYPE_DOUBLE = 8,
183686862fbSopenharmony_ci        VALUE_TYPE_STRING = 9,
184686862fbSopenharmony_ci        VALUE_TYPE_CHARSEQUENCE = 10,
185686862fbSopenharmony_ci        VALUE_TYPE_BOOLEANARRAY = 11,
186686862fbSopenharmony_ci        VALUE_TYPE_BYTEARRAY = 12,
187686862fbSopenharmony_ci        VALUE_TYPE_CHARARRAY = 13,
188686862fbSopenharmony_ci        VALUE_TYPE_SHORTARRAY = 14,
189686862fbSopenharmony_ci        VALUE_TYPE_INTARRAY = 15,
190686862fbSopenharmony_ci        VALUE_TYPE_LONGARRAY = 16,
191686862fbSopenharmony_ci        VALUE_TYPE_FLOATARRAY = 17,
192686862fbSopenharmony_ci        VALUE_TYPE_DOUBLEARRAY = 18,
193686862fbSopenharmony_ci        VALUE_TYPE_STRINGARRAY = 19,
194686862fbSopenharmony_ci        VALUE_TYPE_CHARSEQUENCEARRAY = 20,
195686862fbSopenharmony_ci
196686862fbSopenharmony_ci        VALUE_TYPE_PARCELABLE = 21,
197686862fbSopenharmony_ci        VALUE_TYPE_PARCELABLEARRAY = 22,
198686862fbSopenharmony_ci        VALUE_TYPE_SERIALIZABLE = 23,
199686862fbSopenharmony_ci        VALUE_TYPE_LIST = 50,
200686862fbSopenharmony_ci
201686862fbSopenharmony_ci        VALUE_TYPE_WANTPARAMS = 101,
202686862fbSopenharmony_ci        VALUE_TYPE_ARRAY = 102,
203686862fbSopenharmony_ci        VALUE_TYPE_FD = 103,
204686862fbSopenharmony_ci        VALUE_TYPE_REMOTE_OBJECT = 104
205686862fbSopenharmony_ci    };
206686862fbSopenharmony_ci
207686862fbSopenharmony_ci    friend class DistributedWantParamWrapper;
208686862fbSopenharmony_ci    friend class DistributedWant;
209686862fbSopenharmony_ci    using InterfaceQueryToStrFunc = std::string (*)(const sptr<AAFwk::IInterface> iIt);
210686862fbSopenharmony_ci    using InterfaceQueryEqualsFunc = bool (*)(const sptr<AAFwk::IInterface> iIt);
211686862fbSopenharmony_ci    static std::map<int, InterfaceQueryToStrFunc> interfaceQueryToStrMap;
212686862fbSopenharmony_ci    static std::map<int, InterfaceQueryEqualsFunc> interfaceQueryEqualsMap;
213686862fbSopenharmony_ci
214686862fbSopenharmony_ci    // inner use function
215686862fbSopenharmony_ci    std::map<std::string, sptr<AAFwk::IInterface>> params_;
216686862fbSopenharmony_ci    std::map<std::string, int> fds_;
217686862fbSopenharmony_ci    std::vector<DistributedUnsupportedData> cachedUnsupportedData_;
218686862fbSopenharmony_ci};
219686862fbSopenharmony_ci} // namespace DistributedSchedule
220686862fbSopenharmony_ci} // namespace OHOS
221686862fbSopenharmony_ci#endif // OHOS_DISTRIBUTEDWANT_WANT_PARAMS_H