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_COMPLETED_DISPATCHER_H
17 #define OHOS_ABILITY_RUNTIME_COMPLETED_DISPATCHER_H
18 
19 #include <string>
20 #include <memory>
21 #include "completed_callback.h"
22 #include "event_handler.h"
23 #include "want.h"
24 #include "want_params.h"
25 #include "want_receiver_stub.h"
26 
27 namespace OHOS::AbilityRuntime::WantAgent {
28 class PendingWant;
29 class CompletedDispatcher : public AAFwk::WantReceiverStub {
30 public:
31     CompletedDispatcher(const std::shared_ptr<PendingWant> &pendingWant,
32         const std::shared_ptr<CompletedCallback> &callback, const std::shared_ptr<AppExecFwk::EventHandler> &handler);
33     virtual ~CompletedDispatcher() = default;
34 
35     void Send(const int32_t resultCode) override;
36 
37     void PerformReceive(const AAFwk::Want &want, int resultCode, const std::string &data,
38         const AAFwk::WantParams &extras, bool serialized, bool sticky, int sendingUser) override;
39 
40     void Run();
41 
42 private:
43     const std::shared_ptr<PendingWant> pendingWant_;
44     const std::shared_ptr<CompletedCallback> callback_;
45     const std::shared_ptr<AppExecFwk::EventHandler> handler_;
46     AAFwk::Want want_;
47     int resultCode_ = 0;
48     std::string resultData_;
49     AAFwk::WantParams resultExtras_;
50 };
51 }  // namespace OHOS::AbilityRuntime::WantAgent
52 #endif  // OHOS_ABILITY_RUNTIME_COMPLETED_DISPATCHER_H
53