1 /* Copyright (c) 2009-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 
30 #define LOG_NDDEBUG 0
31 #define LOG_TAG "LocSvc_eng"
32 
33 #include <loc_eng.h>
34 #include <MsgTask.h>
35 #include "log_util.h"
36 #include "platform_lib_includes.h"
37 
38 using namespace loc_core;
39 
40 struct LocEngRequestXtraServer : public LocMsg {
41     LocEngAdapter* mAdapter;
LocEngRequestXtraServerLocEngRequestXtraServer42     inline LocEngRequestXtraServer(LocEngAdapter* adapter) :
43         LocMsg(), mAdapter(adapter)
44     {
45         locallog();
46     }
procLocEngRequestXtraServer47     inline virtual void proc() const {
48         mAdapter->requestXtraServer();
49     }
locallogLocEngRequestXtraServer50     inline void locallog() const {
51         LOC_LOGV("LocEngRequestXtraServer");
52     }
logLocEngRequestXtraServer53     inline virtual void log() const {
54         locallog();
55     }
56 };
57 
58 struct LocEngInjectXtraData : public LocMsg {
59     LocEngAdapter* mAdapter;
60     char* mData;
61     const int mLen;
LocEngInjectXtraDataLocEngInjectXtraData62     inline LocEngInjectXtraData(LocEngAdapter* adapter,
63                                 char* data, int len):
64         LocMsg(), mAdapter(adapter),
65         mData(new char[len]), mLen(len)
66     {
67         memcpy((void*)mData, (void*)data, len);
68         locallog();
69     }
~LocEngInjectXtraDataLocEngInjectXtraData70     inline ~LocEngInjectXtraData()
71     {
72         delete[] mData;
73     }
procLocEngInjectXtraData74     inline virtual void proc() const {
75         mAdapter->setXtraData(mData, mLen);
76     }
locallogLocEngInjectXtraData77     inline  void locallog() const {
78         LOC_LOGV("length: %d\n  data: %p", mLen, mData);
79     }
logLocEngInjectXtraData80     inline virtual void log() const {
81         locallog();
82     }
83 };
84 
85 /*===========================================================================
86 FUNCTION    loc_eng_xtra_init
87 
88 DESCRIPTION
89    Initialize XTRA module.
90 
91 DEPENDENCIES
92    N/A
93 
94 RETURN VALUE
95    0: success
96 
97 SIDE EFFECTS
98    N/A
99 
100 ===========================================================================*/
loc_eng_xtra_init(loc_eng_data_s_type & loc_eng_data,GpsXtraExtCallbacks * callbacks)101 int loc_eng_xtra_init (loc_eng_data_s_type &loc_eng_data,
102                        GpsXtraExtCallbacks* callbacks)
103 {
104     int ret_val = -1;
105     loc_eng_xtra_data_s_type *xtra_module_data_ptr;
106 
107     if(callbacks == NULL) {
108         LOC_LOGE("loc_eng_xtra_init: failed, cb is NULL");
109     } else {
110         xtra_module_data_ptr = &loc_eng_data.xtra_module_data;
111         xtra_module_data_ptr->download_request_cb = callbacks->download_request_cb;
112         xtra_module_data_ptr->report_xtra_server_cb = callbacks->report_xtra_server_cb;
113 
114         ret_val = 0;
115     }
116     return ret_val;
117 }
118 
119 /*===========================================================================
120 FUNCTION    loc_eng_xtra_inject_data
121 
122 DESCRIPTION
123    Injects XTRA file into the engine but buffers the data if engine is busy.
124 
125 DEPENDENCIES
126    N/A
127 
128 RETURN VALUE
129    0: success
130    >0: failure
131 
132 SIDE EFFECTS
133    N/A
134 
135 ===========================================================================*/
loc_eng_xtra_inject_data(loc_eng_data_s_type & loc_eng_data,char * data,int length)136 int loc_eng_xtra_inject_data(loc_eng_data_s_type &loc_eng_data,
137                              char* data, int length)
138 {
139     LocEngAdapter* adapter = loc_eng_data.adapter;
140     adapter->sendMsg(new LocEngInjectXtraData(adapter, data, length));
141 
142     return 0;
143 }
144 /*===========================================================================
145 FUNCTION    loc_eng_xtra_request_server
146 
147 DESCRIPTION
148    Request the Xtra server url from the modem
149 
150 DEPENDENCIES
151    N/A
152 
153 RETURN VALUE
154    length of server string
155 
156 SIDE EFFECTS
157    N/A
158 
159 ===========================================================================*/
loc_eng_xtra_request_server(loc_eng_data_s_type & loc_eng_data)160 int loc_eng_xtra_request_server(loc_eng_data_s_type &loc_eng_data)
161 {
162     LocEngAdapter* adapter = loc_eng_data.adapter;
163     adapter->sendMsg(new LocEngRequestXtraServer(adapter));
164 
165     return 0;
166 
167 }
168