SscCalApiWrapper.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (C) 2024 The LineageOS Project
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #define LOG_TAG "SscCalApiWrapper"
  7. #include "SscCalApi.h"
  8. #include <android-base/logging.h>
  9. #include <dlfcn.h>
  10. SscCalApiWrapper::SscCalApiWrapper() {
  11. mSscCalApiHandle = dlopen("[email protected]", RTLD_NOW);
  12. if (mSscCalApiHandle) {
  13. init_current_sensors =
  14. (init_current_sensors_t)dlsym(mSscCalApiHandle, "_Z20init_current_sensorsb");
  15. if (init_current_sensors == NULL) {
  16. LOG(ERROR) << "could not find init_current_sensors: " << dlerror();
  17. }
  18. process_msg = (process_msg_t)dlsym(mSscCalApiHandle, "_Z11process_msgP8_oem_msg");
  19. if (process_msg == NULL) {
  20. LOG(ERROR) << "could not find process_msg: " << dlerror();
  21. }
  22. } else {
  23. LOG(INFO) << "could not dlopen [email protected]: " << dlerror();
  24. }
  25. }
  26. SscCalApiWrapper::~SscCalApiWrapper() {
  27. dlclose(mSscCalApiHandle);
  28. }
  29. SscCalApiWrapper& SscCalApiWrapper::getInstance() {
  30. static SscCalApiWrapper instance;
  31. return instance;
  32. }
  33. void SscCalApiWrapper::initCurrentSensors(bool debug) {
  34. if (init_current_sensors != NULL) {
  35. init_current_sensors(debug);
  36. }
  37. }
  38. void SscCalApiWrapper::processMsg(_oem_msg* msg) {
  39. if (process_msg != NULL) {
  40. LOG(DEBUG) << "sending oem_msg for sensor " << msg->sensorType
  41. << " with type: " << msg->notifyType << " and value: " << msg->value;
  42. process_msg(msg);
  43. }
  44. }