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