1 /* Copyright (c) 2011-2014,2016, 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 
36 namespace loc_core {
37 
38 class LocAdapterProxyBase;
39 
40 class LocAdapterBase {
41 protected:
42     LOC_API_ADAPTER_EVENT_MASK_T mEvtMask;
43     ContextBase* mContext;
44     LocApiBase* mLocApi;
45     LocAdapterProxyBase* mLocAdapterProxyBase;
46     const MsgTask* mMsgTask;
47 
LocAdapterBase(const MsgTask * msgTask)48     inline LocAdapterBase(const MsgTask* msgTask) :
49         mEvtMask(0), mContext(NULL), mLocApi(NULL),
50         mLocAdapterProxyBase(NULL), mMsgTask(msgTask) {}
51 public:
~LocAdapterBase()52     inline virtual ~LocAdapterBase() { mLocApi->removeAdapter(this); }
53     LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask,
54                    ContextBase* context, LocAdapterProxyBase *adapterProxyBase = NULL);
55     inline LOC_API_ADAPTER_EVENT_MASK_T
checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask)56         checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask) const {
57         return mEvtMask & mask;
58     }
59 
getEvtMask()60     inline LOC_API_ADAPTER_EVENT_MASK_T getEvtMask() const {
61         return mEvtMask;
62     }
63 
sendMsg(const LocMsg * msg)64     inline void sendMsg(const LocMsg* msg) const {
65         mMsgTask->sendMsg(msg);
66     }
67 
sendMsg(const LocMsg * msg)68     inline void sendMsg(const LocMsg* msg) {
69         mMsgTask->sendMsg(msg);
70     }
71 
updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event,loc_registration_mask_status isEnabled)72     inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event,
73                        loc_registration_mask_status isEnabled)
74     {
75         mEvtMask =
76             isEnabled == LOC_REGISTRATION_MASK_ENABLED ? (mEvtMask|event):(mEvtMask&~event);
77 
78         mLocApi->updateEvtMask();
79     }
80 
81     // This will be overridden by the individual adapters
82     // if necessary.
setUlpProxy(UlpProxyBase *)83     inline virtual void setUlpProxy(UlpProxyBase* /* ulp */) {}
84     virtual void handleEngineUpEvent();
85     virtual void handleEngineDownEvent();
setPositionModeInt(LocPosMode &)86     inline virtual void setPositionModeInt(LocPosMode& /* posMode */) {}
startFixInt()87     virtual void startFixInt() {}
stopFixInt()88     virtual void stopFixInt() {}
getZppInt()89     virtual void getZppInt() {}
90     virtual void reportPosition(UlpLocation &location,
91                                 GpsLocationExtended &locationExtended,
92                                 void* locationExt,
93                                 enum loc_sess_status status,
94                                 LocPosTechMask loc_technology_mask);
95     virtual void reportSv(GnssSvStatus &svStatus,
96                           GpsLocationExtended &locationExtended,
97                           void* svExt);
98     virtual void reportStatus(GpsStatusValue status);
99     virtual void reportNmea(const char* nmea, int length);
100     virtual bool reportXtraServer(const char* url1, const char* url2,
101                                   const char* url3, const int maxlength);
102     virtual bool requestXtraData();
103     virtual bool requestTime();
104     virtual bool requestLocation();
105     virtual bool requestATL(int connHandle, AGpsType agps_type);
106     virtual bool releaseATL(int connHandle);
107     virtual bool requestSuplES(int connHandle);
108     virtual bool reportDataCallOpened();
109     virtual bool reportDataCallClosed();
110     virtual bool requestNiNotify(GpsNiNotification &notify,
111                                  const void* data);
isInSession()112     inline virtual bool isInSession() { return false; }
getContext()113     ContextBase* getContext() const { return mContext; }
114     virtual void reportGnssMeasurementData(GnssData &gnssMeasurementData);
115 };
116 
117 } // namespace loc_core
118 
119 #endif //LOC_API_ADAPTER_BASE_H
120