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