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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
|
/*===========================================================================
FILE:
CoreDatabase.h
DESCRIPTION:
Declaration of cCoreDatabase class
PUBLIC CLASSES AND METHODS:
cCoreDatabase
This class represents the run-time (read only) version of the
core library database
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 <list>
#include <map>
#include <set>
#include <vector>
#include "DB2TextFile.h"
//---------------------------------------------------------------------------
// Forward Declarations
//---------------------------------------------------------------------------
class cDB2NavTree;
//---------------------------------------------------------------------------
// Prototypes
//---------------------------------------------------------------------------
// Convert a string (in quotes) to a string (minus) quotes and copy into
// an allocated buffer
LPCSTR CopyQuotedString( LPSTR pString );
//---------------------------------------------------------------------------
// Definitions
//---------------------------------------------------------------------------
// An empty (but not NULL) string
extern LPCSTR EMPTY_STRING;
// Value seperator for database text
extern LPCSTR DB2_VALUE_SEP;
// Sub-value (i.e. within a particular value) seperator for database text
extern LPCSTR DB2_SUBVAL_SEP;
// Database table file names
extern LPCSTR DB2_FILE_PROTOCOL_FIELD;
extern LPCSTR DB2_FILE_PROTOCOL_STRUCT;
extern LPCSTR DB2_FILE_PROTOCOL_ENTITY;
extern LPCSTR DB2_FILE_ENUM_MAIN;
extern LPCSTR DB2_FILE_ENUM_ENTRY;
// Database start pointers
extern const int _binary_QMI_Field_txt_start;
extern const int _binary_QMI_Struct_txt_start;
extern const int _binary_QMI_Entity_txt_start;
extern const int _binary_QMI_Enum_txt_start;
extern const int _binary_QMI_EnumEntry_txt_start;
// Database end pointers
extern const int _binary_QMI_Field_txt_end;
extern const int _binary_QMI_Struct_txt_end;
extern const int _binary_QMI_Entity_txt_end;
extern const int _binary_QMI_Enum_txt_end;
extern const int _binary_QMI_EnumEntry_txt_end;
// Status levels for DB2 logging
enum eDB2StatusLevel
{
eDB2_STATUS_BEGIN = -1,
eDB2_STATUS_INFO, // Informational string
eDB2_STATUS_WARNING, // Warning string
eDB2_STATUS_ERROR, // Error string
eDB2_STATUS_END
};
/*===========================================================================
METHOD:
IsValid (Inline Method)
DESCRIPTION:
eDB2StatusLevel validity check
PARAMETERS:
lvl [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsValid( eDB2StatusLevel lvl )
{
bool retVal = false;
if (lvl > eDB2_STATUS_BEGIN && lvl < eDB2_STATUS_END)
{
retVal = true;
}
return retVal;
};
/*=========================================================================*/
// Class cDB2StatusLog
//
// Class that defines status logging interface for DB2 initialization
// and exit related information
/*=========================================================================*/
class cDB2StatusLog
{
public:
// Log an error string
virtual void Log(
LPCSTR pLog,
eDB2StatusLevel lvl = eDB2_STATUS_ERROR ) = 0;
// Log an error string
virtual void Log(
const std::string & log,
eDB2StatusLevel lvl = eDB2_STATUS_ERROR ) = 0;
};
/*=========================================================================*/
// Class cDB2TraceLog
// Default error logging interface for DB2 initialization and exit
// related information - sends output to TRACE
/*=========================================================================*/
class cDB2TraceLog : public cDB2StatusLog
{
public:
// (Inline) Constructor
cDB2TraceLog() { };
// (Inline) Destructor
~cDB2TraceLog() { };
// (Inline) Log an error string
virtual void Log(
LPCSTR pLog,
eDB2StatusLevel lvl = eDB2_STATUS_ERROR )
{
if (pLog != 0 && pLog[0] != 0)
{
std::string formatString = "[0x%02X] ";
formatString += pLog;
formatString += '\n';
//Note: TRACE is just an alias for printf if DEBUG is used
TRACE( formatString.c_str(), lvl );
}
};
// (Inline) Log an error string
virtual void Log(
const std::string & log,
eDB2StatusLevel lvl = eDB2_STATUS_ERROR )
{
if (log.size() > 0)
{
Log( log.c_str(), lvl );
}
};
};
// The default logger (for backwards compatibility)
extern cDB2TraceLog gDB2DefaultLog;
/*===========================================================================
METHOD:
LoadDB2Table (Free Public Method)
DESCRIPTION:
Load a database table
PARAMETERS:
pFile [ I ] - The file to load the table from
cont [I/0] - The current/resulting database table
bDuplicatesOK [ I ] - Duplicate keys acceptable?
pName [ I ] - Name (for error reporting)
log [I/O] - Where to log errors
RETURN VALUE:
bool
===========================================================================*/
template <class Container>
bool LoadDB2Table(
LPCSTR pFile,
Container & cont,
bool bDuplicatesOK = false,
LPCSTR pName = 0,
cDB2StatusLog & log = gDB2DefaultLog )
{
// Assume success
bool bRC = true;
// Sanity check error reporting name
if (pName == 0 || pName[0] == 0)
{
pName = "?";
}
// Sanity check file name
if (pFile == 0 || pFile[0] == 0)
{
// Bad file
std::ostringstream tmp;
tmp << "DB [" << pName << "] Invalid file name";
log.Log( tmp.str(), eDB2_STATUS_ERROR );
return false;
}
ULONG lineNum = 0;
// Attempt to open the file
cDB2TextFile inFile( pFile );
if (inFile.IsValid() == true)
{
std::string line;
while (inFile.ReadLine( line ) == true)
{
std::string lineCopy = line;
int nLineSize = lineCopy.size();
LPSTR pLine = new CHAR[ nLineSize + 1 ];
if (pLine == NULL)
{
return false;
}
memcpy( pLine, line.c_str(), nLineSize );
// Enforce null terminator
pLine[ nLineSize ] = 0;
typename Container::mapped_type theType;
bool bOK = theType.FromString( pLine );
if (bOK == true)
{
// Grab key
typename Container::key_type theKey = theType.GetKey();
// Key already exists?
typename Container::iterator pIter;
pIter = cont.find( theKey );
if (pIter != cont.end() && bDuplicatesOK == false)
{
// The key already exists which indicates a (recoverable) error
std::ostringstream tmp;
tmp << "DB [" << pName << "] Duplicate key, line "
<< lineNum << " (" << line.c_str() << ")";
log.Log( tmp.str(), eDB2_STATUS_WARNING );
// Free the current object
pIter->second.FreeAllocatedStrings();
// ... and then replace it
pIter->second = theType;
}
else
{
typename Container::value_type entry( theKey, theType );
cont.insert( entry );
}
}
else if (lineCopy.size() > 0)
{
// Error parsing line
std::ostringstream tmp;
tmp << "DB [" << pName << "] Parsing error, line "
<< lineNum << " (" << line.c_str() << ")";
log.Log( tmp.str(), eDB2_STATUS_ERROR );
theType.FreeAllocatedStrings();
bRC = false;
}
delete [] pLine;
lineNum++;
}
}
else
{
#ifdef DEBUG
// Could not open the file
std::ostringstream tmp;
tmp << "DB [" << pName << "] Error opening file";
log.Log( tmp.str(), eDB2_STATUS_WARNING );
#endif
bRC = false;
}
return bRC;
};
/*===========================================================================
METHOD:
LoadDB2Table (Free Public Method)
DESCRIPTION:
Load a database table
PARAMETERS:
pStart [ I ] - Start location of database
nSize [ I ] - Size of database
cont [I/0] - The current/resulting database table
bDuplicatesOK [ I ] - Duplicate keys acceptable?
pName [ I ] - Name (for error reporting)
log [I/O] - Where to log errors
RETURN VALUE:
bool
===========================================================================*/
template <class Container>
bool LoadDB2Table(
const char * pStart,
const int nSize,
Container & cont,
bool bDuplicatesOK = false,
LPCSTR pName = 0,
cDB2StatusLog & log = gDB2DefaultLog )
{
// Assume success
bool bRC = true;
// Sanity check error reporting name
if (pName == 0 || pName[0] == 0)
{
pName = "?";
}
ULONG lineNum = 0;
// Attempt to open the file
cDB2TextFile inFile( pStart, nSize );
if (inFile.IsValid() == true)
{
std::string line;
while (inFile.ReadLine( line ) == true)
{
std::string lineCopy = line;
int nLineSize = lineCopy.size();
LPSTR pLine = new CHAR[ nLineSize + 1 ];
if (pLine == NULL)
{
return false;
}
memcpy( pLine, lineCopy.c_str(), nLineSize );
// Enforce null terminator
pLine[ nLineSize ] = 0;
typename Container::mapped_type theType;
bool bOK = theType.FromString( pLine );
if (bOK == true)
{
// Grab key
typename Container::key_type theKey = theType.GetKey();
// Key already exists?
typename Container::iterator pIter;
pIter = cont.find( theKey );
if (pIter != cont.end() && bDuplicatesOK == false)
{
// The key already exists which indicates a (recoverable) error
std::ostringstream tmp;
tmp << "DB [" << pName << "] Duplicate key, line "
<< lineNum << " (" << line.c_str() << ")";
log.Log( tmp.str(), eDB2_STATUS_WARNING );
// Free the current object
pIter->second.FreeAllocatedStrings();
// ... and then replace it
pIter->second = theType;
}
else
{
typename Container::value_type entry( theKey, theType );
cont.insert( entry );
}
}
else if (lineCopy.size() > 0)
{
// Error parsing line
std::ostringstream tmp;
tmp << "DB [" << pName << "] Parsing error, line "
<< lineNum << " (" << line.c_str() << ")";
log.Log( tmp.str(), eDB2_STATUS_ERROR );
theType.FreeAllocatedStrings();
bRC = false;
}
delete [] pLine;
lineNum++;
}
}
else
{
#ifdef DEBUG
// Could not open the file
std::ostringstream tmp;
tmp << "DB [" << pName << "] Error opening file";
log.Log( tmp.str(), eDB2_STATUS_WARNING );
#endif
bRC = false;
}
return bRC;
};
/*===========================================================================
METHOD:
FreeDB2Table (Free Public Method)
DESCRIPTION:
Free up the string allocations in a database table, emptying the
table in the process
PARAMETERS:
cont [ I ] - The database table
RETURN VALUE:
None
===========================================================================*/
template <class Container>
void FreeDB2Table( Container & cont )
{
typename Container::iterator pIter = cont.begin();
while (pIter != cont.end())
{
typename Container::mapped_type & theType = pIter->second;
theType.FreeAllocatedStrings();
pIter++;
}
cont.clear();
};
/*=========================================================================*/
// eDB2EntityType Enumeration
//
// Database protocol entity header/payload type enumeration
/*=========================================================================*/
enum eDB2EntityType
{
eDB2_ET_ENUM_BEGIN = -1,
eDB2_ET_DIAG_REQ, // 0 Synchronous request
eDB2_ET_DIAG_RSP, // 1 Synchronous response
eDB2_ET_DIAG_SUBSYS_REQ, // 2 Synchronous subsystem dispatch request
eDB2_ET_DIAG_SUBSYS_RSP, // 3 Synchronous subsystem dispatch response
eDB2_ET_DIAG_EVENT, // 4 Asynchronous event
eDB2_ET_DIAG_LOG, // 5 Asynchronous log
eDB2_ET_DIAG_NV_ITEM, // 6 NVRAM item read/write
eDB2_ET_RESERVED7, // 7 Reserved
eDB2_ET_RESERVED8, // 8 Reserved
eDB2_ET_DIAG_SUBSYS2_REQ, // 9 Sync subsystem V2 dispatch request
eDB2_ET_DIAG_SUBSYS2_RSP, // 10 Sync subsystem V2 dispatch response
eDB2_ET_DIAG_SUBSYS2_ASYNC, // 11 Async subsystem V2 dispatch response
eDB2_ET_QMI_BEGIN = 29, // 29 Start of QMI section
eDB2_ET_QMI_CTL_REQ, // 30 QMI CTL request
eDB2_ET_QMI_CTL_RSP, // 31 QMI CTL response
eDB2_ET_QMI_CTL_IND, // 32 QMI CTL indication
eDB2_ET_QMI_WDS_REQ, // 33 QMI WDS request
eDB2_ET_QMI_WDS_RSP, // 34 QMI WDS response
eDB2_ET_QMI_WDS_IND, // 35 QMI WDS indication
eDB2_ET_QMI_DMS_REQ, // 36 QMI DMS request
eDB2_ET_QMI_DMS_RSP, // 37 QMI DMS response
eDB2_ET_QMI_DMS_IND, // 38 QMI DMS indication
eDB2_ET_QMI_NAS_REQ, // 39 QMI NAS request
eDB2_ET_QMI_NAS_RSP, // 40 QMI NAS response
eDB2_ET_QMI_NAS_IND, // 41 QMI NAS indication
eDB2_ET_QMI_QOS_REQ, // 42 QMI QOS request
eDB2_ET_QMI_QOS_RSP, // 43 QMI QOS response
eDB2_ET_QMI_QOS_IND, // 44 QMI QOS indication
eDB2_ET_QMI_WMS_REQ, // 45 QMI WMS request
eDB2_ET_QMI_WMS_RSP, // 46 QMI WMS response
eDB2_ET_QMI_WMS_IND, // 47 QMI WMS indication
eDB2_ET_QMI_PDS_REQ, // 48 QMI PDS request
eDB2_ET_QMI_PDS_RSP, // 49 QMI PDS response
eDB2_ET_QMI_PDS_IND, // 50 QMI PDS indication
eDB2_ET_QMI_AUTH_REQ, // 51 QMI AUTH request
eDB2_ET_QMI_AUTH_RSP, // 52 QMI AUTH response
eDB2_ET_QMI_AUTH_IND, // 53 QMI AUTH indication
eDB2_ET_QMI_CAT_REQ, // 54 QMI CAT request
eDB2_ET_QMI_CAT_RSP, // 55 QMI CAT response
eDB2_ET_QMI_CAT_IND, // 56 QMI CAT indication
eDB2_ET_QMI_RMS_REQ, // 57 QMI RMS request
eDB2_ET_QMI_RMS_RSP, // 58 QMI RMS response
eDB2_ET_QMI_RMS_IND, // 59 QMI RMS indication
eDB2_ET_QMI_OMA_REQ, // 60 QMI OMA request
eDB2_ET_QMI_OMA_RSP, // 61 QMI OMA response
eDB2_ET_QMI_OMA_IND, // 62 QMI OMA indication
eDB2_ET_QMI_VOICE_REQ, // 63 QMI voice request
eDB2_ET_QMI_VOICE_RSP, // 64 QMI voice response
eDB2_ET_QMI_VOICE_IND, // 65 QMI voice indication
eDB2_ET_QMI_END, // 63 End of QMI section
eDB2_ET_ENUM_END
};
/*===========================================================================
METHOD:
IsValid (Inline Method)
DESCRIPTION:
eDB2EntityType validity check
PARAMETERS:
et [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsValid( eDB2EntityType et )
{
bool retVal = false;
if ( (et > eDB2_ET_ENUM_BEGIN && et <= eDB2_ET_DIAG_SUBSYS2_ASYNC)
|| (et > eDB2_ET_QMI_BEGIN && et < eDB2_ET_QMI_END) )
{
retVal = true;
}
return retVal;
};
/*===========================================================================
METHOD:
IsDiagEntityType (Inline Method)
DESCRIPTION:
Does the eDB2EntityType value represent the DIAG protocol?
PARAMETERS:
entityType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsDiagEntityType( eDB2EntityType entityType )
{
bool retVal = false;
if (entityType == eDB2_ET_DIAG_REQ
|| entityType == eDB2_ET_DIAG_RSP
|| entityType == eDB2_ET_DIAG_SUBSYS_REQ
|| entityType == eDB2_ET_DIAG_SUBSYS_RSP
|| entityType == eDB2_ET_DIAG_EVENT
|| entityType == eDB2_ET_DIAG_LOG
|| entityType == eDB2_ET_DIAG_NV_ITEM
|| entityType == eDB2_ET_DIAG_SUBSYS2_REQ
|| entityType == eDB2_ET_DIAG_SUBSYS2_RSP
|| entityType == eDB2_ET_DIAG_SUBSYS2_ASYNC)
{
retVal = true;
}
return retVal;
};
/*===========================================================================
METHOD:
IsDiagEntityRequestType (Inline Method)
DESCRIPTION:
Does the eDB2EntityType value represent the DIAG protocol and if so
does it represent a request?
PARAMETERS:
entityType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsDiagEntityRequestType( eDB2EntityType entityType )
{
bool retVal = false;
if (entityType == eDB2_ET_DIAG_REQ
|| entityType == eDB2_ET_DIAG_SUBSYS_REQ
|| entityType == eDB2_ET_DIAG_SUBSYS2_REQ)
{
retVal = true;
}
return retVal;
};
/*===========================================================================
METHOD:
IsDiagEntityResponseType (Inline Method)
DESCRIPTION:
Does the eDB2EntityType value represent the DIAG protocol and if so
does it represent a response?
PARAMETERS:
entityType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsDiagEntityResponseType( eDB2EntityType entityType )
{
bool retVal = false;
if (entityType == eDB2_ET_DIAG_RSP
|| entityType == eDB2_ET_DIAG_SUBSYS_RSP
|| entityType == eDB2_ET_DIAG_SUBSYS2_RSP)
{
retVal = true;
}
return retVal;
};
/*===========================================================================
METHOD:
IsDiagEntityAsyncType (Inline Method)
DESCRIPTION:
Does the eDB2EntityType value represent the DIAG protocol and if so
does it represent asynchronous incoming data?
PARAMETERS:
entityType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsDiagEntityAsyncType( eDB2EntityType entityType )
{
bool retVal = false;
if (entityType == eDB2_ET_DIAG_EVENT
|| entityType == eDB2_ET_DIAG_LOG
|| entityType == eDB2_ET_DIAG_SUBSYS2_ASYNC)
{
retVal = true;
}
return retVal;
};
/*===========================================================================
METHOD:
IsQMIEntityType (Inline Method)
DESCRIPTION:
Does the eDB2EntityType value represent the QMI protocol?
PARAMETERS:
et [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsQMIEntityType( eDB2EntityType et )
{
bool retVal = false;
if (et > eDB2_ET_QMI_BEGIN && et < eDB2_ET_QMI_END)
{
retVal = true;
}
return retVal;
};
/*===========================================================================
METHOD:
IsQMIEntityRequestType (Inline Method)
DESCRIPTION:
Does the eDB2EntityType value represent the QMI protocol and if so
does it represent a request?
PARAMETERS:
entityType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsQMIEntityRequestType( eDB2EntityType entityType )
{
bool retVal = false;
// One QMI service is always a triplet of REQ/RSP/IND
DWORD baseVal = (DWORD)eDB2_ET_QMI_BEGIN + 1;
if ((DWORD)entityType % baseVal == 0)
{
retVal = true;
}
return retVal;
};
/*===========================================================================
METHOD:
IsQMIEntityResponseType (Inline Method)
DESCRIPTION:
Does the eDB2EntityType value represent the QMI protocol and if so
does it represent a response?
PARAMETERS:
entityType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsQMIEntityResponseType( eDB2EntityType entityType )
{
bool retVal = false;
// One QMI service is always a triplet of REQ/RSP/IND
DWORD baseVal = (DWORD)eDB2_ET_QMI_BEGIN + 1;
if ((DWORD)entityType % baseVal == 1)
{
retVal = true;
}
return retVal;
};
/*===========================================================================
METHOD:
IsQMIEntityIndicationType (Inline Method)
DESCRIPTION:
Does the eDB2EntityType value represent the QMI protocol and if so
does it represent an indication?
PARAMETERS:
entityType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsQMIEntityIndicationType( eDB2EntityType entityType )
{
bool retVal = false;
// One QMI service is always a triplet of REQ/RSP/IND
DWORD baseVal = (DWORD)eDB2_ET_QMI_BEGIN + 1;
if ((DWORD)entityType % baseVal == 2)
{
retVal = true;
}
return retVal;
};
/*=========================================================================*/
// eDB2FragmentType Enumeration
//
// Database fragment type enumeration - determines in what table
// (or manner) the fragment is described
/*=========================================================================*/
enum eDB2FragmentType
{
eDB2_FRAGMENT_TYPE_ENUM_BEGIN = -1,
eDB2_FRAGMENT_FIELD, // 0 Simple field fragment
eDB2_FRAGMENT_STRUCT, // 1 Structure fragment
eDB2_FRAGMENT_CONSTANT_PAD, // 2 Pad fragment, fixed length (bits)
eDB2_FRAGMENT_VARIABLE_PAD_BITS, // 3 Pad fragment, variable (bits)
eDB2_FRAGMENT_VARIABLE_PAD_BYTES, // 4 Pad fragment, variable (bytes)
eDB2_FRAGMENT_FULL_BYTE_PAD, // 5 Pad fragment, pad to a full byte
eDB2_FRAGMENT_MSB_2_LSB, // 6 Switch to MSB -> LSB order
eDB2_FRAGMENT_LSB_2_MSB, // 7 Switch to LSB -> MSB order
eDB2_FRAGMENT_TYPE_ENUM_END
};
/*===========================================================================
METHOD:
IsValid (Inline Method)
DESCRIPTION:
eDB2FragmentType validity check
PARAMETERS:
fragType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsValid( eDB2FragmentType fragType )
{
bool retVal = false;
if (fragType > eDB2_FRAGMENT_TYPE_ENUM_BEGIN
&& fragType < eDB2_FRAGMENT_TYPE_ENUM_END)
{
retVal = true;
}
return retVal;
};
/*=========================================================================*/
// eDB2ModifierType Enumeration
//
// Database fragment modifier type enumeration - determines how a
// fragment is modified/used
/*=========================================================================*/
enum eDB2ModifierType
{
eDB2_MOD_TYPE_ENUM_BEGIN = -1,
eDB2_MOD_NONE, // 0 Modifier is not used
eDB2_MOD_CONSTANT_ARRAY, // 1 Constant (elements) array
eDB2_MOD_VARIABLE_ARRAY, // 2 Variable (elements) array
eDB2_MOD_OBSOLETE_3, // 3 Constant (bits) array [OBS]
eDB2_MOD_OBSOLETE_4, // 4 Variable (bits) array [OBS]
eDB2_MOD_OPTIONAL, // 5 Fragment is optional
eDB2_MOD_VARIABLE_ARRAY2, // 6 Variable (elements) array, start/stop given
eDB2_MOD_VARIABLE_ARRAY3, // 7 Variable (elements) array, simple expression
eDB2_MOD_VARIABLE_STRING1, // 8 Variable length string (bit length)
eDB2_MOD_VARIABLE_STRING2, // 9 Variable length string (byte length)
eDB2_MOD_VARIABLE_STRING3, // 10 Variable length string (character length)
eDB2_MOD_TYPE_ENUM_END
};
/*===========================================================================
METHOD:
ModifiedToArray (Inline Method)
DESCRIPTION:
Does this modifier indicate an array?
PARAMETERS:
modType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool ModifiedToArray( eDB2ModifierType modType )
{
bool bRC = false;
if ( (modType == eDB2_MOD_CONSTANT_ARRAY)
|| (modType == eDB2_MOD_VARIABLE_ARRAY)
|| (modType == eDB2_MOD_VARIABLE_ARRAY2)
|| (modType == eDB2_MOD_VARIABLE_ARRAY3) )
{
bRC = true;
}
return bRC;
};
/*===========================================================================
METHOD:
IsValid (Inline Method)
DESCRIPTION:
eDB2ModifierType validity check
PARAMETERS:
modType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsValid( eDB2ModifierType modType )
{
bool retVal = false;
if (modType > eDB2_MOD_TYPE_ENUM_BEGIN
&& modType < eDB2_MOD_TYPE_ENUM_END)
{
retVal = true;
}
return retVal;
};
/*=========================================================================*/
// eDB2FieldType Enumeration
//
// Database field type enumeration - determines whether the field in
// question is a standard type or an enumeration
/*=========================================================================*/
enum eDB2FieldType
{
eDB2_FIELD_TYPE_ENUM_BEGIN = -1,
eDB2_FIELD_STD, // 0 Field is a standard type (see below)
eDB2_FIELD_ENUM_UNSIGNED, // 1 Field is an unsigned enumerated type
eDB2_FIELD_ENUM_SIGNED, // 2 Field is a signed enumerated type
eDB2_FIELD_TYPE_ENUM_END
};
/*===========================================================================
METHOD:
IsValid (Inline Method)
DESCRIPTION:
eDB2FieldType validity check
PARAMETERS:
fieldType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsValid( eDB2FieldType fieldType )
{
bool retVal = false;
if (fieldType > eDB2_FIELD_TYPE_ENUM_BEGIN
&& fieldType < eDB2_FIELD_TYPE_ENUM_END)
{
retVal = true;
}
return retVal;
};
/*=========================================================================*/
// eDB2StdFieldType Enumeration
//
// Database standard field type enumeration
/*=========================================================================*/
enum eDB2StdFieldType
{
eDB2_FIELD_STDTYPE_ENUM_BEGIN = -1,
eDB2_FIELD_STDTYPE_BOOL, // 0 Field is a boolean (0/1, false/true)
eDB2_FIELD_STDTYPE_INT8, // 1 Field is 8-bit signed integer
eDB2_FIELD_STDTYPE_UINT8, // 2 Field is 8-bit unsigned integer
eDB2_FIELD_STDTYPE_INT16, // 3 Field is 16-bit signed integer
eDB2_FIELD_STDTYPE_UINT16, // 4 Field is 16-bit unsigned integer
eDB2_FIELD_STDTYPE_INT32, // 5 Field is 32-bit signed integer
eDB2_FIELD_STDTYPE_UINT32, // 6 Field is 32-bit unsigned integer
eDB2_FIELD_STDTYPE_INT64, // 7 Field is 64-bit signed integer
eDB2_FIELD_STDTYPE_UINT64, // 8 Field is 64-bit unsigned integer
eDB2_FIELD_STDTYPE_STRING_A, // 9 ANSI fixed length string
eDB2_FIELD_STDTYPE_STRING_U, // 10 UNICODE fixed length string
eDB2_FIELD_STDTYPE_STRING_ANT, // 11 ANSI NULL terminated string
eDB2_FIELD_STDTYPE_STRING_UNT, // 12 UNICODE NULL terminated string
eDB2_FIELD_STDTYPE_FLOAT32, // 13 Field is 32-bit floating point value
eDB2_FIELD_STDTYPE_FLOAT64, // 14 Field is 64-bit floating point value
eDB2_FIELD_STDTYPE_STRING_U8, // 15 UTF-8 encoded fixed length string
eDB2_FIELD_STDTYPE_STRING_U8NT, // 16 UTF-8 encoded NULL terminated string
eDB2_FIELD_STDTYPE_ENUM_END
};
/*===========================================================================
METHOD:
IsValid (Inline Method)
DESCRIPTION:
eDB2StdFieldType validity check
PARAMETERS:
fieldType [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsValid( eDB2StdFieldType fieldType )
{
bool retVal = false;
if (fieldType > eDB2_FIELD_STDTYPE_ENUM_BEGIN
&& fieldType < eDB2_FIELD_STDTYPE_ENUM_END)
{
retVal = true;
}
return retVal;
};
/*=========================================================================*/
// eDB2Operator Enumeration
//
// Database conditional fragment operator type enumeration
/*=========================================================================*/
enum eDB2Operator
{
eDB2_OP_TYPE_ENUM_BEGIN = -1,
eDB2_OP_LT,
eDB2_OP_LTE,
eDB2_OP_EQ,
eDB2_OP_NEQ,
eDB2_OP_GTE,
eDB2_OP_GT,
eDB2_OP_DIV,
eDB2_OP_NDIV,
eDB2_OP_TYPE_ENUM_END
};
/*===========================================================================
METHOD:
IsValid (Inline Method)
DESCRIPTION:
eDB2Operator validity check
PARAMETERS:
op [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsValid( eDB2Operator op )
{
bool retVal = false;
if (op > eDB2_OP_TYPE_ENUM_BEGIN
&& op < eDB2_OP_TYPE_ENUM_END)
{
retVal = true;
}
return retVal;
};
/*=========================================================================*/
// eDB2ExpOperator Enumeration
//
// Database simple expression operator type enumeration
/*=========================================================================*/
enum eDB2ExpOperator
{
eDB2_EXPOP_TYPE_ENUM_BEGIN = -1,
eDB2_EXPOP_ADD,
eDB2_EXPOP_SUB,
eDB2_EXPOP_MUL,
eDB2_EXPOP_DIV,
eDB2_EXPOP_REM,
eDB2_EXPOP_MIN,
eDB2_EXPOP_MAX,
eDB2_EXPOP_TYPE_ENUM_END
};
/*===========================================================================
METHOD:
IsValid (Inline Method)
DESCRIPTION:
eDB2ExpOperator validity check
PARAMETERS:
op [ I ] - Enum value being verified
RETURN VALUE:
bool
===========================================================================*/
inline bool IsValid( eDB2ExpOperator op )
{
bool retVal = false;
if (op > eDB2_EXPOP_TYPE_ENUM_BEGIN
&& op < eDB2_EXPOP_TYPE_ENUM_END)
{
retVal = true;
}
return retVal;
};
/*=========================================================================*/
// Struct sDB2ProtocolEntity
//
// Structure that defines the schema for the protocol entity table
/*=========================================================================*/
struct sDB2ProtocolEntity
{
public:
// (Inline) Default constructor
sDB2ProtocolEntity()
: mType( eDB2_ET_ENUM_BEGIN ),
mStructID( -1 ),
mFormatID( -1 ),
mbInternal( false ),
mFormatExID( -1 ),
mpName( EMPTY_STRING )
{ };
// (Inline) Free up our allocated strings
void FreeAllocatedStrings()
{
if (mpName != 0 && mpName != EMPTY_STRING)
{
delete [] mpName;
mpName = 0;
}
};
// (Inline) Return object key
std::vector <ULONG> GetKey() const
{
return mID;
};
// Populate this object from a string
bool FromString( LPSTR pStr );
// Is this object valid?
bool IsValid() const;
/* Type of protocol entity 'header/payload' */
eDB2EntityType mType;
/* Multi-value ID (includes above type) */
std::vector <ULONG> mID;
/* Associated structure ID (-1 = no structure) */
int mStructID;
/* Associated format specifier (-1 = none) */
int mFormatID;
/* Is this protocol entity internal only? */
bool mbInternal;
/* Associated extended format specifier (-1 = none) */
int mFormatExID;
/* Name of protocol entity */
LPCSTR mpName;
};
/*=========================================================================*/
// Struct sDB2Fragment
//
// Structure that defines the schema for the protocol structure table
/*=========================================================================*/
struct sDB2Fragment
{
public:
// (Inline) Default constructor
sDB2Fragment()
: mStructID( 0 ),
mFragmentOrder( 0 ),
mFragmentOffset( 0 ),
mFragmentType( eDB2_FRAGMENT_TYPE_ENUM_BEGIN ),
mFragmentValue( 0 ),
mModifierType( eDB2_MOD_TYPE_ENUM_BEGIN ),
mpModifierValue( EMPTY_STRING ),
mpName( EMPTY_STRING )
{ };
// (Inline) Free up our allocated strings
void FreeAllocatedStrings()
{
if (mpName != 0 && mpName != EMPTY_STRING)
{
delete [] mpName;
mpName = 0;
}
if (mpModifierValue != 0 && mpModifierValue != EMPTY_STRING)
{
delete [] mpModifierValue;
mpModifierValue = 0;
}
};
// (Inline) Return object key
std::pair <ULONG, ULONG> GetKey() const
{
std::pair <ULONG, ULONG> key( mStructID, mFragmentOrder );
return key;
};
// Populate this object from a string
bool FromString( LPSTR pStr );
// Is this object valid?
bool IsValid() const;
// Build a simple condition string
static std::string BuildCondition(
ULONG id,
eDB2Operator op,
LONGLONG val,
bool bF2F );
// Evaluate a simple condition
static bool EvaluateCondition(
LONGLONG valA,
eDB2Operator op,
LONGLONG valB );
// Parse a simple condition
static bool ParseCondition(
LPCSTR pCondition,
ULONG & id,
eDB2Operator & op,
LONGLONG & val,
bool & bF2F );
// Build a simple expression string
static std::string BuildExpression(
ULONG id,
eDB2ExpOperator op,
LONGLONG val,
bool bF2F );
// Evaluate a simple expression
static bool EvaluateExpression(
LONGLONG valA,
eDB2ExpOperator op,
LONGLONG valB,
LONGLONG & res );
// Parse a simple expression
static bool ParseExpression(
LPCSTR pExpr,
ULONG & id,
eDB2ExpOperator & op,
LONGLONG & val,
bool & bF2F );
/* Enclosing structure ID */
ULONG mStructID;
/* Order of fragment within structure */
ULONG mFragmentOrder;
/* Offset (in bits) of fragment from beginning of enclosing structure */
int mFragmentOffset;
/* Fragment type, how to interpret the following fragment value */
eDB2FragmentType mFragmentType;
/* Fragment Value */
ULONG mFragmentValue;
/* Modifier type, how to interpret the following modifier value */
eDB2ModifierType mModifierType;
/* Modifier value */
LPCSTR mpModifierValue;
/* Fragment Name */
LPCSTR mpName;
};
/*=========================================================================*/
// Struct sDB2Field
//
// Structure that defines the schema for the protocol field table
/*=========================================================================*/
struct sDB2Field
{
public:
// (Inline) Default constructor
sDB2Field()
: mID( 0 ),
mSize( 0 ),
mType( eDB2_FIELD_TYPE_ENUM_BEGIN ),
mTypeVal( 0 ),
mbHex( false ),
mbInternal( false ),
mDescriptionID( -1 ),
mpName( EMPTY_STRING )
{ };
// (Inline) Free up our allocated strings
void FreeAllocatedStrings()
{
if ( (mpName != 0)
&& (mpName != EMPTY_STRING) )
{
delete [] mpName;
mpName = 0;
}
};
// (Inline) Return object key
ULONG GetKey() const
{
return mID;
};
// Populate this object from a string
bool FromString( LPSTR pStr );
// Is this object valid?
bool IsValid() const;
/* Field ID */
ULONG mID;
/* Size of field (in bits, maximum is 64 bits for integral types) */
ULONG mSize;
/* Field type */
eDB2FieldType mType;
/* Actual field type (eDB2StdFieldType or enum ID) */
ULONG mTypeVal;
/* Display integral fields as hexadecimal? */
bool mbHex;
/* Is this field internal only? */
bool mbInternal;
/* Description of field */
int mDescriptionID;
/* Field name */
LPCSTR mpName;
};
/*=========================================================================*/
// Struct sDB2Category
//
// Structure that defines the generic category table schema, gives
// category ID, category name, category description, and parent
// category relationship (specified as a category ID into the very
// same table)
/*=========================================================================*/
struct sDB2Category
{
public:
// (Inline) Default constructor
sDB2Category()
: mID( 0 ),
mParentID( -1 ),
mpName( EMPTY_STRING ),
mDescriptionID( -1 )
{ };
// (Inline) Free up our allocated strings
void FreeAllocatedStrings()
{
if (mpName != 0 && mpName != EMPTY_STRING)
{
delete [] mpName;
mpName = 0;
}
};
// (Inline) Return object key
ULONG GetKey() const
{
return mID;
};
// Populate this object from a string
bool FromString( LPSTR pStr );
// Is this object valid?
bool IsValid() const;
/* Category ID */
ULONG mID;
/* Category ID of parent, -1 implies no parent/category is at root */
int mParentID;
/* Category display name */
LPCSTR mpName;
/* Description of category */
int mDescriptionID;
};
/*===========================================================================
METHOD:
ValidateDB2Categories (Public Method)
DESCRIPTION:
Validate the relationship between a pair of DB category/reference tables
NOTE: Discovered problems will be repaired, i.e. bogus/problematic
category IDs are reset to -1
PARAMETERS:
catMap [ I ] - The category table
refMap [ I ] - The reference table
pName [ I ] - Table name (for error reporting)
log [ I ] - Error log
RETURN VALUE:
bool
===========================================================================*/
template <class Key, class NamedType>
bool ValidateDB2Categories(
std::map <ULONG, sDB2Category> & catMap,
std::map <Key, NamedType> & refMap,
LPCSTR pName,
cDB2StatusLog & log = gDB2DefaultLog )
{
// Assume success
bool bRC = true;
std::string err;
// Sanity check table name
if (pName == 0 || pName[0] == 0)
{
pName = "?";
}
// First validate/repair category map; stage 1: bad parent IDs
std::map <ULONG, sDB2Category>::iterator pCats = catMap.begin();
while (pCats != catMap.end())
{
sDB2Category & cat = pCats->second;
pCats++;
if (cat.IsValid() == false)
{
continue;
}
// The parent ID must be -1 or exist in the category map
if (cat.mParentID != -1)
{
if (catMap.find( cat.mParentID ) == catMap.end())
{
// Unable to locate parent category
std::ostringstream tmp;
tmp << "DB [" << pName << "] Missing ID, parent ID "
<< cat.mParentID;
log.Log( tmp.str(), eDB2_STATUS_ERROR );
cat.mParentID = -1;
bRC = false;
}
}
}
// Validate/repair category map; stage 2: loop detection
pCats = catMap.begin();
while (pCats != catMap.end())
{
std::set <int> catsVisited;
sDB2Category & cat = pCats->second;
// Itererate up through parents
int parentID = cat.mParentID;
while (parentID != -1)
{
// Have we already been here?
if (catsVisited.find( parentID ) == catsVisited.end())
{
// Nope, add ID and go on to the next one
catsVisited.insert( parentID );
std::map <ULONG, sDB2Category>::iterator pParent;
pParent = catMap.find( parentID );
parentID = pParent->second.mParentID;
}
else
{
// Yes, we are caught in a loop
std::ostringstream tmp;
tmp << "DB [" << pName << "] Loop in category, parent ID "
<< cat.mParentID;
log.Log( tmp.str(), eDB2_STATUS_ERROR );
cat.mParentID = -1;
bRC = false;
break;
}
}
pCats++;
}
// Validate that each reference references valid category IDs
typename std::map <Key, NamedType>::iterator pTypes = refMap.begin();
while (pTypes != refMap.end())
{
NamedType & theType = pTypes->second;
std::set <int> cats = theType.mCategoryIDs;
std::set <int>::iterator pRefCats = cats.begin();
while (pRefCats != cats.end())
{
if (*pRefCats != -1)
{
pCats = catMap.find( *pRefCats );
if (pCats == catMap.end())
{
// Unable to locate category
std::ostringstream tmp;
tmp << "DB [" << pName << "] Missing ID, category ID "
<< *pRefCats << ", reference " << theType.mpName;
log.Log( tmp.str(), eDB2_STATUS_ERROR );
*pRefCats = -1;
bRC = false;
}
}
pRefCats++;
}
pTypes++;
}
return bRC;
};
/*=========================================================================*/
// Struct sDB2NVItem
//
// NVRAM item structure for database schema
/*=========================================================================*/
struct sDB2NVItem
{
public:
// (Inline) Default constructor
sDB2NVItem()
: mItem( 0 ),
mpName( EMPTY_STRING ),
mDescriptionID( -1 )
{ };
// (Inline) Free up our allocated strings
void FreeAllocatedStrings()
{
if (mpName != 0 && mpName != EMPTY_STRING)
{
delete [] mpName;
mpName = 0;
}
};
// (Inline) Return object key
ULONG GetKey() const
{
return mItem;
};
// Populate this object from a string
bool FromString( LPSTR pStr );
// Is this object valid?
bool IsValid() const;
/* Category IDs (indices into NV items category table) */
std::set <int> mCategoryIDs;
/* Item number */
ULONG mItem;
/* NV item display name */
LPCSTR mpName;
/* Description of NV item */
int mDescriptionID;
};
/*=========================================================================*/
// Struct sDB2Enum
//
// Structure that defines the schema for the enum table
/*=========================================================================*/
struct sDB2Enum
{
public:
// (Inline) Default constructor
sDB2Enum()
: mID( 0 ),
mbInternal( false ),
mpName( EMPTY_STRING ),
mDescriptionID( -1 )
{ };
// (Inline) Free up our allocated strings
void FreeAllocatedStrings()
{
if (mpName != 0 && mpName != EMPTY_STRING)
{
delete [] mpName;
mpName = 0;
}
};
// (Inline) Return object key
ULONG GetKey() const
{
return mID;
};
// Populate this object from a string
bool FromString( LPSTR pStr );
// Is this object valid?
bool IsValid() const;
/* Enum ID */
ULONG mID;
/* Is this enum used internally? */
bool mbInternal;
/* Description of enum */
int mDescriptionID;
/* Name of enum */
LPCSTR mpName;
};
/*=========================================================================*/
// Struct sDB2EnumEntry
//
// Structure that defines the schema for the enum entry table
/*=========================================================================*/
struct sDB2EnumEntry
{
public:
// (Inline) Default constructor
sDB2EnumEntry()
: mID( 0 ),
mValue( -1 ),
mbHex( false ),
mpName( EMPTY_STRING ),
mDescriptionID( -1 )
{ };
// (Inline) Free up our allocated strings
void FreeAllocatedStrings()
{
if (mpName != 0 && mpName != EMPTY_STRING)
{
delete [] mpName;
mpName = 0;
}
};
// (Inline) Return object key
std::pair <ULONG, int> GetKey() const
{
std::pair <ULONG, int> key( mID, mValue );
return key;
};
// (Inline) Populate this object from a string
bool FromString( LPSTR pStr );
// Is this object valid?
bool IsValid() const;
/* Enum ID */
ULONG mID;
/* Enum entry value */
int mValue;
/* Hexadecimal flag */
bool mbHex;
/* Enum value name */
LPCSTR mpName;
/* Description of enum value */
int mDescriptionID;
};
/*=========================================================================*/
// Struct sDB2SimpleCondition
//
// Structure that defines a (parsed) simple condition modifier
/*=========================================================================*/
struct sDB2SimpleCondition
{
public:
// (Inline) Default constructor
sDB2SimpleCondition()
: mID( 0 ),
mOperator( eDB2_OP_TYPE_ENUM_BEGIN ),
mValue( 0 ),
mbF2F( false )
{ };
// (Inline) Is this object valid?
bool IsValid() const
{
return ::IsValid( mOperator );
};
/* ID of field whose value is to be used */
ULONG mID;
/* Operator to be used */
eDB2Operator mOperator;
/* Value (or field ID) to compare against */
LONGLONG mValue;
/* Field to field expression? */
bool mbF2F;
};
/*=========================================================================*/
// Struct sDB2SimpleExpression
//
// Structure that defines a (parsed) simple expression
/*=========================================================================*/
struct sDB2SimpleExpression
{
public:
// (Inline) Default constructor
sDB2SimpleExpression()
: mID( 0 ),
mOperator( eDB2_EXPOP_TYPE_ENUM_BEGIN ),
mValue( 0 ),
mbF2F( false )
{ };
// (Inline) Is this object valid?
bool IsValid() const
{
return (::IsValid( mOperator ) && mValue != 0);
};
/* ID of field whose value is to be used */
ULONG mID;
/* Operator to be used */
eDB2ExpOperator mOperator;
/* Value (or field ID) to compare against */
LONGLONG mValue;
/* Field to field expression? */
bool mbF2F;
};
/*=========================================================================*/
// Struct sLPCSTRCmp
//
// Structure that defines the '<' operator for string comparison
/*=========================================================================*/
struct sLPCSTRCmp
{
public:
// (Inline) Is A < B?
bool operator () (
LPCSTR pStrA,
LPCSTR pStrB ) const
{
bool bLess = false;
if (pStrA != 0 && pStrB != 0)
{
bLess = (strcmp( pStrA, pStrB ) < 0);
}
return bLess;
};
};
/*=========================================================================*/
// Case insensitive compare function
/*=========================================================================*/
inline bool InsensitiveCompare( CHAR first, CHAR second )
{
return tolower( first ) < tolower( second );
}
/*=========================================================================*/
// Struct sLPCSTRCmpI
//
// Structure that defines the '<' operator for string comparison
// (case insensitive version)
/*=========================================================================*/
struct sLPCSTRCmpI
{
public:
// (Inline) Is A < B?
bool operator () (
LPCSTR pStrA,
LPCSTR pStrB ) const
{
bool bLess = false;
if (pStrA != 0 && pStrB != 0)
{
// Is there a simpler stl function for this?
bLess = std::lexicographical_compare( pStrA,
pStrA +
strlen( pStrA ),
pStrB,
pStrB +
strlen( pStrB ),
InsensitiveCompare );
}
return bLess;
};
};
//---------------------------------------------------------------------------
// Typedefs
//---------------------------------------------------------------------------
// The protocol entity table expressed as a type
typedef std::multimap <std::vector <ULONG>, sDB2ProtocolEntity> tDB2EntityMap;
// Protocol entity entity name to ID (reverse) table
typedef std::map <LPCSTR, std::vector <ULONG>, sLPCSTRCmpI> tDB2EntityNameMap;
// The struct table expressed as a type
typedef std::map <std::pair <ULONG, ULONG>, sDB2Fragment> tDB2FragmentMap;
// The field table expressed as a type
typedef std::map <ULONG, sDB2Field> tDB2FieldMap;
// A generic category table expressed as a type
typedef std::map <ULONG, sDB2Category> tDB2CategoryMap;
// NV item table expressed as a map type
typedef std::map <ULONG, sDB2NVItem> tDB2NVMap;
// Enum table expressed as a map type
typedef std::map <ULONG, sDB2Enum> tDB2EnumNameMap;
// Enum entry table expressed as a map type
typedef std::map <std::pair <ULONG, int>, sDB2EnumEntry> tDB2EnumEntryMap;
// The built enumeration map
typedef std::pair < ULONG, std::map <int, LPCSTR> > tDB2EnumMapPair;
typedef std::map <LPCSTR, tDB2EnumMapPair, sLPCSTRCmp> tDB2EnumMap;
// Parsed fragment modifier map - optional fragment
typedef std::map <LPCSTR, sDB2SimpleCondition> tDB2OptionalModMap;
// Parsed fragment modifier map - simple expression based sizes
typedef std::map <LPCSTR, sDB2SimpleExpression> tDB2ExpressionModMap;
// Parsed fragment modifier map - element count specified arrays
typedef std::map <LPCSTR, ULONG> tDB2Array1ModMap;
// Parsed fragment modifier map - start/stop index specified arrays
typedef std::map <LPCSTR, std::pair <ULONG, ULONG> > tDB2Array2ModMap;
// A protocol entity navigation map expressed as a type
typedef std::map <std::vector <ULONG>, cDB2NavTree *> tDB2EntityNavMap;
/*=========================================================================*/
// Class cCoreDatabase
/*=========================================================================*/
class cCoreDatabase
{
public:
// Constructor
cCoreDatabase();
// Destructor
virtual ~cCoreDatabase();
// Initialize the database - must be done once (and only once) prior
// to any database object access
virtual bool Initialize( LPCSTR pBasePath );
virtual bool Initialize();
// Exit (cleanup) the database
virtual void Exit();
// Get the entity navigation tree for the given protocol entity, if
// none exists one will be built and returned
const cDB2NavTree * GetEntityNavTree(
const std::vector <ULONG> & key ) const;
// Find the protocol entity with the specified key
bool FindEntity(
const std::vector <ULONG> & key,
sDB2ProtocolEntity & entity ) const;
// Find the protocol entity with the specified name
bool FindEntity(
LPCSTR pEntityName,
sDB2ProtocolEntity & entity ) const;
// Map a protocol entity name to an ID
bool MapEntityNameToID(
LPCSTR pName,
std::vector <ULONG> & key ) const;
// Map the given enum value (specified by enum ID, and enum value)
// to the enum value name string
std::string MapEnumToString(
ULONG enumID,
int enumVal,
bool bSimpleErrFmt = false,
bool bHex = false ) const;
// Map the given enum value (specified by enum name, and enum value)
// to the enum value name string
std::string MapEnumToString(
LPCSTR pEnumName,
int enumVal,
bool bSimpleErrFmt = false,
bool bHex = false ) const;
// (Inline) Set status log (object must exist for the duration of
// the DB or at least until being reset)
void SetLog( cDB2StatusLog * pLog )
{
if (pLog != 0)
{
mpLog = pLog;
}
};
// (Inline) Return protocol entities
const tDB2EntityMap & GetProtocolEntities() const
{
return mProtocolEntities;
};
// (Inline) Return protocol entity names
const tDB2EntityNameMap & GetProtocolEntityNames() const
{
return mEntityNames;
};
// (Inline) Return protocol structures
const tDB2FragmentMap & GetProtocolStructs() const
{
return mEntityStructs;
};
// (Inline) Return protocol fields
const tDB2FieldMap & GetProtocolFields() const
{
return mEntityFields;
};
// (Inline) Return assembled enumeration map
const tDB2EnumMap & GetEnums() const
{
return mEnumMap;
};
// (Inline) Return raw enumeration map
const tDB2EnumNameMap & GetRawEnums() const
{
return mEnumNameMap;
};
// (Inline) Return raw enumeration entry map
const tDB2EnumEntryMap & GetRawEnumEntries() const
{
return mEnumEntryMap;
};
// (Inline) Return parsed fragment modifier map - optional
const tDB2OptionalModMap & GetOptionalMods() const
{
return mOptionalModMap;
};
// (Inline) Return parsed fragment modifier map - expressions
const tDB2ExpressionModMap & GetExpressionMods() const
{
return mExpressionModMap;
};
// (Inline) Return parsed fragment modifier map - element
// count specified arrays
const tDB2Array1ModMap & GetArray1Mods() const
{
return mArray1ModMap;
};
// (Inline) Return parsed fragment modifier map - start/stop
// index specified arrays
const tDB2Array2ModMap & GetArray2Mods() const
{
return mArray2ModMap;
};
protected:
// Assemble the internal enum map
bool AssembleEnumMap();
// Assemble the internal protocol entity name map
bool AssembleEntityNameMap();
// Build the modifier tables
bool BuildModifierTables();
// Check and set the passed in path to something that is useful
std::string CheckAndSetBasePath( LPCSTR pBasePath ) const;
// Load all tables related to structure (entity, struct, field)
bool LoadStructureTables( LPCSTR pBasePath );
bool LoadStructureTables();
// Load all enumeration related tables
bool LoadEnumTables( LPCSTR pBasePath );
bool LoadEnumTables();
// Validate (and attempt repair of) structure related tables
bool ValidateStructures();
// Validate a single structure
bool ValidateStructure(
ULONG structID,
std::set <ULONG> & fields,
ULONG depth );
// Validate a single field
bool ValidateField(
ULONG structID,
ULONG fieldID,
std::set <ULONG> & fields );
// Validate an array specifier
bool ValidateArraySpecifier(
const sDB2Fragment & frag,
const std::set <ULONG> & fields );
// Validate a simple optional fragment specifier
bool ValidateOptionalSpecifier(
const sDB2Fragment & frag,
const std::set <ULONG> & fields );
// Validate a simple expression fragment specifier
bool ValidateExpressionSpecifier(
const sDB2Fragment & frag,
const std::set <ULONG> & fields );
/* Status log */
cDB2StatusLog * mpLog;
/* Protocol entity table, referenced by multi-value key */
tDB2EntityMap mProtocolEntities;
/* Protocol entity keys, referenced by indexed by entity name */
tDB2EntityNameMap mEntityNames;
/* The on-demand Protocol entity navigation map */
mutable tDB2EntityNavMap mEntityNavMap;
/* Protocol entity struct table, indexed by struct ID & fragment order */
tDB2FragmentMap mEntityStructs;
/* Protocol entity field table, indexed by field ID */
tDB2FieldMap mEntityFields;
/* Enum map, indexed by enum ID */
tDB2EnumNameMap mEnumNameMap;
/* Enum entry map, indexed by enum ID/value pair */
tDB2EnumEntryMap mEnumEntryMap;
/* The assembled enum map */
tDB2EnumMap mEnumMap;
/* Parsed fragment modifier map - optional fragments */
tDB2OptionalModMap mOptionalModMap;
/* Parsed fragment modifier map - expression fragments */
tDB2ExpressionModMap mExpressionModMap;
/* Parsed fragment modifier map - element count specified arrays */
tDB2Array1ModMap mArray1ModMap;
/* Parsed fragment modifier map - start/stop index specified arrays */
tDB2Array2ModMap mArray2ModMap;
};
|