Home | History | Annotate | Download | only in libloc_api_50001
      1 /* Copyright (c) 2011-2013, 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_ENG_ADAPTER_H
     30 #define LOC_API_ENG_ADAPTER_H
     31 
     32 #include <ctype.h>
     33 #include <hardware/gps.h>
     34 #include <loc.h>
     35 #include <loc_eng_log.h>
     36 #include <log_util.h>
     37 #include <LocAdapterBase.h>
     38 #include <LocDualContext.h>
     39 #include <UlpProxyBase.h>
     40 #include <platform_lib_includes.h>
     41 
     42 #define MAX_URL_LEN 256
     43 
     44 using namespace loc_core;
     45 
     46 class LocEngAdapter;
     47 
     48 class LocInternalAdapter : public LocAdapterBase {
     49     LocEngAdapter* mLocEngAdapter;
     50 public:
     51     LocInternalAdapter(LocEngAdapter* adapter);
     52 
     53     virtual void reportPosition(UlpLocation &location,
     54                                 GpsLocationExtended &locationExtended,
     55                                 void* locationExt,
     56                                 enum loc_sess_status status,
     57                                 LocPosTechMask loc_technology_mask);
     58     virtual void reportSv(GpsSvStatus &svStatus,
     59                           GpsLocationExtended &locationExtended,
     60                           void* svExt);
     61     virtual void setPositionModeInt(LocPosMode& posMode);
     62     virtual void startFixInt();
     63     virtual void stopFixInt();
     64     virtual void setUlpProxy(UlpProxyBase* ulp);
     65 };
     66 
     67 typedef void (*loc_msg_sender)(void* loc_eng_data_p, void* msgp);
     68 
     69 class LocEngAdapter : public LocAdapterBase {
     70     void* mOwner;
     71     LocInternalAdapter* mInternalAdapter;
     72     UlpProxyBase* mUlp;
     73     LocPosMode mFixCriteria;
     74     bool mNavigating;
     75 
     76 public:
     77     bool mAgpsEnabled;
     78 
     79     LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask,
     80                   void* owner,
     81                   MsgTask::tCreate tCreator);
     82     virtual ~LocEngAdapter();
     83 
     84     virtual void setUlpProxy(UlpProxyBase* ulp);
     85     inline void requestUlp(unsigned long capabilities) {
     86         mContext->requestUlp(mInternalAdapter, capabilities);
     87     }
     88     inline LocInternalAdapter* getInternalAdapter() { return mInternalAdapter; }
     89     inline UlpProxyBase* getUlpProxy() { return mUlp; }
     90     inline void* getOwner() { return mOwner; }
     91     inline bool hasAgpsExt() { return mContext->hasAgpsExt(); }
     92     inline const MsgTask* getMsgTask() { return mMsgTask; }
     93 
     94     inline enum loc_api_adapter_err
     95         startFix()
     96     {
     97         return mLocApi->startFix(mFixCriteria);
     98     }
     99     inline enum loc_api_adapter_err
    100         stopFix()
    101     {
    102         return mLocApi->stopFix();
    103     }
    104     inline enum loc_api_adapter_err
    105         deleteAidingData(GpsAidingData f)
    106     {
    107         return mLocApi->deleteAidingData(f);
    108     }
    109     inline enum loc_api_adapter_err
    110         enableData(int enable)
    111     {
    112         return mLocApi->enableData(enable);
    113     }
    114     inline enum loc_api_adapter_err
    115         setAPN(char* apn, int len)
    116     {
    117         return mLocApi->setAPN(apn, len);
    118     }
    119     inline enum loc_api_adapter_err
    120         injectPosition(double latitude, double longitude, float accuracy)
    121     {
    122         return mLocApi->injectPosition(latitude, longitude, accuracy);
    123     }
    124     inline enum loc_api_adapter_err
    125         setTime(GpsUtcTime time, int64_t timeReference, int uncertainty)
    126     {
    127         return mLocApi->setTime(time, timeReference, uncertainty);
    128     }
    129     inline enum loc_api_adapter_err
    130         setXtraData(char* data, int length)
    131     {
    132         return mLocApi->setXtraData(data, length);
    133     }
    134     inline enum loc_api_adapter_err
    135         requestXtraServer()
    136     {
    137         return mLocApi->requestXtraServer();
    138     }
    139     inline enum loc_api_adapter_err
    140         atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bearer, AGpsType agpsType)
    141     {
    142         return mLocApi->atlOpenStatus(handle, is_succ, apn, bearer, agpsType);
    143     }
    144     inline enum loc_api_adapter_err
    145         atlCloseStatus(int handle, int is_succ)
    146     {
    147         return mLocApi->atlCloseStatus(handle, is_succ);
    148     }
    149     inline enum loc_api_adapter_err
    150         setPositionMode(const LocPosMode *posMode)
    151     {
    152         if (NULL != posMode) {
    153             mFixCriteria = *posMode;
    154         }
    155         return mLocApi->setPositionMode(mFixCriteria);
    156     }
    157     inline enum loc_api_adapter_err
    158         setServer(const char* url, int len)
    159     {
    160         return mLocApi->setServer(url, len);
    161     }
    162     inline enum loc_api_adapter_err
    163         setServer(unsigned int ip, int port,
    164                   LocServerType type)
    165     {
    166         return mLocApi->setServer(ip, port, type);
    167     }
    168     inline enum loc_api_adapter_err
    169         informNiResponse(GpsUserResponseType userResponse, const void* passThroughData)
    170     {
    171         return mLocApi->informNiResponse(userResponse, passThroughData);
    172     }
    173     inline enum loc_api_adapter_err
    174         setSUPLVersion(uint32_t version)
    175     {
    176         return mLocApi->setSUPLVersion(version);
    177     }
    178     inline enum loc_api_adapter_err
    179         setLPPConfig(uint32_t profile)
    180     {
    181         return mLocApi->setLPPConfig(profile);
    182     }
    183     inline enum loc_api_adapter_err
    184         setSensorControlConfig(int sensorUsage)
    185     {
    186         return mLocApi->setSensorControlConfig(sensorUsage);
    187     }
    188     inline enum loc_api_adapter_err
    189         setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, float gyroBiasVarianceRandomWalk,
    190                             bool accelBiasVarianceRandomWalk_valid, float accelBiasVarianceRandomWalk,
    191                             bool angleBiasVarianceRandomWalk_valid, float angleBiasVarianceRandomWalk,
    192                             bool rateBiasVarianceRandomWalk_valid, float rateBiasVarianceRandomWalk,
    193                             bool velocityBiasVarianceRandomWalk_valid, float velocityBiasVarianceRandomWalk)
    194     {
    195         return mLocApi->setSensorProperties(gyroBiasVarianceRandomWalk_valid, gyroBiasVarianceRandomWalk,
    196                                            accelBiasVarianceRandomWalk_valid, accelBiasVarianceRandomWalk,
    197                                            angleBiasVarianceRandomWalk_valid, angleBiasVarianceRandomWalk,
    198                                            rateBiasVarianceRandomWalk_valid, rateBiasVarianceRandomWalk,
    199                                            velocityBiasVarianceRandomWalk_valid, velocityBiasVarianceRandomWalk);
    200     }
    201     inline virtual enum loc_api_adapter_err
    202         setSensorPerfControlConfig(int controlMode, int accelSamplesPerBatch, int accelBatchesPerSec,
    203                             int gyroSamplesPerBatch, int gyroBatchesPerSec,
    204                             int accelSamplesPerBatchHigh, int accelBatchesPerSecHigh,
    205                             int gyroSamplesPerBatchHigh, int gyroBatchesPerSecHigh, int algorithmConfig)
    206     {
    207         return mLocApi->setSensorPerfControlConfig(controlMode, accelSamplesPerBatch, accelBatchesPerSec,
    208                                                   gyroSamplesPerBatch, gyroBatchesPerSec,
    209                                                   accelSamplesPerBatchHigh, accelBatchesPerSecHigh,
    210                                                   gyroSamplesPerBatchHigh, gyroBatchesPerSecHigh,
    211                                                   algorithmConfig);
    212     }
    213     inline virtual enum loc_api_adapter_err
    214         setExtPowerConfig(int isBatteryCharging)
    215     {
    216         return mLocApi->setExtPowerConfig(isBatteryCharging);
    217     }
    218     inline virtual enum loc_api_adapter_err
    219         setAGLONASSProtocol(unsigned long aGlonassProtocol)
    220     {
    221         return mLocApi->setAGLONASSProtocol(aGlonassProtocol);
    222     }
    223     inline virtual int initDataServiceClient()
    224     {
    225         return mLocApi->initDataServiceClient();
    226     }
    227     inline virtual int openAndStartDataCall()
    228     {
    229         return mLocApi->openAndStartDataCall();
    230     }
    231     inline virtual void stopDataCall()
    232     {
    233         mLocApi->stopDataCall();
    234     }
    235     inline virtual void closeDataCall()
    236     {
    237         mLocApi->closeDataCall();
    238     }
    239 
    240     virtual void handleEngineDownEvent();
    241     virtual void handleEngineUpEvent();
    242     virtual void reportPosition(UlpLocation &location,
    243                                 GpsLocationExtended &locationExtended,
    244                                 void* locationExt,
    245                                 enum loc_sess_status status,
    246                                 LocPosTechMask loc_technology_mask);
    247     virtual void reportSv(GpsSvStatus &svStatus,
    248                           GpsLocationExtended &locationExtended,
    249                           void* svExt);
    250     virtual void reportStatus(GpsStatusValue status);
    251     virtual void reportNmea(const char* nmea, int length);
    252     virtual bool reportXtraServer(const char* url1, const char* url2,
    253                                   const char* url3, const int maxlength);
    254     virtual bool requestXtraData();
    255     virtual bool requestTime();
    256     virtual bool requestATL(int connHandle, AGpsType agps_type);
    257     virtual bool releaseATL(int connHandle);
    258     virtual bool requestNiNotify(GpsNiNotification &notify, const void* data);
    259     virtual bool requestSuplES(int connHandle);
    260     virtual bool reportDataCallOpened();
    261     virtual bool reportDataCallClosed();
    262 
    263     inline const LocPosMode& getPositionMode() const
    264     {return mFixCriteria;}
    265     inline virtual bool isInSession()
    266     { return mNavigating; }
    267     inline void setInSession(bool inSession)
    268     { mNavigating = inSession; mLocApi->setInSession(inSession); }
    269 };
    270 
    271 #endif //LOC_API_ENG_ADAPTER_H
    272