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