diff options
Diffstat (limited to 'sandbox')
40 files changed, 0 insertions, 1012 deletions
diff --git a/sandbox/context-proxy b/sandbox/context-proxy deleted file mode 100755 index 2b6a366b..00000000 --- a/sandbox/context-proxy +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/python - -from sys import stderr, stdin -from subprocess import Popen, PIPE -from select import select -import re -import os - -class Program: - def __init__(self, cline): - d = dict(os.environ) - d.update({"CONTEXT_CLI_DISABLE_TYPE_CHECK": "1", - "CONTEXT_CLI_IGNORE_COMMANDER": "1"}) - - self.__process = Popen(cline, stdin=PIPE, stdout=PIPE, stderr=PIPE, - env = d) - - def send(self, string): - print >>self.__process.stdin, string - self.__process.stdin.flush() - - def outfd(self): - return self.__process.stdout.fileno() - - def readline(self): - return self.__process.stdout.readline() - - def ready(self): - raise NotImplementedError - -class Listen(Program): - def __init__(self, *properties): - Program.__init__(self, ["context-listen"] + list(properties)) - - def ready(self): - global provide - line = self.readline() - if line: - print >>stderr, "LISTEN:", line, - match = re.match("(.*?) = (.*?):(.*)\n", line) - if match: - property = match.group(1) - type = "" - if match.group(2) == "QString": - type = "string" - elif match.group(2) == "int": - type = "int" - elif match.group(2) == "bool": - type = "truth" - elif match.group(2) == "double": - type = "double" - else: - raise RuntimeError("unknown type from client: " + match.group(2)) - value = match.group(3) - provide.send("add " + type + " " + property + " " + value) - match = re.match("(.*?) is Unknown\n", line) - if match: - property = match.group(1) - provide.send("add " + type + " " + property) - provide.send("unset " + property) - - return True - else: - raise RuntimeError("context-listen terminated") - -class Provide(Program): - def __init__(self): - Program.__init__(self, ["context-provide-internal"]) - - def ready(self): - line = self.readline() - if line: - print "PROVIDE:", line, - return True - else: - raise RuntimeError("context-provide terminated") - -class UserInput(): - def outfd(self): - return stdin.fileno() - - def ready(self): - line = self.readline() - if line: - match = re.match("(.*?) (.*)\n", line) - command = match.group(1) - return True - else: - exit(0) - -class Select: - def __init__(self, *tools): - self.map = dict(map(lambda t: (t.outfd(), t), tools)) - self.rlist = map(lambda t: t.outfd(), tools) - - def select(self): - ret = select(self.rlist, [], [])[0] - for i in ret: - stderr.flush() - if not self.map[i].ready(): - self.rlist.remove(i) - del self.map[i] - -listen = Listen("test.a", "test.b") -provide = Provide() -provide.send("start") -s = Select(listen, provide) - -while True: - s.select() - if not s.rlist: - break diff --git a/sandbox/messaging-to-self/main.cpp b/sandbox/messaging-to-self/main.cpp deleted file mode 100644 index aafda83c..00000000 --- a/sandbox/messaging-to-self/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include <QCoreApplication> -#include <QDebug> -#include <QThread> -#include "myobject.h" -#include "mythread.h" - -int main(int argc, char **argv) -{ - QCoreApplication app(argc, argv); - - qDebug() << "main thread:" << QThread::currentThread(); - - MyObject a; - MyThread t(&a); - t.start(); - -// sleep(1); - - return app.exec(); -} diff --git a/sandbox/messaging-to-self/messaging-to-self.pro b/sandbox/messaging-to-self/messaging-to-self.pro deleted file mode 100644 index bafbb027..00000000 --- a/sandbox/messaging-to-self/messaging-to-self.pro +++ /dev/null @@ -1,12 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Mon Jun 15 11:49:08 2009 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -# Input -HEADERS += myobject.h mythread.h queuedinvoker.h -SOURCES += main.cpp queuedinvoker.cpp diff --git a/sandbox/messaging-to-self/myobject.h b/sandbox/messaging-to-self/myobject.h deleted file mode 100644 index 155ebf3b..00000000 --- a/sandbox/messaging-to-self/myobject.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef MYOBJECT_H -#define MYOBJECT_H - -#include "queuedinvoker.h" -#include <QDebug> -#include <QThread> - -class MyObject : public QueuedInvoker -{ - Q_OBJECT - -private: - int x; - -public: - MyObject() : x(0) - { - } - - Q_INVOKABLE void five() - { - qDebug() << "MyObject::five" << QThread::currentThread() << ++x; - } - Q_INVOKABLE void six() - { - qDebug() << "MyObject::six" << QThread::currentThread() << ++x; - } - Q_INVOKABLE void seven() - { - qDebug() << "MyObject::seven" << QThread::currentThread() << ++x; - } -}; -#endif - - diff --git a/sandbox/messaging-to-self/mythread.h b/sandbox/messaging-to-self/mythread.h deleted file mode 100644 index 4170ccf8..00000000 --- a/sandbox/messaging-to-self/mythread.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef MYTHREAD_H -#define MYTHREAD_H - -#include <QThread> -#include <QDebug> -#include "myobject.h" - -class MyThread : public QThread -{ - Q_OBJECT - -private: - MyObject *obj; - -public: - MyThread(MyObject *obj) : obj(obj) - { - } - -protected: - void run() - { - qDebug() << QThread::currentThread(); - obj->queueOnce("five"); - obj->queueOnce("six"); - obj->queueOnce("five"); - obj->queueOnce("five"); - obj->queueOnce("six"); - obj->queueOnce("seven"); - } -}; -#endif diff --git a/sandbox/messaging-to-self/queuedinvoker.cpp b/sandbox/messaging-to-self/queuedinvoker.cpp deleted file mode 100644 index 85dbb7d1..00000000 --- a/sandbox/messaging-to-self/queuedinvoker.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "queuedinvoker.h" - -#include <QMetaObject> -#include <QThread> -#include <QDebug> -#include <QMutexLocker> - -QueuedInvoker::QueuedInvoker() -{ - connect(this, SIGNAL(queuedCall(const char *)), - this, SLOT(onQueuedCall(const char *)), - Qt::QueuedConnection); -} - -void QueuedInvoker::onQueuedCall(const char *method) -{ - QMutexLocker locker(&callQueueLock); - callQueue.remove(method); - qDebug() << "Hope that i'm in the main loop" << QThread::currentThread(); - locker.unlock(); - if (!QMetaObject::invokeMethod(this, method, Qt::DirectConnection)) { - qFatal(" *****************\n" - "Erroneous usage of queueOnce(%s)\n" - " *****************\n", method); - } -} - -void QueuedInvoker::queueOnce(const char *method) -{ - QMutexLocker locker(&callQueueLock); - if (!callQueue.contains(method)) { - emit queuedCall(method); - callQueue.insert(method); - } -} diff --git a/sandbox/messaging-to-self/queuedinvoker.h b/sandbox/messaging-to-self/queuedinvoker.h deleted file mode 100644 index 8f81f26e..00000000 --- a/sandbox/messaging-to-self/queuedinvoker.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef QUEUEDINVOKER_H -#define QUEUEDINVOKER_H - -#include <QObject> -#include <QMutex> -#include <QSet> -#include <QString> - -class QueuedInvoker : public QObject -{ - Q_OBJECT - -public: - QueuedInvoker(); - -private slots: - void onQueuedCall(const char *method); - -signals: - void queuedCall(const char *method); - -public: - void queueOnce(const char *method); - -private: - QMutex callQueueLock; - QSet<QString> callQueue; -}; -#endif diff --git a/sandbox/multithreading-tests/Makefile.am b/sandbox/multithreading-tests/Makefile.am deleted file mode 100644 index 8da6191d..00000000 --- a/sandbox/multithreading-tests/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = new-property-in-thread old-property-in-thread single-thread stress-test wait-for-subscription-only-in-thread wait-for-subscription-thread using-backend-from-thread diff --git a/sandbox/multithreading-tests/new-property-in-thread/.gitignore b/sandbox/multithreading-tests/new-property-in-thread/.gitignore deleted file mode 100644 index 4390dc85..00000000 --- a/sandbox/multithreading-tests/new-property-in-thread/.gitignore +++ /dev/null @@ -1 +0,0 @@ -run-test diff --git a/sandbox/multithreading-tests/new-property-in-thread/Makefile.am b/sandbox/multithreading-tests/new-property-in-thread/Makefile.am deleted file mode 100644 index 59dc63a7..00000000 --- a/sandbox/multithreading-tests/new-property-in-thread/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -noinst_PROGRAMS = run-test -run_test_SOURCES = main.cpp thread.h - -AM_CXXFLAGS = $(QtCore_CFLAGS) -LIBS += $(QtCore_LIBS) - -# library dependency hack for seamless make in cli/ -AM_CXXFLAGS += -I$(srcdir)/../../src -run_test_LDADD = ../../src/libcontextsubscriber.la - -../../src/libcontextsubscriber.la: FORCE - $(MAKE) -C ../../src libcontextsubscriber.la -.PHONY: FORCE - -# moccing -nodist_run_test_SOURCES = mocs.cpp -QT_TOMOC = $(filter %.h, $(run_test_SOURCES)) -include $(top_srcdir)/am/qt.am diff --git a/sandbox/multithreading-tests/new-property-in-thread/main.cpp b/sandbox/multithreading-tests/new-property-in-thread/main.cpp deleted file mode 100644 index 3ab015fb..00000000 --- a/sandbox/multithreading-tests/new-property-in-thread/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include <contextproperty.h> - -#include "thread.h" - -#include <QCoreApplication> -#include <QThread> - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - - qDebug() << "MAIN THREAD:" << QCoreApplication::instance()->thread(); - - // Start a thread which will create the ContextProperty. - Thread thread; - thread.start(); - - return app.exec(); -} - diff --git a/sandbox/multithreading-tests/new-property-in-thread/thread.h b/sandbox/multithreading-tests/new-property-in-thread/thread.h deleted file mode 100644 index dd9951b3..00000000 --- a/sandbox/multithreading-tests/new-property-in-thread/thread.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef THREAD_H -#define THREAD_H - -#include <contextproperty.h> - -#include <QThread> -#include <QDebug> - -class Listener : public QObject -{ - Q_OBJECT - -public: - Listener() - { - cp = new ContextProperty("test.int"); - connect(cp, SIGNAL(valueChanged()), this, SLOT(onValueChanged())); - } - - ContextProperty* cp; - -public slots: - void onValueChanged() - { - qDebug() << "Listener::valueChanged(), and current thread is" << QThread::currentThread(); - qDebug() << "The value is:" << cp->value(); - exit(1); - } -}; - -class Thread : public QThread -{ - Q_OBJECT - -protected: - void run() - { - qDebug() << "SUB THREAD:" << QThread::currentThread(); - Listener listener; - exec(); - } - -}; - -#endif diff --git a/sandbox/multithreading-tests/old-property-in-thread/.gitignore b/sandbox/multithreading-tests/old-property-in-thread/.gitignore deleted file mode 100644 index 4390dc85..00000000 --- a/sandbox/multithreading-tests/old-property-in-thread/.gitignore +++ /dev/null @@ -1 +0,0 @@ -run-test diff --git a/sandbox/multithreading-tests/old-property-in-thread/Makefile.am b/sandbox/multithreading-tests/old-property-in-thread/Makefile.am deleted file mode 100644 index 59dc63a7..00000000 --- a/sandbox/multithreading-tests/old-property-in-thread/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -noinst_PROGRAMS = run-test -run_test_SOURCES = main.cpp thread.h - -AM_CXXFLAGS = $(QtCore_CFLAGS) -LIBS += $(QtCore_LIBS) - -# library dependency hack for seamless make in cli/ -AM_CXXFLAGS += -I$(srcdir)/../../src -run_test_LDADD = ../../src/libcontextsubscriber.la - -../../src/libcontextsubscriber.la: FORCE - $(MAKE) -C ../../src libcontextsubscriber.la -.PHONY: FORCE - -# moccing -nodist_run_test_SOURCES = mocs.cpp -QT_TOMOC = $(filter %.h, $(run_test_SOURCES)) -include $(top_srcdir)/am/qt.am diff --git a/sandbox/multithreading-tests/old-property-in-thread/main.cpp b/sandbox/multithreading-tests/old-property-in-thread/main.cpp deleted file mode 100644 index c21c9d7f..00000000 --- a/sandbox/multithreading-tests/old-property-in-thread/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include <contextproperty.h> - -#include "thread.h" - -#include <QCoreApplication> -#include <QDebug> - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - - qDebug() << "Main thread is" << QThread::currentThread(); - - ContextProperty* cp = new ContextProperty("test.int"); - delete cp; - // Creating a ContextProperty will result in creating a PropertyHandle, - // and the PropertyHandle is not deleted ever. - - // Start a thread which will create the same ContextProperty. - Thread thread; - thread.start(); - - return app.exec(); -} - diff --git a/sandbox/multithreading-tests/old-property-in-thread/thread.h b/sandbox/multithreading-tests/old-property-in-thread/thread.h deleted file mode 100644 index ec84afdf..00000000 --- a/sandbox/multithreading-tests/old-property-in-thread/thread.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef THREAD_H -#define THREAD_H - -#include <contextproperty.h> - -#include <QThread> -#include <QDebug> - -class Listener : public QObject -{ - Q_OBJECT - -public: - Listener() - { - cp = new ContextProperty("test.int"); - connect(cp, SIGNAL(valueChanged()), this, SLOT(onValueChanged())); - } - - ContextProperty* cp; - -public slots: - void onValueChanged() - { - qDebug() << "Listener::valueChanged(), and current thread is" << QThread::currentThread(); - qDebug() << "The value is:" << cp->value(); - exit(1); - } -}; - -class Thread : public QThread -{ - Q_OBJECT - -protected: - void run() - { - qDebug() << "Thread::run(), and current thread is" << QThread::currentThread(); - Listener listener; - exec(); - } - -}; - -#endif diff --git a/sandbox/multithreading-tests/single-thread/.gitignore b/sandbox/multithreading-tests/single-thread/.gitignore deleted file mode 100644 index 4390dc85..00000000 --- a/sandbox/multithreading-tests/single-thread/.gitignore +++ /dev/null @@ -1 +0,0 @@ -run-test diff --git a/sandbox/multithreading-tests/single-thread/Makefile.am b/sandbox/multithreading-tests/single-thread/Makefile.am deleted file mode 100644 index 010bc826..00000000 --- a/sandbox/multithreading-tests/single-thread/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -noinst_PROGRAMS = run-test -run_test_SOURCES = main.cpp listener.h - -AM_CXXFLAGS = $(QtCore_CFLAGS) -LIBS += $(QtCore_LIBS) - -# library dependency hack for seamless make in cli/ -AM_CXXFLAGS += -I$(srcdir)/../../src -run_test_LDADD = ../../src/libcontextsubscriber.la - -../../src/libcontextsubscriber.la: FORCE - $(MAKE) -C ../../src libcontextsubscriber.la -.PHONY: FORCE - -# moccing -nodist_run_test_SOURCES = mocs.cpp -QT_TOMOC = $(filter %.h, $(run_test_SOURCES)) -include $(top_srcdir)/am/qt.am diff --git a/sandbox/multithreading-tests/single-thread/listener.h b/sandbox/multithreading-tests/single-thread/listener.h deleted file mode 100644 index 9980f62a..00000000 --- a/sandbox/multithreading-tests/single-thread/listener.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef LISTENER_H -#define LISTENER_H - -#include <contextproperty.h> - -#include <QDebug> - -class Listener : public QObject -{ - Q_OBJECT - -public: - Listener() - { - cp = new ContextProperty("test.int"); - connect(cp, SIGNAL(valueChanged()), this, SLOT(onValueChanged())); - } - - ContextProperty* cp; - -public slots: - void onValueChanged() - { - qDebug() << "Listener::valueChanged()"; - qDebug() << "The value is:" << cp->value(); - exit(1); - } -}; - -#endif diff --git a/sandbox/multithreading-tests/single-thread/main.cpp b/sandbox/multithreading-tests/single-thread/main.cpp deleted file mode 100644 index 16dd2f65..00000000 --- a/sandbox/multithreading-tests/single-thread/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include <contextproperty.h> - -#include "listener.h" - -#include <QCoreApplication> - - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - - Listener listener; - - return app.exec(); -} diff --git a/sandbox/multithreading-tests/stress-test/.gitignore b/sandbox/multithreading-tests/stress-test/.gitignore deleted file mode 100644 index e08dedad..00000000 --- a/sandbox/multithreading-tests/stress-test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -run-test -cache.cdb diff --git a/sandbox/multithreading-tests/stress-test/1provider.cdb b/sandbox/multithreading-tests/stress-test/1provider.cdb Binary files differdeleted file mode 100644 index 58655ef3..00000000 --- a/sandbox/multithreading-tests/stress-test/1provider.cdb +++ /dev/null diff --git a/sandbox/multithreading-tests/stress-test/2providers.cdb b/sandbox/multithreading-tests/stress-test/2providers.cdb Binary files differdeleted file mode 100644 index 98324d4c..00000000 --- a/sandbox/multithreading-tests/stress-test/2providers.cdb +++ /dev/null diff --git a/sandbox/multithreading-tests/stress-test/Makefile.am b/sandbox/multithreading-tests/stress-test/Makefile.am deleted file mode 100644 index 59dc63a7..00000000 --- a/sandbox/multithreading-tests/stress-test/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -noinst_PROGRAMS = run-test -run_test_SOURCES = main.cpp thread.h - -AM_CXXFLAGS = $(QtCore_CFLAGS) -LIBS += $(QtCore_LIBS) - -# library dependency hack for seamless make in cli/ -AM_CXXFLAGS += -I$(srcdir)/../../src -run_test_LDADD = ../../src/libcontextsubscriber.la - -../../src/libcontextsubscriber.la: FORCE - $(MAKE) -C ../../src libcontextsubscriber.la -.PHONY: FORCE - -# moccing -nodist_run_test_SOURCES = mocs.cpp -QT_TOMOC = $(filter %.h, $(run_test_SOURCES)) -include $(top_srcdir)/am/qt.am diff --git a/sandbox/multithreading-tests/stress-test/main.cpp b/sandbox/multithreading-tests/stress-test/main.cpp deleted file mode 100644 index d7c334bd..00000000 --- a/sandbox/multithreading-tests/stress-test/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "thread.h" -#include <QCoreApplication> - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - - int maxTasks = 0; - int maxTasks2 = 0; - int task = -1; - - if (argc > 1 && atoi(argv[1]) > 0) - maxTasks = atoi(argv[1]); - if (argc > 2 && atoi(argv[2]) > 0) - maxTasks2 = atoi(argv[2]); - if (argc > 3 && atoi(argv[3]) > 0) - task = atoi(argv[3]); - - TestRunner tests(maxTasks, "test.int", task); - TestRunner tests2(maxTasks2, "test2.int", task); - - return app.exec(); -} diff --git a/sandbox/multithreading-tests/stress-test/provider.py b/sandbox/multithreading-tests/stress-test/provider.py deleted file mode 100755 index 748929a4..00000000 --- a/sandbox/multithreading-tests/stress-test/provider.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python -"""A test provider for the stress testing.""" - - -# change registry this often [msec] -registryChangeTimeout = 2017 - - -from ContextKit.flexiprovider import * -import gobject -import time -import os - -def update(): - t = time.time() - dt = int(1000*(t - round(t))) - gobject.timeout_add(1000 - dt, update) - v = int(round(t)) - fp.set('test.int', v) - fp.set('test.int2', v) - print t - return False - -pcnt = 0 -def chgRegistry(): - global pcnt - pcnt += 1 - if pcnt % 2: - print "1 provider" - os.system('cp 1provider.cdb tmp.cdb; mv tmp.cdb cache.cdb') - else: - print "2 providers" - os.system('cp 2providers.cdb tmp.cdb; mv tmp.cdb cache.cdb') - return True - - -gobject.timeout_add(1000, update) -# uncoment this to see the "Bus error" XXX -gobject.timeout_add(registryChangeTimeout, chgRegistry) - -fp = Flexiprovider([INT('test.int'), INT('test.int2')], 'my.test.provider', 'session') -fp.run() diff --git a/sandbox/multithreading-tests/stress-test/runme.sh b/sandbox/multithreading-tests/stress-test/runme.sh deleted file mode 100755 index a2aa73d6..00000000 --- a/sandbox/multithreading-tests/stress-test/runme.sh +++ /dev/null @@ -1,14 +0,0 @@ -# RunMe & ReadMe -# -# provider.py will run flexiprovider and update test.int every second to the POSIX time. -# Additionally, it will change the registry every two seconds. -# -# stress-test takes two int arguments: the number of threads using the first and the second provider. -# -# Compiling: for now, use qmake & make. Sorry. - -#xterm -e 'rlwrap ../../../python/context-provide my.test.provider int test.int 0 int test.int2 0' & -#xterm -e 'rlwrap ../../../python/context-provide my.test2.provider int test2.int 0 int test2.int2 0' & - -xterm -e './provider.py' & -CONTEXT_PROVIDERS=../stress-test/ ./run-test 3 3 diff --git a/sandbox/multithreading-tests/stress-test/thread.h b/sandbox/multithreading-tests/stress-test/thread.h deleted file mode 100644 index 44cbf7c8..00000000 --- a/sandbox/multithreading-tests/stress-test/thread.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef STRESS_H -#define STRESS_H - -#include <contextproperty.h> - -#include <time.h> -#include <QThread> -#include <QDebug> - -#define NUM_TESTS 9 - -/* - * A thread doing something with a ContextProperty. - * - * First creates a ContextProperty tracking \c propertyName, then does some simple thing - * with it based on the \c task number, then finally the ContextProperty is deleted. - */ -class Thread : public QThread -{ - Q_OBJECT - -public: - Thread(const int task, const QString& propertyName) : task(task), propertyName(propertyName) {}; - -protected: - void run() { - // create property do something and delete it - ContextProperty* cp = new ContextProperty(propertyName); - int value, realValue; - - switch (task) { - case 1: // check value - cp->waitForSubscription(); - value = cp->value().toInt(); - realValue = time(0); - if (value != realValue && value != 0) { - msleep(100); // give it 0.1 sec to arrive - value = cp->value().toInt(); - if (value != realValue && value != 0) - qDebug() << "*** value mismatch:" << propertyName << value << realValue; - } - break; - - case 2: // wait 0-2000 msec before deleting - msleep(qrand()%2000); - break; - - case 3: // unsubscribe - cp->unsubscribe(); - break; - - case 4: // unsubscribe and wait a bit - cp->unsubscribe(); - msleep(qrand()%2000); - break; - - case 5: // unsubscribe and subscribe - cp->unsubscribe(); - cp->subscribe(); - break; - - case 6: // unsubscribe, wait a bit then subscribe and wait some more - cp->unsubscribe(); - msleep(qrand()%2000); - cp->subscribe(); - msleep(qrand()%2000); - break; - - case 7: // subscribe - cp->subscribe(); - break; - - case 8: // subscribe - msleep(qrand()%100); - cp->subscribe(); - msleep(qrand()%100); - break; - - default:; // just create and delete - } - - delete(cp); - exit(); - } - -private: - int task; - QString propertyName; - -}; - - -/* - * Starts \c maxThreads number of threads doing simple tests wit ContextProperty \c propertyName - * until stopped. The tasks are choosen randomly with equal weight. Whenever a thread stops - * an other one will start, ad infinitum. - */ -class TestRunner : public QObject -{ - Q_OBJECT - -private: - int maxThreads; - QSet<Thread*> threads; - QString propertyName; - int count; - int defaultTask; - -public: - TestRunner(const int maxThreads, const QString& propertyName, int task = -1) : - maxThreads(maxThreads), propertyName(propertyName), count(0), defaultTask(task) { - for (int i = 0; i < maxThreads; i++) - addThread(); - } - - void addThread() { - int task = defaultTask != -1 ? defaultTask : qrand() % NUM_TESTS ; - qDebug() << "** starting" << propertyName << task << "/" << ++count; - Thread* t = new Thread(task, propertyName); - QObject::connect(t, SIGNAL(finished()), this, SLOT(onThreadFinished())); - threads.insert(t); - t->start(); - } - -public slots: - void onThreadFinished() { - Thread* t = (Thread*) QObject::sender(); - if (threads.remove(t)) { - delete t; - addThread(); - } - } -}; - -#endif diff --git a/sandbox/multithreading-tests/using-backend-from-thread/.gitignore b/sandbox/multithreading-tests/using-backend-from-thread/.gitignore deleted file mode 100644 index 4390dc85..00000000 --- a/sandbox/multithreading-tests/using-backend-from-thread/.gitignore +++ /dev/null @@ -1 +0,0 @@ -run-test diff --git a/sandbox/multithreading-tests/using-backend-from-thread/Makefile.am b/sandbox/multithreading-tests/using-backend-from-thread/Makefile.am deleted file mode 100644 index b4cf1a5d..00000000 --- a/sandbox/multithreading-tests/using-backend-from-thread/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -noinst_PROGRAMS = run-test -run_test_SOURCES = main.cpp thread.h - -AM_CXXFLAGS = $(QtCore_CFLAGS) $(QtDBus_CFLAGS) -LIBS += $(QtCore_LIBS) $(QtDBus_LIBS) - -# library dependency hack for seamless make in cli/ -AM_CXXFLAGS += -I$(srcdir)/../../src -run_test_LDADD = ../../src/libcontextsubscriber.la - -../../src/libcontextsubscriber.la: FORCE - $(MAKE) -C ../../src libcontextsubscriber.la -.PHONY: FORCE - -# moccing -nodist_run_test_SOURCES = mocs.cpp -QT_TOMOC = $(filter %.h, $(run_test_SOURCES)) -include $(top_srcdir)/am/qt.am diff --git a/sandbox/multithreading-tests/using-backend-from-thread/main.cpp b/sandbox/multithreading-tests/using-backend-from-thread/main.cpp deleted file mode 100644 index a6a7c8aa..00000000 --- a/sandbox/multithreading-tests/using-backend-from-thread/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include <contextproperty.h> - -#include "thread.h" - -#include <QCoreApplication> -#include <QDebug> - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - - qDebug() << "Main thread is" << QThread::currentThread(); - - // Start a thread which will use the backend - Thread* thread = new Thread(); - thread->start(); - - thread->wait(); - // Kill the thread - qDebug() << "Thread stopped, deleting it"; - delete thread; - qDebug() << "Entering main event loop"; - - return app.exec(); -} diff --git a/sandbox/multithreading-tests/using-backend-from-thread/thread.h b/sandbox/multithreading-tests/using-backend-from-thread/thread.h deleted file mode 100644 index cd77a298..00000000 --- a/sandbox/multithreading-tests/using-backend-from-thread/thread.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef THREAD_H -#define THREAD_H - -#include <contextproperty.h> -#include <contextpropertyinfo.h> - -#include <QThread> -#include <QDebug> - -class Listener : public QObject -{ - Q_OBJECT - -public: - Listener() - { - cp = new ContextProperty("test.int"); - qDebug() << "Provider is: " << cp->info()->providerDBusName(); - } - - ContextProperty* cp; -}; - -class Thread : public QThread -{ - Q_OBJECT - -protected: - void run() - { - qDebug() << "Thread::run(), and current thread is" << QThread::currentThread(); - Listener listener; - - qDebug() << "Returning from run"; - } - -}; - -#endif diff --git a/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/.gitignore b/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/.gitignore deleted file mode 100644 index 4390dc85..00000000 --- a/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/.gitignore +++ /dev/null @@ -1 +0,0 @@ -run-test diff --git a/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/Makefile.am b/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/Makefile.am deleted file mode 100644 index 59dc63a7..00000000 --- a/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -noinst_PROGRAMS = run-test -run_test_SOURCES = main.cpp thread.h - -AM_CXXFLAGS = $(QtCore_CFLAGS) -LIBS += $(QtCore_LIBS) - -# library dependency hack for seamless make in cli/ -AM_CXXFLAGS += -I$(srcdir)/../../src -run_test_LDADD = ../../src/libcontextsubscriber.la - -../../src/libcontextsubscriber.la: FORCE - $(MAKE) -C ../../src libcontextsubscriber.la -.PHONY: FORCE - -# moccing -nodist_run_test_SOURCES = mocs.cpp -QT_TOMOC = $(filter %.h, $(run_test_SOURCES)) -include $(top_srcdir)/am/qt.am diff --git a/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/main.cpp b/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/main.cpp deleted file mode 100644 index 1a1727b7..00000000 --- a/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include <contextproperty.h> - -#include "thread.h" - -#include <QCoreApplication> -#include <QThread> - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - - qDebug() << "MAIN THREAD:" << QCoreApplication::instance()->thread(); - - // Start a thread which will create the ContextProperty. - Thread thread; - thread.start(); - - qDebug() << "Entering main loop"; - return app.exec(); -} diff --git a/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/thread.h b/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/thread.h deleted file mode 100644 index e92af6f2..00000000 --- a/sandbox/multithreading-tests/wait-for-subscription-only-in-thread/thread.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef THREAD_H -#define THREAD_H - -#include <contextproperty.h> - -#include <QThread> -#include <QDebug> - -class Listener : public QObject -{ - Q_OBJECT - -public: - Listener() - { - cp = new ContextProperty("test.int"); - connect(cp, SIGNAL(valueChanged()), this, SLOT(onValueChanged())); - qDebug() << "**** Starting to wait"; - cp->waitForSubscription(); - qDebug() << "**** Waiting is done"; - qDebug() << "After waiting, the value is" << cp->value(); - sleep(1); - qDebug() << "After waiting 1 s more, the value is" << cp->value(); - - } - - ContextProperty* cp; - -public slots: - void onValueChanged() - { - qDebug() << "Listener::valueChanged(), and current thread is" << QThread::currentThread(); - qDebug() << "The value is:" << cp->value(); -// exit(1); - } -}; - -class Thread : public QThread -{ - Q_OBJECT - -protected: - void run() - { - qDebug() << "SUB THREAD:" << QThread::currentThread(); - Listener listener; - exec(); - } - -}; - -#endif diff --git a/sandbox/multithreading-tests/wait-for-subscription-thread/.gitignore b/sandbox/multithreading-tests/wait-for-subscription-thread/.gitignore deleted file mode 100644 index 4390dc85..00000000 --- a/sandbox/multithreading-tests/wait-for-subscription-thread/.gitignore +++ /dev/null @@ -1 +0,0 @@ -run-test diff --git a/sandbox/multithreading-tests/wait-for-subscription-thread/Makefile.am b/sandbox/multithreading-tests/wait-for-subscription-thread/Makefile.am deleted file mode 100644 index 59dc63a7..00000000 --- a/sandbox/multithreading-tests/wait-for-subscription-thread/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -noinst_PROGRAMS = run-test -run_test_SOURCES = main.cpp thread.h - -AM_CXXFLAGS = $(QtCore_CFLAGS) -LIBS += $(QtCore_LIBS) - -# library dependency hack for seamless make in cli/ -AM_CXXFLAGS += -I$(srcdir)/../../src -run_test_LDADD = ../../src/libcontextsubscriber.la - -../../src/libcontextsubscriber.la: FORCE - $(MAKE) -C ../../src libcontextsubscriber.la -.PHONY: FORCE - -# moccing -nodist_run_test_SOURCES = mocs.cpp -QT_TOMOC = $(filter %.h, $(run_test_SOURCES)) -include $(top_srcdir)/am/qt.am diff --git a/sandbox/multithreading-tests/wait-for-subscription-thread/main.cpp b/sandbox/multithreading-tests/wait-for-subscription-thread/main.cpp deleted file mode 100644 index 44390e2d..00000000 --- a/sandbox/multithreading-tests/wait-for-subscription-thread/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include <contextproperty.h> - -#include "thread.h" - -#include <QCoreApplication> -#include <QThread> - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - - qDebug() << "MAIN THREAD:" << QCoreApplication::instance()->thread(); - - // Start a thread which will create the ContextProperty. - Thread thread; - thread.start(); - - sleep(2); - ContextProperty *cp = new ContextProperty("test.int"); - cp->waitForSubscription(); - qDebug() << "waiting is done in the main"; - - return app.exec(); -} - diff --git a/sandbox/multithreading-tests/wait-for-subscription-thread/thread.h b/sandbox/multithreading-tests/wait-for-subscription-thread/thread.h deleted file mode 100644 index 7766fe68..00000000 --- a/sandbox/multithreading-tests/wait-for-subscription-thread/thread.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef THREAD_H -#define THREAD_H - -#include <contextproperty.h> - -#include <QThread> -#include <QDebug> - -class Listener : public QObject -{ - Q_OBJECT - -public: - Listener() - { - cp = new ContextProperty("test.int"); - connect(cp, SIGNAL(valueChanged()), this, SLOT(onValueChanged())); - cp->waitForSubscription(); - qDebug() << "Waiting is done"; - } - - ContextProperty* cp; - -public slots: - void onValueChanged() - { - qDebug() << "Listener::valueChanged(), and current thread is" << QThread::currentThread(); - qDebug() << "The value is:" << cp->value(); -// exit(1); - } -}; - -class Thread : public QThread -{ - Q_OBJECT - -protected: - void run() - { - qDebug() << "SUB THREAD:" << QThread::currentThread(); - Listener listener; - exec(); - } - -}; - -#endif |