• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2011-2014, 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 #ifndef LOC_API_BASE_H
30 #define LOC_API_BASE_H
31 
32 #include <stddef.h>
33 #include <ctype.h>
34 #include <gps_extended.h>
35 #include <MsgTask.h>
36 #include <log_util.h>
37 
38 namespace loc_core {
39 class ContextBase;
40 
41 int hexcode(char *hexstring, int string_size,
42             const char *data, int data_size);
43 int decodeAddress(char *addr_string, int string_size,
44                   const char *data, int data_size);
45 
46 #define MAX_ADAPTERS          10
47 
48 #define TO_ALL_ADAPTERS(adapters, call)                                \
49     for (int i = 0; i < MAX_ADAPTERS && NULL != (adapters)[i]; i++) {  \
50         call;                                                          \
51     }
52 
53 #define TO_1ST_HANDLING_ADAPTER(adapters, call)                              \
54     for (int i = 0; i <MAX_ADAPTERS && NULL != (adapters)[i] && !(call); i++);
55 
56 class LocAdapterBase;
57 struct LocSsrMsg;
58 struct LocOpenMsg;
59 
60 class LocApiProxyBase {
61 public:
LocApiProxyBase()62     inline LocApiProxyBase() {}
~LocApiProxyBase()63     inline virtual ~LocApiProxyBase() {}
getSibling2()64     inline virtual void* getSibling2() { return NULL; }
65 };
66 
67 class LocApiBase {
68     friend struct LocSsrMsg;
69     //LocOpenMsg calls open() which makes it necessary to declare
70     //it as a friend
71     friend struct LocOpenMsg;
72     friend class ContextBase;
73     const MsgTask* mMsgTask;
74     ContextBase *mContext;
75     LocAdapterBase* mLocAdapters[MAX_ADAPTERS];
76 
77 protected:
78     virtual enum loc_api_adapter_err
79         open(LOC_API_ADAPTER_EVENT_MASK_T mask);
80     virtual enum loc_api_adapter_err
81         close();
82     LOC_API_ADAPTER_EVENT_MASK_T getEvtMask();
83     LOC_API_ADAPTER_EVENT_MASK_T mMask;
84     LocApiBase(const MsgTask* msgTask,
85                LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
86                ContextBase* context = NULL);
~LocApiBase()87     inline virtual ~LocApiBase() { close(); }
88     bool isInSession();
89     const LOC_API_ADAPTER_EVENT_MASK_T mExcludedMask;
90 
91 public:
sendMsg(const LocMsg * msg)92     inline void sendMsg(const LocMsg* msg) const {
93         mMsgTask->sendMsg(msg);
94     }
95 
96     void addAdapter(LocAdapterBase* adapter);
97     void removeAdapter(LocAdapterBase* adapter);
98 
99     // upward calls
100     void handleEngineUpEvent();
101     void handleEngineDownEvent();
102     void reportPosition(UlpLocation &location,
103                         GpsLocationExtended &locationExtended,
104                         void* locationExt,
105                         enum loc_sess_status status,
106                         LocPosTechMask loc_technology_mask =
107                                   LOC_POS_TECH_MASK_DEFAULT);
108     void reportSv(GpsSvStatus &svStatus,
109                   GpsLocationExtended &locationExtended,
110                   void* svExt);
111     void reportStatus(GpsStatusValue status);
112     void reportNmea(const char* nmea, int length);
113     void reportXtraServer(const char* url1, const char* url2,
114                           const char* url3, const int maxlength);
115     void requestXtraData();
116     void requestTime();
117     void requestLocation();
118     void requestATL(int connHandle, AGpsType agps_type);
119     void releaseATL(int connHandle);
120     void requestSuplES(int connHandle);
121     void reportDataCallOpened();
122     void reportDataCallClosed();
123     void requestNiNotify(GpsNiNotification &notify, const void* data);
124 
125     // downward calls
126     // All below functions are to be defined by adapter specific modules:
127     // RPC, QMI, etc.  The default implementation is empty.
128 
129     virtual void* getSibling();
130     virtual LocApiProxyBase* getLocApiProxy();
131     virtual enum loc_api_adapter_err
132         startFix(const LocPosMode& posMode);
133     virtual enum loc_api_adapter_err
134         stopFix();
135     virtual enum loc_api_adapter_err
136         deleteAidingData(GpsAidingData f);
137     virtual enum loc_api_adapter_err
138         enableData(int enable);
139     virtual enum loc_api_adapter_err
140         setAPN(char* apn, int len);
141     virtual enum loc_api_adapter_err
142         injectPosition(double latitude, double longitude, float accuracy);
143     virtual enum loc_api_adapter_err
144         setTime(GpsUtcTime time, int64_t timeReference, int uncertainty);
145     virtual enum loc_api_adapter_err
146         setXtraData(char* data, int length);
147     virtual enum loc_api_adapter_err
148         requestXtraServer();
149     virtual enum loc_api_adapter_err
150         atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, AGpsType agpsType);
151     virtual enum loc_api_adapter_err
152         atlCloseStatus(int handle, int is_succ);
153     virtual enum loc_api_adapter_err
154         setPositionMode(const LocPosMode& posMode);
155     virtual enum loc_api_adapter_err
156         setServer(const char* url, int len);
157     virtual enum loc_api_adapter_err
158         setServer(unsigned int ip, int port,
159                   LocServerType type);
160     virtual enum loc_api_adapter_err
161         informNiResponse(GpsUserResponseType userResponse, const void* passThroughData);
162     virtual enum loc_api_adapter_err
163         setSUPLVersion(uint32_t version);
164     virtual enum loc_api_adapter_err
165         setLPPConfig(uint32_t profile);
166     virtual enum loc_api_adapter_err
167         setSensorControlConfig(int sensorUsage, int sensorProvider);
168     virtual enum loc_api_adapter_err
169         setSensorProperties(bool gyroBiasVarianceRandomWalk_valid,
170                             float gyroBiasVarianceRandomWalk,
171                             bool accelBiasVarianceRandomWalk_valid,
172                             float accelBiasVarianceRandomWalk,
173                             bool angleBiasVarianceRandomWalk_valid,
174                             float angleBiasVarianceRandomWalk,
175                             bool rateBiasVarianceRandomWalk_valid,
176                             float rateBiasVarianceRandomWalk,
177                             bool velocityBiasVarianceRandomWalk_valid,
178                             float velocityBiasVarianceRandomWalk);
179     virtual enum loc_api_adapter_err
180         setSensorPerfControlConfig(int controlMode,
181                                int accelSamplesPerBatch,
182                                int accelBatchesPerSec,
183                                int gyroSamplesPerBatch,
184                                int gyroBatchesPerSec,
185                                int accelSamplesPerBatchHigh,
186                                int accelBatchesPerSecHigh,
187                                int gyroSamplesPerBatchHigh,
188                                int gyroBatchesPerSecHigh,
189                                int algorithmConfig);
190     virtual enum loc_api_adapter_err
191         setExtPowerConfig(int isBatteryCharging);
192     virtual enum loc_api_adapter_err
193         setAGLONASSProtocol(unsigned long aGlonassProtocol);
194     virtual enum loc_api_adapter_err
195         getWwanZppFix(GpsLocation & zppLoc);
196     virtual enum loc_api_adapter_err
197         getBestAvailableZppFix(GpsLocation & zppLoc);
198     virtual enum loc_api_adapter_err
199         getBestAvailableZppFix(GpsLocation & zppLoc, LocPosTechMask & tech_mask);
200     virtual int initDataServiceClient();
201     virtual int openAndStartDataCall();
202     virtual void stopDataCall();
203     virtual void closeDataCall();
204     virtual void installAGpsCert(const DerEncodedCertificate* pData,
205                                  size_t length,
206                                  uint32_t slotBitMask);
207 
setInSession(bool inSession)208     inline virtual void setInSession(bool inSession) {}
209 
210     /*Values for lock
211       1 = Do not lock any position sessions
212       2 = Lock MI position sessions
213       3 = Lock MT position sessions
214       4 = Lock all position sessions
215      */
216     virtual int setGpsLock(LOC_GPS_LOCK_MASK lock);
217     /*
218       Returns
219       Current value of GPS Lock on success
220       -1 on failure
221      */
222     virtual int getGpsLock(void);
223 };
224 
225 typedef LocApiBase* (getLocApi_t)(const MsgTask* msgTask,
226                                   LOC_API_ADAPTER_EVENT_MASK_T exMask,
227                                   ContextBase *context);
228 
229 } // namespace loc_core
230 
231 #endif //LOC_API_BASE_H
232