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