Skip to content

Commit

Permalink
Monitor: Use enum instead of bool for schedulerState
Browse files Browse the repository at this point in the history
  • Loading branch information
krf committed Oct 26, 2014
1 parent 162e5d1 commit f574a2f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/fakemonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ FakeMonitor::FakeMonitor(HostInfoManager* manager, QObject* parent)
m_updateTimer->start();
connect(m_updateTimer, SIGNAL(timeout()), SLOT(update()));

setSchedulerState(true);
setSchedulerState(Online);

for (HostId i = 0; i < MAX_HOST_COUNT; ++i) {
createHostInfo(i+1);
Expand Down
8 changes: 4 additions & 4 deletions src/icecreammonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void IcecreamMonitor::checkScheduler(bool deleteit)
m_fd_type = QSocketNotifier::Exception;
delete m_discover;
m_discover = 0;
setSchedulerState(false);
setSchedulerState(Offline);
} else if ( m_scheduler )
return;
QTimer::singleShot( 1000+(qrand()&1023), this, SLOT( slotCheckScheduler() ) ); // TODO: check if correct
Expand Down Expand Up @@ -134,7 +134,7 @@ void IcecreamMonitor::slotCheckScheduler()
QTimer::singleShot(0, this, SLOT(slotCheckScheduler()));
}
else {
setSchedulerState( true );
setSchedulerState(Online);
}
return;
}
Expand All @@ -154,7 +154,7 @@ void IcecreamMonitor::slotCheckScheduler()
QTimer::singleShot(1000+(qrand()&1023), this, SLOT(slotCheckScheduler()));

}
setSchedulerState( false );
setSchedulerState(Offline);
}

void IcecreamMonitor::msgReceived()
Expand All @@ -169,7 +169,7 @@ bool IcecreamMonitor::handle_activity()
Msg *m = m_scheduler->get_msg ();
if ( !m ) {
checkScheduler( true );
setSchedulerState( false );
setSchedulerState(Offline);
return false;
}

Expand Down
12 changes: 6 additions & 6 deletions src/monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Monitor::Monitor(HostInfoManager *manager, QObject *parent)
: QObject(parent)
, m_hostInfoManager(manager)
, m_schedulerState(false)
, m_schedulerState(Offline)
{
}

Expand All @@ -39,18 +39,18 @@ void Monitor::setCurrentNetname(const QByteArray& netname)
m_currentNetname = netname;
}

bool Monitor::schedulerState() const
Monitor::SchedulerState Monitor::schedulerState() const
{
return m_schedulerState;
}

void Monitor::setSchedulerState( bool online )
void Monitor::setSchedulerState(SchedulerState state)
{
if (m_schedulerState == online)
if (m_schedulerState == state)
return;

m_schedulerState = online;
emit schedulerStateChanged( online );
m_schedulerState = state;
emit schedulerStateChanged(state);
}

QList<Job> Monitor::jobHistory() const
Expand Down
16 changes: 11 additions & 5 deletions src/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,31 @@ class Job;
class Monitor : public QObject
{
Q_OBJECT
Q_PROPERTY(bool schedulerState READ schedulerState WRITE setSchedulerState NOTIFY schedulerStateChanged)
Q_PROPERTY(SchedulerState schedulerState READ schedulerState WRITE setSchedulerState NOTIFY schedulerStateChanged)
Q_ENUMS(SchedulerState)

public:
enum SchedulerState {
Online,
Offline,
};

explicit Monitor(HostInfoManager *manager, QObject* parent = 0);

QByteArray currentNetname() const;
void setCurrentNetname(const QByteArray &);

bool schedulerState() const;
SchedulerState schedulerState() const;

virtual QList<Job> jobHistory() const;

HostInfoManager *hostInfoManager() const { return m_hostInfoManager; }

protected:
void setSchedulerState(bool online);
void setSchedulerState(SchedulerState online);

Q_SIGNALS:
void schedulerStateChanged(bool);
void schedulerStateChanged(SchedulerState);

void jobUpdated(const Job& job);
void nodeRemoved(HostId id);
Expand All @@ -63,7 +69,7 @@ class Monitor : public QObject
private:
HostInfoManager *m_hostInfoManager;
QByteArray m_currentNetname;
bool m_schedulerState;
SchedulerState m_schedulerState;
};

#endif // ICEMON_MONITOR_H

0 comments on commit f574a2f

Please sign in to comment.