location_batching.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "BatchingAdapter.h"
  30. #include "location_interface.h"
  31. static BatchingAdapter* gBatchingAdapter = 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 startBatching(LocationAPI* client, BatchingOptions&);
  38. static void stopBatching(LocationAPI* client, uint32_t id);
  39. static void updateBatchingOptions(LocationAPI* client, uint32_t id, BatchingOptions&);
  40. static void getBatchedLocations(LocationAPI* client, uint32_t id, size_t count);
  41. static void updateSystemPowerState(PowerStateType systemPowerState);
  42. static const BatchingInterface gBatchingInterface = {
  43. sizeof(BatchingInterface),
  44. initialize,
  45. deinitialize,
  46. addClient,
  47. removeClient,
  48. requestCapabilities,
  49. startBatching,
  50. stopBatching,
  51. updateBatchingOptions,
  52. getBatchedLocations,
  53. updateSystemPowerState
  54. };
  55. #ifndef DEBUG_X86
  56. extern "C" const BatchingInterface* getBatchingInterface()
  57. #else
  58. const BatchingInterface* getBatchingInterface()
  59. #endif // DEBUG_X86
  60. {
  61. return &gBatchingInterface;
  62. }
  63. static void initialize()
  64. {
  65. if (NULL == gBatchingAdapter) {
  66. gBatchingAdapter = new BatchingAdapter();
  67. }
  68. }
  69. static void deinitialize()
  70. {
  71. if (NULL != gBatchingAdapter) {
  72. delete gBatchingAdapter;
  73. gBatchingAdapter = NULL;
  74. }
  75. }
  76. static void addClient(LocationAPI* client, const LocationCallbacks& callbacks)
  77. {
  78. if (NULL != gBatchingAdapter) {
  79. gBatchingAdapter->addClientCommand(client, callbacks);
  80. }
  81. }
  82. static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb)
  83. {
  84. if (NULL != gBatchingAdapter) {
  85. gBatchingAdapter->removeClientCommand(client, rmClientCb);
  86. }
  87. }
  88. static void requestCapabilities(LocationAPI* client)
  89. {
  90. if (NULL != gBatchingAdapter) {
  91. gBatchingAdapter->requestCapabilitiesCommand(client);
  92. }
  93. }
  94. static uint32_t startBatching(LocationAPI* client, BatchingOptions &batchOptions)
  95. {
  96. if (NULL != gBatchingAdapter) {
  97. return gBatchingAdapter->startBatchingCommand(client, batchOptions);
  98. } else {
  99. return 0;
  100. }
  101. }
  102. static void stopBatching(LocationAPI* client, uint32_t id)
  103. {
  104. if (NULL != gBatchingAdapter) {
  105. gBatchingAdapter->stopBatchingCommand(client, id);
  106. }
  107. }
  108. static void updateBatchingOptions(
  109. LocationAPI* client, uint32_t id, BatchingOptions& batchOptions)
  110. {
  111. if (NULL != gBatchingAdapter) {
  112. gBatchingAdapter->updateBatchingOptionsCommand(client, id, batchOptions);
  113. }
  114. }
  115. static void getBatchedLocations(LocationAPI* client, uint32_t id, size_t count)
  116. {
  117. if (NULL != gBatchingAdapter) {
  118. gBatchingAdapter->getBatchedLocationsCommand(client, id, count);
  119. }
  120. }
  121. static void updateSystemPowerState(PowerStateType systemPowerState)
  122. {
  123. if (NULL != gBatchingAdapter) {
  124. gBatchingAdapter->updateSystemPowerStateCommand(systemPowerState);
  125. }
  126. }