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_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 37 namespace loc_core { 38 39 int hexcode(char *hexstring, int string_size, 40 const char *data, int data_size); 41 int decodeAddress(char *addr_string, int string_size, 42 const char *data, int data_size); 43 44 #define MAX_ADAPTERS 10 45 46 #define TO_ALL_ADAPTERS(adapters, call) \ 47 for (int i = 0; i < MAX_ADAPTERS && NULL != (adapters)[i]; i++) { \ 48 call; \ 49 } 50 51 #define TO_1ST_HANDLING_ADAPTER(adapters, call) \ 52 for (int i = 0; i <MAX_ADAPTERS && NULL != (adapters)[i] && !(call); i++); 53 54 55 class LocAdapterBase; 56 struct LocSsrMsg; 57 58 class LocApiBase { 59 friend struct LocSsrMsg; 60 friend class ContextBase; 61 const LOC_API_ADAPTER_EVENT_MASK_T mExcludedMask; 62 const MsgTask* mMsgTask; 63 64 LocAdapterBase* mLocAdapters[MAX_ADAPTERS]; 65 66 protected: 67 virtual enum loc_api_adapter_err 68 open(LOC_API_ADAPTER_EVENT_MASK_T mask); 69 virtual enum loc_api_adapter_err 70 close(); 71 72 LOC_API_ADAPTER_EVENT_MASK_T getEvtMask(); 73 LOC_API_ADAPTER_EVENT_MASK_T mMask; 74 LocApiBase(const MsgTask* msgTask, 75 LOC_API_ADAPTER_EVENT_MASK_T excludedMask); ~LocApiBase()76 inline virtual ~LocApiBase() { close(); } 77 bool isInSession(); 78 79 public: getSibling()80 inline virtual void* getSibling() { return NULL; } 81 82 void addAdapter(LocAdapterBase* adapter); 83 void removeAdapter(LocAdapterBase* adapter); 84 85 // upward calls 86 void handleEngineUpEvent(); 87 void handleEngineDownEvent(); 88 void reportPosition(UlpLocation &location, 89 GpsLocationExtended &locationExtended, 90 void* locationExt, 91 enum loc_sess_status status, 92 LocPosTechMask loc_technology_mask = 93 LOC_POS_TECH_MASK_DEFAULT); 94 void reportSv(GpsSvStatus &svStatus, 95 GpsLocationExtended &locationExtended, 96 void* svExt); 97 void reportStatus(GpsStatusValue status); 98 void reportNmea(const char* nmea, int length); 99 void reportXtraServer(const char* url1, const char* url2, 100 const char* url3, const int maxlength); 101 void requestXtraData(); 102 void requestTime(); 103 void requestLocation(); 104 void requestATL(int connHandle, AGpsType agps_type); 105 void releaseATL(int connHandle); 106 void requestSuplES(int connHandle); 107 void reportDataCallOpened(); 108 void reportDataCallClosed(); 109 void requestNiNotify(GpsNiNotification ¬ify, const void* data); 110 111 // downward calls 112 // All below functions are to be defined by adapter specific modules: 113 // RPC, QMI, etc. The default implementation is empty. 114 virtual enum loc_api_adapter_err 115 startFix(const LocPosMode& posMode); 116 virtual enum loc_api_adapter_err 117 stopFix(); 118 virtual enum loc_api_adapter_err 119 deleteAidingData(GpsAidingData f); 120 virtual enum loc_api_adapter_err 121 enableData(int enable); 122 virtual enum loc_api_adapter_err 123 setAPN(char* apn, int len); 124 virtual enum loc_api_adapter_err 125 injectPosition(double latitude, double longitude, float accuracy); 126 virtual enum loc_api_adapter_err 127 setTime(GpsUtcTime time, int64_t timeReference, int uncertainty); 128 virtual enum loc_api_adapter_err 129 setXtraData(char* data, int length); 130 virtual enum loc_api_adapter_err 131 requestXtraServer(); 132 virtual enum loc_api_adapter_err 133 atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, AGpsType agpsType); 134 virtual enum loc_api_adapter_err 135 atlCloseStatus(int handle, int is_succ); 136 virtual enum loc_api_adapter_err 137 setPositionMode(const LocPosMode& posMode); 138 virtual enum loc_api_adapter_err 139 setServer(const char* url, int len); 140 virtual enum loc_api_adapter_err 141 setServer(unsigned int ip, int port, 142 LocServerType type); 143 virtual enum loc_api_adapter_err 144 informNiResponse(GpsUserResponseType userResponse, const void* passThroughData); 145 virtual enum loc_api_adapter_err 146 setSUPLVersion(uint32_t version); 147 virtual enum loc_api_adapter_err 148 setLPPConfig(uint32_t profile); 149 virtual enum loc_api_adapter_err 150 setSensorControlConfig(int sensorUsage); 151 virtual enum loc_api_adapter_err 152 setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, 153 float gyroBiasVarianceRandomWalk, 154 bool accelBiasVarianceRandomWalk_valid, 155 float accelBiasVarianceRandomWalk, 156 bool angleBiasVarianceRandomWalk_valid, 157 float angleBiasVarianceRandomWalk, 158 bool rateBiasVarianceRandomWalk_valid, 159 float rateBiasVarianceRandomWalk, 160 bool velocityBiasVarianceRandomWalk_valid, 161 float velocityBiasVarianceRandomWalk); 162 virtual enum loc_api_adapter_err 163 setSensorPerfControlConfig(int controlMode, 164 int accelSamplesPerBatch, 165 int accelBatchesPerSec, 166 int gyroSamplesPerBatch, 167 int gyroBatchesPerSec, 168 int accelSamplesPerBatchHigh, 169 int accelBatchesPerSecHigh, 170 int gyroSamplesPerBatchHigh, 171 int gyroBatchesPerSecHigh, 172 int algorithmConfig); 173 virtual enum loc_api_adapter_err 174 setExtPowerConfig(int isBatteryCharging); 175 virtual enum loc_api_adapter_err 176 setAGLONASSProtocol(unsigned long aGlonassProtocol); 177 virtual int initDataServiceClient(); 178 virtual int openAndStartDataCall(); 179 virtual void stopDataCall(); 180 virtual void closeDataCall(); 181 setInSession(bool inSession)182 inline virtual void setInSession(bool inSession) {} 183 }; 184 185 typedef LocApiBase* (getLocApi_t)(const MsgTask* msgTask, 186 LOC_API_ADAPTER_EVENT_MASK_T exMask); 187 188 } // namespace loc_core 189 190 #endif //LOC_API_BASE_H 191