Source Code (Use browser search to find items of interest.)
Class Index
kppp'Accounting (./kdenetwork/kppp/accounting.h:82)
class Accounting : public AccountingBase {
Q_OBJECT
public:
Accounting(QObject *parent, PPPStats *st);
virtual double total();
virtual double session();
virtual bool loadRuleSet(const char *name);
virtual bool running();
private:
virtual void timerEvent(QTimerEvent *t);
public slots:
virtual void slotStart();
virtual void slotStop();
signals:
void changed(QString total, QString session);
private:
int acct_timer_id;
int update_timer_id;
time_t start_time;
double _lastcosts;
double _lastlen;
RuleSet rules;
PPPStats *stats;
};
/////////////////////////////////////////////////////////////////////////////
//
// Accounting based on executable files
//
/////////////////////////////////////////////////////////////////////////////
kppp'Accounting::Accounting() (./kdenetwork/kppp/accounting.cpp:218)
Accounting::Accounting(QObject *parent, PPPStats *st) :
AccountingBase(parent),
acct_timer_id(0),
update_timer_id(0),
stats(st)
{
}
kppp'Accounting::running() (./kdenetwork/kppp/accounting.cpp:227)
bool Accounting::running() {
return (bool)(acct_timer_id != 0);
}
kppp'Accounting::timerEvent() (./kdenetwork/kppp/accounting.cpp:232)
void Accounting::timerEvent(QTimerEvent *t) {
if(t->timerId() == acct_timer_id) {
double newCosts;
double newLen;
double connect_time = difftime(time(0), start_time);
rules.getActiveRule(QDateTime::currentDateTime(), connect_time, newCosts, newLen);
if(newLen < 1) { // changed to < 1
slotStop();
return; // no default rule found
}
// check if we have a new rule. If yes,
// kill the timer and restart it with new
// duration
if((newCosts != _lastcosts) || (newLen != _lastlen)) {
kdDebug(5002).form("SWITCHING RULES, new costs = %0.2f, new len = %0.2f\n",
newCosts, newLen);
killTimer(acct_timer_id);
if(newLen > 0)
acct_timer_id = startTimer((int)(newLen * 1000.0));
_lastlen = newLen;
_lastcosts = newCosts;
}
// emit changed() signal if necessary
if(newCosts != 0) {
_session += newCosts;
emit changed(rules.currencyString(total()),
rules.currencyString(session()));
}
} // if(t->timerId() == acct_timer_id)...
if(t->timerId() == update_timer_id) {
// just to be sure, save the current costs
// every n seconds (see UPDATE_TIME)
saveCosts();
}
}
kppp'Accounting::slotStart() (./kdenetwork/kppp/accounting.cpp:279)
void Accounting::slotStart() {
if(!running()) {
loadCosts();
_lastcosts = 0.0;
_lastlen = 0.0;
_session = rules.perConnectionCosts();
rules.setStartTime(QDateTime::currentDateTime());
acct_timer_id = startTimer(1);
if(UPDATE_TIME > 0)
update_timer_id = startTimer(UPDATE_TIME);
start_time = time(0);
QString s;
s = timet2qstring(start_time);
s += ":";
s += gpppdata.accname();
s += ":";
s += rules.currencySymbol();
logMessage(s, TRUE);
}
}
kppp'Accounting::slotStop() (./kdenetwork/kppp/accounting.cpp:303)
void Accounting::slotStop() {
if(running()) {
killTimer(acct_timer_id);
if(update_timer_id != 0)
killTimer(update_timer_id);
acct_timer_id = 0;
update_timer_id = 0;
QString s;
s.sprintf(":%s:%0.4e:%0.4e:%u:%u\n",
timet2qstring(time(0)).data(),
session(),
total(),
stats->ibytes,
stats->obytes);
logMessage(s, FALSE);
saveCosts();
}
}
kppp'Accounting::loadRuleSet() (./kdenetwork/kppp/accounting.cpp:325)
bool Accounting::loadRuleSet(const char *name) {
if(strlen(name) == 0) {
rules.load(""); // delete old rules
return TRUE;
}
QString d = AccountingBase::getAccountingFile(name);
QFileInfo fg(d);
if(fg.exists()) {
int ret = rules.load(d.data());
_name = rules.name();
return (bool)(ret == 0);
}
return FALSE;
}
kppp'Accounting::total() (./kdenetwork/kppp/accounting.cpp:345)
double Accounting::total() {
if(rules.minimumCosts() <= _session)
return _total + _session;
else
return _total + rules.minimumCosts();
}
kppp'Accounting::session() (./kdenetwork/kppp/accounting.cpp:354)
double Accounting::session() {
if(rules.minimumCosts() <= _session)
return _session;
else
return rules.minimumCosts();
}