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 38 using namespace loc_core; 39 40 class LocApiRpc : public LocApiBase { 41 protected: 42 // RPC communication establishment 43 rpc_loc_client_handle_type client_handle; 44 45 private: 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 65 protected: 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 LocApiRpc(const MsgTask* msgTask, 71 LOC_API_ADAPTER_EVENT_MASK_T exMask); 72 73 public: 74 static LocApiRpc* createLocApiRpc(const MsgTask* msgTask, 75 LOC_API_ADAPTER_EVENT_MASK_T exMask); 76 ~LocApiRpc(); 77 78 virtual int locEventCB(rpc_loc_client_handle_type client_handle, 79 rpc_loc_event_mask_type loc_event, 80 const rpc_loc_event_payload_u_type* loc_event_payload); 81 82 void locRpcGlobalCB(CLIENT* clnt, enum rpc_reset_event event); 83 84 // RPC adapter interface implementations 85 virtual enum loc_api_adapter_err 86 startFix(const LocPosMode& posMode); 87 virtual enum loc_api_adapter_err 88 stopFix(); 89 virtual enum loc_api_adapter_err 90 setPositionMode(const LocPosMode& mode); 91 inline virtual enum loc_api_adapter_err 92 enableData(int enable) { return enableData(enable, false); } 93 virtual enum loc_api_adapter_err 94 enableData(int enable, boolean force); 95 virtual enum loc_api_adapter_err 96 setTime(GpsUtcTime time, int64_t timeReference, int uncertainty); 97 virtual enum loc_api_adapter_err 98 injectPosition(double latitude, double longitude, float accuracy); 99 virtual enum loc_api_adapter_err 100 deleteAidingData(GpsAidingData f); 101 virtual enum loc_api_adapter_err 102 informNiResponse(GpsUserResponseType userResponse, const void* passThroughData); 103 inline virtual enum loc_api_adapter_err 104 setAPN(char* apn, int len) { return setAPN(apn, len, false); } 105 virtual enum loc_api_adapter_err 106 setAPN(char* apn, int len, boolean force); 107 virtual enum loc_api_adapter_err 108 setServer(const char* url, int len); 109 virtual enum loc_api_adapter_err 110 setServer(unsigned int ip, int port, LocServerType type); 111 virtual enum loc_api_adapter_err 112 setXtraData(char* data, int length); 113 virtual enum loc_api_adapter_err 114 requestXtraServer(); 115 virtual enum loc_api_adapter_err 116 atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, AGpsType agpsType); 117 virtual enum loc_api_adapter_err 118 atlCloseStatus(int handle, int is_succ); 119 virtual enum loc_api_adapter_err 120 setSUPLVersion(uint32_t version); 121 virtual void setInSession(bool inSession); 122 123 /*Values for lock 124 1 = Do not lock any position sessions 125 2 = Lock MI position sessions 126 3 = Lock MT position sessions 127 4 = Lock all position sessions 128 */ 129 virtual int setGpsLock(LOC_GPS_LOCK_MASK lock); 130 /* 131 Returns 132 Current value of GPS Lock on success 133 -1 on failure 134 */ 135 virtual int getGpsLock(void); 136 }; 137 138 extern "C" LocApiBase* getLocApi(const MsgTask* msgTask, 139 LOC_API_ADAPTER_EVENT_MASK_T exMask, 140 ContextBase *context); 141 142 #endif //LOC_API_RPC_H 143