location_geofence.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Copyright (c) 2017-2019, 2021, The Linux Foundation. All rights reserved.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are
  5. * met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above
  9. * copyright notice, this list of conditions and the following
  10. * disclaimer in the documentation and/or other materials provided
  11. * with the distribution.
  12. * * Neither the name of The Linux Foundation, nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  20. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  23. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  25. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  26. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. */
  29. #include "GeofenceAdapter.h"
  30. #include "location_interface.h"
  31. static GeofenceAdapter* gGeofenceAdapter = NULL;
  32. static void initialize();
  33. static void deinitialize();
  34. static void addClient(LocationAPI* client, const LocationCallbacks& callbacks);
  35. static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb);
  36. static void requestCapabilities(LocationAPI* client);
  37. static uint32_t* addGeofences(LocationAPI* client, size_t count, GeofenceOption*, GeofenceInfo*);
  38. static void removeGeofences(LocationAPI* client, size_t count, uint32_t* ids);
  39. static void modifyGeofences(LocationAPI* client, size_t count, uint32_t* ids,
  40. GeofenceOption* options);
  41. static void pauseGeofences(LocationAPI* client, size_t count, uint32_t* ids);
  42. static void resumeGeofences(LocationAPI* client, size_t count, uint32_t* ids);
  43. static void updateSystemPowerState(PowerStateType systemPowerState);
  44. static const GeofenceInterface gGeofenceInterface = {
  45. sizeof(GeofenceInterface),
  46. initialize,
  47. deinitialize,
  48. addClient,
  49. removeClient,
  50. requestCapabilities,
  51. addGeofences,
  52. removeGeofences,
  53. modifyGeofences,
  54. pauseGeofences,
  55. resumeGeofences,
  56. updateSystemPowerState
  57. };
  58. #ifndef DEBUG_X86
  59. extern "C" const GeofenceInterface* getGeofenceInterface()
  60. #else
  61. const GeofenceInterface* getGeofenceInterface()
  62. #endif // DEBUG_X86
  63. {
  64. return &gGeofenceInterface;
  65. }
  66. static void initialize()
  67. {
  68. if (NULL == gGeofenceAdapter) {
  69. gGeofenceAdapter = new GeofenceAdapter();
  70. }
  71. }
  72. static void deinitialize()
  73. {
  74. if (NULL != gGeofenceAdapter) {
  75. delete gGeofenceAdapter;
  76. gGeofenceAdapter = NULL;
  77. }
  78. }
  79. static void addClient(LocationAPI* client, const LocationCallbacks& callbacks)
  80. {
  81. if (NULL != gGeofenceAdapter) {
  82. gGeofenceAdapter->addClientCommand(client, callbacks);
  83. }
  84. }
  85. static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb)
  86. {
  87. if (NULL != gGeofenceAdapter) {
  88. gGeofenceAdapter->removeClientCommand(client, rmClientCb);
  89. }
  90. }
  91. static void requestCapabilities(LocationAPI* client)
  92. {
  93. if (NULL != gGeofenceAdapter) {
  94. gGeofenceAdapter->requestCapabilitiesCommand(client);
  95. }
  96. }
  97. static uint32_t* addGeofences(LocationAPI* client, size_t count,
  98. GeofenceOption* options, GeofenceInfo* info)
  99. {
  100. if (NULL != gGeofenceAdapter) {
  101. return gGeofenceAdapter->addGeofencesCommand(client, count, options, info);
  102. } else {
  103. return NULL;
  104. }
  105. }
  106. static void removeGeofences(LocationAPI* client, size_t count, uint32_t* ids)
  107. {
  108. if (NULL != gGeofenceAdapter) {
  109. return gGeofenceAdapter->removeGeofencesCommand(client, count, ids);
  110. }
  111. }
  112. static void modifyGeofences(LocationAPI* client, size_t count, uint32_t* ids,
  113. GeofenceOption* options)
  114. {
  115. if (NULL != gGeofenceAdapter) {
  116. return gGeofenceAdapter->modifyGeofencesCommand(client, count, ids, options);
  117. }
  118. }
  119. static void pauseGeofences(LocationAPI* client, size_t count, uint32_t* ids)
  120. {
  121. if (NULL != gGeofenceAdapter) {
  122. return gGeofenceAdapter->pauseGeofencesCommand(client, count, ids);
  123. }
  124. }
  125. static void resumeGeofences(LocationAPI* client, size_t count, uint32_t* ids)
  126. {
  127. if (NULL != gGeofenceAdapter) {
  128. return gGeofenceAdapter->resumeGeofencesCommand(client, count, ids);
  129. }
  130. }
  131. static void updateSystemPowerState(PowerStateType systemPowerState)
  132. {
  133. if (NULL != gGeofenceAdapter) {
  134. return gGeofenceAdapter->updateSystemPowerStateCommand(systemPowerState);
  135. }
  136. }