* 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:
parent
47150044cf
commit
d0c224af9f
5 changed files with 31 additions and 4 deletions
|
@ -12,6 +12,10 @@
|
||||||
<arg type="v" name="input" direction="in"/>
|
<arg type="v" name="input" direction="in"/>
|
||||||
<arg type="v" name="output" direction="out"/>
|
<arg type="v" name="output" direction="out"/>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="Cat">
|
||||||
|
<arg type="s" name="file" direction="in"/>
|
||||||
|
<arg type="ay" name="stream" direction="out"/>
|
||||||
|
</method>
|
||||||
<method name="Sum">
|
<method name="Sum">
|
||||||
<arg type="ai" name="ints" direction="in"/>
|
<arg type="ai" name="ints" direction="in"/>
|
||||||
<arg type="i" names="sum" direction="out"/>
|
<arg type="i" names="sum" direction="out"/>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
static const char* ECHO_SERVER_NAME = "org.freedesktop.DBus.Examples.Echo";
|
static const char* ECHO_SERVER_NAME = "org.freedesktop.DBus.Examples.Echo";
|
||||||
static const char* ECHO_SERVER_PATH = "/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;
|
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 EchoServer::Sum( const std::vector<DBus::Int32>& ints )
|
||||||
{
|
{
|
||||||
DBus::Int32 sum = 0;
|
DBus::Int32 sum = 0;
|
||||||
|
|
|
@ -19,6 +19,8 @@ public:
|
||||||
|
|
||||||
DBus::Variant Echo( const DBus::Variant & value );
|
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 );
|
DBus::Int32 Sum( const std::vector<DBus::Int32> & ints );
|
||||||
|
|
||||||
std::map< DBus::String, DBus::String > Info();
|
std::map< DBus::String, DBus::String > Info();
|
||||||
|
|
|
@ -288,7 +288,9 @@ inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::vect
|
||||||
template<>
|
template<>
|
||||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::vector<DBus::Byte>& val )
|
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::vector<DBus::Byte>& val )
|
||||||
{
|
{
|
||||||
iter.append_array('y', &val.front(), val.size());
|
DBus::MessageIter ait = iter.new_array("y");
|
||||||
|
ait.append_array('y', &val.front(), val.size());
|
||||||
|
iter.close_container(ait);
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,9 +449,12 @@ inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector<DBu
|
||||||
if(iter.array_type() != 'y')
|
if(iter.array_type() != 'y')
|
||||||
throw DBus::ErrorInvalidArgs("byte-array expected");
|
throw DBus::ErrorInvalidArgs("byte-array expected");
|
||||||
|
|
||||||
val.reserve(iter.array_length());
|
DBus::MessageIter ait = iter.recurse();
|
||||||
|
|
||||||
iter.get_array(const_cast<DBus::Byte*>(&val.front()));
|
DBus::Byte* array;
|
||||||
|
size_t length = ait.get_array(&array);
|
||||||
|
|
||||||
|
val.insert(val.end(), array, array+length);
|
||||||
|
|
||||||
return ++iter;
|
return ++iter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ char* MessageIter::signature() const
|
||||||
|
|
||||||
bool MessageIter::append_array( char type, const void* ptr, size_t length )
|
bool MessageIter::append_array( char type, const void* ptr, size_t length )
|
||||||
{
|
{
|
||||||
return dbus_message_iter_append_fixed_array((DBusMessageIter*)&_iter, type, ptr, length);
|
return dbus_message_iter_append_fixed_array((DBusMessageIter*)&_iter, type, &ptr, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MessageIter::array_type()
|
int MessageIter::array_type()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue