• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "work_scheduler_stub.h"
17 
18 namespace OHOS {
19 namespace WorkScheduler {
20 static constexpr int32_t COMMAND_ON_WORK_START = MIN_TRANSACTION_ID;
21 static constexpr int32_t COMMAND_ON_WORK_STOP = MIN_TRANSACTION_ID + 1;
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)22 int32_t WorkSchedulerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
23     MessageOption& option)
24 {
25     auto remoteDescriptor = data.ReadInterfaceToken();
26     if (GetDescriptor() != remoteDescriptor) {
27         WS_HILOGE("failed, descriptor is not matched!");
28         return ERR_INVALID_STATE;
29     }
30     switch (code) {
31         case COMMAND_ON_WORK_START: {
32             sptr<WorkInfo> workInfo = data.ReadStrongParcelable<WorkInfo>();
33             if (workInfo == nullptr) {
34                 WS_HILOGE("workInfo is nullptr");
35                 return ERR_TRANSACTION_FAILED;
36             }
37             OnWorkStart(*workInfo);
38             return ERR_NONE;
39         }
40         case COMMAND_ON_WORK_STOP: {
41             sptr<WorkInfo> workInfo = data.ReadStrongParcelable<WorkInfo>();
42             if (workInfo == nullptr) {
43                 WS_HILOGE("workInfo is nullptr");
44                 return ERR_TRANSACTION_FAILED;
45             }
46             OnWorkStop(*workInfo);
47             return ERR_NONE;
48         }
49         default:
50             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51     }
52 
53     return ERR_TRANSACTION_FAILED;
54 }
55 } // namespace WorkScheduler
56 } // namespace OHOS
57