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

Commit

Permalink
Browse files Browse the repository at this point in the history
[tools] contextkit-monitor
Signed-off-by: Denis Zalevskiy <denis.zalevskiy@jolla.com>
  • Loading branch information
Denis Zalevskiy committed Oct 29, 2013
1 parent e91ddf6 commit 39661b2
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -90,6 +90,7 @@ endif(ENABLE_QT4)
add_subdirectory(src/util)
add_subdirectory(src/contextkit-subscriber)
add_subdirectory(tests)
add_subdirectory(tools/monitor)

MESSAGE(STATUS "QT4=${ENABLE_QT4}")
MESSAGE(STATUS "STATEFS_QT_VERSION=${STATEFS_QT_VERSION}")
1 change: 1 addition & 0 deletions rpm/statefs-qt5.spec
Expand Up @@ -85,6 +85,7 @@ rm -rf %{buildroot}
%files %{subscriber}
%defattr(-,root,root,-)
%{_libdir}/libcontextkit-statefs-qt5.so
%{_bindir}/contextkit-monitor

%files %{subscriber_devel}
%defattr(-,root,root,-)
Expand Down
34 changes: 34 additions & 0 deletions tools/monitor/CMakeLists.txt
@@ -0,0 +1,34 @@
if(ENABLE_QT4)
# target_link_libraries(contextkit-monitor
# ${QT_QTCORE_LIBRARY}
# )

MESSAGE(STATUS "Monitor tool is not built for Qt4")

else(ENABLE_QT4)

# fix for gcc 4.6 specific compiling/linking issues, no dwarf-4
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -gdwarf-3"
)

set(CMAKE_AUTOMOC TRUE)

add_executable(contextkit-monitor monitor.cpp)
target_link_libraries(contextkit-monitor
contextkit-statefs-qt5
statefs-qt5
)

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

add_executable(file-monitor filemon.cpp)

target_link_libraries(file-monitor
${Qt5Core_LIBRARIES}
)

endif(ENABLE_QT4)
45 changes: 45 additions & 0 deletions tools/monitor/filemon.cpp
@@ -0,0 +1,45 @@
#include <QCoreApplication>
#include <QString>
#include <QStringList>
#include <QDebug>
#include <QDir>
#include <QRegExp>
#include <QSocketNotifier>
#include <map>
#include <memory>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
auto args = app.arguments();
if (args.size() <= 1) {
qDebug() << "Usage: " << args[0] << " <namespace_path>...";
return -1;
}
auto dirname = args[1];
QDir d(dirname);
auto files = d.entryList(QDir::Files);
auto prefix = d.path() + "/";
files = files.replaceInStrings(QRegExp("^"), prefix);
qDebug() << files;

auto begin = files.begin(), end = files.end();
for (auto pos = begin; pos != end; ++pos) {
auto f = std::make_shared<QFile>(*pos);
f->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
auto p = std::make_shared<QSocketNotifier>(f->handle(), QSocketNotifier::Read);
app.connect(p.get(), &QSocketNotifier::activated, [p, f](int) mutable {
qDebug() << "Activated " << f->fileName() << ", " << f->isOpen();
//p->setEnabled(false);
//QFile touchFile(f->fileName());
//touchFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered);
f->seek(0);
QByteArray buf(128, 0);
qDebug() << f->read(buf.data(), 120);
qDebug() << "(" << QString(buf) << ")";
//p->setEnabled(true);
});
p->setEnabled(true);
}
return app.exec();
}
34 changes: 34 additions & 0 deletions tools/monitor/monitor.cpp
@@ -0,0 +1,34 @@
#include <QCoreApplication>
#include <contextproperty.h>
#include <QString>
#include <QStringList>
#include <QDebug>
#include <QDir>
#include <QRegExp>
#include <map>
#include <memory>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
auto args = app.arguments();
if (args.size() <= 1) {
qDebug() << "Usage: " << args[0] << " <namespace_path>...";
return -1;
}
auto dirname = args[1];
QDir d(dirname);
auto files = d.entryList(QDir::Files);
auto prefix = d.dirName() + ".";
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();
});
}
return app.exec();
}

0 comments on commit 39661b2

Please sign in to comment.