chre_api_gnss.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "chre_api/chre/gnss.h"
  17. #include "chre/core/event_loop_manager.h"
  18. #include "chre/util/macros.h"
  19. #include "chre/util/time.h"
  20. using chre::EventLoopManager;
  21. using chre::EventLoopManagerSingleton;
  22. using chre::Milliseconds;
  23. DLL_EXPORT uint32_t chreGnssGetCapabilities() {
  24. #ifdef CHRE_GNSS_SUPPORT_ENABLED
  25. return chre::EventLoopManagerSingleton::get()->getGnssManager()
  26. .getCapabilities();
  27. #else
  28. return CHRE_GNSS_CAPABILITIES_NONE;
  29. #endif // CHRE_GNSS_SUPPORT_ENABLED
  30. }
  31. DLL_EXPORT bool chreGnssLocationSessionStartAsync(uint32_t minIntervalMs,
  32. uint32_t minTimeToNextFixMs,
  33. const void *cookie) {
  34. #ifdef CHRE_GNSS_SUPPORT_ENABLED
  35. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  36. return chre::EventLoopManagerSingleton::get()->getGnssManager()
  37. .getLocationSession().addRequest(
  38. nanoapp, Milliseconds(minIntervalMs),
  39. Milliseconds(minTimeToNextFixMs), cookie);
  40. #else
  41. return false;
  42. #endif // CHRE_GNSS_SUPPORT_ENABLED
  43. }
  44. DLL_EXPORT bool chreGnssLocationSessionStopAsync(const void *cookie) {
  45. #ifdef CHRE_GNSS_SUPPORT_ENABLED
  46. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  47. return chre::EventLoopManagerSingleton::get()->getGnssManager()
  48. .getLocationSession().removeRequest(nanoapp, cookie);
  49. #else
  50. return false;
  51. #endif // CHRE_GNSS_SUPPORT_ENABLED
  52. }
  53. DLL_EXPORT bool chreGnssMeasurementSessionStartAsync(uint32_t minIntervalMs,
  54. const void *cookie) {
  55. #ifdef CHRE_GNSS_SUPPORT_ENABLED
  56. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  57. return chre::EventLoopManagerSingleton::get()->getGnssManager()
  58. .getMeasurementSession().addRequest(
  59. nanoapp, Milliseconds(minIntervalMs),
  60. Milliseconds(0) /* minTimeToNext */, cookie);
  61. #else
  62. return false;
  63. #endif // CHRE_GNSS_SUPPORT_ENABLED
  64. }
  65. DLL_EXPORT bool chreGnssMeasurementSessionStopAsync(const void *cookie) {
  66. #ifdef CHRE_GNSS_SUPPORT_ENABLED
  67. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  68. return chre::EventLoopManagerSingleton::get()->getGnssManager()
  69. .getMeasurementSession().removeRequest(nanoapp, cookie);
  70. #else
  71. return false;
  72. #endif // CHRE_GNSS_SUPPORT_ENABLED
  73. }