Debian Codegraph @

gobi-api/Gobi_2011-11-28-1533/GobiConnectionMgmt/GobiConnectionMgmt.h

raw
1 /*===========================================================================
2 FILE:
3 GobiConnectionMgmt.h
4
5 DESCRIPTION:
6 QUALCOMM Connection Management API for Gobi
7
8 PUBLIC CLASSES AND FUNCTIONS:
9 CGobiConnectionMgmtDLL
10 cGobiConnectionMgmt
11
12 Copyright (c) 2011, Code Aurora Forum. All rights reserved.
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions are met:
16 * Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21 * Neither the name of Code Aurora Forum nor
22 the names of its contributors may be used to endorse or promote
23 products derived from this software without specific prior written
24 permission.
25
26
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 POSSIBILITY OF SUCH DAMAGE.
38 ==========================================================================*/
39
40 /*=========================================================================*/
41 // Pragmas
42 /*=========================================================================*/
43 #pragma once
44
45 //---------------------------------------------------------------------------
46 // Include Files
47 //---------------------------------------------------------------------------
48 #include "GobiQMICore.h"
49
50 #include "QMIBuffers.h"
51
52 //---------------------------------------------------------------------------
53 // Definitions
54 //---------------------------------------------------------------------------
55
56 // Handle to Gobi API
57 typedef ULONG_PTR GOBIHANDLE;
58
59 extern "C"
60 {
61 // Generic callback function pointer
62 typedef void (* tFNGenericCallback)(
63 ULONG svcID,
64 ULONG msgID,
65 ULONG_PTR userValue,
66 ULONG outLen,
67 const BYTE * pOut );
68
69 };
70
71 // CallbackThread prototype
72 // Thread to execute a callback asynchronously
73 void * CallbackThread( PVOID pArg );
74
75 /*=========================================================================*/
76 // Class cGobiCMCallback
77 /*=========================================================================*/
78 class cGobiCMCallback
79 {
80 public:
81 // (Inline) Constructor
82 cGobiCMCallback()
83 { };
84
85 // (Inline) Destructor
86 virtual ~cGobiCMCallback()
87 { };
88
89 // (Inline) Initialize the callback object by starting the thread
90 bool Initialize()
91 {
92 // Start the thread
93 pthread_t threadID;
94 pthread_attr_t attributes;
95 pthread_attr_init( &attributes );
96 pthread_attr_setdetachstate( &attributes, PTHREAD_CREATE_DETACHED );
97
98 int nRC = pthread_create( &threadID,
99 &attributes,
100 CallbackThread,
101 this );
102
103 if (nRC == 0)
104 {
105 // Success!
106 return true;
107 }
108
109 return false;
110 };
111
112 protected:
113 // Call the function
114 virtual void Call() = 0;
115
116 // Function thread gets full access
117 friend void * CallbackThread( PVOID pArg );
118 };
119
120 /*=========================================================================*/
121 // Class cGenericCallback
122 /*=========================================================================*/
123 class cGenericCallback : public cGobiCMCallback
124 {
125 public:
126 // (Inline) Constructor
127 cGenericCallback(
128 tFNGenericCallback pCallback,
129 ULONG svcID,
130 ULONG msgID,
131 ULONG_PTR userValue,
132 ULONG outLen,
133 const BYTE * pOut )
134 : mServiceID( svcID ),
135 mMessageID( msgID ),
136 mUserValue( userValue ),
137 mOutputLen( 0 ),
138 mpCallback( pCallback )
139 {
140 memset( &mOutput[0], 0, QMI_MAX_BUFFER_SIZE );
141 if (outLen <= QMI_MAX_BUFFER_SIZE && pOut != 0)
142 {
143 mOutputLen = outLen;
144 memcpy( &mOutput[0], pOut, outLen );
145 }
146 };
147
148 // (Inline) Destructor
149 virtual ~cGenericCallback()
150 {
151 mpCallback = 0;
152 };
153
154 protected:
155 /* Service ID */
156 ULONG mServiceID;
157
158 /* Message ID */
159 ULONG mMessageID;
160
161 /* User value */
162 ULONG_PTR mUserValue;
163
164 /* Actual size of output content */
165 ULONG mOutputLen;
166
167 /* Output content buffer */
168 BYTE mOutput[QMI_MAX_BUFFER_SIZE];
169
170 /* Callback function */
171 tFNGenericCallback mpCallback;
172
173 // Call the function
174 virtual void Call()
175 {
176 if (mpCallback != 0)
177 {
178 mpCallback( mServiceID,
179 mMessageID,
180 mUserValue,
181 mOutputLen,
182 (const BYTE *)&mOutput[0] );
183 }
184 };
185 };
186
187 /*=========================================================================*/
188 // Class cGobiConnectionMgmt
189 /*=========================================================================*/
190 class cGobiConnectionMgmt : public cGobiQMICore
191 {
192 public:
193 // Constructor
194 cGobiConnectionMgmt();
195
196 // Destructor
197 virtual ~cGobiConnectionMgmt();
198
199 // Connect to the specified Gobi device interface
200 virtual std::set <eQMIService> Connect(
201 LPCSTR pInterface,
202 std::set <eQMIService> & services );
203
204 // Disconnect from the currently connected device interface
205 virtual bool Disconnect();
206
207 // Enable/disable generic callback function
208 eGobiError SetGenericCallback(
209 ULONG svcID,
210 ULONG msgID,
211 tFNGenericCallback pCallback,
212 ULONG_PTR userValue );
213
214 protected:
215 // Process new traffic
216 void ProcessTraffic( eQMIService svc );
217
218 /* Is there an active thread? */
219 bool mbThreadStarted;
220
221 /* ID of traffic processing thread */
222 pthread_t mThreadID;
223
224 /* Traffic processing thread exit event */
225 cEvent mExitEvent;
226
227 /* Has the protocol server thread finished cleanup? */
228 bool mThreadCleanupFinished;
229
230 /* Generic callback function key/value */
231 typedef std::pair <ULONG, ULONG> tCallbackKey;
232 typedef std::pair <tFNGenericCallback, ULONG_PTR> tCallbackValue;
233
234 /* Callback functions */
235 std::map <tCallbackKey, tCallbackValue> mCallbacks;
236
237 // Traffic process thread gets full access
238 friend VOID * TrafficProcessThread( PVOID pArg );
239 };
240
241 /*=========================================================================*/
242 // Class CGobiConnectionMgmtDLL
243 /*=========================================================================*/
244 class CGobiConnectionMgmtDLL
245 {
246 public:
247 // Constructor
248 CGobiConnectionMgmtDLL();
249
250 // Destructor
251 virtual ~CGobiConnectionMgmtDLL();
252
253 // Create a new API object
254 GOBIHANDLE CreateAPI();
255
256 // Delete an existing API object
257 void DeleteAPI( GOBIHANDLE handle );
258
259 // Return the requested API object
260 cGobiConnectionMgmt * GetAPI( GOBIHANDLE handle );
261
262 protected:
263 /* API interface object */
264 std::map <GOBIHANDLE, cGobiConnectionMgmt *> mAPI;
265
266 /* Synchronization object */
267 mutable pthread_mutex_t mSyncSection;
268 };
269
270 extern CGobiConnectionMgmtDLL gDLL;