summaryrefslogtreecommitdiff
path: root/libsowatch/watchserver.cpp
blob: 5ee8a9029930cfc45f91c9190a57c80ec17a5145 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "watch.h"
#include "watchlet.h"
#include "watchserver.h"

using namespace sowatch;

WatchServer::WatchServer(Watch* watch, QObject* parent) :
	QObject(parent), _watch(watch), _currentWatchlet(0)
{
	connect(_watch, SIGNAL(connected()), SLOT(watchConnected()));
	connect(_watch, SIGNAL(disconnected()), SLOT(watchDisconnected()));
}

Watch* WatchServer::watch()
{
	return _watch;
}

void WatchServer::runWatchlet(const QString& id)
{
	if (_currentWatchlet) {
		closeWatchlet();
	}
	_currentWatchlet = watchlets[id];
	if (_watch->isConnected()) {
		_currentWatchlet->activate();
	}
}

void WatchServer::closeWatchlet()
{
	Q_ASSERT(_currentWatchlet != 0);
	if (_watch->isConnected()) {
		_currentWatchlet->deactivate();
	}
	_currentWatchlet = 0;
}

void WatchServer::notification(const Notification &n)
{
	Q_UNUSED(n);
}

void WatchServer::registerWatchlet(Watchlet *watchlet)
{
	Q_ASSERT(watchlet->_server == this);
	watchlets[watchlet->id()] = watchlet;
}

void WatchServer::watchConnected()
{
	if (_currentWatchlet) {
		_currentWatchlet->activate();
	}
}

void WatchServer::watchDisconnected()
{
	if (_currentWatchlet) {
		_currentWatchlet->deactivate();
	}
}