platform_device_xiaomi_sm84.../sensors/utils/SscCalApiWrapper.cpp
Arian b9ef44eff2 sm8450-common: sensors: Introduce LightNotifier and use libssccalapi@2.0
Change-Id: Iec11aa1a8ccc13db5d30cc6fa52e4b10d255c706
2024-08-12 10:24:41 +02:00

53 lines
1.5 KiB
C++

/*
* Copyright (C) 2024 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#define LOG_TAG "SscCalApiWrapper"
#include "SscCalApi.h"
#include <android-base/logging.h>
#include <dlfcn.h>
SscCalApiWrapper::SscCalApiWrapper() {
mSscCalApiHandle = dlopen("libssccalapi@2.0.so", RTLD_NOW);
if (mSscCalApiHandle) {
init_current_sensors =
(init_current_sensors_t)dlsym(mSscCalApiHandle, "_Z20init_current_sensorsb");
if (init_current_sensors == NULL) {
LOG(ERROR) << "could not find init_current_sensors: " << dlerror();
}
process_msg = (process_msg_t)dlsym(mSscCalApiHandle, "_Z11process_msgP8_oem_msg");
if (process_msg == NULL) {
LOG(ERROR) << "could not find process_msg: " << dlerror();
}
} else {
LOG(INFO) << "could not dlopen libssccalapi@2.0.so: " << dlerror();
}
}
SscCalApiWrapper::~SscCalApiWrapper() {
dlclose(mSscCalApiHandle);
}
SscCalApiWrapper& SscCalApiWrapper::getInstance() {
static SscCalApiWrapper instance;
return instance;
}
void SscCalApiWrapper::initCurrentSensors(bool debug) {
if (init_current_sensors != NULL) {
init_current_sensors(debug);
}
}
void SscCalApiWrapper::processMsg(_oem_msg* msg) {
if (process_msg != NULL) {
LOG(DEBUG) << "sending oem_msg for sensor " << msg->sensorType
<< " with type: " << msg->notifyType << " and value: " << msg->value;
process_msg(msg);
}
}