* Fixed reading and writing of fixed-size arrays

git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@9595 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
pdurante 2007-02-02 19:58:02 +00:00
parent 47150044cf
commit d0c224af9f
5 changed files with 31 additions and 4 deletions

View file

@ -12,6 +12,10 @@
<arg type="v" name="input" direction="in"/>
<arg type="v" name="output" direction="out"/>
</method>
<method name="Cat">
<arg type="s" name="file" direction="in"/>
<arg type="ay" name="stream" direction="out"/>
</method>
<method name="Sum">
<arg type="ai" name="ints" direction="in"/>
<arg type="i" names="sum" direction="out"/>

View file

@ -2,6 +2,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
static const char* ECHO_SERVER_NAME = "org.freedesktop.DBus.Examples.Echo";
static const char* ECHO_SERVER_PATH = "/org/freedesktop/DBus/Examples/Echo";
@ -28,6 +29,21 @@ DBus::Variant EchoServer::Echo( const DBus::Variant& value )
return value;
}
std::vector< DBus::Byte > EchoServer::Cat( const DBus::String & file )
{
FILE* handle = fopen(file.c_str(), "rb");
if(!handle) throw DBus::Error("org.freedesktop.DBus.EchoDemo.ErrorFileNotFound", "file not found");
DBus::Byte buff[1024];
size_t nread = fread(buff, 1, sizeof(buff), handle);
fclose(handle);
return std::vector< DBus::Byte > (buff, buff + nread);
}
DBus::Int32 EchoServer::Sum( const std::vector<DBus::Int32>& ints )
{
DBus::Int32 sum = 0;

View file

@ -19,6 +19,8 @@ public:
DBus::Variant Echo( const DBus::Variant & value );
std::vector< DBus::Byte > Cat( const DBus::String & file );
DBus::Int32 Sum( const std::vector<DBus::Int32> & ints );
std::map< DBus::String, DBus::String > Info();