From: <per...@us...> - 2009-11-18 21:39:08
|
Revision: 209 http://netemul.svn.sourceforge.net/netemul/?rev=209&view=rev Author: perezmeyer Date: 2009-11-18 21:38:59 +0000 (Wed, 18 Nov 2009) Log Message: ----------- Fixed some typos: compability -> compatibility ; programm -> program ; programms -> programs. Thanks Ana Guerrero for the tips. Modified Paths: -------------- trunk/src/devices/deviceimpl.h trunk/src/forms/installdialog.ui trunk/src/forms/programmdialog.ui trunk/src/forms/ripproperty.ui Modified: trunk/src/devices/deviceimpl.h =================================================================== --- trunk/src/devices/deviceimpl.h 2009-11-16 18:45:58 UTC (rev 208) +++ trunk/src/devices/deviceimpl.h 2009-11-18 21:38:59 UTC (rev 209) @@ -70,10 +70,10 @@ virtual bool hasTable() const { return false; } virtual void dialog() = 0; virtual void showLogDialog(logDialog*) const = 0; - virtual void tableDialog() { qFatal("error not compability Table!"); } - virtual void adapterDialog() { qFatal("error not compability adapter!"); } - virtual void programmsDialog() { qFatal("error not compability"); } - virtual void arpDialog() { qFatal("error not compability"); } + virtual void tableDialog() { qFatal("error not compatibility Table!"); } + virtual void adapterDialog() { qFatal("error not compatibility adapter!"); } + virtual void programmsDialog() { qFatal("error not compatibility"); } + virtual void arpDialog() { qFatal("error not compatibility"); } virtual void showDesignerDialog() { qFatal("Error designer!"); } virtual void showVirtualNetworkDialog() { qFatal("Error virtual network"); } Modified: trunk/src/forms/installdialog.ui =================================================================== --- trunk/src/forms/installdialog.ui 2009-11-16 18:45:58 UTC (rev 208) +++ trunk/src/forms/installdialog.ui 2009-11-18 21:38:59 UTC (rev 209) @@ -17,7 +17,7 @@ </size> </property> <property name="windowTitle"> - <string>Programms</string> + <string>Programs</string> </property> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> Modified: trunk/src/forms/programmdialog.ui =================================================================== --- trunk/src/forms/programmdialog.ui 2009-11-16 18:45:58 UTC (rev 208) +++ trunk/src/forms/programmdialog.ui 2009-11-18 21:38:59 UTC (rev 209) @@ -17,7 +17,7 @@ </size> </property> <property name="windowTitle"> - <string>Programms</string> + <string>Programs</string> </property> <layout class="QHBoxLayout" name="horizontalLayout"> <item> Modified: trunk/src/forms/ripproperty.ui =================================================================== --- trunk/src/forms/ripproperty.ui 2009-11-16 18:45:58 UTC (rev 208) +++ trunk/src/forms/ripproperty.ui 2009-11-18 21:38:59 UTC (rev 209) @@ -11,7 +11,7 @@ </rect> </property> <property name="windowTitle"> - <string>Rip programm property</string> + <string>Rip program property</string> </property> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <f-r...@us...> - 2011-02-09 01:10:00
|
Revision: 234 http://netemul.svn.sourceforge.net/netemul/?rev=234&view=rev Author: f-r-o-s-t Date: 2011-02-09 01:09:50 +0000 (Wed, 09 Feb 2011) Log Message: ----------- Apply names notation. Modified Paths: -------------- trunk/src/chips/abstractchip.cpp trunk/src/chips/interface.cpp trunk/src/commands/addcablecommand.cpp trunk/src/commands/addcablecommand.h trunk/src/commands/addcommand.cpp trunk/src/commands/addcommand.h trunk/src/commands/addtextcommand.cpp trunk/src/commands/addtextcommand.h trunk/src/commands/deletecommand.cpp trunk/src/commands/deletecommand.h trunk/src/commands/movecommand.cpp trunk/src/commands/movecommand.h trunk/src/controls/scenecontrol.cpp trunk/src/controls/scenecontrol.h trunk/src/delegats/ipaddressdelegate.cpp trunk/src/delegats/ipaddressdelegate.h trunk/src/delegats/macaddressdelegate.cpp trunk/src/delegats/macaddressdelegate.h trunk/src/devices/boxdevice.h trunk/src/devices/computer.cpp trunk/src/devices/computer.h trunk/src/devices/deviceimpl.cpp trunk/src/devices/deviceimpl.h trunk/src/devices/hubdevice.cpp trunk/src/devices/hubdevice.h trunk/src/devices/routerdevice.cpp trunk/src/devices/routerdevice.h trunk/src/devices/sharebus.cpp trunk/src/devices/sharebus.h trunk/src/devices/smartdevice.cpp trunk/src/devices/smartdevice.h trunk/src/devices/switchdevice.cpp trunk/src/devices/switchdevice.h trunk/src/dialogs/adapterproperty.cpp trunk/src/dialogs/adapterproperty.h trunk/src/dialogs/computerproperty.cpp trunk/src/dialogs/computerproperty.h trunk/src/dialogs/devicenotedialog.cpp trunk/src/dialogs/devicenotedialog.h trunk/src/dialogs/dhcpserverproperty.cpp trunk/src/dialogs/dhcpserverproperty.h trunk/src/dialogs/hubproperty.cpp trunk/src/dialogs/hubproperty.h trunk/src/dialogs/routerproperty.cpp trunk/src/dialogs/routerproperty.h trunk/src/dialogs/settingdialog.cpp trunk/src/dialogs/staticsdialog.cpp trunk/src/dialogs/staticsdialog.h trunk/src/dialogs/switchproperty.cpp trunk/src/dialogs/switchproperty.h trunk/src/dialogs/tableswitch.cpp trunk/src/dialogs/tableswitch.h trunk/src/dialogs/testdialog.cpp trunk/src/dialogs/virtualnetworkdialog.cpp trunk/src/dialogs/virtualnetworkdialog.h trunk/src/graphics/cabledev.cpp trunk/src/graphics/cabledev.h trunk/src/graphics/device.cpp trunk/src/graphics/device.h trunk/src/graphics/sendellipse.cpp trunk/src/interfaces/visualizable.h trunk/src/mainwindow.cpp trunk/src/mainwindow.h trunk/src/models/arpmodel.cpp trunk/src/models/dhcpservermodel.cpp trunk/src/models/dhcpservermodel.h trunk/src/models/switchmodel.cpp trunk/src/mycanvas.cpp trunk/src/mycanvas.h trunk/src/other/appsetting.cpp trunk/src/other/appsetting.h trunk/src/programms/dhcpdemon.cpp trunk/src/programms/dhcpdemon.h trunk/src/programms/dhcpserverprogramm.cpp trunk/src/programms/programms.pri trunk/src/states/abstractstate.cpp trunk/src/states/cablestate.cpp trunk/src/states/cablestate.h trunk/src/states/emptystate.h trunk/src/states/insertstate.cpp trunk/src/states/insertstate.h trunk/src/states/movestate.cpp trunk/src/states/movestate.h trunk/src/states/sendstate.cpp trunk/src/states/sendstate.h trunk/src/states/textstate.cpp trunk/src/states/textstate.h trunk/src/tools/scenexmlwriter.cpp trunk/src/tools/scenexmlwriter.h trunk/src/tools/statistics.h trunk/src/tools/statisticsscene.cpp trunk/src/tools/statisticsscene.h trunk/src/tools/tcpsocket.cpp Removed Paths: ------------- trunk/src/programms/programm.cpp trunk/src/programms/programm.h Modified: trunk/src/chips/abstractchip.cpp =================================================================== --- trunk/src/chips/abstractchip.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/chips/abstractchip.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -24,10 +24,8 @@ */ AbstractChip::AbstractChip(QObject *parent) : QObject(parent) { -#ifndef __TESTING__ myMac.setRandom(); resetStatics(); -#endif } //-------------------------------------------------------------- /*! Modified: trunk/src/chips/interface.cpp =================================================================== --- trunk/src/chips/interface.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/chips/interface.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -167,7 +167,7 @@ if ( --i->time ) continue; if ( i->count <= COUNT_AGAINST_SEND ) { i->count++; - i->time = qrand()%(appSetting::arpResponceTime()*i->count)+appSetting::arpResponceTime(); + i->time = qrand()%(AppSetting::arpResponceTime()*i->count)+AppSetting::arpResponceTime(); sendArpRequest( i->dest ); } else { myWaits.removeOne(i); @@ -226,7 +226,7 @@ waitPacket *t = new waitPacket; t->dest = a; t->packets << p; - t->time = appSetting::arpResponceTime(); + t->time = AppSetting::arpResponceTime(); t->count = 0; return t; } Modified: trunk/src/commands/addcablecommand.cpp =================================================================== --- trunk/src/commands/addcablecommand.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/addcablecommand.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -21,26 +21,26 @@ #include "mycanvas.h" #include "cabledev.h" -addCableCommand::addCableCommand(MyCanvas *s, Cable *c) +AddCableCommand::AddCableCommand(MyCanvas *s, Cable *c) { scene = s; cable = c; setText(QObject::tr("Add cable")); } -addCableCommand::~addCableCommand() +AddCableCommand::~AddCableCommand() { if ( !isOnScene) delete cable; } -void addCableCommand::undo() +void AddCableCommand::undo() { // cable->unregisterCable(); scene->unregisterCable(cable); isOnScene = false; } -void addCableCommand::redo() +void AddCableCommand::redo() { // cable->registerCable(); scene->registerCable(cable); Modified: trunk/src/commands/addcablecommand.h =================================================================== --- trunk/src/commands/addcablecommand.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/addcablecommand.h 2011-02-09 01:09:50 UTC (rev 234) @@ -25,11 +25,11 @@ class MyCanvas; class Cable; -class addCableCommand : public QUndoCommand +class AddCableCommand : public QUndoCommand { public: - addCableCommand(MyCanvas *s, Cable *c); - ~addCableCommand(); + AddCableCommand(MyCanvas *s, Cable *c); + ~AddCableCommand(); void redo(); void undo(); private: Modified: trunk/src/commands/addcommand.cpp =================================================================== --- trunk/src/commands/addcommand.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/addcommand.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -21,7 +21,7 @@ #include "addcommand.h" #include "mycanvas.h" -addCommand::addCommand(MyCanvas *s, QPointF point , int type) +AddCommand::AddCommand(MyCanvas *s, QPointF point , int type) { scene = s; myDevice = 0; @@ -29,18 +29,18 @@ myType = type; } -addCommand::~addCommand() +AddCommand::~AddCommand() { if ( !isOnScene ) delete myDevice; } -void addCommand::undo() +void AddCommand::undo() { scene->unregisterDevice(myDevice); isOnScene = false; } -void addCommand::redo() +void AddCommand::redo() { if ( myDevice ) scene->registerDevice(myDevice); else { Modified: trunk/src/commands/addcommand.h =================================================================== --- trunk/src/commands/addcommand.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/addcommand.h 2011-02-09 01:09:50 UTC (rev 234) @@ -25,11 +25,11 @@ class MyCanvas; class Device; -class addCommand : public QUndoCommand +class AddCommand : public QUndoCommand { public: - addCommand(MyCanvas *s , QPointF point , int type); - ~addCommand(); + AddCommand(MyCanvas *s , QPointF point , int type); + ~AddCommand(); void undo(); void redo(); private: Modified: trunk/src/commands/addtextcommand.cpp =================================================================== --- trunk/src/commands/addtextcommand.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/addtextcommand.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -20,7 +20,7 @@ #include "addtextcommand.h" #include "mycanvas.h" -addTextCommand::addTextCommand(MyCanvas *s, QPointF p) +AddTextCommand::AddTextCommand(MyCanvas *s, QPointF p) { scene = s; point = p; @@ -28,18 +28,18 @@ setText(QObject::tr("Add note")); } -addTextCommand::~addTextCommand() +AddTextCommand::~AddTextCommand() { if ( !isOnScene ) delete text; } -void addTextCommand::undo() +void AddTextCommand::undo() { scene->unregisterText(text); isOnScene = false; } -void addTextCommand::redo() +void AddTextCommand::redo() { if ( isFirst ) { text = scene->createTextItem(point); Modified: trunk/src/commands/addtextcommand.h =================================================================== --- trunk/src/commands/addtextcommand.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/addtextcommand.h 2011-02-09 01:09:50 UTC (rev 234) @@ -26,11 +26,11 @@ class MyCanvas; class TextItem; -class addTextCommand : public QUndoCommand +class AddTextCommand : public QUndoCommand { public: - addTextCommand(MyCanvas *s, QPointF p); - ~addTextCommand(); + AddTextCommand(MyCanvas *s, QPointF p); + ~AddTextCommand(); void undo(); void redo(); private: Modified: trunk/src/commands/deletecommand.cpp =================================================================== --- trunk/src/commands/deletecommand.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/deletecommand.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -23,7 +23,7 @@ #include "device.h" #include "textitem.h" -deleteCommand::deleteCommand(MyCanvas *s, QList<QGraphicsItem*> list) +DeleteCommand::DeleteCommand(MyCanvas *s, QList<QGraphicsItem*> list) { scene = s; foreach ( QGraphicsItem *i, list) { @@ -38,7 +38,7 @@ setText(QObject::tr("Delete")); } -deleteCommand::~deleteCommand() +DeleteCommand::~DeleteCommand() { if ( isOnScene ) return; qDeleteAll(extractDevices); @@ -46,7 +46,7 @@ qDeleteAll(extractText); } -void deleteCommand::undo() +void DeleteCommand::undo() { foreach ( Device *i, extractDevices ) scene->registerDevice(i); foreach ( Cable *i, extractCables ) createConnection(i); @@ -54,7 +54,7 @@ isOnScene = true; } -void deleteCommand::redo() +void DeleteCommand::redo() { foreach ( Device *i, extractDevices ) scene->unregisterDevice(i); foreach ( Cable *i, extractCables ) deleteConnection(i); @@ -62,13 +62,13 @@ isOnScene = false; } -void deleteCommand::deleteConnection(Cable *cable) +void DeleteCommand::deleteConnection(Cable *cable) { // cable->unregisterCable(); scene->unregisterCable(cable); } -void deleteCommand::createConnection(Cable *cable) +void DeleteCommand::createConnection(Cable *cable) { // cable->registerCable(); scene->registerCable(cable); Modified: trunk/src/commands/deletecommand.h =================================================================== --- trunk/src/commands/deletecommand.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/deletecommand.h 2011-02-09 01:09:50 UTC (rev 234) @@ -29,11 +29,11 @@ class Device; class TextItem; -class deleteCommand : public QUndoCommand +class DeleteCommand : public QUndoCommand { public: - deleteCommand(MyCanvas *s, QList<QGraphicsItem*> list); - ~deleteCommand(); + DeleteCommand(MyCanvas *s, QList<QGraphicsItem*> list); + ~DeleteCommand(); void undo(); void redo(); void deleteConnection(Cable *cable); Modified: trunk/src/commands/movecommand.cpp =================================================================== --- trunk/src/commands/movecommand.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/movecommand.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -19,7 +19,7 @@ ****************************************************************************************/ #include "movecommand.h" -moveCommand::moveCommand(MyCanvas *s,mapWithCoords o,mapWithCoords r) +MoveCommand::MoveCommand(MyCanvas *s,mapWithCoords o,mapWithCoords r) { scene = s; old = o; @@ -27,12 +27,12 @@ setText(QObject::tr("Move")); } -void moveCommand::undo() +void MoveCommand::undo() { scene->putItems(old); } -void moveCommand::redo() +void MoveCommand::redo() { scene->putItems(recent); } Modified: trunk/src/commands/movecommand.h =================================================================== --- trunk/src/commands/movecommand.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/commands/movecommand.h 2011-02-09 01:09:50 UTC (rev 234) @@ -25,10 +25,10 @@ typedef QMap<QGraphicsItem*,QPointF> mapWithCoords; -class moveCommand : public QUndoCommand +class MoveCommand : public QUndoCommand { public: - moveCommand(MyCanvas *s,mapWithCoords o, mapWithCoords r); + MoveCommand(MyCanvas *s,mapWithCoords o, mapWithCoords r); void undo(); void redo(); private: Modified: trunk/src/controls/scenecontrol.cpp =================================================================== --- trunk/src/controls/scenecontrol.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/controls/scenecontrol.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -21,12 +21,12 @@ #include "device.h" #include "mycanvas.h" -sceneControl::sceneControl(QObject *parent , MyCanvas *s ) : QObject(parent) , scene(s) +SceneControl::SceneControl(QObject *parent , MyCanvas *s ) : QObject(parent) , scene(s) { connect( scene , SIGNAL(selectionChanged()) , SLOT(observeSelection()) ); } -void sceneControl::observeSelection() +void SceneControl::observeSelection() { if ( Device *t = scene->oneSelectedDevice() ) { emit selectTableDevice( t->hasTable() ); @@ -44,77 +44,77 @@ } } -QString sceneControl::tableName() const +QString SceneControl::tableName() const { return scene->oneSelectedDevice()->tableName(); } -void sceneControl::propertyDialog() const +void SceneControl::propertyDialog() const { Device *t = scene->oneSelectedDevice(); t->dialog(); } -void sceneControl::tableDialog() const +void SceneControl::tableDialog() const { Device *t = scene->oneSelectedDevice(); t->tableDialog(); } -void sceneControl::adapterDialog() const +void SceneControl::adapterDialog() const { Device *t = scene->oneSelectedDevice(); t->adapterDialog(); } -void sceneControl::programmsDialog() const +void SceneControl::programmsDialog() const { Device *t = scene->oneSelectedDevice(); t->programmsDialog(); } -void sceneControl::arpDialog() const +void SceneControl::arpDialog() const { Device *t = scene->oneSelectedDevice(); t->arpDialog(); } -void sceneControl::showLogDialog(logDialog *log) const +void SceneControl::showLogDialog(logDialog *log) const { Device *t = scene->oneSelectedDevice(); t->showLogDialog(log); } -void sceneControl::showDesignerDialog() const +void SceneControl::showDesignerDialog() const { Device *t = scene->oneSelectedDevice(); t->showDesignerDialog(); } -void sceneControl::showDeviceNoteDialog() const +void SceneControl::showDeviceNoteDialog() const { Device *t = scene->oneSelectedDevice(); t->showDeviceNoteDialog(); } -void sceneControl::showVirtualNetworkDialog() const +void SceneControl::showVirtualNetworkDialog() const { scene->oneSelectedDevice()->showVirtualNetworkDialog(); } -bool sceneControl::isSelect() const +bool SceneControl::isSelect() const { if ( scene->oneSelectedDevice() ) return true; return false; } -QString sceneControl::note() const +QString SceneControl::note() const { Device *t = scene->oneSelectedDevice(); return t->toolTip(); } -QIcon sceneControl::tableIcon() const +QIcon SceneControl::tableIcon() const { Device *t = scene->oneSelectedDevice(); if ( !t->hasTable() ) return QIcon(); @@ -122,13 +122,13 @@ else return QIcon(":/im/images/table_arp.png"); } -QString sceneControl::deviceName() const +QString SceneControl::deviceName() const { Device *t = scene->oneSelectedDevice(); return t->deviceName(); } -QStringList sceneControl::sockets() const +QStringList SceneControl::sockets() const { Device *t = scene->oneSelectedDevice(); return t->sockets(); Modified: trunk/src/controls/scenecontrol.h =================================================================== --- trunk/src/controls/scenecontrol.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/controls/scenecontrol.h 2011-02-09 01:09:50 UTC (rev 234) @@ -26,11 +26,11 @@ class MyCanvas; class logDialog; -class sceneControl : public QObject +class SceneControl : public QObject { Q_OBJECT public: - sceneControl(QObject *parent,MyCanvas *s); + SceneControl(QObject *parent,MyCanvas *s); bool isSelect() const; QString tableName() const; QString note() const; Modified: trunk/src/delegats/ipaddressdelegate.cpp =================================================================== --- trunk/src/delegats/ipaddressdelegate.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/delegats/ipaddressdelegate.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -21,24 +21,24 @@ #include <QLineEdit> #include <QStringList> -ipAddressDelegate::ipAddressDelegate(QObject *parent /* = 0 */) : QItemDelegate(parent) +IpAddressDelegate::IpAddressDelegate(QObject *parent /* = 0 */) : QItemDelegate(parent) { } -QWidget* ipAddressDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex&) const +QWidget* IpAddressDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex&) const { QLineEdit *line = new QLineEdit(parent); return line; } -void ipAddressDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +void IpAddressDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString data = index.model()->data(index,Qt::EditRole ).toString(); QLineEdit *line = static_cast<QLineEdit*>(editor); line->setText(data); } -void ipAddressDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex &index) const +void IpAddressDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex &index) const { QLineEdit *line = static_cast<QLineEdit*>(editor); QString data = line->text(); @@ -47,7 +47,7 @@ model->setData(index,data,Qt::EditRole); } -void ipAddressDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option,const QModelIndex&) const +void IpAddressDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option,const QModelIndex&) const { editor->setGeometry( option.rect ); } Modified: trunk/src/delegats/ipaddressdelegate.h =================================================================== --- trunk/src/delegats/ipaddressdelegate.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/delegats/ipaddressdelegate.h 2011-02-09 01:09:50 UTC (rev 234) @@ -22,10 +22,10 @@ #include <QItemDelegate> -class ipAddressDelegate : public QItemDelegate +class IpAddressDelegate : public QItemDelegate { public: - ipAddressDelegate(QObject *parent = 0); + IpAddressDelegate(QObject *parent = 0); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex&) const; Modified: trunk/src/delegats/macaddressdelegate.cpp =================================================================== --- trunk/src/delegats/macaddressdelegate.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/delegats/macaddressdelegate.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -20,33 +20,33 @@ #include "macaddressdelegate.h" #include <QLineEdit> -macAddressDelegate::macAddressDelegate(QObject *parent /* = 0 */) : QItemDelegate(parent) +MacAddressDelegate::MacAddressDelegate(QObject *parent /* = 0 */) : QItemDelegate(parent) { } -QWidget* macAddressDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex&) const +QWidget* MacAddressDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex&) const { QLineEdit *line = new QLineEdit(parent); line->setInputMask("HH:HH:HH:HH:HH:HH;_"); return line; } -void macAddressDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +void MacAddressDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString data = index.model()->data(index,Qt::EditRole ).toString(); QLineEdit *line = static_cast<QLineEdit*>(editor); line->setText(data); } -void macAddressDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex &index) const +void MacAddressDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex &index) const { QLineEdit *line = static_cast<QLineEdit*>(editor); QString data = line->text(); model->setData(index,data,Qt::EditRole); } -void macAddressDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option,const QModelIndex&) const +void MacAddressDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option,const QModelIndex&) const { editor->setGeometry( option.rect ); } Modified: trunk/src/delegats/macaddressdelegate.h =================================================================== --- trunk/src/delegats/macaddressdelegate.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/delegats/macaddressdelegate.h 2011-02-09 01:09:50 UTC (rev 234) @@ -22,11 +22,11 @@ #include <QItemDelegate> -class macAddressDelegate : public QItemDelegate +class MacAddressDelegate : public QItemDelegate { Q_OBJECT public: - macAddressDelegate(QObject *parent = 0); + MacAddressDelegate(QObject *parent = 0); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex&) const; Modified: trunk/src/devices/boxdevice.h =================================================================== --- trunk/src/devices/boxdevice.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/boxdevice.h 2011-02-09 01:09:50 UTC (rev 234) @@ -29,8 +29,7 @@ Q_OBJECT Q_PROPERTY( bool isManual READ isManual WRITE setManual ) public: - friend class boxSetting; - BoxDevice(QObject *parent = 0); + BoxDevice(QObject *parent = 0); virtual ~BoxDevice(); bool isConnectSocket(const QString &socket) const { return myChip->isConnectSocket(socket); } QIcon isConnectSocketIcon(const QString &socket) const; @@ -66,12 +65,15 @@ bool myManual; BoxChip *myChip; virtual void write(QDataStream &stream) const; - virtual void read(QDataStream &stream); + virtual void read(QDataStream &stream); + +public: + friend class BoxSetting; }; -class boxSetting : public deviceSetting { +class BoxSetting : public DeviceSetting { public: - boxSetting(BoxDevice *h) : deviceSetting(h) , box(h) { } + BoxSetting(BoxDevice *h) : DeviceSetting(h) , box(h) { } int socketsCount() const { return box->myChip->socketsCount(); } QString snmpMac() const { return box->myChip->mac().toString(); } QString snmpIp() const { return box->myChip->ip().toString(); } Modified: trunk/src/devices/computer.cpp =================================================================== --- trunk/src/devices/computer.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/computer.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -35,7 +35,7 @@ Computer* Computer::create(QObject *parent) { Computer *c = new Computer(parent); - c->setSocketsCount(appSetting::defaultComputerCount()); + c->setSocketsCount(AppSetting::defaultComputerCount()); c->setRouteModel( new RouteModel(c) ); c->routeModel()->addToTable("127.0.0.0","255.0.0.0","127.0.0.1","127.0.0.1",0,RouteModel::connectMode); c->setNote(tr("<b>Computer</b><!--You can use HTML.-->")); @@ -50,11 +50,9 @@ void Computer::dialog() { -#ifndef __TESTING__ computerProperty *d = new computerProperty; - d->setDevice( new computerSetting(this) ); + d->setDevice( new ComputerSetting(this) ); d->exec(); -#endif } void Computer::setSocketsCount(int n) Modified: trunk/src/devices/computer.h =================================================================== --- trunk/src/devices/computer.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/computer.h 2011-02-09 01:09:50 UTC (rev 234) @@ -55,9 +55,9 @@ }; //--------------------------------------------- -class computerSetting : public smartSetting { +class ComputerSetting : public SmartSetting { public: - computerSetting( Computer *c ) : smartSetting(c) , cp(c) { } + ComputerSetting( Computer *c ) : SmartSetting(c) , cp(c) { } QString gateway() const { return cp->gateway().toString(); } void setGateway(const QString &str) { cp->setGateway(str); } private: Modified: trunk/src/devices/deviceimpl.cpp =================================================================== --- trunk/src/devices/deviceimpl.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/deviceimpl.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -28,7 +28,7 @@ void DeviceImpl::showDeviceNoteDialog() { deviceNoteDialog *d = new deviceNoteDialog; - d->setDevice( new deviceSetting(this) ); + d->setDevice( new DeviceSetting(this) ); d->exec(); } Modified: trunk/src/devices/deviceimpl.h =================================================================== --- trunk/src/devices/deviceimpl.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/deviceimpl.h 2011-02-09 01:09:50 UTC (rev 234) @@ -31,7 +31,7 @@ class logDialog; class DevicePort; -typedef QMap<QString,bool> featuresMap; +typedef QMap<QString,bool> FeaturesMap; class DeviceImpl : public QObject { @@ -46,7 +46,7 @@ virtual int type() const = 0; virtual QStringList sockets() const = 0; - virtual featuresMap featuresList() const { return featuresMap(); } + virtual FeaturesMap featuresList() const { return FeaturesMap(); } virtual bool isConnectSocket(const QString &socket) const = 0; virtual QIcon isConnectSocketIcon( const QString &socket) const = 0; virtual QString socketName(const Cable *c) const = 0; @@ -90,7 +90,7 @@ virtual bool isCanSend() const { return false; } - void setVisualizator( visualizable *view ) { myView = view; } + void setVisualizator( Visualizable *view ) { myView = view; } void updateView() const { myView->onImplChange(); } public: @@ -113,14 +113,14 @@ virtual quint64 sendFrameCount(const QString&) { return 0; } virtual quint64 receiveFrameCount(const QString&) { return 0; } protected: - visualizable *myView; + Visualizable *myView; private: QString myNote; }; -class deviceSetting { +class DeviceSetting { public: - deviceSetting(DeviceImpl *d) : dev(d) { } + DeviceSetting(DeviceImpl *d) : dev(d) { } QString note() const { return dev->note(); } void setNote(const QString &str) { dev->setNote(str); } private: Modified: trunk/src/devices/hubdevice.cpp =================================================================== --- trunk/src/devices/hubdevice.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/hubdevice.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -32,8 +32,8 @@ { HubDevice *h = new HubDevice(parent); h->setBoxChip(new HubChip(h)); - h->setSocketsCount( appSetting::defaultHubCount() ); - h->setManual( appSetting::defaultHubManual() ); + h->setSocketsCount( AppSetting::defaultHubCount() ); + h->setManual( AppSetting::defaultHubManual() ); h->setNote(tr( "<b>Hub</b><!--You can use HTML.-->" ) ); return h; } @@ -66,7 +66,7 @@ void HubDevice::dialog() { hubProperty *d = new hubProperty; - hubSetting *set = new hubSetting(this); + HubSetting *set = new HubSetting(this); d->setHub(set); d->exec(); delete set; Modified: trunk/src/devices/hubdevice.h =================================================================== --- trunk/src/devices/hubdevice.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/hubdevice.h 2011-02-09 01:09:50 UTC (rev 234) @@ -44,7 +44,7 @@ QString deviceName() const { return "hub"; } QString deviceCommandName() const { return tr("Hub"); } QString pixmapName() const { return ":/im/images/hub.png"; } - friend class hubSetting; + friend class HubSetting; protected: void write(QDataStream &stream) const; void read(QDataStream &stream); @@ -52,12 +52,12 @@ quint32 m_collision; }; -class hubSetting : public boxSetting +class HubSetting : public BoxSetting { public: - hubSetting(HubDevice *d) : boxSetting(d) , hd(d) { } + HubSetting(HubDevice *d) : BoxSetting(d) , hd(d) { } quint32 collisions() const { return hd->m_collision; } - void reset() { boxSetting::reset(); hd->m_collision = 0; } + void reset() { BoxSetting::reset(); hd->m_collision = 0; } private: HubDevice *hd; }; Modified: trunk/src/devices/routerdevice.cpp =================================================================== --- trunk/src/devices/routerdevice.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/routerdevice.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -31,7 +31,7 @@ RouterDevice* RouterDevice::create(QObject *parent) { RouterDevice *r = new RouterDevice(parent); - r->setSocketsCount( appSetting::defaultRouterCount() ); + r->setSocketsCount( AppSetting::defaultRouterCount() ); r->setRouteModel( new RouteModel() ); r->setNote(tr("<b>Router</b><!--You can use HTML.-->")); return r; @@ -40,7 +40,7 @@ void RouterDevice::dialog() { routerProperty *d = new routerProperty; - routerSetting *set = new routerSetting(this); + RouterSetting *set = new RouterSetting(this); d->setRouter(set); d->exec(); delete d; Modified: trunk/src/devices/routerdevice.h =================================================================== --- trunk/src/devices/routerdevice.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/routerdevice.h 2011-02-09 01:09:50 UTC (rev 234) @@ -42,10 +42,10 @@ void setSocketsCount(int n); }; -class routerSetting : public smartSetting +class RouterSetting : public SmartSetting { public: - routerSetting(RouterDevice *r) : smartSetting(r) , rd(r) { } + RouterSetting(RouterDevice *r) : SmartSetting(r) , rd(r) { } void setSocketsCount(int n) { rd->setSocketsCount(n); } private: RouterDevice *rd; Modified: trunk/src/devices/sharebus.cpp =================================================================== --- trunk/src/devices/sharebus.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/sharebus.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -19,13 +19,13 @@ ****************************************************************************************/ #include "sharebus.h" -shareBus::shareBus(int c) +ShareBus::ShareBus(int c) { Q_UNUSED(c); widthDev = defaultWidth; } -DevicePort* shareBus::addInterface(QString str, int t) +DevicePort* ShareBus::addInterface(QString str, int t) { Q_UNUSED(str); Q_UNUSED(t); Modified: trunk/src/devices/sharebus.h =================================================================== --- trunk/src/devices/sharebus.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/sharebus.h 2011-02-09 01:09:50 UTC (rev 234) @@ -28,11 +28,11 @@ // который унаследован от device , так как у общей шины будет отличаться // реализация и отображение от остальных устройств // -class shareBus : public DeviceImpl +class ShareBus : public DeviceImpl { public: enum { defaultWidth = 200 }; - shareBus(int c); + ShareBus(int c); DevicePort* addInterface(QString str,int t); void dialog() { } bool hasTable() const { return false; } Modified: trunk/src/devices/smartdevice.cpp =================================================================== --- trunk/src/devices/smartdevice.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/smartdevice.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -41,7 +41,9 @@ SmartDevice::~SmartDevice() { qDeleteAll(mySockets); + mySockets.clear(); qDeleteAll(myInterfaces); + myInterfaces.clear(); } const Interface* SmartDevice::adapter(const QString &s) const @@ -290,44 +292,36 @@ void SmartDevice::showLogDialog(logDialog *log) const { -#ifndef __TESTING__ connect( log ,SIGNAL(changeInterface(QString)) , this ,SLOT(setCheckedSocket(QString)) ); foreach ( Interface *i , myInterfaces ) { connect( i , SIGNAL(receiveData(frame,QString)) , log , SLOT(receiveData(frame,QString)) ); connect( i , SIGNAL(sendData(frame,QString)) , log , SLOT(sendData(frame,QString)) ); } -#endif } void SmartDevice::adapterDialog() { -#ifndef __TESTING__ - adapterProperty *d = new adapterProperty( new adapterSetting(this) ); + adapterProperty *d = new adapterProperty( new AdapterSetting(this) ); d->show(); -#endif } void SmartDevice::programmsDialog() { -#ifndef __TESTING__ programmDialog *d = new programmDialog; d->setDevice(this); d->show(); -#endif } void SmartDevice::arpDialog() { -#ifndef __TESTING__ tableArp *d = new tableArp; d->setDevice(this); d->exec(); -#endif } -featuresMap SmartDevice::featuresList() const +FeaturesMap SmartDevice::featuresList() const { - featuresMap t; + FeaturesMap t; foreach ( Program *i , myPrograms ) t.insert(i->featureName(),i->isEnable()); return t; @@ -552,15 +546,15 @@ } connect( s , SIGNAL(imFinished(AbstractSocket*)) , this , SLOT(disposeSocket(AbstractSocket*)) ); mySockets << s; - qDebug("Socket %d created",type); return s; } void SmartDevice::disposeSocket(AbstractSocket *socket) { - qDebug("Socket removed"); - mySockets.removeOne(socket); - delete socket; + if ( mySockets.contains(socket) ) { + mySockets.removeOne(socket); + delete socket; + } } //------------------------------------------------------------------------------ @@ -569,7 +563,7 @@ /*! * Функция устанавливает текущий выбранный интерфейс в настройках адаптеров. */ -void adapterSetting::setCurrent(int n) +void AdapterSetting::setCurrent(int n) { cur = n; oldMask = sd->myInterfaces[cur]->mask(); @@ -579,7 +573,7 @@ /*! * Изменяет таблицу маршрутизации в соответсвии с новыми настройками интрефейсов. */ -void adapterSetting::connectedNet() +void AdapterSetting::connectedNet() { RouteRecord *t = sd->routeModel()->recordAt( oldMask & oldIp ); if ( t ) { // Удаляем запись со старыми натсройками @@ -589,13 +583,13 @@ } //-------------------------------------------------------------------------- -bool adapterSetting::isUnderDhcpControl() const +bool AdapterSetting::isUnderDhcpControl() const { DhcpClientProgram *t = qobject_cast<DhcpClientProgram*>( sd->programAt(Program::DHCPClient) ); return t->isUnderDhcpControl( sd->myInterfaces.at(cur)->name() ); } -void adapterSetting::setUnderDhcpControl(bool isUnder) +void AdapterSetting::setUnderDhcpControl(bool isUnder) { DhcpClientProgram *t = qobject_cast<DhcpClientProgram*>( sd->programAt( Program::DHCPClient) ); t->observeInterface( sd->myInterfaces.at(cur)->name() , isUnder ); Modified: trunk/src/devices/smartdevice.h =================================================================== --- trunk/src/devices/smartdevice.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/smartdevice.h 2011-02-09 01:09:50 UTC (rev 234) @@ -67,7 +67,7 @@ QStringList interfacesIp() const; QList<Cable*> cableList() const; DevicePort* findPortByName(const QString &name) const; - featuresMap featuresList() const; + FeaturesMap featuresList() const; void addInterface(); bool isConnectSocket(const QString &socket) const { return adapter(socket)->isConnect(); } bool hasConnentSockets() const; @@ -139,15 +139,15 @@ virtual void read(QDataStream &stream); // FRIENDS: public: - friend class adapterSetting; + friend class AdapterSetting; }; //------------------------------------------------------------------- /*! Модель данных для настроек адаптеров. */ -class adapterSetting { +class AdapterSetting { public: - adapterSetting(SmartDevice *s) : sd(s) { } + AdapterSetting(SmartDevice *s) : sd(s) { } void setCurrent(int n); int current() const { return cur; } void resetStatics() { sd->myInterfaces.at(cur)->resetStatics(); } @@ -179,9 +179,9 @@ }; //------------------------------------------------------------- -class smartSetting : public deviceSetting { +class SmartSetting : public DeviceSetting { public: - smartSetting(SmartDevice *d) : deviceSetting(d) , sd(d) { } + SmartSetting(SmartDevice *d) : DeviceSetting(d) , sd(d) { } int socketsCount() const { return sd->socketsCount(); } bool isRouter() const { return sd->isRouter(); } void setRouter(bool b) { sd->setRouter(b); } Modified: trunk/src/devices/switchdevice.cpp =================================================================== --- trunk/src/devices/switchdevice.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/switchdevice.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -33,8 +33,8 @@ { SwitchDevice *s = new SwitchDevice(parent); s->setBoxChip( SwitchChip::create(s) ); - s->setSocketsCount( appSetting::defaultSwitchCount() ); - s->setManual( appSetting::defaultSwitchManual() ); + s->setSocketsCount( AppSetting::defaultSwitchCount() ); + s->setManual( AppSetting::defaultSwitchManual() ); s->setNote(tr("<b>Switch</b><!--You can use HTML.-->")); return s; } @@ -58,13 +58,13 @@ void SwitchDevice::dialog() { switchProperty *d = new switchProperty; - d->setSwitch( new boxSetting(this) ); + d->setSwitch( new BoxSetting(this) ); d->show(); } void SwitchDevice::tableDialog() { - switchTableSetting *set = new switchTableSetting(this); + SwitchTableSetting *set = new SwitchTableSetting(this); TableSwitch *t = new TableSwitch(set); t->exec(); delete t; @@ -74,7 +74,7 @@ void SwitchDevice::showVirtualNetworkDialog() { virtualNetworkDialog *d = new virtualNetworkDialog; - d->setDevice( new virtualNetworkSetting(this) ); + d->setDevice( new VirtualNetworkSetting(this) ); d->show(); } @@ -90,7 +90,7 @@ //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- -SwitchModel* switchTableSetting::switchTable() +SwitchModel* SwitchTableSetting::switchTable() { return sw->concreteChip()->modelAt( sw->concreteChip()->vlanAt(0) ); } Modified: trunk/src/devices/switchdevice.h =================================================================== --- trunk/src/devices/switchdevice.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/devices/switchdevice.h 2011-02-09 01:09:50 UTC (rev 234) @@ -25,7 +25,7 @@ class frame; class SwitchModel; -class switchTableSetting; +class SwitchTableSetting; class SwitchChip; // Пока такое коротенькое объявление для свитча @@ -34,7 +34,6 @@ { Q_OBJECT public: - friend class switchTableSetting; enum { switchDev = 5 }; int type() const { return switchDev; } SwitchDevice(QObject *parent = 0); //Пока конструктор и прорисовка @@ -55,11 +54,14 @@ protected: void write(QDataStream &stream) const; void read(QDataStream &stream); + +public: + friend class SwitchTableSetting; }; -class switchTableSetting { +class SwitchTableSetting { public: - switchTableSetting(SwitchDevice *s) : sw(s) { } + SwitchTableSetting(SwitchDevice *s) : sw(s) { } SwitchModel* switchTable(); int socketsCount() const { return sw->myChip->socketsCount(); } void removeFromTable(int row); @@ -68,9 +70,9 @@ SwitchDevice *sw; }; -class virtualNetworkSetting { +class VirtualNetworkSetting { public: - virtualNetworkSetting( SwitchDevice *device ) : myDevice(device) { } + VirtualNetworkSetting( SwitchDevice *device ) : myDevice(device) { } private: SwitchDevice *myDevice; }; Modified: trunk/src/dialogs/adapterproperty.cpp =================================================================== --- trunk/src/dialogs/adapterproperty.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/adapterproperty.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -29,7 +29,7 @@ /*! Конструктор создает основной интерфейс диалога. */ -adapterProperty::adapterProperty(adapterSetting *s) +adapterProperty::adapterProperty(AdapterSetting *s) { setWindowTitle(tr("Netcard")); sd = s; Modified: trunk/src/dialogs/adapterproperty.h =================================================================== --- trunk/src/dialogs/adapterproperty.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/adapterproperty.h 2011-02-09 01:09:50 UTC (rev 234) @@ -30,7 +30,7 @@ class DevicePort; class ipEdit; -class adapterSetting; +class AdapterSetting; /** Класс диалога настройки адаптеров. @@ -40,7 +40,7 @@ Q_OBJECT Q_DISABLE_COPY(adapterProperty) public: - adapterProperty(adapterSetting *s); + adapterProperty(AdapterSetting *s); ~adapterProperty(); private slots: void updateTab(int n); @@ -51,7 +51,7 @@ void onAutoClicked(bool isAuto); void apply(); private: - adapterSetting *sd; + AdapterSetting *sd; QLabel *lb_statics; QTabBar *tab_interfaces; QLineEdit *le_name; Modified: trunk/src/dialogs/computerproperty.cpp =================================================================== --- trunk/src/dialogs/computerproperty.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/computerproperty.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -49,7 +49,7 @@ delete comp; } -void computerProperty::setDevice(computerSetting *c) +void computerProperty::setDevice(ComputerSetting *c) { comp = c; gateway->setText( c->gateway() ); Modified: trunk/src/dialogs/computerproperty.h =================================================================== --- trunk/src/dialogs/computerproperty.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/computerproperty.h 2011-02-09 01:09:50 UTC (rev 234) @@ -24,7 +24,7 @@ class QCheckBox; -class computerSetting; +class ComputerSetting; class ipEdit; class computerProperty : public dialogTemplate @@ -34,9 +34,9 @@ public: computerProperty(); ~computerProperty(); - void setDevice(computerSetting *c); + void setDevice(ComputerSetting *c); private: - computerSetting *comp; + ComputerSetting *comp; QCheckBox *cb_route; ipEdit *gateway; public slots: Modified: trunk/src/dialogs/devicenotedialog.cpp =================================================================== --- trunk/src/dialogs/devicenotedialog.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/devicenotedialog.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -7,7 +7,7 @@ setAttribute(Qt::WA_DeleteOnClose); } -void deviceNoteDialog::setDevice(deviceSetting *device) +void deviceNoteDialog::setDevice(DeviceSetting *device) { myDevice = device; te_text->setPlainText( device->note() ); Modified: trunk/src/dialogs/devicenotedialog.h =================================================================== --- trunk/src/dialogs/devicenotedialog.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/devicenotedialog.h 2011-02-09 01:09:50 UTC (rev 234) @@ -3,20 +3,20 @@ #include "ui_devicenotedialog.h" -class deviceSetting; +class DeviceSetting; class deviceNoteDialog : public QDialog, private Ui::deviceNoteDialog { Q_OBJECT public: deviceNoteDialog(QWidget *parent = 0); - void setDevice(deviceSetting *device); + void setDevice(DeviceSetting *device); ~deviceNoteDialog(); public slots: void apply(); protected: void changeEvent(QEvent *e); private: - deviceSetting *myDevice; + DeviceSetting *myDevice; }; #endif // DEVICENOTEDIALOG_H Modified: trunk/src/dialogs/dhcpserverproperty.cpp =================================================================== --- trunk/src/dialogs/dhcpserverproperty.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/dhcpserverproperty.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -32,8 +32,8 @@ setAttribute(Qt::WA_DeleteOnClose); foreach ( Interface *i, device->interfaces() ) if ( i->isConnect() ) cb_interface->addItem( QIcon(":im/images/ok.png"), i->name() ); - macDelegate = new macAddressDelegate(this); - ipDelegate = new ipAddressDelegate(this); + macDelegate = new MacAddressDelegate(this); + ipDelegate = new IpAddressDelegate(this); tv_static->setItemDelegateForColumn(0, macDelegate ); for ( int i = 1 ; i <= 3 ; i++ ) tv_static->setItemDelegateForColumn(i,ipDelegate); Modified: trunk/src/dialogs/dhcpserverproperty.h =================================================================== --- trunk/src/dialogs/dhcpserverproperty.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/dhcpserverproperty.h 2011-02-09 01:09:50 UTC (rev 234) @@ -24,10 +24,10 @@ #include "ipedit.h" class DhcpServerProgram; -class dhcpServerModel; +class DhcpServerModel; class SmartDevice; -class macAddressDelegate; -class ipAddressDelegate; +class MacAddressDelegate; +class IpAddressDelegate; class dhcpServerProperty : public QDialog, private Ui::dhspServerProperty { @@ -44,10 +44,10 @@ protected: void changeEvent(QEvent *e); private: - macAddressDelegate *macDelegate; - ipAddressDelegate *ipDelegate; + MacAddressDelegate *macDelegate; + IpAddressDelegate *ipDelegate; DhcpServerProgram *myProgramm; - dhcpServerModel *myModel; + DhcpServerModel *myModel; SmartDevice *device; }; Modified: trunk/src/dialogs/hubproperty.cpp =================================================================== --- trunk/src/dialogs/hubproperty.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/hubproperty.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -69,7 +69,7 @@ { } -void hubProperty::setHub(hubSetting *s) +void hubProperty::setHub(HubSetting *s) { st = s; cb_count->setCurrentIndex( cb_count->findText( QString::number(st->socketsCount() ) )); Modified: trunk/src/dialogs/hubproperty.h =================================================================== --- trunk/src/dialogs/hubproperty.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/hubproperty.h 2011-02-09 01:09:50 UTC (rev 234) @@ -28,7 +28,7 @@ class QPushButton; class ipEdit; -class hubSetting; +class HubSetting; class hubProperty : public dialogTemplate { @@ -36,9 +36,9 @@ public: hubProperty(); ~hubProperty(); - void setHub(hubSetting *s); + void setHub(HubSetting *s); private: - hubSetting *st; + HubSetting *st; QComboBox *cb_count; QLabel *lb_statics; QLabel *lb_mac; Modified: trunk/src/dialogs/routerproperty.cpp =================================================================== --- trunk/src/dialogs/routerproperty.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/routerproperty.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -52,7 +52,7 @@ Задает диалогу устройство для работы. @param r - указатель на роутер. */ -void routerProperty::setRouter(routerSetting *r) +void routerProperty::setRouter(RouterSetting *r) { rt = r; cb_route->setChecked(r->isRouter()); Modified: trunk/src/dialogs/routerproperty.h =================================================================== --- trunk/src/dialogs/routerproperty.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/routerproperty.h 2011-02-09 01:09:50 UTC (rev 234) @@ -22,7 +22,7 @@ #include "dialogtemplate.h" -class routerSetting; +class RouterSetting; class QCheckBox; class QGroupBox; class QComboBox; @@ -33,9 +33,9 @@ Q_DISABLE_COPY(routerProperty) public: routerProperty(); - void setRouter(routerSetting *r); + void setRouter(RouterSetting *r); private: - routerSetting *rt; + RouterSetting *rt; QCheckBox *cb_route; QComboBox *cb_count; public slots: Modified: trunk/src/dialogs/settingdialog.cpp =================================================================== --- trunk/src/dialogs/settingdialog.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/settingdialog.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -29,38 +29,38 @@ void settingDialog::currentValues() { - sp_arpResponce->setValue( appSetting::arpResponceTime() ); + sp_arpResponce->setValue( AppSetting::arpResponceTime() ); - sp_ttlArp->setValue( appSetting::ttlArp() ); + sp_ttlArp->setValue( AppSetting::ttlArp() ); computerComboBox->setCurrentIndex( computerComboBox->findText(QString::number( - appSetting::defaultComputerCount() ) ) ); + AppSetting::defaultComputerCount() ) ) ); hubComboBox->setCurrentIndex( hubComboBox->findText( - QString::number( appSetting::defaultHubCount() ) ) ); + QString::number( AppSetting::defaultHubCount() ) ) ); switchComboBox->setCurrentIndex( switchComboBox->findText( - QString::number( appSetting::defaultSwitchCount() ) ) ); + QString::number( AppSetting::defaultSwitchCount() ) ) ); - sp_ttlMac->setValue( appSetting::ttlMac() ); + sp_ttlMac->setValue( AppSetting::ttlMac() ); routerComboBox->setCurrentIndex( routerComboBox->findText(QString::number( - appSetting::defaultRouterCount() ) ) ); + AppSetting::defaultRouterCount() ) ) ); - int s = appSetting::animateSpeed(); + int s = AppSetting::animateSpeed(); sl_speed->setValue(s); - languageBox->setCurrentIndex( appSetting::language() ); + languageBox->setCurrentIndex( AppSetting::language() ); - sb_send->setValue(appSetting::sendingNum()); + sb_send->setValue(AppSetting::sendingNum()); - sb_waitingTime->setValue(appSetting::waitingTime()); + sb_waitingTime->setValue(AppSetting::waitingTime()); - cb_opengl->setChecked( appSetting::hasOpengl() ); + cb_opengl->setChecked( AppSetting::hasOpengl() ); - cb_autosave->setChecked( appSetting::isAutosave() ); + cb_autosave->setChecked( AppSetting::isAutosave() ); - sb_autosave->setValue( appSetting::autosaveInterval() ); + sb_autosave->setValue( AppSetting::autosaveInterval() ); btn_apply->setEnabled(false); } @@ -72,20 +72,20 @@ void settingDialog::apply() { - appSetting::setDefaultComputerCount( computerComboBox->currentText().toInt() ); - appSetting::setDefaultHubCount( hubComboBox->currentText().toInt() ); - appSetting::setDefaultSwitchCount( switchComboBox->currentText().toInt() ); - appSetting::setDefaultRouterCount( routerComboBox->currentText().toInt() ); - appSetting::setTtlArp( sp_ttlArp->value() ); - appSetting::setArpResponceTime( sp_arpResponce->value() ); - appSetting::setTtlMac( sp_ttlMac->value() ); - appSetting::setAnimateSpeed(sl_speed->value()); - appSetting::setLanguage( languageBox->currentIndex() ); - appSetting::setSendingNum(sb_send->value()); - appSetting::setWaitingTime(sb_waitingTime->value()); - appSetting::setHasOpengl( cb_opengl->isChecked() ); - appSetting::setAutosaveInterval( sb_autosave->value() ); - appSetting::setAutosave( cb_autosave->isChecked() ); + AppSetting::setDefaultComputerCount( computerComboBox->currentText().toInt() ); + AppSetting::setDefaultHubCount( hubComboBox->currentText().toInt() ); + AppSetting::setDefaultSwitchCount( switchComboBox->currentText().toInt() ); + AppSetting::setDefaultRouterCount( routerComboBox->currentText().toInt() ); + AppSetting::setTtlArp( sp_ttlArp->value() ); + AppSetting::setArpResponceTime( sp_arpResponce->value() ); + AppSetting::setTtlMac( sp_ttlMac->value() ); + AppSetting::setAnimateSpeed(sl_speed->value()); + AppSetting::setLanguage( languageBox->currentIndex() ); + AppSetting::setSendingNum(sb_send->value()); + AppSetting::setWaitingTime(sb_waitingTime->value()); + AppSetting::setHasOpengl( cb_opengl->isChecked() ); + AppSetting::setAutosaveInterval( sb_autosave->value() ); + AppSetting::setAutosave( cb_autosave->isChecked() ); btn_apply->setEnabled(false); if ( sender() == btn_ok ) accept(); } @@ -97,7 +97,7 @@ void settingDialog::defaultSettings() { - appSetting::defaultNums(); + AppSetting::defaultNums(); currentValues(); } @@ -106,7 +106,7 @@ switch (e->type()) { case QEvent::LanguageChange: retranslateUi(this); - languageBox->setCurrentIndex( appSetting::language() ); + languageBox->setCurrentIndex( AppSetting::language() ); listWidget->setSpacing( listWidget->spacing() ); break; default: Modified: trunk/src/dialogs/staticsdialog.cpp =================================================================== --- trunk/src/dialogs/staticsdialog.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/staticsdialog.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -21,7 +21,7 @@ #include "mycanvas.h" #include "statisticsscene.h" -staticsDialog::staticsDialog(statisticsScene *statistics, QWidget *parent) :QDialog(parent) +staticsDialog::staticsDialog(StatisticsScene *statistics, QWidget *parent) :QDialog(parent) { setupUi(this); deviceLabel->setText( statistics->devicesString() ); Modified: trunk/src/dialogs/staticsdialog.h =================================================================== --- trunk/src/dialogs/staticsdialog.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/staticsdialog.h 2011-02-09 01:09:50 UTC (rev 234) @@ -23,13 +23,13 @@ #include "ui_staticsdialog.h" class MyCanvas; -class statisticsScene; +class StatisticsScene; class staticsDialog : public QDialog, private Ui::staticsDialog { Q_OBJECT Q_DISABLE_COPY(staticsDialog) public: - staticsDialog(statisticsScene *statistics, QWidget *parent = 0); + staticsDialog(StatisticsScene *statistics, QWidget *parent = 0); protected: void changeEvent(QEvent *e); }; Modified: trunk/src/dialogs/switchproperty.cpp =================================================================== --- trunk/src/dialogs/switchproperty.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/switchproperty.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -72,7 +72,7 @@ delete sw; } -void switchProperty::setSwitch(boxSetting *d) +void switchProperty::setSwitch(BoxSetting *d) { sw = d; cb_count->setCurrentIndex( cb_count->findText( QString::number( d->socketsCount() ) ) ); Modified: trunk/src/dialogs/switchproperty.h =================================================================== --- trunk/src/dialogs/switchproperty.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/switchproperty.h 2011-02-09 01:09:50 UTC (rev 234) @@ -27,7 +27,7 @@ class QLabel; class QCheckBox; -class boxSetting; +class BoxSetting; class ipEdit; class switchProperty : public dialogTemplate @@ -37,9 +37,9 @@ public: switchProperty(); ~switchProperty(); - void setSwitch(boxSetting *d); + void setSwitch(BoxSetting *d); private: - boxSetting *sw; + BoxSetting *sw; QComboBox *cb_count; QCheckBox *chb_manual; QLabel *lb_statics; Modified: trunk/src/dialogs/tableswitch.cpp =================================================================== --- trunk/src/dialogs/tableswitch.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/tableswitch.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -21,7 +21,7 @@ #include "switchdevice.h" #include "switchmodel.h" -TableSwitch::TableSwitch(switchTableSetting *s) +TableSwitch::TableSwitch(SwitchTableSetting *s) { sw = s; t_sw = s->switchTable(); Modified: trunk/src/dialogs/tableswitch.h =================================================================== --- trunk/src/dialogs/tableswitch.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/tableswitch.h 2011-02-09 01:09:50 UTC (rev 234) @@ -22,16 +22,16 @@ #include "ui_tableswitch.h" -class switchTableSetting; +class SwitchTableSetting; class SwitchModel; class TableSwitch : public QDialog , private Ui::tableSwitch { Q_OBJECT public: - explicit TableSwitch(switchTableSetting *s); + explicit TableSwitch(SwitchTableSetting *s); private: - switchTableSetting *sw; + SwitchTableSetting *sw; SwitchModel *t_sw; private slots: void addRecord(); Modified: trunk/src/dialogs/testdialog.cpp =================================================================== --- trunk/src/dialogs/testdialog.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/testdialog.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -71,7 +71,7 @@ void testDialog::updateList() { listWidget->clear(); - QDir t(appSetting::scriptPath()); + QDir t(AppSetting::scriptPath()); QStringList h; h << "*.js"; QStringList s = t.entryList(h); @@ -114,7 +114,7 @@ bool testDialog::test(QString s) { qDebug() << s << " started"; - QString g = appSetting::scriptPath()+s+".js"; + QString g = AppSetting::scriptPath()+s+".js"; QFile file(g); file.open(QIODevice::ReadOnly); QString temporary = file.readAll(); @@ -144,10 +144,10 @@ void testDialog::setScriptPath() { QString name = QFileDialog::getExistingDirectory( this, - tr("Choose a directory with scripts"), appSetting::scriptPath() ); + tr("Choose a directory with scripts"), AppSetting::scriptPath() ); if ( name.isEmpty() ) return; if ( name.at( name.length() - 1 ) != '/' ) name.push_back('/'); - appSetting::setScriptPath(name); + AppSetting::setScriptPath(name); updateList(); } Modified: trunk/src/dialogs/virtualnetworkdialog.cpp =================================================================== --- trunk/src/dialogs/virtualnetworkdialog.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/virtualnetworkdialog.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -6,7 +6,7 @@ setAttribute(Qt::WA_DeleteOnClose); } -void virtualNetworkDialog::setDevice( virtualNetworkSetting *device) +void virtualNetworkDialog::setDevice( VirtualNetworkSetting *device) { myDevice = device; } Modified: trunk/src/dialogs/virtualnetworkdialog.h =================================================================== --- trunk/src/dialogs/virtualnetworkdialog.h 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/dialogs/virtualnetworkdialog.h 2011-02-09 01:09:50 UTC (rev 234) @@ -3,17 +3,17 @@ #include "ui_virtualnetworkdialog.h" -class virtualNetworkSetting; +class VirtualNetworkSetting; class virtualNetworkDialog : public QDialog, private Ui::virtualNetworkDialog { Q_OBJECT public: virtualNetworkDialog(QWidget *parent = 0); - void setDevice( virtualNetworkSetting *device); + void setDevice( VirtualNetworkSetting *device); protected: void changeEvent(QEvent *e); private: - virtualNetworkSetting *myDevice; + VirtualNetworkSetting *myDevice; }; #endif // VIRTUALNETWORKDIALOG_H Modified: trunk/src/graphics/cabledev.cpp =================================================================== --- trunk/src/graphics/cabledev.cpp 2011-02-08 23:18:03 UTC (rev 233) +++ trunk/src/graphics/cabledev.cpp 2011-02-09 01:09:50 UTC (rev 234) @@ -20,13 +20,15 @@ #include "cabledev.h" #include "deviceport.h" -Cable::Cable(QGraphicsObject *parent) : QGraphicsObject(parent) , myStartPort(0) , - myEndPort(0) , - isCollision(false), myChecked(false) , - myShared(false) , mySpeed(5) +Cable::Cable(QGraphicsObject *parent) : QGraphicsObject(parent) , startItem(0), +endItem(0) , myStartPort(0) , +myEndPort(0) , +isCollision(false), myChecked(false) , +myShared(false) , mySpeed(5) {... [truncated message content] |
From: <f-r...@us...> - 2011-02-11 19:25:37
|
Revision: 239 http://netemul.svn.sourceforge.net/netemul/?rev=239&view=rev Author: f-r-o-s-t Date: 2011-02-11 19:25:30 +0000 (Fri, 11 Feb 2011) Log Message: ----------- rename program files Added Paths: ----------- trunk/src/dialogs/programdialog.cpp trunk/src/dialogs/programdialog.h trunk/src/forms/programdialog.ui Removed Paths: ------------- trunk/src/dialogs/programmdialog.cpp trunk/src/dialogs/programmdialog.h trunk/src/forms/programmdialog.ui Copied: trunk/src/dialogs/programdialog.cpp (from rev 238, trunk/src/dialogs/programmdialog.cpp) =================================================================== --- trunk/src/dialogs/programdialog.cpp (rev 0) +++ trunk/src/dialogs/programdialog.cpp 2011-02-11 19:25:30 UTC (rev 239) @@ -0,0 +1,119 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#include "programmdialog.h" +#include "smartdevice.h" +#include "installdialog.h" +#include <QCheckBox> + +programmDialog::programmDialog(QWidget *parent) : QDialog(parent) +{ + setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); +} + +/*! + Обновляет список программ. +*/ +void programmDialog::updateList() +{ + list->clear(); + foreach ( Program *i, s->programs() ){ + QListWidgetItem *item = new QListWidgetItem(i->name()); + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable); + item->setData( Qt::UserRole , i->id() ); + if ( i->isEnable() ) item->setCheckState(Qt::Checked); + else item->setCheckState(Qt::Unchecked); + list->addItem(item); + } +} +//------------------------------------------------- +void programmDialog::programmChanged() +{ + btn_remove->setEnabled( list->currentItem() ); + btn_settings->setEnabled( list->currentItem() ); +} + +void programmDialog::stateChanged(QListWidgetItem *item) +{ + if ( !item ) return; + Program *p = s->programAt( item->data( Qt::UserRole).toInt() ); + p->setEnable( item->checkState() == Qt::Checked ); + p->updateView(); +} + +void programmDialog::setDevice( SmartDevice *d ) +{ + s = d; + updateList(); +} +/*! + Слот, вызываемый при нажатии на кнопку Ok, + выполняет все принятые изменения, закрывает диалог. +*/ +void programmDialog::apply() +{ + for ( int i = 0; i < list->count(); i++) { + QListWidgetItem *n = list->item(i); + if (n->checkState() == Qt::Checked ) s->programAt( n->data(Qt::UserRole).toInt() )->setEnable(true); + else s->programAt( n->data(Qt::UserRole).toInt() )->setEnable(false); + } + accept(); +} +//---------------------------------------------------- +/*! + Слот вызывает диалог установки программ, + обновляет список установленных программ. +*/ +void programmDialog::add() +{ + installDialog *d = new installDialog; + d->setDevice( s ); + d->exec(); + btn_ok->setFocus(); + updateList(); +} +//----------------------------------------------------- +/*! + Слот удаляет выделенную программу. +*/ +void programmDialog::remove() +{ + QListWidgetItem *w = list->currentItem(); + s->removeProgram( s->programAt(w->data(Qt::UserRole).toInt() ) ); + updateList(); +} + +void programmDialog::settings() +{ + s->programAt( list->currentItem()->data(Qt::UserRole).toInt() )->showProperty(); +} + +//----------------------------------------------------- +void programmDialog::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + retranslateUi(this); + break; + default: + break; + } +} Copied: trunk/src/dialogs/programdialog.h (from rev 238, trunk/src/dialogs/programmdialog.h) =================================================================== --- trunk/src/dialogs/programdialog.h (rev 0) +++ trunk/src/dialogs/programdialog.h 2011-02-11 19:25:30 UTC (rev 239) @@ -0,0 +1,51 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#ifndef PROGRAMMDIALOG_H +#define PROGRAMMDIALOG_H + +#include "ui_programmdialog.h" + +class SmartDevice; + +/*! + Реализует диалог установленных пограмм устройства. +*/ +class programmDialog : public QDialog, private Ui::programmDialog { + Q_OBJECT + Q_DISABLE_COPY(programmDialog) +public: + programmDialog(QWidget *parent = 0); + void setDevice( SmartDevice *d ); +protected: + void updateList(); + void changeEvent(QEvent *e); +private: + SmartDevice *s; //!< Указатель на устройство. +public slots: + void apply(); +private slots: + void stateChanged(QListWidgetItem *item); + void programmChanged(); + void settings(); + void add(); + void remove(); +}; + +#endif // PROGRAMMDIALOG_H Deleted: trunk/src/dialogs/programmdialog.cpp =================================================================== --- trunk/src/dialogs/programmdialog.cpp 2011-02-11 18:54:11 UTC (rev 238) +++ trunk/src/dialogs/programmdialog.cpp 2011-02-11 19:25:30 UTC (rev 239) @@ -1,119 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#include "programmdialog.h" -#include "smartdevice.h" -#include "installdialog.h" -#include <QCheckBox> - -programmDialog::programmDialog(QWidget *parent) : QDialog(parent) -{ - setupUi(this); - setAttribute(Qt::WA_DeleteOnClose); -} - -/*! - Обновляет список программ. -*/ -void programmDialog::updateList() -{ - list->clear(); - foreach ( Program *i, s->programs() ){ - QListWidgetItem *item = new QListWidgetItem(i->name()); - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable); - item->setData( Qt::UserRole , i->id() ); - if ( i->isEnable() ) item->setCheckState(Qt::Checked); - else item->setCheckState(Qt::Unchecked); - list->addItem(item); - } -} -//------------------------------------------------- -void programmDialog::programmChanged() -{ - btn_remove->setEnabled( list->currentItem() ); - btn_settings->setEnabled( list->currentItem() ); -} - -void programmDialog::stateChanged(QListWidgetItem *item) -{ - if ( !item ) return; - Program *p = s->programAt( item->data( Qt::UserRole).toInt() ); - p->setEnable( item->checkState() == Qt::Checked ); - p->updateView(); -} - -void programmDialog::setDevice( SmartDevice *d ) -{ - s = d; - updateList(); -} -/*! - Слот, вызываемый при нажатии на кнопку Ok, - выполняет все принятые изменения, закрывает диалог. -*/ -void programmDialog::apply() -{ - for ( int i = 0; i < list->count(); i++) { - QListWidgetItem *n = list->item(i); - if (n->checkState() == Qt::Checked ) s->programAt( n->data(Qt::UserRole).toInt() )->setEnable(true); - else s->programAt( n->data(Qt::UserRole).toInt() )->setEnable(false); - } - accept(); -} -//---------------------------------------------------- -/*! - Слот вызывает диалог установки программ, - обновляет список установленных программ. -*/ -void programmDialog::add() -{ - installDialog *d = new installDialog; - d->setDevice( s ); - d->exec(); - btn_ok->setFocus(); - updateList(); -} -//----------------------------------------------------- -/*! - Слот удаляет выделенную программу. -*/ -void programmDialog::remove() -{ - QListWidgetItem *w = list->currentItem(); - s->removeProgram( s->programAt(w->data(Qt::UserRole).toInt() ) ); - updateList(); -} - -void programmDialog::settings() -{ - s->programAt( list->currentItem()->data(Qt::UserRole).toInt() )->showProperty(); -} - -//----------------------------------------------------- -void programmDialog::changeEvent(QEvent *e) -{ - QDialog::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - retranslateUi(this); - break; - default: - break; - } -} Deleted: trunk/src/dialogs/programmdialog.h =================================================================== --- trunk/src/dialogs/programmdialog.h 2011-02-11 18:54:11 UTC (rev 238) +++ trunk/src/dialogs/programmdialog.h 2011-02-11 19:25:30 UTC (rev 239) @@ -1,51 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#ifndef PROGRAMMDIALOG_H -#define PROGRAMMDIALOG_H - -#include "ui_programmdialog.h" - -class SmartDevice; - -/*! - Реализует диалог установленных пограмм устройства. -*/ -class programmDialog : public QDialog, private Ui::programmDialog { - Q_OBJECT - Q_DISABLE_COPY(programmDialog) -public: - programmDialog(QWidget *parent = 0); - void setDevice( SmartDevice *d ); -protected: - void updateList(); - void changeEvent(QEvent *e); -private: - SmartDevice *s; //!< Указатель на устройство. -public slots: - void apply(); -private slots: - void stateChanged(QListWidgetItem *item); - void programmChanged(); - void settings(); - void add(); - void remove(); -}; - -#endif // PROGRAMMDIALOG_H Copied: trunk/src/forms/programdialog.ui (from rev 238, trunk/src/forms/programmdialog.ui) =================================================================== --- trunk/src/forms/programdialog.ui (rev 0) +++ trunk/src/forms/programdialog.ui 2011-02-11 19:25:30 UTC (rev 239) @@ -0,0 +1,260 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>programmDialog</class> + <widget class="QDialog" name="programmDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>250</height> + </rect> + </property> + <property name="minimumSize"> + <size> + <width>400</width> + <height>250</height> + </size> + </property> + <property name="windowTitle"> + <string>Programs</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QLabel" name="lb_prog"> + <property name="text"> + <string>Installed programs</string> + </property> + </widget> + </item> + <item> + <widget class="QListWidget" name="list"/> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <spacer name="verticalSpacer_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="btn_add"> + <property name="text"> + <string>Add</string> + </property> + <property name="icon"> + <iconset> + <normaloff>:/im/images/edit_add.png</normaloff>:/im/images/edit_add.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btn_settings"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Settings</string> + </property> + <property name="icon"> + <iconset> + <normaloff>:/im/images/setting.png</normaloff>:/im/images/setting.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btn_remove"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Delete</string> + </property> + <property name="icon"> + <iconset> + <normaloff>:/im/images/edit_remove.png</normaloff>:/im/images/edit_remove.png</iconset> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="btn_ok"> + <property name="text"> + <string>Ok</string> + </property> + <property name="icon"> + <iconset> + <normaloff>:/im/images/ok.png</normaloff>:/im/images/ok.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btn_cancel"> + <property name="text"> + <string>Cancel</string> + </property> + <property name="icon"> + <iconset> + <normaloff>:/im/images/not.png</normaloff>:/im/images/not.png</iconset> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>btn_cancel</sender> + <signal>clicked()</signal> + <receiver>programmDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>393</x> + <y>243</y> + </hint> + <hint type="destinationlabel"> + <x>188</x> + <y>245</y> + </hint> + </hints> + </connection> + <connection> + <sender>btn_ok</sender> + <signal>clicked()</signal> + <receiver>programmDialog</receiver> + <slot>apply()</slot> + <hints> + <hint type="sourcelabel"> + <x>393</x> + <y>214</y> + </hint> + <hint type="destinationlabel"> + <x>180</x> + <y>277</y> + </hint> + </hints> + </connection> + <connection> + <sender>btn_add</sender> + <signal>clicked()</signal> + <receiver>programmDialog</receiver> + <slot>add()</slot> + <hints> + <hint type="sourcelabel"> + <x>343</x> + <y>63</y> + </hint> + <hint type="destinationlabel"> + <x>313</x> + <y>18</y> + </hint> + </hints> + </connection> + <connection> + <sender>btn_remove</sender> + <signal>clicked()</signal> + <receiver>programmDialog</receiver> + <slot>remove()</slot> + <hints> + <hint type="sourcelabel"> + <x>393</x> + <y>132</y> + </hint> + <hint type="destinationlabel"> + <x>315</x> + <y>135</y> + </hint> + </hints> + </connection> + <connection> + <sender>btn_settings</sender> + <signal>clicked()</signal> + <receiver>programmDialog</receiver> + <slot>settings()</slot> + <hints> + <hint type="sourcelabel"> + <x>360</x> + <y>89</y> + </hint> + <hint type="destinationlabel"> + <x>386</x> + <y>23</y> + </hint> + </hints> + </connection> + <connection> + <sender>list</sender> + <signal>currentRowChanged(int)</signal> + <receiver>programmDialog</receiver> + <slot>programmChanged()</slot> + <hints> + <hint type="sourcelabel"> + <x>140</x> + <y>120</y> + </hint> + <hint type="destinationlabel"> + <x>351</x> + <y>13</y> + </hint> + </hints> + </connection> + <connection> + <sender>list</sender> + <signal>itemClicked(QListWidgetItem*)</signal> + <receiver>programmDialog</receiver> + <slot>stateChanged(QListWidgetItem*)</slot> + <hints> + <hint type="sourcelabel"> + <x>232</x> + <y>109</y> + </hint> + <hint type="destinationlabel"> + <x>335</x> + <y>30</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>apply()</slot> + <slot>add()</slot> + <slot>remove()</slot> + <slot>settings()</slot> + <slot>programmChanged()</slot> + <slot>stateChanged(QListWidgetItem*)</slot> + </slots> +</ui> Deleted: trunk/src/forms/programmdialog.ui =================================================================== --- trunk/src/forms/programmdialog.ui 2011-02-11 18:54:11 UTC (rev 238) +++ trunk/src/forms/programmdialog.ui 2011-02-11 19:25:30 UTC (rev 239) @@ -1,260 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>programmDialog</class> - <widget class="QDialog" name="programmDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>250</height> - </rect> - </property> - <property name="minimumSize"> - <size> - <width>400</width> - <height>250</height> - </size> - </property> - <property name="windowTitle"> - <string>Programs</string> - </property> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <widget class="QLabel" name="lb_prog"> - <property name="text"> - <string>Installed programs</string> - </property> - </widget> - </item> - <item> - <widget class="QListWidget" name="list"/> - </item> - </layout> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <spacer name="verticalSpacer_3"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="btn_add"> - <property name="text"> - <string>Add</string> - </property> - <property name="icon"> - <iconset> - <normaloff>:/im/images/edit_add.png</normaloff>:/im/images/edit_add.png</iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="btn_settings"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Settings</string> - </property> - <property name="icon"> - <iconset> - <normaloff>:/im/images/setting.png</normaloff>:/im/images/setting.png</iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="btn_remove"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Delete</string> - </property> - <property name="icon"> - <iconset> - <normaloff>:/im/images/edit_remove.png</normaloff>:/im/images/edit_remove.png</iconset> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="btn_ok"> - <property name="text"> - <string>Ok</string> - </property> - <property name="icon"> - <iconset> - <normaloff>:/im/images/ok.png</normaloff>:/im/images/ok.png</iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="btn_cancel"> - <property name="text"> - <string>Cancel</string> - </property> - <property name="icon"> - <iconset> - <normaloff>:/im/images/not.png</normaloff>:/im/images/not.png</iconset> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>btn_cancel</sender> - <signal>clicked()</signal> - <receiver>programmDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>393</x> - <y>243</y> - </hint> - <hint type="destinationlabel"> - <x>188</x> - <y>245</y> - </hint> - </hints> - </connection> - <connection> - <sender>btn_ok</sender> - <signal>clicked()</signal> - <receiver>programmDialog</receiver> - <slot>apply()</slot> - <hints> - <hint type="sourcelabel"> - <x>393</x> - <y>214</y> - </hint> - <hint type="destinationlabel"> - <x>180</x> - <y>277</y> - </hint> - </hints> - </connection> - <connection> - <sender>btn_add</sender> - <signal>clicked()</signal> - <receiver>programmDialog</receiver> - <slot>add()</slot> - <hints> - <hint type="sourcelabel"> - <x>343</x> - <y>63</y> - </hint> - <hint type="destinationlabel"> - <x>313</x> - <y>18</y> - </hint> - </hints> - </connection> - <connection> - <sender>btn_remove</sender> - <signal>clicked()</signal> - <receiver>programmDialog</receiver> - <slot>remove()</slot> - <hints> - <hint type="sourcelabel"> - <x>393</x> - <y>132</y> - </hint> - <hint type="destinationlabel"> - <x>315</x> - <y>135</y> - </hint> - </hints> - </connection> - <connection> - <sender>btn_settings</sender> - <signal>clicked()</signal> - <receiver>programmDialog</receiver> - <slot>settings()</slot> - <hints> - <hint type="sourcelabel"> - <x>360</x> - <y>89</y> - </hint> - <hint type="destinationlabel"> - <x>386</x> - <y>23</y> - </hint> - </hints> - </connection> - <connection> - <sender>list</sender> - <signal>currentRowChanged(int)</signal> - <receiver>programmDialog</receiver> - <slot>programmChanged()</slot> - <hints> - <hint type="sourcelabel"> - <x>140</x> - <y>120</y> - </hint> - <hint type="destinationlabel"> - <x>351</x> - <y>13</y> - </hint> - </hints> - </connection> - <connection> - <sender>list</sender> - <signal>itemClicked(QListWidgetItem*)</signal> - <receiver>programmDialog</receiver> - <slot>stateChanged(QListWidgetItem*)</slot> - <hints> - <hint type="sourcelabel"> - <x>232</x> - <y>109</y> - </hint> - <hint type="destinationlabel"> - <x>335</x> - <y>30</y> - </hint> - </hints> - </connection> - </connections> - <slots> - <slot>apply()</slot> - <slot>add()</slot> - <slot>remove()</slot> - <slot>settings()</slot> - <slot>programmChanged()</slot> - <slot>stateChanged(QListWidgetItem*)</slot> - </slots> -</ui> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <f-r...@us...> - 2011-02-11 21:27:28
|
Revision: 240 http://netemul.svn.sourceforge.net/netemul/?rev=240&view=rev Author: f-r-o-s-t Date: 2011-02-11 21:27:21 +0000 (Fri, 11 Feb 2011) Log Message: ----------- Henceforth DHCP works on all configured ports! Cheers!!! Modified Paths: -------------- trunk/src/dialogs/dhcpserverproperty.cpp trunk/src/dialogs/dhcpserverproperty.h trunk/src/factories/classfactory.cpp trunk/src/forms/dhcpserverproperty.ui trunk/src/models/arpmodel.h trunk/src/models/dhcpservermodel.cpp trunk/src/models/dhcpservermodel.h Modified: trunk/src/dialogs/dhcpserverproperty.cpp =================================================================== --- trunk/src/dialogs/dhcpserverproperty.cpp 2011-02-11 19:25:30 UTC (rev 239) +++ trunk/src/dialogs/dhcpserverproperty.cpp 2011-02-11 21:27:21 UTC (rev 240) @@ -18,6 +18,8 @@ ** 02111-1307 USA. ****************************************************************************************/ #include <QMessageBox> +//#include <QApplication> +//#include <QStyle> #include "dhcpserverproperty.h" #include "dhcpservermodel.h" #include "smartdevice.h" @@ -31,6 +33,7 @@ mySetting = setting; SmartDevice *dev = mySetting->program()->device(); setAttribute(Qt::WA_DeleteOnClose); + btn_apply->setIcon(QIcon(qApp->style()->standardIcon( QStyle::SP_DialogApplyButton))); port_tb = new QTabBar; tab_lay->addWidget(port_tb); foreach ( Interface *i, dev->interfaces() ) { @@ -139,8 +142,14 @@ myDaemon->setMask(ie_mask->ipAddress()); myDaemon->setTime(sb_time->value()); myDaemon->setWaitingTime(sb_waitingTime->value()); +} + +void DhcpServerProperty::onOkButtonClicked() +{ + apply(); accept(); } + //----------------------------------------- void DhcpServerProperty::changeEvent(QEvent *e) Modified: trunk/src/dialogs/dhcpserverproperty.h =================================================================== --- trunk/src/dialogs/dhcpserverproperty.h 2011-02-11 19:25:30 UTC (rev 239) +++ trunk/src/dialogs/dhcpserverproperty.h 2011-02-11 21:27:21 UTC (rev 240) @@ -46,6 +46,7 @@ void deleteRecord(); void changeState(bool); void apply(); + void onOkButtonClicked(); private: // Functions void clearForm(); Modified: trunk/src/factories/classfactory.cpp =================================================================== --- trunk/src/factories/classfactory.cpp 2011-02-11 19:25:30 UTC (rev 239) +++ trunk/src/factories/classfactory.cpp 2011-02-11 21:27:21 UTC (rev 240) @@ -13,6 +13,7 @@ #include "dhcpdaemon.h" #include "dhcpclientprogram.h" #include "dhcpserverprogram.h" +#include "dhcpservermodel.h" #include "spoofingprogram.h" #include "statistics.h" #include "textitem.h" @@ -69,6 +70,10 @@ return new ArpRecordObject(parent); } else if ( str == "DhcpDaemon" ) { return new DhcpDaemon(parent); + } else if ( str == "DhcpServerModel" ) { + return new DhcpServerModel(parent); + } else if ( str == "StaticDhcpRecordObject" ) { + return new StaticDhcpRecordObject(parent); } else { return 0; } Modified: trunk/src/forms/dhcpserverproperty.ui =================================================================== --- trunk/src/forms/dhcpserverproperty.ui 2011-02-11 19:25:30 UTC (rev 239) +++ trunk/src/forms/dhcpserverproperty.ui 2011-02-11 21:27:21 UTC (rev 240) @@ -285,6 +285,13 @@ </spacer> </item> <item> + <widget class="QPushButton" name="btn_apply"> + <property name="text"> + <string>Apply</string> + </property> + </widget> + </item> + <item> <widget class="QPushButton" name="btn_ok"> <property name="text"> <string>Ok</string> @@ -386,34 +393,50 @@ </hints> </connection> <connection> + <sender>cb_turnOn</sender> + <signal>toggled(bool)</signal> + <receiver>dhspServerProperty</receiver> + <slot>onTurnedOnOff(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>153</x> + <y>32</y> + </hint> + <hint type="destinationlabel"> + <x>248</x> + <y>3</y> + </hint> + </hints> + </connection> + <connection> <sender>btn_ok</sender> <signal>clicked()</signal> <receiver>dhspServerProperty</receiver> - <slot>apply()</slot> + <slot>onOkButtonClicked()</slot> <hints> <hint type="sourcelabel"> - <x>693</x> - <y>451</y> + <x>644</x> + <y>436</y> </hint> <hint type="destinationlabel"> - <x>540</x> - <y>364</y> + <x>448</x> + <y>440</y> </hint> </hints> </connection> <connection> - <sender>cb_turnOn</sender> - <signal>toggled(bool)</signal> + <sender>btn_apply</sender> + <signal>clicked()</signal> <receiver>dhspServerProperty</receiver> - <slot>onTurnedOnOff(bool)</slot> + <slot>apply()</slot> <hints> <hint type="sourcelabel"> - <x>144</x> - <y>15</y> + <x>564</x> + <y>448</y> </hint> <hint type="destinationlabel"> - <x>248</x> - <y>3</y> + <x>524</x> + <y>446</y> </hint> </hints> </connection> @@ -424,5 +447,6 @@ <slot>changeState(bool)</slot> <slot>apply()</slot> <slot>onTurnedOnOff(bool)</slot> + <slot>onOkButtonClicked()</slot> </slots> </ui> Modified: trunk/src/models/arpmodel.h =================================================================== --- trunk/src/models/arpmodel.h 2011-02-11 19:25:30 UTC (rev 239) +++ trunk/src/models/arpmodel.h 2011-02-11 21:27:21 UTC (rev 240) @@ -69,7 +69,8 @@ } }; -class ArpRecordObject : public QObject { +class ArpRecordObject : public QObject +{ Q_OBJECT Q_PROPERTY( QString mac READ mac WRITE setMac ) Q_PROPERTY( QString ip READ ip WRITE setIp ) Modified: trunk/src/models/dhcpservermodel.cpp =================================================================== --- trunk/src/models/dhcpservermodel.cpp 2011-02-11 19:25:30 UTC (rev 239) +++ trunk/src/models/dhcpservermodel.cpp 2011-02-11 21:27:21 UTC (rev 240) @@ -19,16 +19,18 @@ ****************************************************************************************/ #include "dhcpservermodel.h" +DhcpServerModel::DhcpServerModel(QObject *parent /*= 0*/) : QAbstractTableModel(parent) {} + DhcpServerModel::~DhcpServerModel() { - qDeleteAll(table); - table.clear(); + qDeleteAll(myTable); + myTable.clear(); } int DhcpServerModel::rowCount( const QModelIndex &r/* = QModelIndex() */) const { - if ( r.isValid() || table.isEmpty() ) return 0; - return table.size(); + if ( r.isValid() || myTable.isEmpty() ) return 0; + return myTable.size(); } int DhcpServerModel::columnCount( const QModelIndex &r/* = QModelIndex() */) const @@ -60,8 +62,8 @@ QVariant DhcpServerModel::data(const QModelIndex &r, int role/* = Qt::DisplayRole */) const { - if ( !r.isValid() || table.isEmpty() ) return QVariant(); - StaticDhcpRecord *rec = table.at( r.row() ); + if ( !r.isValid() || myTable.isEmpty() ) return QVariant(); + StaticDhcpRecord *rec = myTable.at( r.row() ); if ( role == Qt::DisplayRole || role == Qt::EditRole ) switch( r.column() ) { case 0: return rec->chaddr.toString(); @@ -76,7 +78,7 @@ bool DhcpServerModel::setData(const QModelIndex &index, const QVariant &value, int role/* = Qt::EditRole*/) { if ( index.isValid() && role == Qt::EditRole ) { - StaticDhcpRecord *rec = table.at(index.row()); + StaticDhcpRecord *rec = myTable.at(index.row()); if ( value.toString().isEmpty() ) return false; switch ( index.column() ) { case 0: rec->chaddr.setMac(value.toString()); break; @@ -85,7 +87,7 @@ case 3: rec->gateway.setIp(value.toString()); break; case 4: rec->time = value.toInt(); break; } - table.replace( index.row(), rec); + myTable.replace( index.row(), rec); emit dataChanged(index, index); return true; } @@ -97,7 +99,7 @@ Q_UNUSED(parent); StaticDhcpRecord *newRecord = new StaticDhcpRecord; newRecord->time = 0; - table << newRecord; + myTable << newRecord; reset(); return true; } @@ -105,7 +107,7 @@ bool DhcpServerModel::removeRow(int row, const QModelIndex &parent) { Q_UNUSED(parent); - StaticDhcpRecord *record = table.takeAt(row); + StaticDhcpRecord *record = myTable.takeAt(row); if ( record ) delete record; reset(); return true; @@ -113,37 +115,55 @@ bool DhcpServerModel::containRecord(StaticDhcpRecord *rec) const { - if ( table.isEmpty() ) return false; - foreach ( StaticDhcpRecord *i, table ) + if ( myTable.isEmpty() ) return false; + foreach ( StaticDhcpRecord *i, myTable ) if ( i == rec ) return true; return false; } bool DhcpServerModel::containRecord(IpAddress ip) const { - if ( table.isEmpty() ) return false; - foreach ( StaticDhcpRecord *i, table ) + if ( myTable.isEmpty() ) return false; + foreach ( StaticDhcpRecord *i, myTable ) if ( i->yiaddr == ip ) return true; return false; } StaticDhcpRecord* DhcpServerModel::recordWithMac(MacAddress cha) const { - if ( table.isEmpty() ) return 0; - foreach ( StaticDhcpRecord *i, table ) + if ( myTable.isEmpty() ) return 0; + foreach ( StaticDhcpRecord *i, myTable ) if ( i->chaddr == cha ) return i; return 0; } void DhcpServerModel::addStaticRecord(StaticDhcpRecord *rec) { - table << rec; + myTable << rec; } +QVariantList DhcpServerModel::staticDhcpRecordObjectsList() const +{ + QVariantList list; + foreach ( StaticDhcpRecord *i , myTable ) { + QObject *o = new StaticDhcpRecordObject(i); + list << qVariantFromValue(o); + } + return list; +} + +void DhcpServerModel::addStaticDhcpRecordObject(StaticDhcpRecordObject *r) +{ + addStaticRecord( r->record() ); + r->deleteLater(); +} + +//----------------------------------------------------------------------------- + void DhcpServerModel::write(QDataStream &stream) const { - stream << table.size(); - foreach ( StaticDhcpRecord *i, table ) + stream << myTable.size(); + foreach ( StaticDhcpRecord *i, myTable ) i->write(stream); } @@ -157,7 +177,6 @@ addStaticRecord(rec); } } - //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -170,4 +189,5 @@ { stream >> chaddr >> yiaddr >> mask >> gateway >> time; } - +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ Modified: trunk/src/models/dhcpservermodel.h =================================================================== --- trunk/src/models/dhcpservermodel.h 2011-02-11 19:25:30 UTC (rev 239) +++ trunk/src/models/dhcpservermodel.h 2011-02-11 21:27:21 UTC (rev 240) @@ -24,6 +24,8 @@ #include "macaddress.h" #include "ipaddress.h" +class StaticDhcpRecordObject; + struct StaticDhcpRecord { MacAddress chaddr; IpAddress yiaddr; @@ -38,8 +40,10 @@ class DhcpServerModel : public QAbstractTableModel { + Q_OBJECT + Q_PROPERTY( QVariantList staticDhcpRecordObject READ staticDhcpRecordObjectsList ) public: - DhcpServerModel(QObject *parent = 0) : QAbstractTableModel(parent) { } + DhcpServerModel(QObject *parent = 0); ~DhcpServerModel(); int rowCount( const QModelIndex &r = QModelIndex() ) const; int columnCount( const QModelIndex &r = QModelIndex() ) const; @@ -50,14 +54,52 @@ bool removeRow(int row, const QModelIndex &parent = QModelIndex() ); bool setData(const QModelIndex &index,const QVariant &value, int role = Qt::EditRole); + Q_INVOKABLE void addStaticDhcpRecordObject(StaticDhcpRecordObject *r); + QVariantList staticDhcpRecordObjectsList() const; + bool containRecord( StaticDhcpRecord *rec) const; bool containRecord(IpAddress ip) const; StaticDhcpRecord* recordWithMac(MacAddress cha) const; void addStaticRecord(StaticDhcpRecord *rec); + void write(QDataStream &stream) const; void read(QDataStream &stream); private: - QList<StaticDhcpRecord*> table; + QList<StaticDhcpRecord*> myTable; }; +class StaticDhcpRecordObject : public QObject +{ + Q_OBJECT + Q_PROPERTY( QString chaddr READ chaddr WRITE setChaddr ) + Q_PROPERTY( QString yiaddr READ yiaddr WRITE setYiaddr ) + Q_PROPERTY( QString mask READ mask WRITE setMask ) + Q_PROPERTY( QString gateway READ gateway WRITE setGateway ) + Q_PROPERTY( int time READ time WRITE setTime ) +public: + StaticDhcpRecordObject(StaticDhcpRecord *record) { + myRecord = record; + } + + StaticDhcpRecordObject(QObject *parent = 0) : QObject(parent) { + myRecord = new StaticDhcpRecord(); + } + + StaticDhcpRecord* record() const { return myRecord; } + + void setChaddr(const QString &str) { myRecord->chaddr.setMac(str); } + void setYiaddr(const QString &str) { myRecord->yiaddr.setIp(str); } + void setMask(const QString &str) { myRecord->mask.setIp(str); } + void setGateway(const QString &str) { myRecord->gateway.setIp(str); } + void setTime(int t) { myRecord->time = t; } + QString chaddr() const { return myRecord->chaddr.toString(); } + QString yiaddr() const { return myRecord->yiaddr.toString(); } + QString mask() const { return myRecord->mask.toString(); } + QString gateway() const { return myRecord->gateway.toString(); } + int time() const { return myRecord->time; } +private: + StaticDhcpRecord *myRecord; + +}; + #endif // DHCPSERVERMODEL_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <f-r...@us...> - 2011-02-12 21:06:44
|
Revision: 244 http://netemul.svn.sourceforge.net/netemul/?rev=244&view=rev Author: f-r-o-s-t Date: 2011-02-12 21:06:36 +0000 (Sat, 12 Feb 2011) Log Message: ----------- All troubles of last revision are resolved, dhcp program works Modified Paths: -------------- trunk/src/deviceport.cpp trunk/src/dialogs/dhcpserverproperty.cpp trunk/src/dialogs/programdialog.cpp trunk/src/dialogs/programdialog.h trunk/src/forms/programdialog.ui trunk/src/programs/dhcpserverprogram.cpp trunk/src/programs/dhcpserverprogram.h trunk/src/programs/programs.pri Added Paths: ----------- trunk/src/programs/dhcpdaemon.cpp trunk/src/programs/dhcpdaemon.h Removed Paths: ------------- trunk/src/programs/dhcpdemon.cpp trunk/src/programs/dhcpdemon.h Modified: trunk/src/deviceport.cpp =================================================================== --- trunk/src/deviceport.cpp 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/deviceport.cpp 2011-02-12 21:06:36 UTC (rev 244) @@ -21,7 +21,7 @@ #include "cabledev.h" #include "frame.h" -DevicePort::DevicePort(QObject *parent) +DevicePort::DevicePort(QObject *parent) :QObject(parent) { myShared = false; myCable = 0; Modified: trunk/src/dialogs/dhcpserverproperty.cpp =================================================================== --- trunk/src/dialogs/dhcpserverproperty.cpp 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/dialogs/dhcpserverproperty.cpp 2011-02-12 21:06:36 UTC (rev 244) @@ -135,11 +135,11 @@ return; } myDaemon->setTurnOn(cb_turnOn->isChecked()); - myDaemon->setBeginIp(ie_begin->ipAddress()); - myDaemon->setEndIp(ie_end->ipAddress()); + myDaemon->setBeginIp(ie_begin->ipText()); + myDaemon->setEndIp(ie_end->ipText()); myDaemon->setDynamic(cb_dynamic->isChecked()); - myDaemon->setGateway(ie_gatew->ipAddress()); - myDaemon->setMask(ie_mask->ipAddress()); + myDaemon->setGateway(ie_gatew->ipText()); + myDaemon->setMask(ie_mask->ipText()); myDaemon->setTime(sb_time->value()); myDaemon->setWaitingTime(sb_waitingTime->value()); } Modified: trunk/src/dialogs/programdialog.cpp =================================================================== --- trunk/src/dialogs/programdialog.cpp 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/dialogs/programdialog.cpp 2011-02-12 21:06:36 UTC (rev 244) @@ -17,12 +17,12 @@ ** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA ** 02111-1307 USA. ****************************************************************************************/ -#include "programmdialog.h" +#include "programdialog.h" #include "smartdevice.h" #include "installdialog.h" #include <QCheckBox> -programmDialog::programmDialog(QWidget *parent) : QDialog(parent) +ProgramDialog::ProgramDialog(QWidget *parent) : QDialog(parent) { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); @@ -31,7 +31,7 @@ /*! Обновляет список программ. */ -void programmDialog::updateList() +void ProgramDialog::updateList() { list->clear(); foreach ( Program *i, s->programs() ){ @@ -44,13 +44,13 @@ } } //------------------------------------------------- -void programmDialog::programmChanged() +void ProgramDialog::programmChanged() { btn_remove->setEnabled( list->currentItem() ); btn_settings->setEnabled( list->currentItem() ); } -void programmDialog::stateChanged(QListWidgetItem *item) +void ProgramDialog::stateChanged(QListWidgetItem *item) { if ( !item ) return; Program *p = s->programAt( item->data( Qt::UserRole).toInt() ); @@ -58,7 +58,7 @@ p->updateView(); } -void programmDialog::setDevice( SmartDevice *d ) +void ProgramDialog::setDevice( SmartDevice *d ) { s = d; updateList(); @@ -67,7 +67,7 @@ Слот, вызываемый при нажатии на кнопку Ok, выполняет все принятые изменения, закрывает диалог. */ -void programmDialog::apply() +void ProgramDialog::apply() { for ( int i = 0; i < list->count(); i++) { QListWidgetItem *n = list->item(i); @@ -81,7 +81,7 @@ Слот вызывает диалог установки программ, обновляет список установленных программ. */ -void programmDialog::add() +void ProgramDialog::add() { installDialog *d = new installDialog; d->setDevice( s ); @@ -93,20 +93,20 @@ /*! Слот удаляет выделенную программу. */ -void programmDialog::remove() +void ProgramDialog::remove() { QListWidgetItem *w = list->currentItem(); s->removeProgram( s->programAt(w->data(Qt::UserRole).toInt() ) ); updateList(); } -void programmDialog::settings() +void ProgramDialog::settings() { s->programAt( list->currentItem()->data(Qt::UserRole).toInt() )->showProperty(); } //----------------------------------------------------- -void programmDialog::changeEvent(QEvent *e) +void ProgramDialog::changeEvent(QEvent *e) { QDialog::changeEvent(e); switch (e->type()) { Modified: trunk/src/dialogs/programdialog.h =================================================================== --- trunk/src/dialogs/programdialog.h 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/dialogs/programdialog.h 2011-02-12 21:06:36 UTC (rev 244) @@ -27,11 +27,12 @@ /*! Реализует диалог установленных пограмм устройства. */ -class programmDialog : public QDialog, private Ui::programmDialog { +class ProgramDialog : public QDialog, private Ui::ProgramDialog +{ Q_OBJECT - Q_DISABLE_COPY(programmDialog) + Q_DISABLE_COPY(ProgramDialog) public: - programmDialog(QWidget *parent = 0); + ProgramDialog(QWidget *parent = 0); void setDevice( SmartDevice *d ); protected: void updateList(); Modified: trunk/src/forms/programdialog.ui =================================================================== --- trunk/src/forms/programdialog.ui 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/forms/programdialog.ui 2011-02-12 21:06:36 UTC (rev 244) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>programmDialog</class> - <widget class="QDialog" name="programmDialog"> + <class>ProgramDialog</class> + <widget class="QDialog" name="ProgramDialog"> <property name="geometry"> <rect> <x>0</x> @@ -60,7 +60,7 @@ <string>Add</string> </property> <property name="icon"> - <iconset> + <iconset resource="../../netemul.qrc"> <normaloff>:/im/images/edit_add.png</normaloff>:/im/images/edit_add.png</iconset> </property> </widget> @@ -74,7 +74,7 @@ <string>Settings</string> </property> <property name="icon"> - <iconset> + <iconset resource="../../netemul.qrc"> <normaloff>:/im/images/setting.png</normaloff>:/im/images/setting.png</iconset> </property> </widget> @@ -88,7 +88,7 @@ <string>Delete</string> </property> <property name="icon"> - <iconset> + <iconset resource="../../netemul.qrc"> <normaloff>:/im/images/edit_remove.png</normaloff>:/im/images/edit_remove.png</iconset> </property> </widget> @@ -112,7 +112,7 @@ <string>Ok</string> </property> <property name="icon"> - <iconset> + <iconset resource="../../netemul.qrc"> <normaloff>:/im/images/ok.png</normaloff>:/im/images/ok.png</iconset> </property> </widget> @@ -123,7 +123,7 @@ <string>Cancel</string> </property> <property name="icon"> - <iconset> + <iconset resource="../../netemul.qrc"> <normaloff>:/im/images/not.png</normaloff>:/im/images/not.png</iconset> </property> </widget> @@ -134,12 +134,14 @@ </item> </layout> </widget> - <resources/> + <resources> + <include location="../../netemul.qrc"/> + </resources> <connections> <connection> <sender>btn_cancel</sender> <signal>clicked()</signal> - <receiver>programmDialog</receiver> + <receiver>ProgramDialog</receiver> <slot>reject()</slot> <hints> <hint type="sourcelabel"> @@ -155,7 +157,7 @@ <connection> <sender>btn_ok</sender> <signal>clicked()</signal> - <receiver>programmDialog</receiver> + <receiver>ProgramDialog</receiver> <slot>apply()</slot> <hints> <hint type="sourcelabel"> @@ -171,7 +173,7 @@ <connection> <sender>btn_add</sender> <signal>clicked()</signal> - <receiver>programmDialog</receiver> + <receiver>ProgramDialog</receiver> <slot>add()</slot> <hints> <hint type="sourcelabel"> @@ -187,7 +189,7 @@ <connection> <sender>btn_remove</sender> <signal>clicked()</signal> - <receiver>programmDialog</receiver> + <receiver>ProgramDialog</receiver> <slot>remove()</slot> <hints> <hint type="sourcelabel"> @@ -203,7 +205,7 @@ <connection> <sender>btn_settings</sender> <signal>clicked()</signal> - <receiver>programmDialog</receiver> + <receiver>ProgramDialog</receiver> <slot>settings()</slot> <hints> <hint type="sourcelabel"> @@ -219,7 +221,7 @@ <connection> <sender>list</sender> <signal>currentRowChanged(int)</signal> - <receiver>programmDialog</receiver> + <receiver>ProgramDialog</receiver> <slot>programmChanged()</slot> <hints> <hint type="sourcelabel"> @@ -235,7 +237,7 @@ <connection> <sender>list</sender> <signal>itemClicked(QListWidgetItem*)</signal> - <receiver>programmDialog</receiver> + <receiver>ProgramDialog</receiver> <slot>stateChanged(QListWidgetItem*)</slot> <hints> <hint type="sourcelabel"> Copied: trunk/src/programs/dhcpdaemon.cpp (from rev 243, trunk/src/programs/dhcpdemon.cpp) =================================================================== --- trunk/src/programs/dhcpdaemon.cpp (rev 0) +++ trunk/src/programs/dhcpdaemon.cpp 2011-02-12 21:06:36 UTC (rev 244) @@ -0,0 +1,254 @@ +#include "dhcpdaemon.h" +#include "interface.h" +#include "udppacket.h" +#include "dhcppacket.h" +#include "dhcpservermodel.h" + +void DhcpDaemon::setInterface(Interface *inter) +{ + myInterface = inter; + connect(myInterface, SIGNAL(receivedPacket(IpPacket)), SLOT(execute(IpPacket))); +} + +DhcpDaemon::DhcpDaemon(QObject *parent) : QObject(parent) +{ + myInterface = 0; + initialize(); +} + +DhcpDaemon::DhcpDaemon(Interface *inter, QObject *parent) : QObject(parent) +{ + setInterface(inter); + myInterfaceName = inter->name(); + myDhcpModel = new DhcpServerModel(this); + initialize(); +} + +DhcpDaemon::~DhcpDaemon() { + delete myDhcpModel; + clients.clear(); +} + +void DhcpDaemon::initialize() +{ + myDynamic = false; + myTime = 300; + myWaitingTime = 60; +} + +void DhcpDaemon::executeDiscover(DhcpPacket packet) +{ + ClientState *client = findClient( packet.xid() ); + if ( client && client->state == ClientState::IN_USE ) return; + client = chooseStatic(packet); + if ( client ) { + makeAnswer(client, DhcpPacket::DHCPOFFER); + return; + } + if ( !myDynamic ) return; + client = chooseDynamic(packet); + if ( client ) makeAnswer(client,DhcpPacket::DHCPOFFER); +} + +void DhcpDaemon::executeRequest(DhcpPacket packet) +{ + ClientState *client = findClient( packet.xid() ); + if ( !client ) return; + if ( packet.siaddr() != myInterface->ip() ) { + clients.removeOne(client); + delete client; + return; + } + makeAnswer( client, DhcpPacket::DHCPACK ); +} + +void DhcpDaemon::executeDecline(DhcpPacket packet) +{ + ClientState *client = findClient(packet.yiaddr()); + if ( !client ) return; + client->state = ClientState::DECLINE; +} + +ClientState* DhcpDaemon::chooseStatic(DhcpPacket packet) +{ + StaticDhcpRecord *rec = myDhcpModel->recordWithMac(packet.chaddr()); + if ( !rec ) return 0; + ClientState *client = new ClientState(rec); + if ( findClient(client->ip) ) return 0; + client->requestTimer = 0; + client->xid = packet.xid(); + clients << client; + return client; +} + +/*! + Выбираем адрес из динамического диапазона. + @return указатель на созданную запись. + */ +ClientState* DhcpDaemon::chooseDynamic(DhcpPacket packet) +{ + ClientState *cl = new ClientState; + cl->requestTimer = 0; + ClientState *c = findClient(packet.yiaddr()); + if ( !packet.yiaddr().isEmpty() && !c ) cl->ip = packet.yiaddr(); + else cl->ip = giveDynamicIp(); + if ( cl->ip.isEmpty() ) return NULL; + cl->mac = packet.chaddr(); + cl->xid = packet.xid(); + cl->time = myTime; + cl->mask = myMask; + cl->gateway = myGateway; + clients << cl; + return cl; +} + +/*! + Создаем dhcp пакет. + @param client - запись клиента на основе которой будем создавать пакет. + @param state - тип отправляемого сообщения. + @return созданный пакет. + */ +DhcpPacket DhcpDaemon::createDhcpPacket( ClientState *client, int state ) const +{ + if ( state == DhcpPacket::DHCPOFFER ) client->state = ClientState::WAIT_REQUEST; + else client->state = ClientState::IN_USE; + DhcpPacket p; + p.setType( state ); + p.setXid( client->xid ); + p.setChaddr( client->mac ); + p.setYiaddr( client->ip ); + p.setMask( client->mask ); + p.setGateway( client->gateway ); + p.setSiaddr( myInterface->ip() ); + p.setTime( client->time ); + return p; +} +//------------------------------------------------------------ + +void DhcpDaemon::sendDhcp(DhcpPacket packet) const +{ + UdpPacket udp; + udp.setSender( SERVER_SOCKET ); + udp.setReceiver( CLIENT_SOCKET ); + udp.pack( packet.toData() ); + IpPacket p( myInterface->ip(), IpAddress::full() ); + p.pack( udp.toData() ); + p.setUpProtocol( IpPacket::udp ); + myInterface->sendPacket(p); +} + +void DhcpDaemon::makeAnswer(ClientState *client, int type) +{ + DhcpPacket dhcp = createDhcpPacket(client,type); + sendDhcp(dhcp); +} + +/*! Ищет в списке клиента с данным идентификатрором и проверкой состояния записи. + @param xid - идентификатрор. + @return указатель на запись из списка, если xid совпали, или 0 в противном случае. + */ +ClientState* DhcpDaemon::findClient(int xid) const +{ + foreach ( ClientState *i, clients ) + if ( i->xid == xid && i->state != ClientState::DECLINE ) return i; + return 0; +} +//------------------------------------------------------------ +/*! Ищет в списке клиента с данным ip-адресом. + @param ip - адрес. + @return указатель на запись из списка, если ip совпали, или 0 в противном случае. + */ +ClientState* DhcpDaemon::findClient(IpAddress ip) const +{ + foreach ( ClientState *i, clients ) + if ( i->ip == ip ) return i; + return 0; +} +//-------------------------------------------------------------- +/*! + Выбирает ip-адрес из динамического диапазона + @return выбранный адрес, или "0.0.0.0", если нет свободных адресов. + */ +IpAddress DhcpDaemon::giveDynamicIp() const +{ + bool isContains = false; + quint32 i = myBeginIp.toInt(); + while ( i <= myEndIp.toInt() ) { + isContains = myDhcpModel->containRecord( IpAddress(i) ) || findClient(IpAddress(i)) + || myInterface->ip().toInt() == i; + if ( isContains ) { + i++; + isContains = false; + } + else { + return IpAddress(i); + } + } + return IpAddress("0.0.0.0"); +} +//------------------------------------------------------------- +void DhcpDaemon::incTime() { + bool canDelete = false; + foreach ( ClientState *i, clients ) { + if ( i->state == ClientState::WAIT_REQUEST ) { + if ( ++i->requestTimer == myWaitingTime ) canDelete = true; + } + else if ( i->state == ClientState::IN_USE && --i->time == 0 ) canDelete = true; + if ( canDelete ) { + canDelete = false; + clients.removeOne(i); + delete i; + } + } +} + +void DhcpDaemon::addDhcpServerModel(DhcpServerModel *model) +{ + myDhcpModel = model; +} + +//--------------------Public slots------------------ +void DhcpDaemon::execute(IpPacket p) +{ + if ( !isTurnOn() ) return; + if ( p.receiverSocket() == DhcpDaemon::SERVER_SOCKET ) { + UdpPacket u( p.unpack() ); + DhcpPacket d(u.unpack()); + switch ( d.type() ) { + case DhcpPacket::DHCPDISCOVER : + executeDiscover(d); + break; + case DhcpPacket::DHCPREQUEST : + executeRequest(d); + break; + case DhcpPacket::DHCPDECLINE : + executeDecline(d); + break; + } + } +} + +//-------------------------------------------------- + + +void DhcpDaemon::read(QDataStream &stream) +{ + stream >> myInterfaceName; + stream >> myBeginIp; + stream >> myEndIp; + stream >> myMask; + stream >> myGateway; + stream >> myTime; + stream >> myDynamic; + stream >> myWaitingTime; +} + +//----------------------------------------------------------------- +ClientState::ClientState(StaticDhcpRecord *rec) +{ + ip = rec->yiaddr; + mac = rec->chaddr; + mask = rec->mask; + gateway = rec->gateway; + time = rec->time; +} Copied: trunk/src/programs/dhcpdaemon.h (from rev 243, trunk/src/programs/dhcpdemon.h) =================================================================== --- trunk/src/programs/dhcpdaemon.h (rev 0) +++ trunk/src/programs/dhcpdaemon.h 2011-02-12 21:06:36 UTC (rev 244) @@ -0,0 +1,115 @@ +#ifndef DHCPDEMON_H +#define DHCPDEMON_H + +#include "ipaddress.h" +#include "macaddress.h" +#include "ippacket.h" + +class UdpSocket; +class DhcpPacket; +class Interface; +class StaticDhcpRecord; +class DhcpServerModel; + +struct ClientState { + int xid; + int state; + MacAddress mac; + IpAddress ip; + IpAddress mask; + IpAddress gateway; + int time; + int requestTimer; + enum { WAIT_REQUEST = 0, IN_USE = 1, DECLINE = 2 }; + ClientState(StaticDhcpRecord *rec); + ClientState() { } +}; + +class DhcpDaemon : public QObject +{ + Q_OBJECT + Q_PROPERTY( QString interfaceName READ interfaceName WRITE setInterfaceName ) + Q_PROPERTY( QString beginIp READ beginIp WRITE setBeginIp ) + Q_PROPERTY( QString endIp READ endIp WRITE setEndIp ) + Q_PROPERTY( QString mask READ mask WRITE setMask ) + Q_PROPERTY( QString gateway READ gateway WRITE setGateway ) + Q_PROPERTY( int time READ time WRITE setTime ) + Q_PROPERTY( int waitingTime READ waitingTime WRITE setWaitingTime ) + Q_PROPERTY( bool dynamic READ dynamic WRITE setDynamic ) + Q_PROPERTY( bool turnOn READ isTurnOn WRITE setTurnOn ) +public: + enum { CLIENT_SOCKET = 67 , SERVER_SOCKET = 68 }; + + DhcpDaemon(QObject* parent = 0); + DhcpDaemon(Interface *inter, QObject* parent = 0); + ~DhcpDaemon(); + void setInterface(Interface *inter); + void setInterfaceName(const QString &inter) { myInterfaceName = inter; } + void setBeginIp(const QString &ip) { myBeginIp.setIp(ip); } + void setEndIp(const QString &ip) { myEndIp.setIp(ip); } + void setMask(const QString &ip) { myMask.setIp(ip); } + void setGateway(const QString &ip) { myGateway.setIp(ip); } + void setTime(int t) { myTime = t; } + void setWaitingTime(int t) { myWaitingTime = t; } + void setDynamic(bool b) { myDynamic = b; } + void setTurnOn(bool b) { myTurnOn = b; } + Interface* interface() const { return myInterface; } + QString interfaceName() const { return myInterfaceName; } + QString beginIp() const { return myBeginIp.toString(); } + QString endIp() const { return myEndIp.toString(); } + QString mask() const { return myMask.toString(); } + QString gateway() const { return myGateway.toString(); } + int time() const { return myTime; } + int waitingTime() const { return myWaitingTime; } + bool dynamic() const { return myDynamic; } + bool isTurnOn() const { return myTurnOn; } + DhcpServerModel* dhcpModel() { return myDhcpModel; } + void incTime(); + IpAddress giveDynamicIp() const; + + void read(QDataStream &stream); + + Q_INVOKABLE void addDhcpServerModel(DhcpServerModel *model); + +// Обработка пакетов +public: + void executeDiscover(DhcpPacket packet); + void executeRequest(DhcpPacket packet); + void executeDecline(DhcpPacket packet); + +public slots: + void execute(IpPacket p); + +// Функция инициализации для конструкторов +private: + void initialize(); + +// Функции создания и отправки ответа +private: + void makeAnswer(ClientState* client, int type); + void sendDhcp(DhcpPacket packet) const; + DhcpPacket createDhcpPacket(ClientState *client, int state) const; + +// Функции выбора и нахождения записи клиента +private: + ClientState* chooseStatic(DhcpPacket packet); + ClientState* chooseDynamic(DhcpPacket packet); + ClientState* findClient( int xid ) const; + ClientState* findClient(IpAddress ip) const; + +private: + QList<ClientState*> clients; + Interface *myInterface; + QString myInterfaceName; + DhcpServerModel *myDhcpModel; + IpAddress myBeginIp; + IpAddress myEndIp; + IpAddress myMask; + IpAddress myGateway; + int myTime; + int myWaitingTime; + bool myDynamic; + bool myTurnOn; +}; + +#endif // DHCPDEMON_H Deleted: trunk/src/programs/dhcpdemon.cpp =================================================================== --- trunk/src/programs/dhcpdemon.cpp 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/programs/dhcpdemon.cpp 2011-02-12 21:06:36 UTC (rev 244) @@ -1,207 +0,0 @@ -#include "dhcpdemon.h" -#include "interface.h" -#include "udppacket.h" -#include "dhcppacket.h" -#include "dhcpservermodel.h" - -DhcpDemon::DhcpDemon(QObject *parent) : QObject(parent) -{ - initialize(); -} - -DhcpDemon::DhcpDemon(Interface *inter) { - myInterface = inter->name(); - initialize(); -} - -DhcpDemon::~DhcpDemon() { - delete myDhcpModel; - //delete receiver; - clients.clear(); -} - -void DhcpDemon::executeDiscover(DhcpPacket packet) -{ - ClientState *client = findClient( packet.xid() ); - if ( client && client->state == ClientState::IN_USE ) return; - client = chooseStatic(packet); - if ( client ) { - makeAnswer(client, DhcpPacket::DHCPOFFER); - return; - } - if ( !myDynamic ) return; - client = chooseDynamic(packet); - if ( client ) makeAnswer(client,DhcpPacket::DHCPOFFER); -} - -void DhcpDemon::executeRequest(DhcpPacket packet) -{ - ClientState *client = findClient( packet.xid() ); - if ( !client ) return; -// if ( packet.siaddr() != myDevice->adapter(myInterface)->ip() ) { -// clients.removeOne(client); -// delete client; -// return; -// } - makeAnswer( client, DhcpPacket::DHCPACK ); -} - -void DhcpDemon::executeDecline(DhcpPacket packet) -{ - ClientState *client = findClient(packet.yiaddr()); - if ( !client ) return; - client->state = ClientState::DECLINE; -} - -void DhcpDemon::initialize() -{ - myDhcpModel = new DhcpServerModel; - myDynamic = false; - myTime = 300; - myWaitingTime = 60; -} - -ClientState* DhcpDemon::chooseStatic(DhcpPacket packet) -{ - StaticDhcpRecord *rec = myDhcpModel->recordWithMac(packet.chaddr()); - if ( !rec ) return 0; - ClientState *client = new ClientState(rec); - if ( findClient(client->ip) ) return 0; - client->requestTimer = 0; - client->xid = packet.xid(); - clients << client; - return client; -} - -/*! - Выбираем адрес из динамического диапазона. - @return указатель на созданную запись. - */ -ClientState* DhcpDemon::chooseDynamic(DhcpPacket packet) -{ - ClientState *cl = new ClientState; - cl->requestTimer = 0; - ClientState *c = findClient(packet.yiaddr()); - if ( !packet.yiaddr().isEmpty() && !c ) cl->ip = packet.yiaddr(); - else cl->ip = giveDynamicIp(); - if ( cl->ip.isEmpty() ) return NULL; - cl->mac = packet.chaddr(); - cl->xid = packet.xid(); - cl->time = myTime; - cl->mask = myMask; - cl->gateway = myGateway; - clients << cl; - return cl; -} - -/*! - Создаем dhcp пакет. - @param client - запись клиента на основе которой будем создавать пакет. - @param state - тип отправляемого сообщения. - @return созданный пакет. - */ -DhcpPacket DhcpDemon::createDhcpPacket( ClientState *client, int state ) const -{ - if ( state == DhcpPacket::DHCPOFFER ) client->state = ClientState::WAIT_REQUEST; - else client->state = ClientState::IN_USE; - DhcpPacket p; - p.setType( state ); - p.setXid( client->xid ); - p.setChaddr( client->mac ); - p.setYiaddr( client->ip ); - p.setMask( client->mask ); - p.setGateway( client->gateway ); - //p.setSiaddr( myDevice->adapter(myInterface)->ip() ); - p.setTime( client->time ); - return p; -} -//------------------------------------------------------------ - -void DhcpDemon::sendDhcp(DhcpPacket packet) const -{ - UdpPacket udp; - udp.setSender( SERVER_SOCKET ); - udp.setReceiver( CLIENT_SOCKET ); - udp.pack( packet.toData() ); - //ipPacket p( myDevice->adapter(myInterface)->ip(), ipAddress::full() ); - //p.pack( udp.toData() ); - //p.setUpProtocol( ipPacket::udp ); - //myDevice->adapter(myInterface)->sendPacket(p); -} - -void DhcpDemon::makeAnswer(ClientState *client, int type) -{ - DhcpPacket dhcp = createDhcpPacket(client,type); - sendDhcp(dhcp); -} - -/*! Ищет в списке клиента с данным идентификатрором и проверкой состояния записи. - @param xid - идентификатрор. - @return указатель на запись из списка, если xid совпали, или 0 в противном случае. - */ -ClientState* DhcpDemon::findClient(int xid) const -{ - foreach ( ClientState *i, clients ) - if ( i->xid == xid && i->state != ClientState::DECLINE ) return i; - return 0; -} -//------------------------------------------------------------ -/*! Ищет в списке клиента с данным ip-адресом. - @param ip - адрес. - @return указатель на запись из списка, если ip совпали, или 0 в противном случае. - */ -ClientState* DhcpDemon::findClient(IpAddress ip) const -{ - foreach ( ClientState *i, clients ) - if ( i->ip == ip ) return i; - return 0; -} -//-------------------------------------------------------------- -/*! - Выбирает ip-адрес из динамического диапазона - @return выбранный адрес, или "0.0.0.0", если нет свободных адресов. - */ -IpAddress DhcpDemon::giveDynamicIp() const -{ - bool isContains = false; - quint32 i = myBeginIp.toInt(); - while ( i <= myEndIp.toInt() ) { -// isContains = myDhcpModel->containRecord( ipAddress(i) ) || findClient(ipAddress(i)) -// || myDevice->adapter(myInterface)->ip().toInt() == i; - if ( isContains ) { - i++; - isContains = false; - } - else { - return IpAddress(i); - } - } - return IpAddress("0.0.0.0"); -} -//------------------------------------------------------------- -void DhcpDemon::incTime() { - bool canDelete = false; - foreach ( ClientState *i, clients ) { - if ( i->state == ClientState::WAIT_REQUEST ) { - if ( ++i->requestTimer == myWaitingTime ) canDelete = true; - } - else if ( i->state == ClientState::IN_USE && --i->time == 0 ) canDelete = true; - if ( canDelete ) { - canDelete = false; - clients.removeOne(i); - delete i; - } - } -} - -void DhcpDemon::read(QDataStream &stream) -{ - stream >> myInterface; - stream >> myBeginIp; - stream >> myEndIp; - stream >> myMask; - stream >> myGateway; - stream >> myTime; - stream >> myDynamic; - stream >> myWaitingTime; -} Deleted: trunk/src/programs/dhcpdemon.h =================================================================== --- trunk/src/programs/dhcpdemon.h 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/programs/dhcpdemon.h 2011-02-12 21:06:36 UTC (rev 244) @@ -1,105 +0,0 @@ -#ifndef DHCPDEMON_H -#define DHCPDEMON_H - -#include "ipaddress.h" -#include "macaddress.h" - -class UdpSocket; -class DhcpPacket; -class Interface; -class StaticDhcpRecord; -class DhcpServerModel; - -struct ClientState { - int xid; - int state; - MacAddress mac; - IpAddress ip; - IpAddress mask; - IpAddress gateway; - int time; - int requestTimer; - enum { WAIT_REQUEST = 0, IN_USE = 1, DECLINE = 2 }; - ClientState(StaticDhcpRecord *rec) { - - } - - ClientState() { } -}; - -class DhcpDemon : public QObject -{ - Q_OBJECT - Q_PROPERTY( QString interfaceName READ interfaceName WRITE setInterfaceName ) - Q_PROPERTY( QString beginIp READ beginIp WRITE setBeginIp ) - Q_PROPERTY( QString endIp READ endIp WRITE setEndIp ) - Q_PROPERTY( QString mask READ mask WRITE setMask ) - Q_PROPERTY( QString gateway READ gateway WRITE setGateway ) - Q_PROPERTY( int time READ time WRITE setTime ) - Q_PROPERTY( int waitingTime READ waitingTime WRITE setWaitingTime ) - Q_PROPERTY( bool dynamic READ dynamic WRITE setDynamic ) -public: - enum { CLIENT_SOCKET = 67 , SERVER_SOCKET = 68 }; - - DhcpDemon(QObject* parent = 0); - DhcpDemon(Interface *inter); - ~DhcpDemon(); - void setInterfaceName( QString inter ) { myInterface = inter; } - void setBeginIp(QString ip) { myBeginIp.setIp(ip); } - void setEndIp(QString ip) { myEndIp.setIp(ip); } - void setMask(QString m) { myMask.setIp(m); } - void setGateway(QString g) { myGateway.setIp(g); } - void setTime(int t) { myTime = t; } - void setWaitingTime(int t) { myWaitingTime = t; } - void setDynamic(bool b) { myDynamic = b; } - QString interfaceName() const { return myInterface; } - QString beginIp() const { return myBeginIp.toString(); } - QString endIp() const { return myEndIp.toString(); } - QString mask() const { return myMask.toString(); } - QString gateway() const { return myGateway.toString(); } - int time() const { return myTime; } - int waitingTime() const { return myWaitingTime; } - bool dynamic() const { return myDynamic; } - DhcpServerModel* dhcpModel() { return myDhcpModel; } - void incTime(); - IpAddress giveDynamicIp() const; - - void read(QDataStream &stream); - -// Обработка пакетов -public: - void executeDiscover(DhcpPacket packet); - void executeRequest(DhcpPacket packet); - void executeDecline(DhcpPacket packet); - -// Функция инициализации для конструкторов -private: - void initialize(); - -// Функции создания и отправки ответа -private: - void makeAnswer(ClientState* client, int type); - void sendDhcp(DhcpPacket packet) const; - DhcpPacket createDhcpPacket(ClientState *client, int state) const; - -// Функции выбора и нахождения записи клиента -private: - ClientState* chooseStatic(DhcpPacket packet); - ClientState* chooseDynamic(DhcpPacket packet); - ClientState* findClient( int xid ) const; - ClientState* findClient(IpAddress ip) const; - -private: - QList<ClientState*> clients; - QString myInterface; - DhcpServerModel *myDhcpModel; - IpAddress myBeginIp; - IpAddress myEndIp; - IpAddress myMask; - IpAddress myGateway; - int myTime; - int myWaitingTime; - bool myDynamic; -}; - -#endif // DHCPDEMON_H Modified: trunk/src/programs/dhcpserverprogram.cpp =================================================================== --- trunk/src/programs/dhcpserverprogram.cpp 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/programs/dhcpserverprogram.cpp 2011-02-12 21:06:36 UTC (rev 244) @@ -34,83 +34,77 @@ myName = tr("DHCP server"); myServerCount++; myServerName = QString("Server%1").arg(myServerCount); - myDemons.clear(); - qDeleteAll(myDemons); + myDaemons.clear(); + qDeleteAll(myDaemons); } DhcpServerProgram::~DhcpServerProgram() { - myDevice->disposeSocket(receiver); - myDemons.clear(); - qDeleteAll(myDemons); + myDaemons.clear(); + qDeleteAll(myDaemons); } void DhcpServerProgram::setDevice(SmartDevice *s) { if ( s == 0 ) return; Program::setDevice(s); - receiver = myDevice->openSocket(DhcpDemon::SERVER_SOCKET, SocketFactory::UDP); - //receiver = new udpSocket(myDevice, SERVER_SOCKET); foreach ( Interface *i, myDevice->interfaces() ) { if ( i->isConnect() ) { - DhcpDemon *demon = new DhcpDemon(i); - myDemons << demon; + DhcpDaemon *daemon = new DhcpDaemon(i, this); + myDaemons.insert(i, daemon); } } - receiver->setBind("0.0.0.0"); - connect( receiver , SIGNAL(readyRead(QByteArray)), SLOT(execute(QByteArray))); - connect( myDevice, SIGNAL(interfaceConnected(QString)), SLOT(checkInterface(QString)) ); + connect( myDevice, SIGNAL(interfaceConnected(QString)), SLOT(checkInterfaceOnConnect(QString)) ); + connect( myDevice, SIGNAL(interfaceDeleted(QString)), SLOT(checkInterfaceOnDelete(QString)) ); } -//void dhcpServerProgramm::checkInterface(QString port) -//{ -// if ( myInterface.isEmpty() ) setInterfaceName(port); -//} - -void DhcpServerProgram::execute(QByteArray data) +void DhcpServerProgram::checkInterfaceOnConnect(QString port) { - DhcpPacket packet(data); - foreach ( DhcpDemon *demon, myDemons ) { - IpAddress deviceIp = myDevice->adapter(demon->interfaceName())->ip(); - if ( deviceIp.isEmpty() ) { - QMessageBox::warning(0,tr("Warning"), - tr("Your DHCP server <i>%1</i> isn't configured.").arg(myServerName), - QMessageBox::Ok, QMessageBox::Ok); - return; - } + Interface *i = myDevice->adapter(port); + if ( !myDaemons.contains(i) ) { + DhcpDaemon *daem = new DhcpDaemon(i, this); + myDaemons.insert(i, daem); + } +} - if ( deviceIp == packet.siaddr() ) { - switch ( packet.type() ) { - case DhcpPacket::DHCPDISCOVER : - demon->executeDiscover(packet); - break; - case DhcpPacket::DHCPREQUEST : - demon->executeRequest(packet); - break; - case DhcpPacket::DHCPDECLINE : - demon->executeDecline(packet); - break; - } - } +void DhcpServerProgram::checkInterfaceOnDelete(QString port) +{ + Interface *i = myDevice->adapter(port); + if ( !myDaemons.contains(i) ) { + DhcpDaemon *daem = myDaemons.take(i); + delete daem; } } - - void DhcpServerProgram::incTime() { - foreach ( DhcpDemon *demon, myDemons ) { + foreach ( DhcpDaemon *demon, myDaemons.values() ) { demon->incTime(); } } void DhcpServerProgram::showProperty() { - DhcpServerProperty *d = new DhcpServerProperty(myDevice); - d->setProgramm(this); + DhcpServerSetting *setting = new DhcpServerSetting(this); + DhcpServerProperty *d = new DhcpServerProperty(setting); d->exec(); } +DhcpDaemon* DhcpServerProgram::daemonOf(Interface *inter) +{ + return myDaemons.value(inter); +} + +void DhcpServerProgram::addDhcpDaemon(DhcpDaemon *daemon) +{ + Interface *i = daemon->interface(); + if ( !i ) { + i = myDevice->adapter(daemon->interfaceName()); + daemon->setInterface(i); + } + myDaemons.insert(i, daemon); +} + /*! Записывает отличительные черты в поток. @param stream - поток для записи. @@ -119,7 +113,7 @@ { stream << DHCPServer; Program::write(stream); - DhcpDemon *d = myDemons.at(0); + DhcpDaemon *d = myDaemons.values().at(0); d->dhcpModel()->write(stream); stream << d->interfaceName(); stream << d->beginIp(); @@ -139,21 +133,9 @@ void DhcpServerProgram::read(QDataStream &stream) { Program::read(stream); - DhcpDemon *d = new DhcpDemon(device()->interfaces().at(0)); + DhcpDaemon *d = new DhcpDaemon(device()->interfaces().at(0)); d->dhcpModel()->read(stream); d->read(stream); } //--------------------------------------------------- - - -//--------------------------------------------------- -//СlientState::СlientState(StaticDhcpRecord *rec) -//{ -// ip = rec->yiaddr; -// mac = rec->chaddr; -// mask = rec->mask; -// gateway = rec->gateway; -// time = rec->time; -//} - Modified: trunk/src/programs/dhcpserverprogram.h =================================================================== --- trunk/src/programs/dhcpserverprogram.h 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/programs/dhcpserverprogram.h 2011-02-12 21:06:36 UTC (rev 244) @@ -21,7 +21,7 @@ #define DHCPSERVERPROGRAMM_H #include "program.h" -#include "dhcpdemon.h" +#include "dhcpdaemon.h" class AbstractSocket; @@ -47,17 +47,31 @@ void write(QDataStream &stream) const; void read(QDataStream &stream); -// Слоты + DhcpDaemon* daemonOf(Interface *inter); + + Q_INVOKABLE void addDhcpDaemon(DhcpDaemon *daemon); + + // Слоты public slots: - void execute(QByteArray data); -// void checkInterface(QString port); + void checkInterfaceOnConnect(QString port); + void checkInterfaceOnDelete(QString port); // Переменные private: static int myServerCount; QString myServerName; - QList<DhcpDemon*> myDemons; - AbstractSocket *receiver; + QMap<Interface*, DhcpDaemon*> myDaemons; }; +class DhcpServerSetting +{ +public: + DhcpServerSetting(DhcpServerProgram *prog) { myProgram = prog; } + DhcpServerProgram* program() { return myProgram; } + DhcpDaemon* daemonOf(Interface *inter) { return myProgram->daemonOf(inter); } + +private: + DhcpServerProgram *myProgram; +}; + #endif // DHCPSERVERPROGRAMM_H Modified: trunk/src/programs/programs.pri =================================================================== --- trunk/src/programs/programs.pri 2011-02-11 23:05:12 UTC (rev 243) +++ trunk/src/programs/programs.pri 2011-02-12 21:06:36 UTC (rev 244) @@ -3,10 +3,10 @@ src/programs/dhcpserverprogram.h \ src/programs/dhcpclientprogram.h \ src/programs/spoofingprogram.h \ - src/programs/dhcpdemon.h + src/programs/dhcpdaemon.h SOURCES += src/programs/ripprogram.cpp \ src/programs/program.cpp \ src/programs/dhcpserverprogram.cpp \ src/programs/dhcpclientprogram.cpp \ src/programs/spoofingprogram.cpp \ - src/programs/dhcpdemon.cpp + src/programs/dhcpdaemon.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <f-r...@us...> - 2011-02-11 23:05:21
|
Revision: 243 http://netemul.svn.sourceforge.net/netemul/?rev=243&view=rev Author: f-r-o-s-t Date: 2011-02-11 23:05:12 +0000 (Fri, 11 Feb 2011) Log Message: ----------- I'm sorry =( Modified Paths: -------------- trunk/src/devices/smartdevice.h trunk/src/programs/dhcpdemon.h Added Paths: ----------- trunk/src/programs/ trunk/src/programs/dhcpclientprogram.cpp trunk/src/programs/dhcpclientprogram.h trunk/src/programs/dhcpserverprogram.cpp trunk/src/programs/dhcpserverprogram.h trunk/src/programs/program.cpp trunk/src/programs/program.h trunk/src/programs/programs.pri trunk/src/programs/ripprogram.cpp trunk/src/programs/ripprogram.h trunk/src/programs/spoofingprogram.cpp trunk/src/programs/spoofingprogram.h Removed Paths: ------------- trunk/src/programs/dhcpclientprogramm.cpp trunk/src/programs/dhcpclientprogramm.h trunk/src/programs/dhcpserverprogramm.cpp trunk/src/programs/dhcpserverprogramm.h trunk/src/programs/programmrep.cpp trunk/src/programs/programmrep.h trunk/src/programs/programms.pri trunk/src/programs/ripprogramm.cpp trunk/src/programs/ripprogramm.h trunk/src/programs/spoofingprogramm.cpp trunk/src/programs/spoofingprogramm.h Modified: trunk/src/devices/smartdevice.h =================================================================== --- trunk/src/devices/smartdevice.h 2011-02-11 21:56:14 UTC (rev 242) +++ trunk/src/devices/smartdevice.h 2011-02-11 23:05:12 UTC (rev 243) @@ -24,7 +24,7 @@ #include <QtGui/QIcon> #include "deviceimpl.h" #include "interface.h" -#include "programrep.h" +#include "program.h" class RouteModel; class ArpModel; Copied: trunk/src/programs/dhcpclientprogram.cpp (from rev 240, trunk/src/programms/dhcpclientprogramm.cpp) =================================================================== --- trunk/src/programs/dhcpclientprogram.cpp (rev 0) +++ trunk/src/programs/dhcpclientprogram.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,376 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#include "dhcpclientprogram.h" +#include "smartdevice.h" +#include "udpsocket.h" +#include "dhcpclientproperty.h" +#include "udppacket.h" + +DhcpClientProgram::DhcpClientProgram(QObject *parent) : Program(parent) +{ + myName = tr("DHCP client"); + myOfferTime = 60; +} + +DhcpClientProgram::~DhcpClientProgram() +{ + qDeleteAll(myStates); + // Make it + //delete listener; + myDevice->disposeSocket(listener); +} + +void DhcpClientProgram::incTime() +{ + foreach ( InterfaceState *i , myStates ) { + --i->time; + if ( i->time <= 0 ) { + switch ( i->state ) { + case InterfaceState::CS_ALL_RIGHT: restartSession(i); break; + case InterfaceState::CS_WAIT_VARIANT: sendDiscover( i->name ); break; + case InterfaceState::CS_WAIT_RESPONSE: sendRequest(i->name ); break; + } + } + } +} +/*! + * Переопределяем функцию установки устройства чтобы соединиться со слотом. + * @param s - указатель на устройство на которое установлена программа. + */ +void DhcpClientProgram::setDevice(SmartDevice *s) +{ + if ( s == 0 ) { + foreach ( InterfaceState *i , myStates ) resetClient(i); + return; + } + Program::setDevice(s); + listener = s->openSocket( CLIENT_SOCKET , SmartDevice::UDP ); + listener->setBind("0.0.0.0"); + connect( listener , SIGNAL(readyRead(QByteArray)) , SLOT(processData(QByteArray)) ); + connect( s , SIGNAL(interfaceDeleted(QString)), SLOT(deleteInterface(QString)) ); + foreach ( InterfaceState *i , myStates ) { + resetClient( i ); + } +} +//------------------------------------------------------ + +void DhcpClientProgram::resetClient(InterfaceState *session) +{ + myDevice->adapter(session->name)->setIp(IpAddress("0.0.0.0")); + myDevice->adapter(session->name)->setMask(IpAddress("0.0.0.0")); + myDevice->connectedNet( myDevice->adapter( session->name ) ); + myDevice->setGateway("0.0.0.0"); +} + +bool DhcpClientProgram::isUnderDhcpControl(const QString name) const +{ + foreach ( InterfaceState *i , myStates ) + if ( i->name == name ) { + return true; + } + return false; +} + +/*! + Посылает Request серверу + @param name - имя интерфейса + */ +void DhcpClientProgram::sendRequest(const QString &name) +{ + InterfaceState *t = stateAt(name); + if ( !t ) return; + if ( REPEAT_COUNT < ++t->count ) { + restartSession(t); + return; + } + t->time = myOfferTime; + DhcpPacket message; + message.setType( DhcpPacket::DHCPREQUEST ); + message.setXid( t->xid ); + message.setChaddr( myDevice->adapter(t->name)->mac() ); + message.setSiaddr( t->serverAddress ); + sendDhcpMessage(message,t); +} +//------------------------------------------------------ +/*! + * Посылает запрос на получение настроек. + * @param name - имя интерфейса. + */ +void DhcpClientProgram::sendDiscover(const QString &name) +{ + InterfaceState *t = stateAt(name); + if ( !t ) return; + t->state = InterfaceState::CS_WAIT_VARIANT; + t->time = myOfferTime; + t->count = 0; + DhcpPacket message; + message.setType( DhcpPacket::DHCPDISCOVER ); + message.setXid(t->xid); + message.setChaddr( myDevice->adapter(t->name)->mac() ); + if ( !t->lastIp.isEmpty() ) message.setYiaddr( t->lastIp ); + sendDhcpMessage(message,t); +} +//-------------------------------------------------------------- +void DhcpClientProgram::sendDecLine(const QString &name) +{ + InterfaceState *t = stateAt(name); + if ( !t ) return; + DhcpPacket message; + message.setType( DhcpPacket::DHCPDECLINE ); + message.setXid( t->xid ); + if ( !t->lastIp.isEmpty() ) message.setYiaddr( t->lastIp ); + message.setChaddr( myDevice->adapter( t->name )->mac() ); + sendDhcpMessage( message , t ); +} +/*! + Обрабатывает входящие данные. + @param data - пришедщие данные. + */ +void DhcpClientProgram::processData(QByteArray data) +{ + DhcpPacket packet(data); + switch ( packet.type() ) { + case DhcpPacket::DHCPOFFER: receiveOffer(packet); break; + case DhcpPacket::DHCPACK: receiveAck(packet); break; + } +} +//--------------------------------------------------------------- +/*! + Начинает заново сессию + @param session - указатель на сессию + */ +void DhcpClientProgram::restartSession(InterfaceState *session) +{ + resetClient(session); + sendDiscover( session->name ); +} +//--------------------------------------------------------------- +/*! + Обрабатывает входящее предложение настроек. + @param packet - пакет с настройками. + */ +void DhcpClientProgram::receiveOffer(DhcpPacket packet) +{ + foreach ( InterfaceState *i , myStates ) + if ( i->xid == packet.xid() && i->state == InterfaceState::CS_WAIT_VARIANT ) { + i->state = InterfaceState::CS_WAIT_RESPONSE; + i->serverAddress = packet.siaddr(); + sendRequest( i->name ); + return; + } +} +//--------------------------------------------------------------- +/*! + Обрабатывает вхоодящий АСК. + @param packet - ack пакет + */ +void DhcpClientProgram::receiveAck(DhcpPacket packet) +{ + foreach ( InterfaceState *i , myStates ) + if ( i->xid == packet.xid() && i->state == InterfaceState::CS_WAIT_RESPONSE ) { + i->state = InterfaceState::CS_ALL_RIGHT; + myDevice->adapter(i->name)->setIp( packet.yiaddr() ); + myDevice->adapter(i->name)->setMask( packet.mask() ); + myDevice->connectedNet(myDevice->adapter(i->name)); + myDevice->setGateway( packet.gateway().toString() ); + myDevice->updateView(); + i->time = packet.time(); + i->lastIp = packet.yiaddr(); + myDevice->adapter(i->name)->sendArpRequest( packet.yiaddr() ); + return; + } +} +//--------------------------------------------------------------- +/*! + Отправляет пакет с нужного интерфейса. + @param message - пакет. + @param state - поток-отправитель. + */ +void DhcpClientProgram::sendDhcpMessage(DhcpPacket message, InterfaceState *state) +{ + if (!myDevice->adapter(state->name)->isConnect() ) return; + UdpPacket udp; + udp.setSender(CLIENT_SOCKET); + udp.setReceiver(SERVER_SOCKET); + udp.pack( message.toData() ); + IpPacket packet( myDevice->adapter(state->name)->ip() , IpAddress::full() ); + packet.pack( udp.toData() ); + packet.setUpProtocol( IpPacket::udp ); + myDevice->adapter(state->name)->sendPacket( packet); +} +//--------------------------------------------------------------- +/*! + * Показывает диалог программы. + */ +void DhcpClientProgram::showProperty() +{ + dhcpClientProperty *d = new dhcpClientProperty; + d->setProgramm(this); + d->exec(); +} +//--------------------------------------------------------------- +/*! + * Ищет указанный сеанс связи для интерфейса. + * @param name - имя интерфейса. + * @return указатель на сеанс, если такого нет то 0 + */ +InterfaceState* DhcpClientProgram::stateAt(const QString name) +{ + foreach ( InterfaceState *i , myStates ) + if ( i->name == name ) return i; + return 0; +} +//-------------------------------------------------------------- +QStringList DhcpClientProgram::interfacesList() const +{ + return myDevice->sockets(); +} +/*! + * Возвращаем иконку подключения, для указанного интерфейса. + * @param имя интерефейса + * @return иконка соединения + */ +QIcon DhcpClientProgram::isConnectSocketIcon(const QString &name) const +{ + return myDevice->isConnectSocketIcon(name); +} +//----------------------------------------------------------------------- +/*! + * Вызывается когда у устройства удаляется интерфейс, если мы за + * ним следим, то мы прекращаем это делать и удаляем его из списка. + */ +void DhcpClientProgram::deleteInterface(const QString name) +{ + InterfaceState *t = stateAt(name); + if ( !t ) return; + myStates.removeOne(t); + delete t; +} +//-------------------------------------------------------------------- +/*! + * Если интерфейс еще не добавлен под наблюдение, то добавляем его. + * @param name - имя интерфейса. + * @param b - включить или выключить наблюдение. + */ +void DhcpClientProgram::observeInterface(const QString &name, bool b) +{ + if ( !myEnable ) return; + InterfaceState *temp = stateAt(name); + if ( temp ) { + if ( b ) return; + resetClient( temp ); + myStates.removeOne(temp); + delete temp; + return; + } + if ( !b ) return; + InterfaceState *session = new InterfaceState; + session->name = name; + session->xid = qrand()%5000; + session->time = 0; + connect( myDevice->adapter(session->name) , SIGNAL(equalIpDetected()) , SLOT(onDetectEqualIp()) ); + myStates << session; + sendDiscover(session->name); +} +//-------------------------------------------------------------------- + +void DhcpClientProgram::onDetectEqualIp() +{ + Interface *t = qobject_cast<Interface*>(sender()); + InterfaceState *client = 0; + foreach ( InterfaceState *i , myStates ) + if ( myDevice->adapter( i->name ) == t ) client = i; + if ( !client ) return; + sendDecLine(client->name); + client->xid = qrand()%5000; + client->lastIp.setIp("0.0.0.0"); + restartSession( client); +} + +Qt::CheckState DhcpClientProgram::checkedState(const QString &name) const +{ + foreach ( InterfaceState *i , myStates ) + if ( i->name == name ) return Qt::Checked; + return Qt::Unchecked; +} +/*! + Записывает отличительные черты в поток. + @param stream - поток для записи. +*/ +void DhcpClientProgram::write(QDataStream &stream) const +{ + stream << DHCPClient; + Program::write(stream); + stream << myOfferTime; + stream << myStates.size(); + foreach ( InterfaceState *i , myStates ) i->write(stream); +} +//--------------------------------------------------- +/*! + Считывает отличительные черты из потока. + @param stream - поток для чтения. +*/ +void DhcpClientProgram::read(QDataStream &stream) +{ + Program::read(stream); + stream >> myOfferTime; + int n; + stream >> n; + for ( int i = 0 ; i < n ; i++ ) { + InterfaceState *temp = new InterfaceState; + temp->read(stream); + temp->time = 0; + temp->state = InterfaceState::CS_WAIT_VARIANT; + myStates << temp; + } +} +//--------------------------------------------------- +QVariantList DhcpClientProgram::statesObjectList() const +{ + QVariantList list; + foreach ( InterfaceState *i , myStates ) { + QObject *o = new InterfaceStateObject(i); + list << qVariantFromValue(o); + } + return list; +} + +void DhcpClientProgram::addInterfaceStateObject(InterfaceStateObject *obj) +{ + InterfaceState *s = obj->object(); + s->state = InterfaceState::CS_WAIT_VARIANT; + myStates << s; + obj->deleteLater(); +} + +//--------------------------------------------------- +//--------------------------------------------------- +void InterfaceState::write(QDataStream &stream) const +{ + stream << xid << time << serverAddress << lastIp << name; +} + +void InterfaceState::read(QDataStream &stream) +{ + stream >> xid >> time >> serverAddress >> lastIp >> name; +} + + + Copied: trunk/src/programs/dhcpclientprogram.h (from rev 240, trunk/src/programms/dhcpclientprogramm.h) =================================================================== --- trunk/src/programs/dhcpclientprogram.h (rev 0) +++ trunk/src/programs/dhcpclientprogram.h 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,130 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#ifndef DHCPCLIENTPROGRAMM_H +#define DHCPCLIENTPROGRAMM_H + +#include <QMetaType> +#include <QIcon> +#include "program.h" +#include "dhcppacket.h" + +static const int MINUTE = 60; +static const int REPEAT_COUNT = 3; + +class Interface; +class AbstractSocket; + +struct InterfaceState { + enum { CS_NONE , CS_WAIT_VARIANT , CS_WAIT_RESPONSE , CS_ALL_RIGHT }; + int state; + int xid; + int time; + qint8 count; + IpAddress serverAddress; + IpAddress lastIp; + QString name; + void write(QDataStream &stream) const; + void read(QDataStream &stream); +}; +typedef QList<InterfaceState*> InterfaceStateList; + +//xid << time << serverAddress << lastIp << name; + +class InterfaceStateObject : public QObject +{ + Q_OBJECT + Q_PROPERTY( int xid READ xid WRITE setXid ) + Q_PROPERTY( QString serverAddress READ serverAddress WRITE setServerAddress ) + Q_PROPERTY( QString lastIp READ lastIp WRITE setLastIp ) + Q_PROPERTY( QString name READ name WRITE setName ) +public: + InterfaceStateObject(InterfaceState *s) { st = s; } + InterfaceStateObject(QObject *parent = 0) : QObject(parent) { st = new InterfaceState(); } + + InterfaceState* object() { return st; } + + int xid() const { return st->xid; } + QString serverAddress() const { return st->serverAddress.toString(); } + QString lastIp() const { return st->lastIp.toString(); } + QString name() const { return st->name; } + + void setXid( int x ) { st->xid = x; } + void setServerAddress( const QString &x ) { st->serverAddress.setIp(x); } + void setLastIp( const QString &x ) { st->lastIp.setIp(x); } + void setName( const QString &x ) { st->name = x; } + +private: + InterfaceState *st; +}; + + +class DhcpClientProgram : public Program +{ + Q_OBJECT + Q_PROPERTY( int offerTime READ offerTime WRITE setOfferTime ) + Q_PROPERTY( QVariantList states READ statesObjectList ) +public: + enum { DHCPClient = 1 ,CLIENT_SOCKET = 67, SERVER_SOCKET = 68 }; + DhcpClientProgram(QObject *parent = 0); + ~DhcpClientProgram(); + int id() const { return DHCPClient; } + bool interrupt(int) { return false; } + void setDevice(SmartDevice *s); + void showProperty(); + void incTime(); + bool isUnderDhcpControl(const QString name) const; + void write(QDataStream &stream) const; + void read(QDataStream &stream); + void observeInterface(const QString &name, bool b); + QStringList interfacesList() const; + QIcon isConnectSocketIcon(const QString &name) const; + Qt::CheckState checkedState(const QString &name) const; + virtual QString featureName() const { return "dc"; } +public slots: + void deleteInterface(const QString name); +private slots: + void processData(QByteArray data); + void onDetectEqualIp(); +//Property +public: + Q_INVOKABLE void addInterfaceStateObject(InterfaceStateObject *obj); + void setOfferTime(int time) { myOfferTime = time; } + int offerTime() const { return myOfferTime; } + InterfaceStateList states() { return myStates; } + QVariantList statesObjectList() const; + +private: + InterfaceStateList myStates; + int myOfferTime; + +private: + void sendDhcpMessage(DhcpPacket message, InterfaceState *state); + void sendRequest(const QString &name); + void sendDiscover(const QString &name); + void sendDecLine(const QString &name); + void receiveOffer(DhcpPacket packet); + void receiveAck(DhcpPacket packet); + void restartSession( InterfaceState *session); + InterfaceState* stateAt(const QString name); + void resetClient( InterfaceState *session); + AbstractSocket *listener; +}; + +#endif // DHCPCLIENTPROGRAMM_H Deleted: trunk/src/programs/dhcpclientprogramm.cpp =================================================================== --- trunk/src/programms/dhcpclientprogramm.cpp 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpclientprogramm.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -1,376 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#include "dhcpclientprogramm.h" -#include "smartdevice.h" -#include "udpsocket.h" -#include "dhcpclientproperty.h" -#include "udppacket.h" - -DhcpClientProgram::DhcpClientProgram(QObject *parent) : Program(parent) -{ - myName = tr("DHCP client"); - myOfferTime = 60; -} - -DhcpClientProgram::~DhcpClientProgram() -{ - qDeleteAll(myStates); - // Make it - //delete listener; - myDevice->disposeSocket(listener); -} - -void DhcpClientProgram::incTime() -{ - foreach ( InterfaceState *i , myStates ) { - --i->time; - if ( i->time <= 0 ) { - switch ( i->state ) { - case InterfaceState::CS_ALL_RIGHT: restartSession(i); break; - case InterfaceState::CS_WAIT_VARIANT: sendDiscover( i->name ); break; - case InterfaceState::CS_WAIT_RESPONSE: sendRequest(i->name ); break; - } - } - } -} -/*! - * Переопределяем функцию установки устройства чтобы соединиться со слотом. - * @param s - указатель на устройство на которое установлена программа. - */ -void DhcpClientProgram::setDevice(SmartDevice *s) -{ - if ( s == 0 ) { - foreach ( InterfaceState *i , myStates ) resetClient(i); - return; - } - Program::setDevice(s); - listener = s->openSocket( CLIENT_SOCKET , SmartDevice::UDP ); - listener->setBind("0.0.0.0"); - connect( listener , SIGNAL(readyRead(QByteArray)) , SLOT(processData(QByteArray)) ); - connect( s , SIGNAL(interfaceDeleted(QString)), SLOT(deleteInterface(QString)) ); - foreach ( InterfaceState *i , myStates ) { - resetClient( i ); - } -} -//------------------------------------------------------ - -void DhcpClientProgram::resetClient(InterfaceState *session) -{ - myDevice->adapter(session->name)->setIp(IpAddress("0.0.0.0")); - myDevice->adapter(session->name)->setMask(IpAddress("0.0.0.0")); - myDevice->connectedNet( myDevice->adapter( session->name ) ); - myDevice->setGateway("0.0.0.0"); -} - -bool DhcpClientProgram::isUnderDhcpControl(const QString name) const -{ - foreach ( InterfaceState *i , myStates ) - if ( i->name == name ) { - return true; - } - return false; -} - -/*! - Посылает Request серверу - @param name - имя интерфейса - */ -void DhcpClientProgram::sendRequest(const QString &name) -{ - InterfaceState *t = stateAt(name); - if ( !t ) return; - if ( REPEAT_COUNT < ++t->count ) { - restartSession(t); - return; - } - t->time = myOfferTime; - DhcpPacket message; - message.setType( DhcpPacket::DHCPREQUEST ); - message.setXid( t->xid ); - message.setChaddr( myDevice->adapter(t->name)->mac() ); - message.setSiaddr( t->serverAddress ); - sendDhcpMessage(message,t); -} -//------------------------------------------------------ -/*! - * Посылает запрос на получение настроек. - * @param name - имя интерфейса. - */ -void DhcpClientProgram::sendDiscover(const QString &name) -{ - InterfaceState *t = stateAt(name); - if ( !t ) return; - t->state = InterfaceState::CS_WAIT_VARIANT; - t->time = myOfferTime; - t->count = 0; - DhcpPacket message; - message.setType( DhcpPacket::DHCPDISCOVER ); - message.setXid(t->xid); - message.setChaddr( myDevice->adapter(t->name)->mac() ); - if ( !t->lastIp.isEmpty() ) message.setYiaddr( t->lastIp ); - sendDhcpMessage(message,t); -} -//-------------------------------------------------------------- -void DhcpClientProgram::sendDecLine(const QString &name) -{ - InterfaceState *t = stateAt(name); - if ( !t ) return; - DhcpPacket message; - message.setType( DhcpPacket::DHCPDECLINE ); - message.setXid( t->xid ); - if ( !t->lastIp.isEmpty() ) message.setYiaddr( t->lastIp ); - message.setChaddr( myDevice->adapter( t->name )->mac() ); - sendDhcpMessage( message , t ); -} -/*! - Обрабатывает входящие данные. - @param data - пришедщие данные. - */ -void DhcpClientProgram::processData(QByteArray data) -{ - DhcpPacket packet(data); - switch ( packet.type() ) { - case DhcpPacket::DHCPOFFER: receiveOffer(packet); break; - case DhcpPacket::DHCPACK: receiveAck(packet); break; - } -} -//--------------------------------------------------------------- -/*! - Начинает заново сессию - @param session - указатель на сессию - */ -void DhcpClientProgram::restartSession(InterfaceState *session) -{ - resetClient(session); - sendDiscover( session->name ); -} -//--------------------------------------------------------------- -/*! - Обрабатывает входящее предложение настроек. - @param packet - пакет с настройками. - */ -void DhcpClientProgram::receiveOffer(DhcpPacket packet) -{ - foreach ( InterfaceState *i , myStates ) - if ( i->xid == packet.xid() && i->state == InterfaceState::CS_WAIT_VARIANT ) { - i->state = InterfaceState::CS_WAIT_RESPONSE; - i->serverAddress = packet.siaddr(); - sendRequest( i->name ); - return; - } -} -//--------------------------------------------------------------- -/*! - Обрабатывает вхоодящий АСК. - @param packet - ack пакет - */ -void DhcpClientProgram::receiveAck(DhcpPacket packet) -{ - foreach ( InterfaceState *i , myStates ) - if ( i->xid == packet.xid() && i->state == InterfaceState::CS_WAIT_RESPONSE ) { - i->state = InterfaceState::CS_ALL_RIGHT; - myDevice->adapter(i->name)->setIp( packet.yiaddr() ); - myDevice->adapter(i->name)->setMask( packet.mask() ); - myDevice->connectedNet(myDevice->adapter(i->name)); - myDevice->setGateway( packet.gateway().toString() ); - myDevice->updateView(); - i->time = packet.time(); - i->lastIp = packet.yiaddr(); - myDevice->adapter(i->name)->sendArpRequest( packet.yiaddr() ); - return; - } -} -//--------------------------------------------------------------- -/*! - Отправляет пакет с нужного интерфейса. - @param message - пакет. - @param state - поток-отправитель. - */ -void DhcpClientProgram::sendDhcpMessage(DhcpPacket message, InterfaceState *state) -{ - if (!myDevice->adapter(state->name)->isConnect() ) return; - UdpPacket udp; - udp.setSender(CLIENT_SOCKET); - udp.setReceiver(SERVER_SOCKET); - udp.pack( message.toData() ); - IpPacket packet( myDevice->adapter(state->name)->ip() , IpAddress::full() ); - packet.pack( udp.toData() ); - packet.setUpProtocol( IpPacket::udp ); - myDevice->adapter(state->name)->sendPacket( packet); -} -//--------------------------------------------------------------- -/*! - * Показывает диалог программы. - */ -void DhcpClientProgram::showProperty() -{ - dhcpClientProperty *d = new dhcpClientProperty; - d->setProgramm(this); - d->exec(); -} -//--------------------------------------------------------------- -/*! - * Ищет указанный сеанс связи для интерфейса. - * @param name - имя интерфейса. - * @return указатель на сеанс, если такого нет то 0 - */ -InterfaceState* DhcpClientProgram::stateAt(const QString name) -{ - foreach ( InterfaceState *i , myStates ) - if ( i->name == name ) return i; - return 0; -} -//-------------------------------------------------------------- -QStringList DhcpClientProgram::interfacesList() const -{ - return myDevice->sockets(); -} -/*! - * Возвращаем иконку подключения, для указанного интерфейса. - * @param имя интерефейса - * @return иконка соединения - */ -QIcon DhcpClientProgram::isConnectSocketIcon(const QString &name) const -{ - return myDevice->isConnectSocketIcon(name); -} -//----------------------------------------------------------------------- -/*! - * Вызывается когда у устройства удаляется интерфейс, если мы за - * ним следим, то мы прекращаем это делать и удаляем его из списка. - */ -void DhcpClientProgram::deleteInterface(const QString name) -{ - InterfaceState *t = stateAt(name); - if ( !t ) return; - myStates.removeOne(t); - delete t; -} -//-------------------------------------------------------------------- -/*! - * Если интерфейс еще не добавлен под наблюдение, то добавляем его. - * @param name - имя интерфейса. - * @param b - включить или выключить наблюдение. - */ -void DhcpClientProgram::observeInterface(const QString &name, bool b) -{ - if ( !myEnable ) return; - InterfaceState *temp = stateAt(name); - if ( temp ) { - if ( b ) return; - resetClient( temp ); - myStates.removeOne(temp); - delete temp; - return; - } - if ( !b ) return; - InterfaceState *session = new InterfaceState; - session->name = name; - session->xid = qrand()%5000; - session->time = 0; - connect( myDevice->adapter(session->name) , SIGNAL(equalIpDetected()) , SLOT(onDetectEqualIp()) ); - myStates << session; - sendDiscover(session->name); -} -//-------------------------------------------------------------------- - -void DhcpClientProgram::onDetectEqualIp() -{ - Interface *t = qobject_cast<Interface*>(sender()); - InterfaceState *client = 0; - foreach ( InterfaceState *i , myStates ) - if ( myDevice->adapter( i->name ) == t ) client = i; - if ( !client ) return; - sendDecLine(client->name); - client->xid = qrand()%5000; - client->lastIp.setIp("0.0.0.0"); - restartSession( client); -} - -Qt::CheckState DhcpClientProgram::checkedState(const QString &name) const -{ - foreach ( InterfaceState *i , myStates ) - if ( i->name == name ) return Qt::Checked; - return Qt::Unchecked; -} -/*! - Записывает отличительные черты в поток. - @param stream - поток для записи. -*/ -void DhcpClientProgram::write(QDataStream &stream) const -{ - stream << DHCPClient; - Program::write(stream); - stream << myOfferTime; - stream << myStates.size(); - foreach ( InterfaceState *i , myStates ) i->write(stream); -} -//--------------------------------------------------- -/*! - Считывает отличительные черты из потока. - @param stream - поток для чтения. -*/ -void DhcpClientProgram::read(QDataStream &stream) -{ - Program::read(stream); - stream >> myOfferTime; - int n; - stream >> n; - for ( int i = 0 ; i < n ; i++ ) { - InterfaceState *temp = new InterfaceState; - temp->read(stream); - temp->time = 0; - temp->state = InterfaceState::CS_WAIT_VARIANT; - myStates << temp; - } -} -//--------------------------------------------------- -QVariantList DhcpClientProgram::statesObjectList() const -{ - QVariantList list; - foreach ( InterfaceState *i , myStates ) { - QObject *o = new InterfaceStateObject(i); - list << qVariantFromValue(o); - } - return list; -} - -void DhcpClientProgram::addInterfaceStateObject(InterfaceStateObject *obj) -{ - InterfaceState *s = obj->object(); - s->state = InterfaceState::CS_WAIT_VARIANT; - myStates << s; - obj->deleteLater(); -} - -//--------------------------------------------------- -//--------------------------------------------------- -void InterfaceState::write(QDataStream &stream) const -{ - stream << xid << time << serverAddress << lastIp << name; -} - -void InterfaceState::read(QDataStream &stream) -{ - stream >> xid >> time >> serverAddress >> lastIp >> name; -} - - - Deleted: trunk/src/programs/dhcpclientprogramm.h =================================================================== --- trunk/src/programms/dhcpclientprogramm.h 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpclientprogramm.h 2011-02-11 23:05:12 UTC (rev 243) @@ -1,130 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#ifndef DHCPCLIENTPROGRAMM_H -#define DHCPCLIENTPROGRAMM_H - -#include <QMetaType> -#include <QIcon> -#include "programmrep.h" -#include "dhcppacket.h" - -static const int MINUTE = 60; -static const int REPEAT_COUNT = 3; - -class Interface; -class AbstractSocket; - -struct InterfaceState { - enum { CS_NONE , CS_WAIT_VARIANT , CS_WAIT_RESPONSE , CS_ALL_RIGHT }; - int state; - int xid; - int time; - qint8 count; - IpAddress serverAddress; - IpAddress lastIp; - QString name; - void write(QDataStream &stream) const; - void read(QDataStream &stream); -}; -typedef QList<InterfaceState*> InterfaceStateList; - -//xid << time << serverAddress << lastIp << name; - -class InterfaceStateObject : public QObject -{ - Q_OBJECT - Q_PROPERTY( int xid READ xid WRITE setXid ) - Q_PROPERTY( QString serverAddress READ serverAddress WRITE setServerAddress ) - Q_PROPERTY( QString lastIp READ lastIp WRITE setLastIp ) - Q_PROPERTY( QString name READ name WRITE setName ) -public: - InterfaceStateObject(InterfaceState *s) { st = s; } - InterfaceStateObject(QObject *parent = 0) : QObject(parent) { st = new InterfaceState(); } - - InterfaceState* object() { return st; } - - int xid() const { return st->xid; } - QString serverAddress() const { return st->serverAddress.toString(); } - QString lastIp() const { return st->lastIp.toString(); } - QString name() const { return st->name; } - - void setXid( int x ) { st->xid = x; } - void setServerAddress( const QString &x ) { st->serverAddress.setIp(x); } - void setLastIp( const QString &x ) { st->lastIp.setIp(x); } - void setName( const QString &x ) { st->name = x; } - -private: - InterfaceState *st; -}; - - -class DhcpClientProgram : public Program -{ - Q_OBJECT - Q_PROPERTY( int offerTime READ offerTime WRITE setOfferTime ) - Q_PROPERTY( QVariantList states READ statesObjectList ) -public: - enum { DHCPClient = 1 ,CLIENT_SOCKET = 67, SERVER_SOCKET = 68 }; - DhcpClientProgram(QObject *parent = 0); - ~DhcpClientProgram(); - int id() const { return DHCPClient; } - bool interrupt(int) { return false; } - void setDevice(SmartDevice *s); - void showProperty(); - void incTime(); - bool isUnderDhcpControl(const QString name) const; - void write(QDataStream &stream) const; - void read(QDataStream &stream); - void observeInterface(const QString &name, bool b); - QStringList interfacesList() const; - QIcon isConnectSocketIcon(const QString &name) const; - Qt::CheckState checkedState(const QString &name) const; - virtual QString featureName() const { return "dc"; } -public slots: - void deleteInterface(const QString name); -private slots: - void processData(QByteArray data); - void onDetectEqualIp(); -//Property -public: - Q_INVOKABLE void addInterfaceStateObject(InterfaceStateObject *obj); - void setOfferTime(int time) { myOfferTime = time; } - int offerTime() const { return myOfferTime; } - InterfaceStateList states() { return myStates; } - QVariantList statesObjectList() const; - -private: - InterfaceStateList myStates; - int myOfferTime; - -private: - void sendDhcpMessage(DhcpPacket message, InterfaceState *state); - void sendRequest(const QString &name); - void sendDiscover(const QString &name); - void sendDecLine(const QString &name); - void receiveOffer(DhcpPacket packet); - void receiveAck(DhcpPacket packet); - void restartSession( InterfaceState *session); - InterfaceState* stateAt(const QString name); - void resetClient( InterfaceState *session); - AbstractSocket *listener; -}; - -#endif // DHCPCLIENTPROGRAMM_H Modified: trunk/src/programs/dhcpdemon.h =================================================================== --- trunk/src/programms/dhcpdemon.h 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpdemon.h 2011-02-11 23:05:12 UTC (rev 243) @@ -30,7 +30,6 @@ class DhcpDemon : public QObject { Q_OBJECT - Q_PROPERTY( QString interfaceName READ interfaceName WRITE setInterfaceName ) Q_PROPERTY( QString beginIp READ beginIp WRITE setBeginIp ) Q_PROPERTY( QString endIp READ endIp WRITE setEndIp ) @@ -39,7 +38,6 @@ Q_PROPERTY( int time READ time WRITE setTime ) Q_PROPERTY( int waitingTime READ waitingTime WRITE setWaitingTime ) Q_PROPERTY( bool dynamic READ dynamic WRITE setDynamic ) - public: enum { CLIENT_SOCKET = 67 , SERVER_SOCKET = 68 }; Copied: trunk/src/programs/dhcpserverprogram.cpp (from rev 240, trunk/src/programms/dhcpserverprogramm.cpp) =================================================================== --- trunk/src/programs/dhcpserverprogram.cpp (rev 0) +++ trunk/src/programs/dhcpserverprogram.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,159 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#include "dhcpserverprogram.h" +#include "dhcpserverproperty.h" +#include "dhcppacket.h" +#include "smartdevice.h" +#include "udpsocket.h" +#include "socketfactory.h" +#include <QMessageBox> + +#include "dhcpservermodel.h" + +int DhcpServerProgram::myServerCount = 0; + +DhcpServerProgram::DhcpServerProgram(QObject *parent) : Program(parent) +{ + myName = tr("DHCP server"); + myServerCount++; + myServerName = QString("Server%1").arg(myServerCount); + myDemons.clear(); + qDeleteAll(myDemons); +} + +DhcpServerProgram::~DhcpServerProgram() +{ + myDevice->disposeSocket(receiver); + myDemons.clear(); + qDeleteAll(myDemons); +} + +void DhcpServerProgram::setDevice(SmartDevice *s) +{ + if ( s == 0 ) return; + Program::setDevice(s); + receiver = myDevice->openSocket(DhcpDemon::SERVER_SOCKET, SocketFactory::UDP); + //receiver = new udpSocket(myDevice, SERVER_SOCKET); + foreach ( Interface *i, myDevice->interfaces() ) { + if ( i->isConnect() ) { + DhcpDemon *demon = new DhcpDemon(i); + myDemons << demon; + } + } + receiver->setBind("0.0.0.0"); + connect( receiver , SIGNAL(readyRead(QByteArray)), SLOT(execute(QByteArray))); + connect( myDevice, SIGNAL(interfaceConnected(QString)), SLOT(checkInterface(QString)) ); +} + +//void dhcpServerProgramm::checkInterface(QString port) +//{ +// if ( myInterface.isEmpty() ) setInterfaceName(port); +//} + +void DhcpServerProgram::execute(QByteArray data) +{ + DhcpPacket packet(data); + foreach ( DhcpDemon *demon, myDemons ) { + IpAddress deviceIp = myDevice->adapter(demon->interfaceName())->ip(); + if ( deviceIp.isEmpty() ) { + QMessageBox::warning(0,tr("Warning"), + tr("Your DHCP server <i>%1</i> isn't configured.").arg(myServerName), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + + if ( deviceIp == packet.siaddr() ) { + switch ( packet.type() ) { + case DhcpPacket::DHCPDISCOVER : + demon->executeDiscover(packet); + break; + case DhcpPacket::DHCPREQUEST : + demon->executeRequest(packet); + break; + case DhcpPacket::DHCPDECLINE : + demon->executeDecline(packet); + break; + } + } + } +} + + + +void DhcpServerProgram::incTime() +{ + foreach ( DhcpDemon *demon, myDemons ) { + demon->incTime(); + } +} + +void DhcpServerProgram::showProperty() +{ + DhcpServerProperty *d = new DhcpServerProperty(myDevice); + d->setProgramm(this); + d->exec(); +} + +/*! + Записывает отличительные черты в поток. + @param stream - поток для записи. +*/ +void DhcpServerProgram::write(QDataStream &stream) const +{ + stream << DHCPServer; + Program::write(stream); + DhcpDemon *d = myDemons.at(0); + d->dhcpModel()->write(stream); + stream << d->interfaceName(); + stream << d->beginIp(); + stream << d->endIp(); + stream << d->mask(); + stream << d->gateway(); + stream << d->time(); + stream << d->dynamic(); + stream << d->waitingTime(); +} +//--------------------------------------------------- + +/*! + Считывает отличительные черты из потока. + @param stream - поток для чтения. +*/ +void DhcpServerProgram::read(QDataStream &stream) +{ + Program::read(stream); + DhcpDemon *d = new DhcpDemon(device()->interfaces().at(0)); + d->dhcpModel()->read(stream); + d->read(stream); +} +//--------------------------------------------------- + + + +//--------------------------------------------------- +//СlientState::СlientState(StaticDhcpRecord *rec) +//{ +// ip = rec->yiaddr; +// mac = rec->chaddr; +// mask = rec->mask; +// gateway = rec->gateway; +// time = rec->time; +//} + Copied: trunk/src/programs/dhcpserverprogram.h (from rev 240, trunk/src/programms/dhcpserverprogramm.h) =================================================================== --- trunk/src/programs/dhcpserverprogram.h (rev 0) +++ trunk/src/programs/dhcpserverprogram.h 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,63 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#ifndef DHCPSERVERPROGRAMM_H +#define DHCPSERVERPROGRAMM_H + +#include "program.h" +#include "dhcpdemon.h" + +class AbstractSocket; + +class DhcpServerProgram : public Program +{ + Q_OBJECT +public: + enum { DHCPServer = 2 }; + DhcpServerProgram(QObject *parent = 0); + ~DhcpServerProgram(); + +// Атрибуты +public: + int id() const { return DHCPServer; } + void setDevice(SmartDevice *s); + void setServerName(QString n) { myServerName = n; } + QString serverName() const { return myServerName; } + virtual QString featureName() const { return "ds"; } +public: + void showProperty(); + void incTime(); + bool interrupt(int) { return false; } + void write(QDataStream &stream) const; + void read(QDataStream &stream); + +// Слоты +public slots: + void execute(QByteArray data); +// void checkInterface(QString port); + +// Переменные +private: + static int myServerCount; + QString myServerName; + QList<DhcpDemon*> myDemons; + AbstractSocket *receiver; +}; + +#endif // DHCPSERVERPROGRAMM_H Deleted: trunk/src/programs/dhcpserverprogramm.cpp =================================================================== --- trunk/src/programms/dhcpserverprogramm.cpp 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpserverprogramm.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -1,159 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#include "dhcpserverprogramm.h" -#include "dhcpserverproperty.h" -#include "dhcppacket.h" -#include "smartdevice.h" -#include "udpsocket.h" -#include "socketfactory.h" -#include <QMessageBox> - -#include "dhcpservermodel.h" - -int DhcpServerProgram::myServerCount = 0; - -DhcpServerProgram::DhcpServerProgram(QObject *parent) : Program(parent) -{ - myName = tr("DHCP server"); - myServerCount++; - myServerName = QString("Server%1").arg(myServerCount); - myDemons.clear(); - qDeleteAll(myDemons); -} - -DhcpServerProgram::~DhcpServerProgram() -{ - myDevice->disposeSocket(receiver); - myDemons.clear(); - qDeleteAll(myDemons); -} - -void DhcpServerProgram::setDevice(SmartDevice *s) -{ - if ( s == 0 ) return; - Program::setDevice(s); - receiver = myDevice->openSocket(DhcpDemon::SERVER_SOCKET, SocketFactory::UDP); - //receiver = new udpSocket(myDevice, SERVER_SOCKET); - foreach ( Interface *i, myDevice->interfaces() ) { - if ( i->isConnect() ) { - DhcpDemon *demon = new DhcpDemon(i); - myDemons << demon; - } - } - receiver->setBind("0.0.0.0"); - connect( receiver , SIGNAL(readyRead(QByteArray)), SLOT(execute(QByteArray))); - connect( myDevice, SIGNAL(interfaceConnected(QString)), SLOT(checkInterface(QString)) ); -} - -//void dhcpServerProgramm::checkInterface(QString port) -//{ -// if ( myInterface.isEmpty() ) setInterfaceName(port); -//} - -void DhcpServerProgram::execute(QByteArray data) -{ - DhcpPacket packet(data); - foreach ( DhcpDemon *demon, myDemons ) { - IpAddress deviceIp = myDevice->adapter(demon->interfaceName())->ip(); - if ( deviceIp.isEmpty() ) { - QMessageBox::warning(0,tr("Warning"), - tr("Your DHCP server <i>%1</i> isn't configured.").arg(myServerName), - QMessageBox::Ok, QMessageBox::Ok); - return; - } - - if ( deviceIp == packet.siaddr() ) { - switch ( packet.type() ) { - case DhcpPacket::DHCPDISCOVER : - demon->executeDiscover(packet); - break; - case DhcpPacket::DHCPREQUEST : - demon->executeRequest(packet); - break; - case DhcpPacket::DHCPDECLINE : - demon->executeDecline(packet); - break; - } - } - } -} - - - -void DhcpServerProgram::incTime() -{ - foreach ( DhcpDemon *demon, myDemons ) { - demon->incTime(); - } -} - -void DhcpServerProgram::showProperty() -{ - DhcpServerProperty *d = new DhcpServerProperty(myDevice); - d->setProgramm(this); - d->exec(); -} - -/*! - Записывает отличительные черты в поток. - @param stream - поток для записи. -*/ -void DhcpServerProgram::write(QDataStream &stream) const -{ - stream << DHCPServer; - Program::write(stream); - DhcpDemon *d = myDemons.at(0); - d->dhcpModel()->write(stream); - stream << d->interfaceName(); - stream << d->beginIp(); - stream << d->endIp(); - stream << d->mask(); - stream << d->gateway(); - stream << d->time(); - stream << d->dynamic(); - stream << d->waitingTime(); -} -//--------------------------------------------------- - -/*! - Считывает отличительные черты из потока. - @param stream - поток для чтения. -*/ -void DhcpServerProgram::read(QDataStream &stream) -{ - Program::read(stream); - DhcpDemon *d = new DhcpDemon(device()->interfaces().at(0)); - d->dhcpModel()->read(stream); - d->read(stream); -} -//--------------------------------------------------- - - - -//--------------------------------------------------- -//СlientState::СlientState(StaticDhcpRecord *rec) -//{ -// ip = rec->yiaddr; -// mac = rec->chaddr; -// mask = rec->mask; -// gateway = rec->gateway; -// time = rec->time; -//} - Deleted: trunk/src/programs/dhcpserverprogramm.h =================================================================== --- trunk/src/programms/dhcpserverprogramm.h 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpserverprogramm.h 2011-02-11 23:05:12 UTC (rev 243) @@ -1,63 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#ifndef DHCPSERVERPROGRAMM_H -#define DHCPSERVERPROGRAMM_H - -#include "programmrep.h" -#include "dhcpdemon.h" - -class AbstractSocket; - -class DhcpServerProgram : public Program -{ - Q_OBJECT -public: - enum { DHCPServer = 2 }; - DhcpServerProgram(QObject *parent = 0); - ~DhcpServerProgram(); - -// Атрибуты -public: - int id() const { return DHCPServer; } - void setDevice(SmartDevice *s); - void setServerName(QString n) { myServerName = n; } - QString serverName() const { return myServerName; } - virtual QString featureName() const { return "ds"; } -public: - void showProperty(); - void incTime(); - bool interrupt(int) { return false; } - void write(QDataStream &stream) const; - void read(QDataStream &stream); - -// Слоты -public slots: - void execute(QByteArray data); -// void checkInterface(QString port); - -// Переменные -private: - static int myServerCount; - QString myServerName; - QList<DhcpDemon*> myDemons; - AbstractSocket *receiver; -}; - -#endif // DHCPSERVERPROGRAMM_H Copied: trunk/src/programs/program.cpp (from rev 240, trunk/src/programms/programmrep.cpp) =================================================================== --- trunk/src/programs/program.cpp (rev 0) +++ trunk/src/programs/program.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,87 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#include "program.h" +#include "smartdevice.h" +#include "ripprogram.h" +#include "dhcpserverprogram.h" +#include "dhcpclientprogram.h" +#include "spoofingprogram.h" + +static const int MAGIC_PROGRAMM_NUMBER = 50; + +Program::Program(QObject *parent) : QObject(parent) +{ +} + +Program::~Program() +{ +} + +void Program::setEnable(bool b) +{ + if ( b != myEnable ) { + myEnable = b; + } +} + +void Program::updateView() +{ + myDevice->updateView(); +} + +Program* Program::createFromStream(QObject *parent, QDataStream &stream) +{ + int n; + stream >> n; + Program *p = createImpl(parent,n); + p->read(stream); + return p; +} + +Program* Program::createImpl(QObject *parent, int n) +{ + switch (n%MAGIC_PROGRAMM_NUMBER) { + case RIP: return new RipProgram(parent); + case DHCPClient : return new DhcpClientProgram(parent); + case DHCPServer : return new DhcpServerProgram(parent); + case SPOOFING : return new SpoofingProgram(parent); + default: break; + } + return 0; +} + +/*! + Записывает программу в поток. + @param stream - поток для записи. +*/ +void Program::write(QDataStream &stream) const +{ + stream << myEnable; +} +//-------------------------------------------- +/*! + Считывает программу из потока. + @param stream - поток для чтения. +*/ +void Program::read(QDataStream &stream) +{ + stream >> myEnable; +} +//------------------------------------------- Copied: trunk/src/programs/program.h (from rev 240, trunk/src/programms/programmrep.h) =================================================================== --- trunk/src/programs/program.h (rev 0) +++ trunk/src/programs/program.h 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,64 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#ifndef PROGRAMMREP_H +#define PROGRAMMREP_H + +#include <QDataStream> + +class Device; +class SmartDevice; +class Program; + +typedef QList<Program*> ProgramList; + +class Program : public QObject +{ + Q_OBJECT + Q_PROPERTY( bool enable READ isEnable WRITE setEnable ) +public: + Program(QObject *parent = 0); + virtual ~Program(); + + static Program* createFromStream(QObject *parent , QDataStream &stream); + static Program* createImpl(QObject *parent , int n); + +public: + enum { RIP = 0 , DHCPClient = 1 , DHCPServer = 2, SPOOFING = 3 }; + + void setEnable(bool b); + bool isEnable() const { return myEnable; } + QString name() const { return myName; } + virtual void setDevice(SmartDevice *s) { myDevice = s; } + void updateView(); + SmartDevice* device() const { return myDevice; } + virtual bool interrupt(int u) = 0; + virtual void showProperty() = 0; + virtual QString featureName() const = 0; + virtual void incTime() { } + virtual void write(QDataStream &stream) const; + virtual void read(QDataStream &stream); + virtual int id() const = 0; +protected: + SmartDevice *myDevice; + bool myEnable; + QString myName; //!< Имя программы. +}; + +#endif // PROGRAMMREP_H Deleted: trunk/src/programs/programmrep.cpp =================================================================== --- trunk/src/programms/programmrep.cpp 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/programmrep.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -1,87 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#include "programmrep.h" -#include "smartdevice.h" -#include "ripprogramm.h" -#include "dhcpserverprogramm.h" -#include "dhcpclientprogramm.h" -#include "spoofingprogramm.h" - -static const int MAGIC_PROGRAMM_NUMBER = 50; - -Program::Program(QObject *parent) : QObject(parent) -{ -} - -Program::~Program() -{ -} - -void Program::setEnable(bool b) -{ - if ( b != myEnable ) { - myEnable = b; - } -} - -void Program::updateView() -{ - myDevice->updateView(); -} - -Program* Program::createFromStream(QObject *parent, QDataStream &stream) -{ - int n; - str... [truncated message content] |