blob: 66729f44443cf36f23b6f5579b14cd104900b11d [file] [log] [blame]
Michael Bestas3a0209e2023-05-04 01:15:47 +03001/* 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 "GeofenceAdapter.h"
30#include "location_interface.h"
31
32static GeofenceAdapter* gGeofenceAdapter = NULL;
33
34static void initialize();
35static void deinitialize();
36
37static void addClient(LocationAPI* client, const LocationCallbacks& callbacks);
38static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb);
39static void requestCapabilities(LocationAPI* client);
40
41static uint32_t* addGeofences(LocationAPI* client, size_t count, GeofenceOption*, GeofenceInfo*);
42static void removeGeofences(LocationAPI* client, size_t count, uint32_t* ids);
43static void modifyGeofences(LocationAPI* client, size_t count, uint32_t* ids,
44 GeofenceOption* options);
45static void pauseGeofences(LocationAPI* client, size_t count, uint32_t* ids);
46static void resumeGeofences(LocationAPI* client, size_t count, uint32_t* ids);
47
48static const GeofenceInterface gGeofenceInterface = {
49 sizeof(GeofenceInterface),
50 initialize,
51 deinitialize,
52 addClient,
53 removeClient,
54 requestCapabilities,
55 addGeofences,
56 removeGeofences,
57 modifyGeofences,
58 pauseGeofences,
59 resumeGeofences
60};
61
62#ifndef DEBUG_X86
63extern "C" const GeofenceInterface* getGeofenceInterface()
64#else
65const GeofenceInterface* getGeofenceInterface()
66#endif // DEBUG_X86
67{
68 return &gGeofenceInterface;
69}
70
71static void initialize()
72{
73 if (NULL == gGeofenceAdapter) {
74 gGeofenceAdapter = new GeofenceAdapter();
75 }
76}
77
78static void deinitialize()
79{
80 if (NULL != gGeofenceAdapter) {
81 delete gGeofenceAdapter;
82 gGeofenceAdapter = NULL;
83 }
84}
85
86static void addClient(LocationAPI* client, const LocationCallbacks& callbacks)
87{
88 if (NULL != gGeofenceAdapter) {
89 gGeofenceAdapter->addClientCommand(client, callbacks);
90 }
91}
92
93static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb)
94{
95 if (NULL != gGeofenceAdapter) {
96 gGeofenceAdapter->removeClientCommand(client, rmClientCb);
97 }
98}
99
100static void requestCapabilities(LocationAPI* client)
101{
102 if (NULL != gGeofenceAdapter) {
103 gGeofenceAdapter->requestCapabilitiesCommand(client);
104 }
105}
106
107static uint32_t* addGeofences(LocationAPI* client, size_t count,
108 GeofenceOption* options, GeofenceInfo* info)
109{
110 if (NULL != gGeofenceAdapter) {
111 return gGeofenceAdapter->addGeofencesCommand(client, count, options, info);
112 } else {
113 return NULL;
114 }
115}
116
117static void removeGeofences(LocationAPI* client, size_t count, uint32_t* ids)
118{
119 if (NULL != gGeofenceAdapter) {
120 return gGeofenceAdapter->removeGeofencesCommand(client, count, ids);
121 }
122}
123
124static void modifyGeofences(LocationAPI* client, size_t count, uint32_t* ids,
125 GeofenceOption* options)
126{
127 if (NULL != gGeofenceAdapter) {
128 return gGeofenceAdapter->modifyGeofencesCommand(client, count, ids, options);
129 }
130}
131
132static void pauseGeofences(LocationAPI* client, size_t count, uint32_t* ids)
133{
134 if (NULL != gGeofenceAdapter) {
135 return gGeofenceAdapter->pauseGeofencesCommand(client, count, ids);
136 }
137}
138
139static void resumeGeofences(LocationAPI* client, size_t count, uint32_t* ids)
140{
141 if (NULL != gGeofenceAdapter) {
142 return gGeofenceAdapter->resumeGeofencesCommand(client, count, ids);
143 }
144}
145