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 #include <unistd.h>
17 #include "work_scheduler_connection.h"
18
19 #include "work_sched_hilog.h"
20
21 namespace OHOS {
22 namespace WorkScheduler {
WorkSchedulerConnection(std::shared_ptr<WorkInfo> workInfo)23 WorkSchedulerConnection::WorkSchedulerConnection(std::shared_ptr<WorkInfo> workInfo)
24 {
25 this->workInfo_ = workInfo;
26 }
27
StopWork()28 void WorkSchedulerConnection::StopWork()
29 {
30 if (proxy_ == nullptr) {
31 WS_HILOGE("proxy is null");
32 return;
33 }
34 proxy_->OnWorkStop(*workInfo_);
35 }
36
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)37 void WorkSchedulerConnection::OnAbilityConnectDone(
38 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode)
39 {
40 proxy_ = (new (std::nothrow) WorkSchedulerProxy(remoteObject));
41 if (proxy_ == nullptr) {
42 WS_HILOGE("proxy is null");
43 return;
44 }
45 sleep(1);
46 proxy_->OnWorkStart(*workInfo_);
47 WS_HILOGI("On ability connectDone, workId = %{public}d.", workInfo_->GetWorkId());
48 isConnected_.store(true);
49 }
50
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)51 void WorkSchedulerConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode)
52 {
53 WS_HILOGI("On ability disconnect done.");
54 }
55
IsConnected()56 bool WorkSchedulerConnection::IsConnected()
57 {
58 return isConnected_.load();
59 }
60 } // namespace WorkScheduler
61 } // namespace OHOS
62