• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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 IMPLEMENT_SINGLE_INSTANCE(IpcClientStub);
27 
ClientIpcInterfaceMsgHandle(const IpcContext * ctx,void * ipcMsg,IpcIo * io,void * arg)28 static int32_t ClientIpcInterfaceMsgHandle(const IpcContext *ctx, void *ipcMsg, IpcIo *io, void *arg)
29 {
30     (void)arg;
31     if (ipcMsg == nullptr || io == nullptr) {
32         LOGE("invalid param");
33         return DM_INPUT_PARA_EMPTY;
34     }
35 
36     uint32_t code = 0;
37     GetCode(ipcMsg, &code);
38     int32_t errCode = DM_OK;
39 
40     errCode = IpcCmdRegister::GetInstance().OnIpcCmd(code, *io);
41     LOGI("receive ipc transact code:%u, retCode=%d", code, errCode);
42     FreeBuffer(ctx, ipcMsg);
43     return errCode;
44 }
45 
Init()46 int32_t IpcClientStub::Init()
47 {
48     std::lock_guard<std::mutex> autoLock(lock_);
49     if (bInit) {
50         return DM_OK;
51     }
52     if (RegisterIpcCallback(ClientIpcInterfaceMsgHandle, 0, IPC_WAIT_FOREVER, &clientIdentity_, nullptr) != 0) {
53         LOGE("register ipc cb failed");
54         return DM_FAILED;
55     }
56     bInit = true;
57     return DM_OK;
58 }
59 } // namespace DistributedHardware
60 } // namespace OHOS
61