1/* Copyright (c) 2011,2014, 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_RPC_H 30#define LOC_API_RPC_H 31 32#include <rpc/rpc.h> 33#include <loc_api_rpcgen_common_rpc.h> 34#include <loc_api_rpc_glue.h> 35#include <LocApiBase.h> 36#include <loc_log.h> 37 38using namespace loc_core; 39 40class LocApiRpc : public LocApiBase { 41protected: 42 // RPC communication establishment 43 rpc_loc_client_handle_type client_handle; 44 45private: 46 int dataEnableLastSet; 47 char apnLastSet[MAX_APN_LEN]; 48 49 static const LOC_API_ADAPTER_EVENT_MASK_T maskAll; 50 static const rpc_loc_event_mask_type locBits[]; 51 static rpc_loc_event_mask_type convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask); 52 static rpc_loc_lock_e_type convertGpsLockMask(LOC_GPS_LOCK_MASK lockMask); 53 static enum loc_api_adapter_err convertErr(int rpcErr); 54 static GpsNiEncodingType convertNiEncodingType(int loc_encoding); 55 static int NIEventFillVerfiyType(GpsNiNotification ¬if, 56 rpc_loc_ni_notify_verify_e_type notif_priv); 57 58 void reportPosition(const rpc_loc_parsed_position_s_type *location_report_ptr); 59 void reportSv(const rpc_loc_gnss_info_s_type *gnss_report_ptr); 60 void reportStatus(const rpc_loc_status_event_s_type *status_report_ptr); 61 void reportNmea(const rpc_loc_nmea_report_s_type *nmea_report_ptr); 62 void ATLEvent(const rpc_loc_server_request_s_type *server_request_ptr); 63 void NIEvent(const rpc_loc_ni_event_s_type *ni_req_ptr); 64 65protected: 66 virtual enum loc_api_adapter_err 67 open(LOC_API_ADAPTER_EVENT_MASK_T mask); 68 virtual enum loc_api_adapter_err 69 close(); 70 71public: 72 LocApiRpc(const MsgTask* msgTask, 73 LOC_API_ADAPTER_EVENT_MASK_T exMask); 74 ~LocApiRpc(); 75 76 virtual int locEventCB(rpc_loc_client_handle_type client_handle, 77 rpc_loc_event_mask_type loc_event, 78 const rpc_loc_event_payload_u_type* loc_event_payload); 79 80 void locRpcGlobalCB(CLIENT* clnt, enum rpc_reset_event event); 81 82 // RPC adapter interface implementations 83 virtual enum loc_api_adapter_err 84 startFix(const LocPosMode& posMode); 85 virtual enum loc_api_adapter_err 86 stopFix(); 87 virtual enum loc_api_adapter_err 88 setPositionMode(const LocPosMode& mode); 89 inline virtual enum loc_api_adapter_err 90 enableData(int enable) { return enableData(enable, false); } 91 virtual enum loc_api_adapter_err 92 enableData(int enable, boolean force); 93 virtual enum loc_api_adapter_err 94 setTime(GpsUtcTime time, int64_t timeReference, int uncertainty); 95 virtual enum loc_api_adapter_err 96 injectPosition(double latitude, double longitude, float accuracy); 97 virtual enum loc_api_adapter_err 98 deleteAidingData(GpsAidingData f); 99 virtual enum loc_api_adapter_err 100 informNiResponse(GpsUserResponseType userResponse, const void* passThroughData); 101 inline virtual enum loc_api_adapter_err 102 setAPN(char* apn, int len) { return setAPN(apn, len, false); } 103 virtual enum loc_api_adapter_err 104 setAPN(char* apn, int len, boolean force); 105 virtual enum loc_api_adapter_err 106 setServer(const char* url, int len); 107 virtual enum loc_api_adapter_err 108 setServer(unsigned int ip, int port, LocServerType type); 109 virtual enum loc_api_adapter_err 110 setXtraData(char* data, int length); 111 virtual enum loc_api_adapter_err 112 requestXtraServer(); 113 virtual enum loc_api_adapter_err 114 atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, AGpsType agpsType); 115 virtual enum loc_api_adapter_err 116 atlCloseStatus(int handle, int is_succ); 117 virtual enum loc_api_adapter_err 118 setSUPLVersion(uint32_t version); 119 virtual void setInSession(bool inSession); 120 121 /*Values for lock 122 1 = Do not lock any position sessions 123 2 = Lock MI position sessions 124 3 = Lock MT position sessions 125 4 = Lock all position sessions 126 */ 127 virtual int setGpsLock(LOC_GPS_LOCK_MASK lock); 128 /* 129 Returns 130 Current value of GPS Lock on success 131 -1 on failure 132 */ 133 virtual int getGpsLock(void); 134}; 135 136extern "C" LocApiBase* getLocApi(const MsgTask* msgTask, 137 LOC_API_ADAPTER_EVENT_MASK_T exMask, 138 ContextBase *context); 139 140#endif //LOC_API_RPC_H 141