Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
tool: basic support for property writing
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Zalevskiy <denis.zalevskiy@jolla.com>
  • Loading branch information
Denis Zalevskiy committed Nov 14, 2014
1 parent 4268258 commit a63f3f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions tools/monitor/CMakeLists.txt
Expand Up @@ -13,6 +13,7 @@ target_link_libraries(contextkit-monitor

target_link_libraries(contextkit-monitor
${Qt5Core_LIBRARIES}
${QTAROUND_LIBRARIES}
)
install(TARGETS contextkit-monitor DESTINATION bin)

Expand Down
42 changes: 33 additions & 9 deletions tools/monitor/monitor.cpp
Expand Up @@ -5,15 +5,19 @@
#include <QDebug>
#include <QDir>
#include <QRegExp>
#include <QTimer>
#include <map>
#include <memory>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <QSocketNotifier>
#include <qtaround/debug.hpp>
#include <statefs/qt/client.hpp>

namespace debug = qtaround::debug;

static int sigFd[2];

void onExit(int)
Expand All @@ -30,10 +34,28 @@ int usage(QStringList const &args, int rc)

void writeProp(QString const &key, QString const &v)
{
auto w = new statefs::qt::PropertyWriter{key};
using statefs::qt::PropertyWriter;
auto app = QCoreApplication::instance();
debug::info("Writing", key, "=", v);
auto w = new PropertyWriter{key, app};
app->connect(w, &PropertyWriter::updated, [key](bool b) {
debug::info("Updated?", b, key);
});
w->set(v);
}

void monitorProps(QStringList keys)
{
using statefs::qt::DiscreteProperty;
auto app = QCoreApplication::instance();
for (auto name : keys) {
auto p = new DiscreteProperty(name, app);
app->connect(p, &DiscreteProperty::changed, [name](QVariant v) {
debug::info(name, "=", v);
});
}
}

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Expand All @@ -51,11 +73,16 @@ int main(int argc, char *argv[])
});
for (auto i : {SIGTERM, SIGINT})
::signal(i, onExit);

auto t = new QTimer(&app);
t->setSingleShot(true);
if (args[1] == "-w") {
if (args.size() <= 3)
return usage(args, -1);

writeProp(args[2], args[3]);
app.connect(t, &QTimer::timeout, [args]() {
writeProp(args[2], args[3]);
});
} else {
auto dirname = args[1];
QDir d(dirname);
Expand All @@ -64,13 +91,10 @@ int main(int argc, char *argv[])
files = files.replaceInStrings(QRegExp("^"), prefix);
qDebug() << files;

auto begin = files.begin(), end = files.end();
for (auto pos = begin; pos != end; ++pos) {
auto p = std::make_shared<ContextProperty>(*pos);
app.connect(p.get(), &ContextProperty::valueChanged, [p]() {
qDebug() << p->key() << "=" << p->value();
});
}
app.connect(t, &QTimer::timeout, [files]() {
monitorProps(files);
});
}
t->start(0);
return app.exec();
}

0 comments on commit a63f3f5

Please sign in to comment.