* Added another simple D-Bus C++ example
git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@8167 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
parent
f62efeac80
commit
a9e3429b9e
25 changed files with 14253 additions and 9562 deletions
62
examples/echo/echo-server.cpp
Normal file
62
examples/echo/echo-server.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include "echo-server.h"
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
static const char* ECHO_SERVER_NAME = "org.freedesktop.DBus.Examples.Echo";
|
||||
static const char* ECHO_SERVER_PATH = "/org/freedesktop/DBus/Examples/Echo";
|
||||
|
||||
EchoServer::EchoServer( DBus::Connection& connection )
|
||||
: DBus::ObjectAdaptor(connection, ECHO_SERVER_PATH)
|
||||
{
|
||||
}
|
||||
|
||||
DBus::Int32 EchoServer::Random()
|
||||
{
|
||||
return rand();
|
||||
}
|
||||
|
||||
DBus::String EchoServer::Hello( const DBus::String& name )
|
||||
{
|
||||
return "Hello " + name + "!";
|
||||
}
|
||||
|
||||
DBus::Variant EchoServer::Echo( const DBus::Variant& value )
|
||||
{
|
||||
this->Echoed(value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
DBus::Int32 EchoServer::Sum( const std::vector<DBus::Int32>& ints )
|
||||
{
|
||||
DBus::Int32 sum = 0;
|
||||
|
||||
for(size_t i = 0; i < ints.size(); ++i) sum += ints[i];
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
DBus::BusDispatcher dispatcher;
|
||||
|
||||
void niam( int sig )
|
||||
{
|
||||
dispatcher.leave();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGTERM, niam);
|
||||
signal(SIGINT, niam);
|
||||
|
||||
DBus::default_dispatcher = &dispatcher;
|
||||
|
||||
DBus::Connection conn = DBus::Connection::SessionBus();
|
||||
conn.request_name(ECHO_SERVER_NAME);
|
||||
|
||||
EchoServer server(conn);
|
||||
|
||||
dispatcher.enter();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue