summaryrefslogtreecommitdiff
path: root/watchserver.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-09-16 17:47:24 +0200
committerJavier <javier@pcjavier.(none)>2011-09-16 17:47:24 +0200
commitaa1c0fd3146b4ed055d181c99d52463afa6bedbb (patch)
treef6fb8d9693ad8c545ddabf76312f8f33b5b9878f /watchserver.cpp
downloadsowatch-aa1c0fd3146b4ed055d181c99d52463afa6bedbb.tar.gz
sowatch-aa1c0fd3146b4ed055d181c99d52463afa6bedbb.zip
Initial import
Diffstat (limited to 'watchserver.cpp')
-rw-r--r--watchserver.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/watchserver.cpp b/watchserver.cpp
new file mode 100644
index 0000000..ad49995
--- /dev/null
+++ b/watchserver.cpp
@@ -0,0 +1,57 @@
+#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::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();
+ }
+}