1 /*
2  * Copyright (c) 2022 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 FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_STATIC_SUBSCRIBER_CONNECTION_H
17 #define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_STATIC_SUBSCRIBER_CONNECTION_H
18 
19 #include "ability_connect_callback_stub.h"
20 #include "work_info.h"
21 #include "work_scheduler_proxy.h"
22 
23 namespace OHOS {
24 namespace WorkScheduler {
25 class WorkSchedulerConnection : public AAFwk::AbilityConnectionStub {
26 public:
27     explicit WorkSchedulerConnection(std::shared_ptr<WorkInfo> workInfo);
28     /**
29      * @brief Stop work.
30      */
31     void StopWork();
32     /**
33      * @brief The OnAbilityConnectDone callback.
34      *
35      * @param element The element.
36      * @param remoteObject The remote object.
37      * @param resultCode The result code.
38      */
39     void OnAbilityConnectDone(
40         const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override;
41 
42     /**
43      * @brief The OnAbilityDisconnectDone callback.
44      *
45      * @param element The element.
46      * @param resultCode The result code.
47      */
48     void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override;
49     bool IsConnected();
50 private:
51     sptr<WorkSchedulerProxy> proxy_ = nullptr;
52     std::shared_ptr<WorkInfo> workInfo_;
53     std::atomic<bool> isConnected_ {false};
54 };
55 } // namespace WorkScheduler
56 } // namespace OHOS
57 #endif // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_STATIC_SUBSCRIBER_CONNECTION_H
58