1 /*
2 * Copyright (c) 2021 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 DM_POINT_NULL;
32 }
33 MessageParcel data;
34 MessageParcel reply;
35 MessageOption option;
36 if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DM_OK) {
37 return DM_IPC_FAILED;
38 }
39 if (remote->SendRequest((uint32_t)cmdCode, data, reply, option) != DM_OK) {
40 LOGE("SendRequest fail, cmd:%d", cmdCode);
41 return DM_IPC_FAILED;
42 }
43 return IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp);
44 }
45 } // namespace DistributedHardware
46 } // namespace OHOS
47