1 /*
2 * Copyright (c) 2022-2024 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_stub.h"
17
18 #include "device_manager_notify.h"
19 #include "dm_constants.h"
20 #include "dm_log.h"
21 #include "ipc_cmd_register.h"
22 #include "ipc_def.h"
23
24 namespace OHOS {
25 namespace DistributedHardware {
26 DM_IMPLEMENT_SINGLE_INSTANCE(IpcClientStub);
27
ClientIpcInterfaceMsgHandle(uint32_t code,IpcIo * data,IpcIo * reply,MessageOption option)28 static int32_t ClientIpcInterfaceMsgHandle(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
29 {
30 if (data== nullptr) {
31 LOGE("invalid param");
32 return ERR_DM_INPUT_PARA_INVALID;
33 }
34
35 int32_t errCode = IpcCmdRegister::GetInstance().OnIpcCmd(code, *data);
36 LOGI("receive ipc transact code:%{public}u, retCode = %{public}d", code, errCode);
37 return errCode;
38 }
39
Init()40 int32_t IpcClientStub::Init()
41 {
42 std::lock_guard<std::mutex> autoLock(lock_);
43 if (bInit) {
44 return DM_OK;
45 }
46
47 objectStub_.func = ClientIpcInterfaceMsgHandle;
48 objectStub_.args = nullptr;
49 objectStub_.isRemote = false;
50 clientIdentity_.handle = IPC_INVALID_HANDLE;
51 clientIdentity_.token = 0;
52 clientIdentity_.cookie = (uintptr_t)&objectStub_;
53
54 bInit = true;
55 return DM_OK;
56 }
57 } // namespace DistributedHardware
58 } // namespace OHOS
59