• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2011-2014, 2016-2018 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_ADAPTER_BASE_H
30 #define LOC_API_ADAPTER_BASE_H
31 
32 #include <gps_extended.h>
33 #include <UlpProxyBase.h>
34 #include <ContextBase.h>
35 #include <LocationAPI.h>
36 #include <map>
37 
38 #define MIN_TRACKING_INTERVAL (100) // 100 msec
39 
40 typedef struct LocationSessionKey {
41     LocationAPI* client;
42     uint32_t id;
LocationSessionKeyLocationSessionKey43     inline LocationSessionKey(LocationAPI* _client, uint32_t _id) :
44         client(_client), id(_id) {}
45 } LocationSessionKey;
46 inline bool operator <(LocationSessionKey const& left, LocationSessionKey const& right) {
47     return left.id < right.id || (left.id == right.id && left.client < right.client);
48 }
49 inline bool operator ==(LocationSessionKey const& left, LocationSessionKey const& right) {
50     return left.id == right.id && left.client == right.client;
51 }
52 inline bool operator !=(LocationSessionKey const& left, LocationSessionKey const& right) {
53     return left.id != right.id || left.client != right.client;
54 }
55 typedef std::map<LocationSessionKey, LocationOptions> LocationSessionMap;
56 typedef std::map<LocationSessionKey, TrackingOptions> TrackingOptionsMap;
57 
58 namespace loc_core {
59 
60 class LocAdapterProxyBase;
61 
62 class LocAdapterBase {
63 private:
64     static uint32_t mSessionIdCounter;
65     const bool mIsMaster;
66 protected:
67     LOC_API_ADAPTER_EVENT_MASK_T mEvtMask;
68     ContextBase* mContext;
69     LocApiBase* mLocApi;
70     LocAdapterProxyBase* mLocAdapterProxyBase;
71     const MsgTask* mMsgTask;
LocAdapterBase(const MsgTask * msgTask)72     inline LocAdapterBase(const MsgTask* msgTask) :
73         mIsMaster(false), mEvtMask(0), mContext(NULL), mLocApi(NULL),
74         mLocAdapterProxyBase(NULL), mMsgTask(msgTask) {}
75     LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask,
76         ContextBase* context, bool isMaster,
77         LocAdapterProxyBase *adapterProxyBase = NULL);
78 public:
~LocAdapterBase()79     inline virtual ~LocAdapterBase() { mLocApi->removeAdapter(this); }
80     inline LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask,
81                           ContextBase* context,
82                           LocAdapterProxyBase *adapterProxyBase = NULL) :
LocAdapterBase(mask,context,false,adapterProxyBase)83         LocAdapterBase(mask, context, false, adapterProxyBase) {}
84 
85     inline LOC_API_ADAPTER_EVENT_MASK_T
checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask)86         checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask) const {
87         return mEvtMask & mask;
88     }
89 
getEvtMask()90     inline LOC_API_ADAPTER_EVENT_MASK_T getEvtMask() const {
91         return mEvtMask;
92     }
93 
sendMsg(const LocMsg * msg)94     inline void sendMsg(const LocMsg* msg) const {
95         mMsgTask->sendMsg(msg);
96     }
97 
sendMsg(const LocMsg * msg)98     inline void sendMsg(const LocMsg* msg) {
99         mMsgTask->sendMsg(msg);
100     }
101 
updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event,loc_registration_mask_status status)102     inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event,
103                               loc_registration_mask_status status)
104     {
105         switch(status) {
106             case (LOC_REGISTRATION_MASK_ENABLED):
107                 mEvtMask = mEvtMask | event;
108                 break;
109             case (LOC_REGISTRATION_MASK_DISABLED):
110                 mEvtMask = mEvtMask &~ event;
111                 break;
112             case (LOC_REGISTRATION_MASK_SET):
113                 mEvtMask = event;
114                 break;
115         }
116         mLocApi->updateEvtMask();
117     }
118 
isFeatureSupported(uint8_t featureVal)119     inline bool isFeatureSupported(uint8_t featureVal) {
120         return mLocApi->isFeatureSupported(featureVal);
121     }
122 
123     uint32_t generateSessionId();
124 
isAdapterMaster()125     inline bool isAdapterMaster() {
126         return mIsMaster;
127     }
128 
129     // This will be overridden by the individual adapters
130     // if necessary.
setUlpProxyCommand(UlpProxyBase * ulp)131     inline virtual void setUlpProxyCommand(UlpProxyBase* ulp) {
132 
133         (void)ulp;
134     }
135     virtual void handleEngineUpEvent();
136     virtual void handleEngineDownEvent();
setPositionModeCommand(LocPosMode & posMode)137     inline virtual void setPositionModeCommand(LocPosMode& posMode) {
138 
139         (void)posMode;
140     }
startTrackingCommand()141     virtual void startTrackingCommand() {}
stopTrackingCommand()142     virtual void stopTrackingCommand() {}
getZppCommand()143     virtual void getZppCommand() {}
144     virtual void reportPositionEvent(const UlpLocation& location,
145                                      const GpsLocationExtended& locationExtended,
146                                      enum loc_sess_status status,
147                                      LocPosTechMask loc_technology_mask,
148                                      bool fromUlp=false);
149     virtual void reportSvEvent(const GnssSvNotification& svNotify, bool fromUlp=false);
150     virtual void reportNmeaEvent(const char* nmea, size_t length, bool fromUlp=false);
151     virtual void reportSvMeasurementEvent(GnssSvMeasurementSet &svMeasurementSet);
152     virtual void reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial);
153     virtual void reportStatus(LocGpsStatusValue status);
154     virtual bool reportXtraServer(const char* url1, const char* url2,
155                                   const char* url3, const int maxlength);
156     virtual bool requestXtraData();
157     virtual bool requestTime();
158     virtual bool requestLocation();
159     virtual bool requestATL(int connHandle, LocAGpsType agps_type, LocApnTypeMask mask);
160     virtual bool releaseATL(int connHandle);
161     virtual bool requestSuplES(int connHandle, LocApnTypeMask mask);
162     virtual bool reportDataCallOpened();
163     virtual bool reportDataCallClosed();
164     virtual bool requestNiNotifyEvent(const GnssNiNotification &notify, const void* data);
isInSession()165     inline virtual bool isInSession() { return false; }
getContext()166     ContextBase* getContext() const { return mContext; }
167     virtual void reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurements,
168                                                 int msInWeek);
169     virtual bool reportWwanZppFix(LocGpsLocation &zppLoc);
170     virtual void reportGnssSvIdConfigEvent(const GnssSvIdConfig& config);
171     virtual void reportGnssSvTypeConfigEvent(const GnssSvTypeConfig& config);
172     virtual bool reportOdcpiRequestEvent(OdcpiRequestInfo& request);
173 };
174 
175 } // namespace loc_core
176 
177 #endif //LOC_API_ADAPTER_BASE_H
178