14035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
24035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *
34035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * Redistribution and use in source and binary forms, with or without
44035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * modification, are permitted provided that the following conditions are
54035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * met:
64035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *     * Redistributions of source code must retain the above copyright
74035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *       notice, this list of conditions and the following disclaimer.
84035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *     * Redistributions in binary form must reproduce the above
94035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *       copyright notice, this list of conditions and the following
104035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *       disclaimer in the documentation and/or other materials provided
114035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *       with the distribution.
124035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *     * Neither the name of The Linux Foundation, nor the names of its
134035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *       contributors may be used to endorse or promote products derived
144035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *       from this software without specific prior written permission.
154035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *
164035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
174035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
184035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
194035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
204035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
214035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
224035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
234035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
244035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
254035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
264035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin *
284035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin */
294035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin#ifndef __LOC_CONTEXT_BASE__
304035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin#define __LOC_CONTEXT_BASE__
314035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin
324035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin#include <stdbool.h>
334035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin#include <ctype.h>
344035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin#include <MsgTask.h>
354035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin#include <LocApiBase.h>
364035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin#include <LBSProxyBase.h>
374035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin
388cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo#define MAX_XTRA_SERVER_URL_LENGTH 256
398cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo
408cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo/* GPS.conf support */
418cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo/* NOTE: the implementaiton of the parser casts number
428cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo   fields to 32 bit. To ensure all 'n' fields working,
438cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo   they must all be 32 bit fields. */
448cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russotypedef struct loc_gps_cfg_s
458cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo{
468cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       INTERMEDIATE_POS;
478cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       ACCURACY_THRES;
488cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SUPL_VER;
498cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SUPL_MODE;
508cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       CAPABILITIES;
518cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       LPP_PROFILE;
528cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       XTRA_VERSION_CHECK;
538cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    char        XTRA_SERVER_1[MAX_XTRA_SERVER_URL_LENGTH];
548cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    char        XTRA_SERVER_2[MAX_XTRA_SERVER_URL_LENGTH];
558cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    char        XTRA_SERVER_3[MAX_XTRA_SERVER_URL_LENGTH];
568cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL;
578cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       NMEA_PROVIDER;
588cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       GPS_LOCK;
598cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       A_GLONASS_POS_PROTOCOL_SELECT;
608cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       AGPS_CERT_WRITABLE_MASK;
618cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo} loc_gps_cfg_s_type;
628cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo
638cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo/* NOTE: the implementaiton of the parser casts number
648cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo   fields to 32 bit. To ensure all 'n' fields working,
658cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo   they must all be 32 bit fields. */
668cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo/* Meanwhile, *_valid fields are 8 bit fields, and 'f'
678cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo   fields are double. Rigid as they are, it is the
688cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo   the status quo, until the parsing mechanism is
698cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo   change, that is. */
708cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russotypedef struct
718cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo{
728cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint8_t        GYRO_BIAS_RANDOM_WALK_VALID;
738cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    double         GYRO_BIAS_RANDOM_WALK;
748cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_ACCEL_BATCHES_PER_SEC;
758cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_ACCEL_SAMPLES_PER_BATCH;
768cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_GYRO_BATCHES_PER_SEC;
778cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_GYRO_SAMPLES_PER_BATCH;
788cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_ACCEL_BATCHES_PER_SEC_HIGH;
798cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH;
808cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_GYRO_BATCHES_PER_SEC_HIGH;
818cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH;
828cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_CONTROL_MODE;
838cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_USAGE;
848cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_ALGORITHM_CONFIG_MASK;
858cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint8_t        ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
868cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    double         ACCEL_RANDOM_WALK_SPECTRAL_DENSITY;
878cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint8_t        ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
888cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    double         ANGLE_RANDOM_WALK_SPECTRAL_DENSITY;
898cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint8_t        RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
908cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    double         RATE_RANDOM_WALK_SPECTRAL_DENSITY;
918cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint8_t        VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
928cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    double         VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY;
938cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    uint32_t       SENSOR_PROVIDER;
948cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo} loc_sap_cfg_s_type;
958cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo
964035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjinnamespace loc_core {
974035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin
984035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjinclass LocAdapterBase;
994035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin
1004035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjinclass ContextBase {
1014035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    static LBSProxyBase* getLBSProxy(const char* libName);
1024035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    LocApiBase* createLocApi(LOC_API_ADAPTER_EVENT_MASK_T excludedMask);
1034035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjinprotected:
1044035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    const LBSProxyBase* mLBSProxy;
1054035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    const MsgTask* mMsgTask;
1064035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    LocApiBase* mLocApi;
1074035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    LocApiProxyBase *mLocApiProxy;
1084035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjinpublic:
1094035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    ContextBase(const MsgTask* msgTask,
1104035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin                LOC_API_ADAPTER_EVENT_MASK_T exMask,
1114035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin                const char* libName);
1124035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    inline virtual ~ContextBase() { delete mLocApi; delete mLBSProxy; }
1134035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin
1144035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    inline const MsgTask* getMsgTask() { return mMsgTask; }
1154035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    inline LocApiBase* getLocApi() { return mLocApi; }
1164035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    inline LocApiProxyBase* getLocApiProxy() { return mLocApiProxy; }
1174035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    inline bool hasAgpsExtendedCapabilities() { return mLBSProxy->hasAgpsExtendedCapabilities(); }
1184035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    inline bool hasCPIExtendedCapabilities() { return mLBSProxy->hasCPIExtendedCapabilities(); }
119e0bc79ad558c27738e4777f5c00745979aa703eeDante Russo    inline bool hasNativeXtraClient() { return mLBSProxy->hasNativeXtraClient(); }
1204035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    inline void modemPowerVote(bool power) const { return mLBSProxy->modemPowerVote(power); }
1214035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    inline void requestUlp(LocAdapterBase* adapter,
1224035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin                           unsigned long capabilities) {
1234035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin        mLBSProxy->requestUlp(adapter, capabilities);
1244035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    }
1254035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin    inline void sendMsg(const LocMsg *msg) { getMsgTask()->sendMsg(msg); }
1268cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo
1278cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    static loc_gps_cfg_s_type mGps_conf;
1288cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    static loc_sap_cfg_s_type mSap_conf;
1298cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo
1308cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo    static uint32_t getCarrierCapabilities();
1318cf3e0e4ddbbb98ddf51be7685bcea37b32cfabeDante Russo
1324035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin};
1334035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin
1344035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin} // namespace loc_core
1354035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin
1364035be28a255eaa5605dbd9abeb2340db584249cPatrick Tjin#endif //__LOC_CONTEXT_BASE__
137