• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "touch_screen.h"
17 
18 #include "platform/common/rs_log.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace {
23 constexpr std::string_view TOUCHSCREEN_WRAPPER_PATH = "libthp_extra_innerapi.z.so";
24 
25 template<typename Handle>
GetHandleBySymbol(void * dlHandle,Handle & handle,const char * symbol)26 void GetHandleBySymbol(void* dlHandle, Handle& handle, const char* symbol)
27 {
28     handle = reinterpret_cast<Handle>(dlsym(dlHandle, symbol));
29     if (handle == nullptr) {
30         RS_LOGE("touch screen get handle by %{public}s failed, error: %{public}s",
31             symbol, dlerror());
32     } else {
33         RS_LOGI("touch screen get handle by %{public}s success", symbol);
34     }
35 }
36 } // namespace
37 
TouchScreen()38 TouchScreen::TouchScreen() {}
~TouchScreen()39 TouchScreen::~TouchScreen()
40 {
41     if (touchScreenHandle_ != nullptr) {
42         dlclose(touchScreenHandle_);
43         touchScreenHandle_ = nullptr;
44         setFeatureConfigHandle_ = nullptr;
45         setAftConfigHandle_ = nullptr;
46     }
47 }
48 
InitTouchScreen()49 void TouchScreen::InitTouchScreen()
50 {
51     touchScreenHandle_ = dlopen(TOUCHSCREEN_WRAPPER_PATH.data(), RTLD_NOW);
52     if (touchScreenHandle_ == nullptr) {
53         RS_LOGE("%{public}s load library failed, error: %{public}s", __func__, dlerror());
54         return;
55     }
56 
57     GetHandleBySymbol(touchScreenHandle_, setFeatureConfigHandle_, "SetFeatureConfig");
58     GetHandleBySymbol(touchScreenHandle_, setAftConfigHandle_, "SetAftConfig");
59 }
60 } // namespace Rosen
61 } // namespace OHOS
62