aboutsummaryrefslogtreecommitdiffstats
path: root/gobi-api/GobiAPI_1.0.40/Core/DB2Utilities.h
blob: b3223e1e44f1ebe31556a6e20c361e5b19cbe741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*===========================================================================
FILE:
   DB2Utilities.h

DESCRIPTION:
   Utility functions for packing/parsing protocol entities using the
   database

PUBLIC ENUMERATIONS AND METHODS:
   sProtocolEntityKey
   sDB2PackingInput
   sDB2NavInput

   MapQMIEntityTypeToProtocolType
   MapQMIEntityTypeToQMIServiceType
   MapQMIProtocolTypeToEntityType
   DB2GetMaxBufferSize
   DB2BuildQMIBuffer
   DB2PackQMIBuffer
   DB2ReduceQMIBuffer

Copyright (c) 2011, Code Aurora Forum. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Code Aurora Forum nor
      the names of its contributors may be used to endorse or promote
      products derived from this software without specific prior written
      permission.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
===========================================================================*/

//---------------------------------------------------------------------------
// Pragmas
//---------------------------------------------------------------------------
#pragma once

//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include "CoreDatabase.h"
#include "SharedBuffer.h"
#include "ProtocolBuffer.h"
#include "QMIEnum.h"

#include <vector>

//---------------------------------------------------------------------------
// Definitions
//---------------------------------------------------------------------------

/*=========================================================================*/
// Struct sProtocolEntityKey
//    Simple structure to initializing protocol entity keys easier
/*=========================================================================*/
struct sProtocolEntityKey
{
   public:
      // (Inline) Constructor - default
      sProtocolEntityKey()
      { };
 
      // (Inline) Constructor - single value keys
      sProtocolEntityKey( ULONG val1 )
      {
         mKey.push_back( val1 );
      };

      // (Inline) Constructor - two value keys
      sProtocolEntityKey( 
         ULONG                      val1,
         ULONG                      val2 )
      {
         mKey.push_back( val1 );
         mKey.push_back( val2 );
      };

      // (Inline) Constructor - three value keys
      sProtocolEntityKey( 
         ULONG                      val1,
         ULONG                      val2,
         ULONG                      val3 )
      {
         mKey.push_back( val1 );
         mKey.push_back( val2 );
         mKey.push_back( val3 );
      };

      // (Inline) Constructor - psuedo-copy constructor
      sProtocolEntityKey( const std::vector <ULONG> & key )
         :  mKey( key )
      { };

      // (Inline) Constructor - copy constructor
      sProtocolEntityKey( const sProtocolEntityKey & key )
         :  mKey( key.mKey )
      { };

      // (Inline) Assignment operator
      sProtocolEntityKey & operator = ( const sProtocolEntityKey & key )
      {
         mKey = key.mKey;
         return *this;
      };

      // Cast operator to a protocol entity key
      operator std::vector <ULONG>() const
      {
         return mKey;
      };

      /* Underlying key */
      std::vector <ULONG> mKey;
};

/*=========================================================================*/
// Struct sDB2PackingInput
//    Simple structure to make dealing packing easier
/*=========================================================================*/
struct sDB2PackingInput
{
   public:
      // (Inline) Constructor - default
      sDB2PackingInput()
         :  mpData( 0 ),
            mDataLen( 0 ),
            mbString( true )
      { };
 
      // (Inline) Constructor - parameterized (string payload)
      sDB2PackingInput( 
         const sProtocolEntityKey & key,
         LPCSTR                     pValue )
         :  mKey( key ),
            mpData( 0 ),
            mDataLen( 0 ),
            mbString( true )
      { 
         if (pValue != 0 && pValue[0] != 0)
         {
            mValues = pValue;
         }
      };

      // (Inline) Constructor - parameterized (buffer payload)
      sDB2PackingInput( 
         const sProtocolEntityKey & key,
         const BYTE *               pData,
         ULONG                      dataLen )
         :  mKey( key ),
            mpData( pData ),
            mDataLen( dataLen ),
            mbString( false )
      { 
         // Nothing to do
      };

      // (Inline) Is this object in a valid state?
      bool IsValid() const
      {
         // We need a key
         if (mKey.size() <= 0)
         {
            return false;
         }

         return true;
      };

      /* Underlying key */
      std::vector <ULONG> mKey;

      /* Are the values specified by a string? */
      bool mbString;

      /* String of space delimited field values */
      std::string mValues;
      
      /* Buffer containing pre-formatted fields */
      const BYTE * mpData;

      /* Length of above buffer */
      ULONG mDataLen;
};

/*=========================================================================*/
// Struct sDB2NavInput
//    Simple structure to make dealing with key/payload easier
/*=========================================================================*/
struct sDB2NavInput
{
   public:
      // (Inline) Constructor - default
      sDB2NavInput()
         :  mpPayload( 0 ),
            mPayloadLen( 0 )
      { };

      // (Inline) Constructor - parameterized
      sDB2NavInput( 
         const std::vector <ULONG> &   key,
         const BYTE *                  pData,
         ULONG                         dataLen )
         :  mKey( key ),
            mpPayload( pData ),
            mPayloadLen( dataLen )
      { };

      // (Inline) Is this object in a valid state?
      bool IsValid() const
      {
         return (mKey.size() > 0 && mpPayload != 0 && mPayloadLen > 0);
      };

      /* Database key for payload entity */
      std::vector <ULONG> mKey;

      /* Payload */
      const BYTE * mpPayload;

      /* Size of above payload */
      ULONG mPayloadLen;
};

// Map a DB protocol entity type to a buffer protocol type
eProtocolType MapQMIEntityTypeToProtocolType( eDB2EntityType et );

// Map a DB protocol entity type to a QMI service type
eQMIService MapQMIEntityTypeToQMIServiceType( eDB2EntityType et );

// Map a buffer protocol type to a DB protocol entity type
eDB2EntityType MapQMIProtocolTypeToEntityType( 
   eProtocolType              pt,
   bool                       bIndication = false );

// Return the maximum size of a payload buffer for given type of 
// protocol entity
ULONG DB2GetMaxBufferSize( eDB2EntityType et );

// Build an allocated shared buffer for the QMI protocol
sSharedBuffer * DB2BuildQMIBuffer(
   const std::vector <sDB2NavInput> &  input );

// Build an allocated shared buffer for the QMI protocol
sSharedBuffer * DB2PackQMIBuffer(
   const cCoreDatabase &                  db,
   const std::vector <sDB2PackingInput> & input );

// Reduce a QMI buffer to DB keys and payload
std::vector <sDB2NavInput> DB2ReduceQMIBuffer( const sProtocolBuffer & buf );