| 1 | /* |
| 2 | * File: DevicesPane.h |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Aug 7, 2009 |
| 6 | * |
| 7 | * Copyright (c) 2009-2013 Jacob Dekel |
| 8 | * $Id$ |
| 9 | * |
| 10 | * This object displays the devices pane during hercules run time |
| 11 | * |
| 12 | * This program is free software: you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation, either version 3 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #ifndef DEVICESPANE_H |
| 28 | #define DEVICESPANE_H |
| 29 | |
| 30 | #include "DeviceTypes.h" |
| 31 | #include "DeviceListView.h" |
| 32 | #include "StatusUpdateCollector.h" |
| 33 | #include "DeviceMenuProcessor.h" |
| 34 | |
| 35 | #include <QtWidgets/QWidget> |
| 36 | #include "ui_Devices.h" |
| 37 | #include <QGridLayout> |
| 38 | #include <QScrollArea> |
| 39 | #include <QLabel> |
| 40 | |
| 41 | #include <utility> |
| 42 | #include <vector> |
| 43 | #include <map> |
| 44 | |
| 45 | typedef std::pair<int,int> TokenPair; |
| 46 | |
| 47 | class VisualizedDeviceEntry; |
| 48 | |
| 49 | /* |
| 50 | NOTE: look for BEGIN_DEVICE_CLASS_QUERY in hercules source |
| 51 | |
| 52 | note: DEVA=0180 3390 DASD 1001 /media/Data/Hercules/zLinux/CentOS-4.7/180.cckd [3339 cyls] |
| 53 | */ |
| 54 | |
| 55 | struct DynDeviceLine |
| 56 | { |
| 57 | char DEV[3]; |
| 58 | char action; |
| 59 | char eq; |
| 60 | char devNo[4]; |
| 61 | char pad1; |
| 62 | char devTypeN[4]; |
| 63 | char pad2; |
| 64 | char devType[4]; |
| 65 | char pid3; |
| 66 | char statusBytes[4]; |
| 67 | }; |
| 68 | |
| 69 | template <class Key, class T> class dbgmap |
| 70 | { |
| 71 | public: |
| 72 | dbgmap() |
| 73 | { |
| 74 | mMap = new std::map<Key, T>(); |
| 75 | } |
| 76 | |
| 77 | typedef typename std::map<const Key, T>::iterator iterator ; |
| 78 | typedef typename std::map<Key, T>::const_iterator const_iterator ; |
| 79 | |
| 80 | std::pair< iterator, bool > insert(std::pair< const Key, T> t) |
| 81 | { |
| 82 | return mMap->insert(t); |
| 83 | } |
| 84 | |
| 85 | void clear() |
| 86 | { |
| 87 | mMap->clear(); |
| 88 | } |
| 89 | |
| 90 | typename std::map<Key, T>::iterator begin() const |
| 91 | { |
| 92 | return mMap->begin(); |
| 93 | } |
| 94 | |
| 95 | iterator end() const |
| 96 | { |
| 97 | return mMap->end(); |
| 98 | } |
| 99 | |
| 100 | iterator find(const Key& k) |
| 101 | { |
| 102 | return mMap->find(k); |
| 103 | } |
| 104 | |
| 105 | void erase(iterator p) |
| 106 | { |
| 107 | mMap->erase(p); |
| 108 | } |
| 109 | |
| 110 | size_t size() |
| 111 | { |
| 112 | return mMap->size(); |
| 113 | } |
| 114 | |
| 115 | T& operator[] (const Key& k) |
| 116 | { |
| 117 | return (*mMap)[k]; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | private: |
| 122 | std::map<Key,T> *mMap; |
| 123 | }; |
| 124 | |
| 125 | class MainWindow; |
| 126 | class DeviceConfigLine; |
| 127 | class DevicesRename; |
| 128 | class DevicesPane : public DeviceMenuProcessor, public StatusUpdateCollector |
| 129 | { |
| 130 | Q_OBJECT |
| 131 | public: |
| 132 | DevicesPane(QWidget *parent = 0); |
| 133 | virtual ~DevicesPane(); |
| 134 | |
| 135 | virtual bool notify(const QByteArray& statusLine); |
| 136 | void clear(); |
| 137 | |
| 138 | public slots: |
| 139 | void mousePressed(QModelIndex index); |
| 140 | void menuRename(); |
| 141 | void menuDelete(); |
| 142 | void doAddDevice(bool); |
| 143 | void updateDevice(bool); |
| 144 | void menuProperties(); |
| 145 | void doRename(QString oldDevNum, QString newDevNum); |
| 146 | void menuInterrupt(); |
| 147 | void menuStatus(); |
| 148 | void menuTraceCCW(); |
| 149 | void rejected(); |
| 150 | |
| 151 | protected: |
| 152 | virtual bool isRealDev(int lineNumber); |
| 153 | virtual bool canAddSYSG(); |
| 154 | virtual bool isConfig() { return false; } |
| 155 | virtual bool realDevice(); |
| 156 | virtual DeviceTypes::Type getType(int lineNumber); |
| 157 | virtual void doLoadTape(QString& tapeFileName); |
| 158 | virtual bool hasConfig(); |
| 159 | virtual bool traced(); |
| 160 | |
| 161 | private: |
| 162 | Ui::DevicesClass ui; |
| 163 | MainWindow * mMainWindow; |
| 164 | QGridLayout * mLayout; |
| 165 | QScrollArea * mScrollArea; |
| 166 | DeviceListView * mListView; |
| 167 | std::vector<TokenPair> mTokens; |
| 168 | std::map<int, VisualizedDeviceEntry> mDevices; |
| 169 | QStandardItemModel * mModel; |
| 170 | DevicesRename * mRenameDlg; |
| 171 | int mOldDevNum; |
| 172 | |
| 173 | QSize sizeHint() const; |
| 174 | void clearDevices(QWidget * parent); |
| 175 | void resizeEvent ( QResizeEvent * event ); |
| 176 | void adjustSize(); |
| 177 | VisualizedDeviceEntry * getDeviceEntry(); |
| 178 | QString textFromValue(int value) const; |
| 179 | int getNextDev(std::map<int, VisualizedDeviceEntry>::iterator it) const; |
| 180 | QIcon * mYellowIcon; |
| 181 | QIcon * mYellowHighIcon; |
| 182 | |
| 183 | signals: |
| 184 | void restartDevices(); |
| 185 | }; |
| 186 | |
| 187 | #endif // DEVICES_H |