a test for byte

This commit is contained in:
Andreas Volz 2011-11-18 18:07:06 +01:00
parent 9be39fb628
commit 84978b67b5
5 changed files with 71 additions and 26 deletions

View file

@ -15,12 +15,16 @@ DBus::BusDispatcher dispatcher;
TestAppIntro *g_testComIntro; TestAppIntro *g_testComIntro;
DBus::Pipe *mTestToDBusPipe; DBus::Pipe *mTestToDBusPipe;
bool testResult = false; bool testResult = false;
std::list <std::string> testList;
pthread_mutex_t clientMutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t clientMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t clientCondition = PTHREAD_COND_INITIALIZER; pthread_cond_t clientCondition = PTHREAD_COND_INITIALIZER;
TestApp::TestApp () TestApp::TestApp ()
{ {
testList.push_back ("test1");
testList.push_back ("testByte");
cout << "initialize DBus..." << endl; cout << "initialize DBus..." << endl;
initDBus (); initDBus ();
} }
@ -56,24 +60,28 @@ void TestApp::initDBus ()
void *TestApp::testThreadRunner (void *arg) void *TestApp::testThreadRunner (void *arg)
{ {
char idstr[16]; for (std::list <std::string>::const_iterator tl_it = testList.begin ();
tl_it != testList.end ();
snprintf (idstr, sizeof(idstr), "%lu", pthread_self()); ++tl_it)
mTestToDBusPipe->write (idstr, strlen (idstr) + 1);
struct timespec abstime;
clock_gettime(CLOCK_REALTIME, &abstime);
abstime.tv_sec += 1;
pthread_mutex_lock (&clientMutex);
if (pthread_cond_timedwait (&clientCondition, &clientMutex, &abstime) == ETIMEDOUT)
{ {
cout << "client timeout!" << endl; const string &testString = *tl_it;
testResult = false;
cout << "write to pipe" << endl;
mTestToDBusPipe->write (testString.c_str (), testString.length () + 1);
struct timespec abstime;
clock_gettime(CLOCK_REALTIME, &abstime);
abstime.tv_sec += 1;
pthread_mutex_lock (&clientMutex);
if (pthread_cond_timedwait (&clientCondition, &clientMutex, &abstime) == ETIMEDOUT)
{
cout << "client timeout!" << endl;
testResult = false;
}
pthread_mutex_unlock (&clientMutex);
} }
pthread_mutex_unlock (&clientMutex);
cout << "leave!" << endl; cout << "leave!" << endl;
dispatcher.leave (); dispatcher.leave ();
@ -87,5 +95,12 @@ void TestApp::testHandler (const void *data, void *buffer, unsigned int nbyte)
cout << "buffer1: " << str << ", size: " << nbyte << endl; cout << "buffer1: " << str << ", size: " << nbyte << endl;
cout << "run it!" << endl; cout << "run it!" << endl;
g_testComIntro->test1 (); if (string (str) == "test1")
{
g_testComIntro->test1 ();
}
else if (string (str) == "testByte")
{
g_testComIntro->testByte (4);
}
} }

View file

@ -2,7 +2,9 @@
#define TEST_APP_H #define TEST_APP_H
// STD // STD
#include <string.h> #include <cstring>
#include <list>
#include <string>
/* DBus-cxx */ /* DBus-cxx */
#include <dbus-c++/dbus.h> #include <dbus-c++/dbus.h>
@ -21,7 +23,6 @@ private:
static void *testThreadRunnerProvider (void *arg); static void *testThreadRunnerProvider (void *arg);
// variables // variables
pthread_t testThread; pthread_t testThread;
}; };

View file

@ -2,8 +2,12 @@
#define TEST_APP_INTRO_H #define TEST_APP_INTRO_H
#include "TestAppIntroPrivate.h" #include "TestAppIntroPrivate.h"
#include "../../../tools/generator_utils.h"
#include <iostream> #include <iostream>
#include <cstdio>
using namespace std;
class TestAppIntro : class TestAppIntro :
public DBusCpp::Test::Com::Intro_proxy, public DBusCpp::Test::Com::Intro_proxy,
@ -19,7 +23,14 @@ public:
void test1Result () void test1Result ()
{ {
std::cout << "Test1Result" << std::endl; cout << "Test1Result" << endl;
mTestResult = true;
pthread_cond_signal (&mCondition);
}
void testByteResult (const uint8_t& Byte)
{
printf ("TestByteResult: %d\n", Byte);
mTestResult = true; mTestResult = true;
pthread_cond_signal (&mCondition); pthread_cond_signal (&mCondition);
} }

View file

@ -9,5 +9,15 @@
<signal name="test1Result"> <signal name="test1Result">
</signal> </signal>
<method name="testByte">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
<arg type="y" name="Byte" direction="in"/>
</method>
<signal name="testByteResult">
<arg type="y" name="Byte" direction="in"/>
</signal>
</interface> </interface>
</node> </node>

View file

@ -2,11 +2,13 @@
#define TEST_APP_INTRO_PROVIDER_H #define TEST_APP_INTRO_PROVIDER_H
#include "TestAppIntroProviderPrivate.h" #include "TestAppIntroProviderPrivate.h"
#include "TestAppIntro.h" #include "TestAppIntro.h"
#include "../../../tools/generator_utils.h"
#include <iostream> #include <iostream>
using namespace std;
class TestAppIntroProvider : class TestAppIntroProvider :
public DBusCpp::Test::Com::Intro_adaptor, public DBusCpp::Test::Com::Intro_adaptor,
public DBus::IntrospectableAdaptor, public DBus::IntrospectableAdaptor,
@ -20,10 +22,16 @@ public:
void test1 () void test1 ()
{ {
std::cout << "Test1" << std::endl; cout << "Test1" << endl;
mTestAppIntro->test1Result (); mTestAppIntro->test1Result ();
} }
void testByte (const uint8_t& Byte)
{
printf ("TestByte: %d\n", Byte);
mTestAppIntro->testByteResult (Byte);
}
private: private:
TestAppIntro *mTestAppIntro; TestAppIntro *mTestAppIntro;
}; };