| 1 |
/*=========================================================================== |
| 2 |
FILE: |
| 3 |
GobiQMICore.h |
| 4 |
|
| 5 |
DESCRIPTION: |
| 6 |
QUALCOMM Gobi QMI Based API Core |
| 7 |
|
| 8 |
PUBLIC CLASSES AND FUNCTIONS: |
| 9 |
cGobiQMICore |
| 10 |
|
| 11 |
Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 12 |
|
| 13 |
Redistribution and use in source and binary forms, with or without |
| 14 |
modification, are permitted provided that the following conditions are met: |
| 15 |
* Redistributions of source code must retain the above copyright |
| 16 |
notice, this list of conditions and the following disclaimer. |
| 17 |
* Redistributions in binary form must reproduce the above copyright |
| 18 |
notice, this list of conditions and the following disclaimer in the |
| 19 |
documentation and/or other materials provided with the distribution. |
| 20 |
* Neither the name of Code Aurora Forum nor |
| 21 |
the names of its contributors may be used to endorse or promote |
| 22 |
products derived from this software without specific prior written |
| 23 |
permission. |
| 24 |
|
| 25 |
|
| 26 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 27 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 28 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 29 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 30 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 31 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 32 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 33 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 34 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 35 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 |
POSSIBILITY OF SUCH DAMAGE. |
| 37 |
==========================================================================*/ |
| 38 |
|
| 39 |
/*=========================================================================*/ |
| 40 |
// Pragmas |
| 41 |
/*=========================================================================*/ |
| 42 |
#pragma once |
| 43 |
|
| 44 |
//--------------------------------------------------------------------------- |
| 45 |
// Include Files |
| 46 |
//--------------------------------------------------------------------------- |
| 47 |
#include "ProtocolBuffer.h" |
| 48 |
#include "QMIProtocolServer.h" |
| 49 |
#include "SyncQueue.h" |
| 50 |
#include "GobiError.h" |
| 51 |
|
| 52 |
/*=========================================================================*/ |
| 53 |
// Class cGobiQMICore |
| 54 |
/*=========================================================================*/ |
| 55 |
class cGobiQMICore |
| 56 |
{ |
| 57 |
public: |
| 58 |
// Constructor |
| 59 |
cGobiQMICore(); |
| 60 |
|
| 61 |
// Destructor |
| 62 |
virtual ~cGobiQMICore(); |
| 63 |
|
| 64 |
// Initialize the object |
| 65 |
virtual bool Initialize(); |
| 66 |
|
| 67 |
// Cleanup the object |
| 68 |
virtual bool Cleanup(); |
| 69 |
|
| 70 |
// (Inline) Return the server as determined by the service type |
| 71 |
cQMIProtocolServer * GetServer( eQMIService svc ) |
| 72 |
{ |
| 73 |
cQMIProtocolServer * pSvr = 0; |
| 74 |
|
| 75 |
std::map <eQMIService, sServerInfo>::const_iterator pIter; |
| 76 |
pIter = mServers.find( svc ); |
| 77 |
|
| 78 |
if (pIter != mServers.end()) |
| 79 |
{ |
| 80 |
const sServerInfo & si = pIter->second; |
| 81 |
pSvr = si.mpServer; |
| 82 |
} |
| 83 |
|
| 84 |
return pSvr; |
| 85 |
}; |
| 86 |
|
| 87 |
// (Inline) Clear last error recorded |
| 88 |
void ClearLastError() |
| 89 |
{ |
| 90 |
mLastError = eGOBI_ERR_NONE; |
| 91 |
}; |
| 92 |
|
| 93 |
// (Inline) Get last error recorded |
| 94 |
eGobiError GetLastError() |
| 95 |
{ |
| 96 |
return mLastError; |
| 97 |
}; |
| 98 |
|
| 99 |
// (Inline) Return the last recorded error (if this happens to indicate |
| 100 |
// that no error occurred then return eGOBI_ERR_INTERNAL) |
| 101 |
eGobiError GetCorrectedLastError() |
| 102 |
{ |
| 103 |
eGobiError ec = GetLastError(); |
| 104 |
if (ec == eGOBI_ERR_NONE) |
| 105 |
{ |
| 106 |
ec = eGOBI_ERR_INTERNAL; |
| 107 |
} |
| 108 |
|
| 109 |
return ec; |
| 110 |
}; |
| 111 |
|
| 112 |
// (Inline) Return the correct QMI error (if this happens to indicate |
| 113 |
// that no error occurred then return the mapped eQMI_ERR_INTERNAL |
| 114 |
// value) |
| 115 |
eGobiError GetCorrectedQMIError( ULONG qmiErrorCode ) |
| 116 |
{ |
| 117 |
ULONG ec = (ULONG)eQMI_ERR_INTERNAL + (ULONG)eGOBI_ERR_QMI_OFFSET; |
| 118 |
if (qmiErrorCode != (ULONG)eQMI_ERR_NONE) |
| 119 |
{ |
| 120 |
ec = qmiErrorCode + (ULONG)eGOBI_ERR_QMI_OFFSET; |
| 121 |
} |
| 122 |
|
| 123 |
return (eGobiError)ec; |
| 124 |
}; |
| 125 |
|
| 126 |
// Connect to the specified Gobi device interface |
| 127 |
virtual std::set <eQMIService> Connect( |
| 128 |
LPCSTR pInterface, |
| 129 |
std::set <eQMIService> & services ); |
| 130 |
|
| 131 |
// Disconnect from the currently connected device interface |
| 132 |
virtual bool Disconnect(); |
| 133 |
|
| 134 |
// Send a request using the specified QMI protocol server and wait |
| 135 |
// for (and then return) the response |
| 136 |
eGobiError Send( |
| 137 |
ULONG svcID, |
| 138 |
ULONG msgID, |
| 139 |
ULONG to, |
| 140 |
ULONG inLen, |
| 141 |
const BYTE * pIn, |
| 142 |
ULONG * pOutLen, |
| 143 |
BYTE * pOut ); |
| 144 |
|
| 145 |
// Cancel the most recent in-progress Send() based operation |
| 146 |
eGobiError CancelSend( |
| 147 |
ULONG svcID, |
| 148 |
ULONG * pTXID ); |
| 149 |
|
| 150 |
protected: |
| 151 |
/* Device interface */ |
| 152 |
CHAR mInterface[MAX_PATH]; |
| 153 |
|
| 154 |
/* QMI protocol server/protocol server log count */ |
| 155 |
struct sServerInfo |
| 156 |
{ |
| 157 |
public: |
| 158 |
// Constructor (default) |
| 159 |
sServerInfo() |
| 160 |
: mpServer( 0 ), |
| 161 |
mLogsProcessed( 0 ), |
| 162 |
mRequestID( 0xffffffff ), |
| 163 |
mRequestTXID( 0xffffffff ) |
| 164 |
{ }; |
| 165 |
|
| 166 |
// Constructor (parameterized) |
| 167 |
sServerInfo( cQMIProtocolServer * pServer ) |
| 168 |
: mpServer( pServer ), |
| 169 |
mLogsProcessed( 0 ), |
| 170 |
mRequestID( 0xffffffff ), |
| 171 |
mRequestTXID( 0xffffffff ) |
| 172 |
{ }; |
| 173 |
|
| 174 |
/* Protocol server */ |
| 175 |
cQMIProtocolServer * mpServer; |
| 176 |
|
| 177 |
/* Protocol server logs processed */ |
| 178 |
ULONG mLogsProcessed; |
| 179 |
|
| 180 |
/* Last scheduled request ID */ |
| 181 |
ULONG mRequestID; |
| 182 |
|
| 183 |
/* Last schedule request QMI transaction ID */ |
| 184 |
ULONG mRequestTXID; |
| 185 |
}; |
| 186 |
|
| 187 |
/* QMI protocol servers */ |
| 188 |
std::map <eQMIService, sServerInfo> mServers; |
| 189 |
|
| 190 |
/* Last error recorded */ |
| 191 |
eGobiError mLastError; |
| 192 |
}; |