Skip to content

Commit

Permalink
Change "bool drop" > "int dropRate"
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbert Lee committed Jul 30, 2014
1 parent 4401da8 commit 5990b64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions include/process/snoopblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REGISTER_METACLASS(SnoopBlock, SnoopProcess)
// ----------------------------------------------------------------------------
SnoopBlock::SnoopBlock(void* owner) : SnoopProcess(owner)
{
drop = true;
dropRate = 100;
}

SnoopBlock::~SnoopBlock()
Expand All @@ -17,36 +17,37 @@ SnoopBlock::~SnoopBlock()

void SnoopBlock::block(SnoopPacket* packet)
{
if (this->drop)
int r = rand() % 100; // 0 <= r <= 99
if (r < dropRate)
packet->drop = true;
}

void SnoopBlock::load(VXml xml)
{
SnoopProcess::load(xml);

drop = xml.getBool("drop", drop);
dropRate = xml.getInt("dropRate", dropRate);
}

void SnoopBlock::save(VXml xml)
{
SnoopProcess::save(xml);

xml.setBool("drop", drop);
xml.setInt("dropRate", dropRate);
}

#ifdef QT_GUI_LIB
void SnoopBlock::optionAddWidget(QLayout* layout)
{
SnoopProcess::optionAddWidget(layout);

VOptionable::addCheckBox(layout, "chkDrop", "Drop", drop);
VOptionable::addLineEdit(layout, "leDropRate", "Drop Rate(%)", QString::number(dropRate));
}

void SnoopBlock::optionSaveDlg(QDialog* dialog)
{
SnoopProcess::optionSaveDlg(dialog);

drop = dialog->findChild<QCheckBox*>("chkDrop")->checkState() == Qt::Checked;
dropRate = dialog->findChild<QLineEdit*>("leDropRate")->text().toInt();
}
#endif // QT_GUI_LIB
2 changes: 1 addition & 1 deletion include/process/snoopblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SnoopBlock : public SnoopProcess
virtual ~SnoopBlock();

public:
bool drop;
int dropRate; // 0%(all allow) ~ 100%(all drop)

public slots:
void block(SnoopPacket* packet);
Expand Down

0 comments on commit 5990b64

Please sign in to comment.