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_server_proxy.h"
17
18 #include "device_manager_ipc_interface_code.h"
19 #include "dm_error_type.h"
20 #include "dm_log.h"
21 #include "ipc_cmd_register.h"
22
23 namespace OHOS {
24 namespace DistributedHardware {
SendCmd(int32_t cmdCode,std::shared_ptr<IpcReq> req,std::shared_ptr<IpcRsp> rsp)25 int32_t IpcClientServerProxy::SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
26 {
27 if (cmdCode < 0 || cmdCode >= IPC_MSG_BUTT) {
28 LOGE("IpcCmdRegister::SetRequest cmdCode param invalid!");
29 return ERR_DM_UNSUPPORTED_IPC_COMMAND;
30 }
31 sptr<IRemoteObject> remote = Remote();
32 if (remote == nullptr) {
33 LOGE("remote service null");
34 return ERR_DM_POINT_NULL;
35 }
36
37 MessageParcel data;
38 MessageParcel reply;
39 MessageOption option;
40 if (!data.WriteInterfaceToken(GetDescriptor())) {
41 LOGE("WriteInterfaceToken fail!");
42 return ERR_DM_IPC_WRITE_FAILED;
43 }
44 if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DM_OK) {
45 return ERR_DM_IPC_SEND_REQUEST_FAILED;
46 }
47 if (remote->SendRequest(static_cast<uint32_t>(cmdCode), data, reply, option) != DM_OK) {
48 LOGE("SendRequest fail, cmd:%{public}d", cmdCode);
49 return ERR_DM_IPC_SEND_REQUEST_FAILED;
50 }
51 return IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp);
52 }
53 } // namespace DistributedHardware
54 } // namespace OHOS
55