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_WRAPPER_H
16 #define OHOS_DISTRIBUTEDWANT_WANT_PARAMS_WRAPPER_H
17 
18 #include "base_def.h"
19 #include "base_obj.h"
20 #include "distributed_want_params.h"
21 
22 using InterfaceID = OHOS::AAFwk::InterfaceID;
23 using IInterface = OHOS::AAFwk::IInterface;
24 namespace OHOS {
25 namespace DistributedSchedule {
26 class DistributedWantParams;
27 INTERFACE(IDistributedWantParams, a75b9db6 - 9813 - 4371 - 8848 - d2966ce6ec68)
28 {
Query(AAFwk::IInterface * object)29     inline static IDistributedWantParams* Query(AAFwk::IInterface* object)
30     {
31         if (object == nullptr) {
32             return nullptr;
33         }
34         return static_cast<IDistributedWantParams*>(object->Query(g_IID_IDistributedWantParams));
35     }
36 
37     virtual ErrCode GetValue(DistributedWantParams& value) = 0;
38 };
39 class DistributedWantParamWrapper final : public AAFwk::Object, public IDistributedWantParams {
40 public:
DistributedWantParamWrapper(const DistributedWantParams & value)41     inline DistributedWantParamWrapper(const DistributedWantParams& value) : wantParams_(value)
42     {}
43     /**
44      * @brief Constructor for move semantics
45      */
DistributedWantParamWrapper(DistributedWantParams && value)46     inline DistributedWantParamWrapper(DistributedWantParams&& value) : wantParams_(std::move(value))
47     {}
48 
~DistributedWantParamWrapper()49     inline ~DistributedWantParamWrapper()
50     {}
51 
52     IINTERFACE_DECL();
53 
54     ErrCode GetValue(DistributedWantParams& value) override;
55 
56     bool Equals(IObject& other) override;
57 
58     std::string ToString() override;
59 
60     static sptr<IDistributedWantParams> Box(const DistributedWantParams& value);
61     /**
62      * @brief Wrap a wantParam into a DistributedWantParamWrapper using move semantics and return the wrapper.
63      *
64      * @param value
65      * @return sptr<IDistributedWantParams>
66      */
67     static sptr<IDistributedWantParams> Box(DistributedWantParams&& value);
68 
69     static DistributedWantParams Unbox(IDistributedWantParams* object);
70 
71     static bool ValidateStr(const std::string& str);
72 
73     static size_t FindMatchingBrace(const std::string& str, size_t strnum);
74 
75     static sptr<IDistributedWantParams> Parse(const std::string& str);
76 
77     static int GerTypedId(const std::string& str, size_t& strnum);
78 
79     static DistributedWantParams ParseWantParams(const std::string& str);
80 
81     static constexpr char SIGNATURE = 'W';
82 
83 private:
84     DistributedWantParams wantParams_;
85 };
86 } // namespace DistributedSchedule
87 } // namespace OHOS
88 #endif // OHOS_DISTRIBUTEDWANT_WANT_PARAMS_WRAPPER_H