1 /*
2 * Copyright (c) 2022-2023 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 "ipc_client_proxy.h"
17
18 #include "device_manager_ipc_interface_code.h"
19 #include "dm_constants.h"
20 #include "dm_log.h"
21 namespace OHOS::DistributedHardware { class IpcReq; }
22 namespace OHOS::DistributedHardware { class IpcRsp; }
23
24 namespace OHOS {
25 namespace DistributedHardware {
Init(const std::string & pkgName)26 int32_t IpcClientProxy::Init(const std::string &pkgName)
27 {
28 if (ipcClientManager_ == nullptr) {
29 return ERR_DM_POINT_NULL;
30 }
31 return ipcClientManager_->Init(pkgName);
32 }
33
UnInit(const std::string & pkgName)34 int32_t IpcClientProxy::UnInit(const std::string &pkgName)
35 {
36 if (ipcClientManager_ == nullptr) {
37 return ERR_DM_POINT_NULL;
38 }
39 return ipcClientManager_->UnInit(pkgName);
40 }
41
SendRequest(int32_t cmdCode,std::shared_ptr<IpcReq> req,std::shared_ptr<IpcRsp> rsp)42 int32_t IpcClientProxy::SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
43 {
44 if (cmdCode < 0 || cmdCode >= IPC_MSG_BUTT) {
45 return ERR_DM_UNSUPPORTED_IPC_COMMAND;
46 }
47 if (ipcClientManager_ == nullptr || req == nullptr || rsp == nullptr) {
48 LOGE("req,rsp or ipc client is null");
49 return ERR_DM_POINT_NULL;
50 }
51 return ipcClientManager_->SendRequest(cmdCode, req, rsp);
52 }
53
OnDmServiceDied()54 int32_t IpcClientProxy::OnDmServiceDied()
55 {
56 if (ipcClientManager_ == nullptr) {
57 LOGE("IpcClientProxy::ipcClientManager_ is null");
58 return ERR_DM_POINT_NULL;
59 }
60 return ipcClientManager_->OnDmServiceDied();
61 }
62 } // namespace DistributedHardware
63 } // namespace OHOS
64