1 /*
2  * Copyright (c) 2021 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_ABILITY_RUNTIME_WANT_AGENT_H
17 #define OHOS_ABILITY_RUNTIME_WANT_AGENT_H
18 
19 #include <string>
20 #include <memory>
21 #include "parcel.h"
22 #include "pending_want.h"
23 #include "want.h"
24 #include "want_params.h"
25 
26 namespace OHOS::AbilityRuntime::WantAgent {
27 class WantAgent final : public std::enable_shared_from_this<WantAgent>, public Parcelable {
28 public:
WantAgent()29     WantAgent() {};
30     virtual ~WantAgent() = default;
31     /**
32      * Constructor.
33      *
34      * @param obj The proxy object.
35      */
36     explicit WantAgent(const std::shared_ptr<PendingWant> &pendingWant);
37 
38     /**
39      * Gets proxy obj.
40      *
41      * @return Return obj.
42      */
43     std::shared_ptr<PendingWant> GetPendingWant();
44 
45     /**
46      * Sets proxy obj.
47      *
48      * @param obj The proxy object.
49      */
50     void SetPendingWant(const std::shared_ptr<PendingWant> &pendingWant);
51 
52     /**
53      * @description: Marshals a Want into a Parcel.
54      * Fields in the Want are marshalled separately. If any field fails to be marshalled, false is returned.
55      * @param parcel Indicates the Parcel object for marshalling.
56      * @return Returns true if the marshalling is successful; returns false otherwise.
57      */
58     virtual bool Marshalling(Parcel &parcel) const;
59 
60     /**
61      * @description: Unmarshals a Want from a Parcel.
62      * Fields in the Want are unmarshalled separately. If any field fails to be unmarshalled, false is returned.
63      * @param parcel Indicates the Parcel object for unmarshalling.
64      * @return Returns true if the unmarshalling is successful; returns false otherwise.
65      */
66     static WantAgent *Unmarshalling(Parcel &parcel);
67 
68 private:
69     std::shared_ptr<PendingWant> pendingWant_;
70 };
71 }  // namespace OHOS::AbilityRuntime::WantAgent
72 #endif  // OHOS_ABILITY_RUNTIME_WANT_AGENT_H
73