Debian Codegraph @

HercConfiguration/DeviceConfigLine.cpp

raw symbols SCIP
1 /*
2 * File: DeviceConfigLine.cpp
3 *
4 * Author: Jacob Dekel
5 * Created on: Aug 7, 2009
6 *
7 * Copyright (c) 2009-2013 Jacob Dekel
8 * $Id$
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25 #include "HerculesStudio.h"
26 #include "DeviceConfigLine.h"
27 #include "ConfigurationEditor.h"
28
29 #include <cstdlib>
30 #include <sstream>
31
32
33 DeviceConfigLine::DeviceTypesMap *DeviceConfigLine::mDeviceTypes = NULL;
34 std::map<std::string,DeviceTypes::BaseType> *DeviceConfigLine::mDeviceBaseTypes = NULL;
35
36 DeviceConfigLine::DeviceConfigLine(const char *line):
37 ConfigLine(line), mMultiCount(0)
38 {
39 initilize();
40 handleMultiLine();
41 }
42
43 DeviceConfigLine::~DeviceConfigLine()
44 {
45 hOutDebug(5,"~DeviceConfigLine");
46 }
47
48 void DeviceConfigLine::clear()
49 {
50 if (mDeviceTypes != NULL) mDeviceTypes->clear();
51 if (mDeviceBaseTypes != NULL) mDeviceBaseTypes->clear();
52 }
53
54 int DeviceConfigLine::getDeviceNumber() const
55 {
56 return std::strtol(getToken(0).c_str(),NULL, 16);
57 }
58
59 DeviceTypes::Type DeviceConfigLine::getDeviceType() const
60 {
61 QString token = getToken(1).c_str();
62 DeviceTypesMap::iterator it = (*mDeviceTypes).find(token.toUpper().toStdString());
63 if (it == (*mDeviceTypes).end())
64 return (*mDeviceTypes)["0000"];
65 hOutDebug(5,"getDeviceType " << token.toStdString());
66 return it->second;
67 }
68
69 void DeviceConfigLine::handleMultiLine()
70 {
71 std::string devno = getToken(0);
72 int first = -1, last = -1;
73 size_t dash = devno.find_first_of("-");
74 if (dash != std::string::npos)
75 {
76 first = ConfigurationEditor::parseNum(devno.substr(0,dash), 16);
77 last = ConfigurationEditor::parseNum(devno.substr(dash+1), 16);
78 }
79 size_t dot = devno.find_first_of(".");
80 if (dot != std::string::npos)
81 {
82 first = ConfigurationEditor::parseNum(devno.substr(0,dot), 16);
83 last = first+ConfigurationEditor::parseNum(devno.substr(dot+1), 10)-1;
84 }
85 size_t comma = devno.find_first_of(",");
86 if (comma != std::string::npos)
87 {
88 first = ConfigurationEditor::parseNum(devno.substr(0,comma), 16);
89 last = ConfigurationEditor::parseNum(devno.substr(comma+1), 16);
90 }
91
92 if (first > -1)
93 {
94 mMultiCount = last-first+1;
95 hOutDebug(5, devno << " multiCount:" << mMultiCount);
96 std::stringstream line;
97 line << std::hex << first ;
98 line << " " + getMultiToken(1,0) + "\n";
99 replaceLine(line.str());
100 }
101 else
102 {
103 first = ConfigurationEditor::parseNum(devno, 16);
104 }
105 }
106
107 int DeviceConfigLine::getMultiCount()
108 {
109 hOutDebug(5, "get multiCount:" << mMultiCount);
110 return mMultiCount;
111 }
112
113 void DeviceConfigLine::initilize()
114 {
115 if (mDeviceTypes != NULL)
116 return;
117
118 mDeviceTypes = new std::map<std::string,DeviceTypes::Type>;
119 mDeviceBaseTypes = new std::map<std::string,DeviceTypes::BaseType>;
120
121 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("0000",DeviceTypes::Other));
122 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3270",DeviceTypes::Terminal));
123 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3287",DeviceTypes::Terminal));
124 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("SYSG",DeviceTypes::Sysg));
125 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("1052",DeviceTypes::Console));
126 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3215",DeviceTypes::Console));
127 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("1052-C",DeviceTypes::Console));
128 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3215-C",DeviceTypes::Console));
129 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("1442",DeviceTypes::CardReader));
130 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("2501",DeviceTypes::CardReader));
131 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3505",DeviceTypes::CardReader));
132 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3525",DeviceTypes::CardPunch));
133 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("1403",DeviceTypes::Printer));
134 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3211",DeviceTypes::Printer));
135 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3410",DeviceTypes::Tape));
136 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3420",DeviceTypes::Tape));
137 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3422",DeviceTypes::Tape));
138 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3430",DeviceTypes::Tape));
139 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3480",DeviceTypes::Tape));
140 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3490",DeviceTypes::Tape));
141 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3590",DeviceTypes::Tape));
142 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("9347",DeviceTypes::Tape));
143 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("8809",DeviceTypes::Tape));
144 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3088",DeviceTypes::CTC));
145 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("CTCI",DeviceTypes::CTC));
146 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("LCS", DeviceTypes::CTC));
147 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("QETH", DeviceTypes::CTC));
148 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("CTCT", DeviceTypes::CTC));
149 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("2305",DeviceTypes::DASD));
150 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("2311",DeviceTypes::DASD));
151 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("2314",DeviceTypes::DASD));
152 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3330",DeviceTypes::DASD));
153 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3340",DeviceTypes::DASD));
154 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3350",DeviceTypes::DASD));
155 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3375",DeviceTypes::DASD));
156 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3380",DeviceTypes::DASD));
157 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3390",DeviceTypes::DASD));
158 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("9345",DeviceTypes::DASD));
159 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3310",DeviceTypes::DASD));
160 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("3370",DeviceTypes::DASD));
161 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("9332",DeviceTypes::DASD));
162 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("9335",DeviceTypes::DASD));
163 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("9336",DeviceTypes::DASD));
164 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("0671",DeviceTypes::DASD));
165 mDeviceTypes->insert(std::pair<std::string,DeviceTypes::Type>("2703",DeviceTypes::Comm));
166
167 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("3088",DeviceTypes::CTCT));
168 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("CTCI",DeviceTypes::CTCI));
169 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("LCS", DeviceTypes::LCS));
170 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("QETH", DeviceTypes::QETH));
171 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("2305",DeviceTypes::CKD));
172 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("2311",DeviceTypes::CKD));
173 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("2314",DeviceTypes::CKD));
174 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("3330",DeviceTypes::CKD));
175 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("3340",DeviceTypes::CKD));
176 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("3350",DeviceTypes::CKD));
177 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("3375",DeviceTypes::CKD));
178 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("3380",DeviceTypes::CKD));
179 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("3390",DeviceTypes::CKD));
180 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("9345",DeviceTypes::CKD));
181 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("3310",DeviceTypes::FBA));
182 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("3370",DeviceTypes::FBA));
183 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("9332",DeviceTypes::FBA));
184 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("9335",DeviceTypes::FBA));
185 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("9336",DeviceTypes::FBA));
186 mDeviceBaseTypes->insert(std::pair<std::string,DeviceTypes::BaseType>("9336",DeviceTypes::FBA));
187
188 }
189
190 std::string DeviceConfigLine::toString() const
191 {
192 int i=mLine.length()-3;
193 while (i>=0)
194 {
195 if ( (mLine[i] != ' ') && (mLine[i] != '\t') && (mLine[i] != '\n') && (mLine[i] != '\r') )
196 break;
197 --i;
198 }
199 return mLine.substr(0,i);
200 }