1 /*
2  * Copyright (c) 2024 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 "single_execute_strategy.h"
17 
18 #include "edm_log.h"
19 #include "plugin_manager.h"
20 
21 namespace OHOS {
22 namespace EDM {
OnGetExecute(std::uint32_t funcCode,std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)23 ErrCode SingleExecuteStrategy::OnGetExecute(std::uint32_t funcCode, std::string &policyData, MessageParcel &data,
24     MessageParcel &reply, int32_t userId)
25 {
26     auto plugin = PluginManager::GetInstance()->GetPluginByFuncCode(funcCode);
27     if (plugin != nullptr) {
28         EDMLOGD("SingleExecuteStrategy::OnGetExecute plugin %{public}d execute single strategy.", plugin->GetCode());
29         return plugin->OnGetPolicy(policyData, data, reply, userId);
30     }
31     EDMLOGE("SingleExecuteStrategy::OnGetExecute plugin %{public}d is not exist.", funcCode);
32     return ERR_EDM_GET_POLICY_FAILED;
33 }
34 
OnSetExecute(std::uint32_t funcCode,MessageParcel & data,MessageParcel & reply,HandlePolicyData & policyData,int32_t userId)35 ErrCode SingleExecuteStrategy::OnSetExecute(std::uint32_t funcCode, MessageParcel &data, MessageParcel &reply,
36     HandlePolicyData &policyData, int32_t userId)
37 {
38     auto plugin = PluginManager::GetInstance()->GetPluginByFuncCode(funcCode);
39     if (plugin != nullptr) {
40         EDMLOGD("SingleExecuteStrategy::OnSetExecute plugin %{public}d execute single strategy.", plugin->GetCode());
41         return plugin->OnHandlePolicy(funcCode, data, reply, policyData, userId);
42     }
43     EDMLOGE("SingleExecuteStrategy::OnGetExecute plugin %{public}d is not exist.", funcCode);
44     return ERR_EDM_HANDLE_POLICY_FAILED;
45 }
46 } // namespace EDM
47 } // namespace OHOS
48