imported D-Bus C++ library
git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@7382 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
commit
acfeb85b87
89 changed files with 92818 additions and 0 deletions
58
include/dbus-c++/config.h.in
Normal file
58
include/dbus-c++/config.h.in
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* include/dbus-c++/config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the <expat.h> header file. */
|
||||
#undef HAVE_EXPAT_H
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
117
include/dbus-c++/connection.h
Normal file
117
include/dbus-c++/connection.h
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_CONNECTION_H
|
||||
#define __DBUSXX_CONNECTION_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "types.h"
|
||||
#include "util.h"
|
||||
#include "message.h"
|
||||
#include "pendingcall.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
class Connection;
|
||||
|
||||
typedef Slot<bool, const Message&> MessageSlot;
|
||||
|
||||
typedef std::list<Connection*> ConnectionPList;
|
||||
|
||||
class ObjectAdaptor;
|
||||
class Dispatcher;
|
||||
|
||||
class Connection
|
||||
{
|
||||
public:
|
||||
|
||||
static Connection SystemBus();
|
||||
|
||||
static Connection SessionBus();
|
||||
|
||||
static Connection ActivationBus();
|
||||
|
||||
struct Private;
|
||||
|
||||
typedef std::list<Private*> PrivatePList;
|
||||
|
||||
Connection( Private* );
|
||||
|
||||
Connection( const char* address, bool priv = false );
|
||||
|
||||
Connection( const Connection& c );
|
||||
|
||||
virtual ~Connection();
|
||||
|
||||
Dispatcher* setup( Dispatcher* );
|
||||
|
||||
bool operator == ( const Connection& ) const;
|
||||
|
||||
void add_match( const char* rule );
|
||||
|
||||
void remove_match( const char* rule );
|
||||
|
||||
bool add_filter( MessageSlot& );
|
||||
|
||||
void remove_filter( MessageSlot& );
|
||||
|
||||
bool unique_name( const char* n );
|
||||
|
||||
const char* unique_name() const;
|
||||
|
||||
bool connected() const;
|
||||
|
||||
void disconnect();
|
||||
|
||||
void flush();
|
||||
|
||||
bool send( const Message&, unsigned int* serial = NULL );
|
||||
|
||||
Message send_blocking( Message& msg, int timeout );
|
||||
|
||||
PendingCall send_async( Message& msg, int timeout );
|
||||
|
||||
void request_name( const char* name, int flags = 0 );
|
||||
|
||||
bool has_name( const char* name );
|
||||
|
||||
bool start_service( const char* name, unsigned long flags );
|
||||
|
||||
const std::vector<std::string>& names();
|
||||
|
||||
private:
|
||||
|
||||
void init();
|
||||
|
||||
private:
|
||||
|
||||
RefPtrI<Private> _pvt;
|
||||
|
||||
friend class ObjectAdaptor; // needed in order to register object paths for a connection
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_CONNECTION_H
|
44
include/dbus-c++/dbus-c++.h
Normal file
44
include/dbus-c++/dbus-c++.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_DBUSXX_H
|
||||
#define __DBUSXX_DBUSXX_H
|
||||
|
||||
#include "types.h"
|
||||
#include "interface.h"
|
||||
#include "object.h"
|
||||
#include "connection.h"
|
||||
#include "server.h"
|
||||
#include "error.h"
|
||||
#include "message.h"
|
||||
#include "debug.h"
|
||||
#include "pendingcall.h"
|
||||
#include "server.h"
|
||||
#include "util.h"
|
||||
#include "dispatcher.h"
|
||||
#include "eventloop.h"
|
||||
#include "xml.h"
|
||||
#include "introspection.h"
|
||||
|
||||
#endif//__DBUSXX_DBUSXX_H
|
36
include/dbus-c++/debug.h
Normal file
36
include/dbus-c++/debug.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_DEBUG_H
|
||||
#define __DBUSXX_DEBUG_H
|
||||
|
||||
namespace DBus {
|
||||
|
||||
typedef void (*LogFunction)(const char* format, ...);
|
||||
|
||||
extern LogFunction debug_log;
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif
|
241
include/dbus-c++/dispatcher.h
Normal file
241
include/dbus-c++/dispatcher.h
Normal file
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_DISPATCHER_H
|
||||
#define __DBUSXX_DISPATCHER_H
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
class Timeout
|
||||
{
|
||||
public:
|
||||
|
||||
class Internal;
|
||||
|
||||
Timeout( Internal* i );
|
||||
|
||||
virtual ~Timeout(){}
|
||||
|
||||
int interval() const;
|
||||
|
||||
bool enabled() const;
|
||||
|
||||
bool handle();
|
||||
|
||||
virtual void toggle() = 0;
|
||||
|
||||
private:
|
||||
|
||||
Timeout( const Timeout& );
|
||||
|
||||
private:
|
||||
|
||||
Internal* _int;
|
||||
};
|
||||
|
||||
class Watch
|
||||
{
|
||||
public:
|
||||
|
||||
class Internal;
|
||||
|
||||
Watch( Internal* i );
|
||||
|
||||
virtual ~Watch(){}
|
||||
|
||||
int descriptor() const;
|
||||
|
||||
int flags() const;
|
||||
|
||||
bool enabled() const;
|
||||
|
||||
bool handle( int flags );
|
||||
|
||||
virtual void toggle() = 0;
|
||||
|
||||
private:
|
||||
|
||||
Watch( const Watch& );
|
||||
|
||||
private:
|
||||
|
||||
Internal* _int;
|
||||
};
|
||||
|
||||
class Dispatcher
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Dispatcher()
|
||||
{}
|
||||
|
||||
void queue_connection( Connection::Private* );
|
||||
|
||||
void dispatch_pending();
|
||||
|
||||
virtual void enter() = 0;
|
||||
|
||||
virtual void leave() = 0;
|
||||
|
||||
virtual Timeout* add_timeout( Timeout::Internal* ) = 0;
|
||||
|
||||
virtual void rem_timeout( Timeout* ) = 0;
|
||||
|
||||
virtual Watch* add_watch( Watch::Internal* ) = 0;
|
||||
|
||||
virtual void rem_watch( Watch* ) = 0;
|
||||
|
||||
struct Private;
|
||||
|
||||
private:
|
||||
|
||||
Connection::PrivatePList _pending_queue;
|
||||
};
|
||||
|
||||
extern Dispatcher* default_dispatcher;
|
||||
|
||||
/* classes for multithreading support
|
||||
*/
|
||||
|
||||
class Mutex
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Mutex() {}
|
||||
|
||||
virtual bool lock() = 0;
|
||||
|
||||
virtual bool unlock() = 0;
|
||||
|
||||
struct Internal;
|
||||
|
||||
protected:
|
||||
|
||||
Internal* _int;
|
||||
};
|
||||
|
||||
class CondVar
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~CondVar() {}
|
||||
|
||||
virtual void wait( Mutex* ) = 0;
|
||||
|
||||
virtual bool wait_timeout( Mutex*, int timeout ) = 0;
|
||||
|
||||
virtual void wake_one() = 0;
|
||||
|
||||
virtual void wake_all() = 0;
|
||||
|
||||
struct Internal;
|
||||
|
||||
protected:
|
||||
|
||||
Internal* _int;
|
||||
};
|
||||
|
||||
typedef Mutex* (*MutexNewFn)();
|
||||
typedef void (*MutexFreeFn)( Mutex* mx );
|
||||
typedef void (*MutexLockFn)( Mutex* mx );
|
||||
typedef void (*MutexUnlockFn)( Mutex* mx );
|
||||
typedef CondVar* (*CondVarNewFn)();
|
||||
typedef void (*CondVarFreeFn)( CondVar* cv );
|
||||
typedef void (*CondVarWaitFn)( CondVar* cv, Mutex* mx );
|
||||
typedef bool (*CondVarWaitTimeoutFn)( CondVar* cv, Mutex* mx, int timeout );
|
||||
typedef void (*CondVarWakeOneFn)( CondVar* cv );
|
||||
typedef void (*CondVarWakeAllFn)( CondVar* cv );
|
||||
|
||||
void _init_threading(
|
||||
MutexNewFn, MutexFreeFn, MutexLockFn, MutexUnlockFn,
|
||||
CondVarNewFn, CondVarFreeFn, CondVarWaitFn, CondVarWaitTimeoutFn, CondVarWakeOneFn, CondVarWakeAllFn
|
||||
);
|
||||
|
||||
template<class Mx, class Cv>
|
||||
struct Threading
|
||||
{
|
||||
static void init()
|
||||
{
|
||||
_init_threading(
|
||||
mutex_new, mutex_free, mutex_lock, mutex_unlock,
|
||||
condvar_new, condvar_free, condvar_wait, condvar_wait_timeout, condvar_wake_one, condvar_wake_all
|
||||
);
|
||||
}
|
||||
|
||||
static Mutex* mutex_new()
|
||||
{
|
||||
return new Mx;
|
||||
}
|
||||
|
||||
static void mutex_free( Mutex* mx )
|
||||
{
|
||||
delete mx;
|
||||
}
|
||||
|
||||
static void mutex_lock( Mutex* mx )
|
||||
{
|
||||
mx->lock();
|
||||
}
|
||||
|
||||
static void mutex_unlock( Mutex* mx )
|
||||
{
|
||||
mx->unlock();
|
||||
}
|
||||
|
||||
static CondVar* condvar_new()
|
||||
{
|
||||
return new Cv;
|
||||
}
|
||||
|
||||
static void condvar_free( CondVar* cv )
|
||||
{
|
||||
delete cv;
|
||||
}
|
||||
|
||||
static void condvar_wait( CondVar* cv, Mutex* mx )
|
||||
{
|
||||
cv->wait(mx);
|
||||
}
|
||||
|
||||
static bool condvar_wait_timeout( CondVar* cv, Mutex* mx, int timeout )
|
||||
{
|
||||
return cv->wait_timeout(mx, timeout);
|
||||
}
|
||||
|
||||
static void condvar_wake_one( CondVar* cv )
|
||||
{
|
||||
cv->wake_one();
|
||||
}
|
||||
|
||||
static void condvar_wake_all( CondVar* cv )
|
||||
{
|
||||
cv->wake_all();
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_DISPATCHER_H
|
231
include/dbus-c++/error.h
Normal file
231
include/dbus-c++/error.h
Normal file
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_ERROR_H
|
||||
#define __DBUSXX_ERROR_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <exception>
|
||||
|
||||
namespace DBus {
|
||||
|
||||
class Message;
|
||||
class InternalError;
|
||||
|
||||
class Error : public std::exception
|
||||
{
|
||||
public:
|
||||
|
||||
Error();
|
||||
|
||||
Error( InternalError& );
|
||||
|
||||
Error( const char* name, const char* message );
|
||||
|
||||
Error( Message& );
|
||||
|
||||
~Error() throw()
|
||||
{}
|
||||
|
||||
const char* what() const throw();
|
||||
|
||||
const char* name();
|
||||
|
||||
const char* message();
|
||||
|
||||
void set( const char* name, const char* message );
|
||||
// parameters MUST be static strings
|
||||
|
||||
bool is_set();
|
||||
|
||||
operator bool()
|
||||
{
|
||||
return is_set();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
RefPtrI<InternalError> _int;
|
||||
};
|
||||
|
||||
struct ErrorFailed : public Error
|
||||
{
|
||||
ErrorFailed( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.Failed", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorNoMemory : public Error
|
||||
{
|
||||
ErrorNoMemory( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.NoMemory", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorServiceUnknown : public Error
|
||||
{
|
||||
ErrorServiceUnknown( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.ServiceUnknown", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorNameHasNoOwner : public Error
|
||||
{
|
||||
ErrorNameHasNoOwner( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.NameHasNoOwner", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorNoReply : public Error
|
||||
{
|
||||
ErrorNoReply( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.NoReply", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorIOError : public Error
|
||||
{
|
||||
ErrorIOError( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.IOError", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorBadAddress : public Error
|
||||
{
|
||||
ErrorBadAddress( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.BadAddress", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorNotSupported : public Error
|
||||
{
|
||||
ErrorNotSupported( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.NotSupported", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorLimitsExceeded : public Error
|
||||
{
|
||||
ErrorLimitsExceeded( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.LimitsExceeded", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorAccessDenied : public Error
|
||||
{
|
||||
ErrorAccessDenied( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.AccessDenied", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorAuthFailed : public Error
|
||||
{
|
||||
ErrorAuthFailed( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.AuthFailed", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorNoServer : public Error
|
||||
{
|
||||
ErrorNoServer( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.NoServer", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorTimeout : public Error
|
||||
{
|
||||
ErrorTimeout( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.Timeout", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorNoNetwork : public Error
|
||||
{
|
||||
ErrorNoNetwork( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.NoNetwork", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorAddressInUse : public Error
|
||||
{
|
||||
ErrorAddressInUse( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.AddressInUse", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorDisconnected : public Error
|
||||
{
|
||||
ErrorDisconnected( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.Disconnected", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorInvalidArgs : public Error
|
||||
{
|
||||
ErrorInvalidArgs( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.InvalidArgs", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorFileNotFound : public Error
|
||||
{
|
||||
ErrorFileNotFound( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.FileNotFound", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorUnknownMethod : public Error
|
||||
{
|
||||
ErrorUnknownMethod( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.UnknownMethod", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorTimedOut : public Error
|
||||
{
|
||||
ErrorTimedOut( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.TimedOut", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorMatchRuleNotFound : public Error
|
||||
{
|
||||
ErrorMatchRuleNotFound( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.MatchRuleNotFound", message)
|
||||
{}
|
||||
};
|
||||
|
||||
struct ErrorMatchRuleInvalid : public Error
|
||||
{
|
||||
ErrorMatchRuleInvalid( const char* message )
|
||||
: Error("org.freedesktop.DBus.Error.MatchRuleInvalid", message)
|
||||
{}
|
||||
};
|
||||
|
||||
/* TODO: add the remaining error codes from dbus-protocol.h */
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_ERROR_H
|
197
include/dbus-c++/eventloop.h
Normal file
197
include/dbus-c++/eventloop.h
Normal file
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_EVENTLOOP_H
|
||||
#define __DBUSXX_EVENTLOOP_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "dispatcher.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
class EepleMainLoop;
|
||||
|
||||
class EepleTimeout
|
||||
{
|
||||
public:
|
||||
|
||||
EepleTimeout( int interval, bool repeat, EepleMainLoop* );
|
||||
|
||||
virtual ~EepleTimeout();
|
||||
|
||||
bool enabled(){ return _enabled; }
|
||||
void enabled(bool e){ _enabled = e; }
|
||||
|
||||
int interval(){ return _interval; }
|
||||
void interval(int i){ _interval = i; }
|
||||
|
||||
bool repeat(){ return _repeat; }
|
||||
void repeat(bool r){ _repeat = r; }
|
||||
|
||||
void* data(){ return _data; }
|
||||
void data(void* d){ _data = d; }
|
||||
|
||||
Slot<void, EepleTimeout&> expired;
|
||||
|
||||
private:
|
||||
|
||||
bool _enabled;
|
||||
|
||||
int _interval;
|
||||
bool _repeat;
|
||||
|
||||
double _expiration;
|
||||
|
||||
void* _data;
|
||||
|
||||
EepleMainLoop* _disp;
|
||||
|
||||
friend class EepleMainLoop;
|
||||
};
|
||||
|
||||
typedef std::list< EepleTimeout* > Timeouts;
|
||||
|
||||
class EepleWatch
|
||||
{
|
||||
public:
|
||||
|
||||
EepleWatch( int fd, int flags, EepleMainLoop* );
|
||||
|
||||
virtual ~EepleWatch();
|
||||
|
||||
bool enabled(){ return _enabled; }
|
||||
void enabled(bool e){ _enabled = e; }
|
||||
|
||||
int descriptor(){ return _fd; }
|
||||
|
||||
int flags(){ return _flags; }
|
||||
void flags( int f ){ _flags = f; }
|
||||
|
||||
int state(){ return _state; }
|
||||
|
||||
void* data(){ return _data; }
|
||||
void data(void* d){ _data = d; }
|
||||
|
||||
Slot<void, EepleWatch&> ready;
|
||||
|
||||
private:
|
||||
|
||||
bool _enabled;
|
||||
|
||||
int _fd;
|
||||
int _flags;
|
||||
int _state;
|
||||
|
||||
void* _data;
|
||||
|
||||
EepleMainLoop* _disp;
|
||||
|
||||
friend class EepleMainLoop;
|
||||
};
|
||||
|
||||
typedef std::list< EepleWatch* > Watches;
|
||||
|
||||
class EepleMainLoop
|
||||
{
|
||||
public:
|
||||
|
||||
EepleMainLoop();
|
||||
|
||||
virtual ~EepleMainLoop();
|
||||
|
||||
virtual void dispatch();
|
||||
|
||||
private:
|
||||
|
||||
Timeouts _timeouts;
|
||||
Watches _watches;
|
||||
|
||||
friend class EepleTimeout;
|
||||
friend class EepleWatch;
|
||||
};
|
||||
|
||||
/* the classes below are those you are going to implement if you
|
||||
* want to use another event loop (Qt, Glib, boost, whatever).
|
||||
*
|
||||
* Don't forget to set 'default_dispatcher' accordingly!
|
||||
*/
|
||||
|
||||
class BusDispatcher;
|
||||
|
||||
class BusTimeout : public Timeout, public EepleTimeout
|
||||
{
|
||||
BusTimeout( Timeout::Internal*, BusDispatcher* );
|
||||
|
||||
void toggle();
|
||||
|
||||
friend class BusDispatcher;
|
||||
};
|
||||
|
||||
class BusWatch : public Watch, public EepleWatch
|
||||
{
|
||||
BusWatch( Watch::Internal*, BusDispatcher* );
|
||||
|
||||
void toggle();
|
||||
|
||||
friend class BusDispatcher;
|
||||
};
|
||||
|
||||
class BusDispatcher : public Dispatcher, public EepleMainLoop
|
||||
{
|
||||
public:
|
||||
|
||||
BusDispatcher() : _running(false)
|
||||
{}
|
||||
|
||||
~BusDispatcher()
|
||||
{}
|
||||
|
||||
virtual void enter();
|
||||
|
||||
virtual void leave();
|
||||
|
||||
virtual void do_iteration();
|
||||
|
||||
virtual Timeout* add_timeout( Timeout::Internal* );
|
||||
|
||||
virtual void rem_timeout( Timeout* );
|
||||
|
||||
virtual Watch* add_watch( Watch::Internal* );
|
||||
|
||||
virtual void rem_watch( Watch* );
|
||||
|
||||
void watch_ready( EepleWatch& );
|
||||
|
||||
void timeout_expired( EepleTimeout& );
|
||||
|
||||
private:
|
||||
|
||||
bool _running;
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_EVENTLOOP_H
|
152
include/dbus-c++/interface.h
Normal file
152
include/dbus-c++/interface.h
Normal file
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_INTERFACE_H
|
||||
#define __DBUSXX_INTERFACE_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "util.h"
|
||||
|
||||
#include "message.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
class Interface;
|
||||
class IfaceTracker;
|
||||
|
||||
typedef std::map<std::string, Interface*> InterfaceTable;
|
||||
|
||||
class Object;
|
||||
|
||||
class CallMessage;
|
||||
class SignalMessage;
|
||||
|
||||
class IntrospectedInterface;
|
||||
|
||||
class IfaceTracker
|
||||
{
|
||||
public:
|
||||
|
||||
virtual const Object* object() const = 0 ;
|
||||
|
||||
protected:
|
||||
|
||||
InterfaceTable _interfaces;
|
||||
|
||||
virtual ~IfaceTracker()
|
||||
{}
|
||||
|
||||
virtual void remit_signal( SignalMessage& )
|
||||
{}
|
||||
|
||||
virtual Message rinvoke_method( CallMessage& );
|
||||
};
|
||||
|
||||
typedef std::map< std::string, Slot<Message, const CallMessage&> > MethodTable;
|
||||
typedef std::map< std::string, Slot<void, const SignalMessage&> > SignalTable;
|
||||
|
||||
class Interface : public virtual IfaceTracker
|
||||
{
|
||||
public:
|
||||
|
||||
Interface( const char* name );
|
||||
|
||||
virtual ~Interface();
|
||||
|
||||
inline const std::string& iname() const;
|
||||
|
||||
virtual Message invoke_method( const CallMessage& );
|
||||
|
||||
virtual bool dispatch_signal( const SignalMessage& );
|
||||
|
||||
virtual IntrospectedInterface* const introspect() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void register_interface( const char* name );
|
||||
|
||||
private:
|
||||
|
||||
std::string _name;
|
||||
};
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
const std::string& Interface::iname() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
class InterfaceAdaptor : public Interface
|
||||
{
|
||||
public:
|
||||
|
||||
InterfaceAdaptor( const char* name );
|
||||
|
||||
Message invoke_method( const CallMessage& );
|
||||
|
||||
void emit_signal( const SignalMessage& );
|
||||
|
||||
protected:
|
||||
|
||||
MethodTable _methods;
|
||||
};
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
class InterfaceProxy : public Interface
|
||||
{
|
||||
public:
|
||||
|
||||
InterfaceProxy( const char* name );
|
||||
|
||||
Message invoke_method( const CallMessage& );
|
||||
|
||||
bool dispatch_signal( const SignalMessage& );
|
||||
|
||||
protected:
|
||||
|
||||
SignalTable _signals;
|
||||
};
|
||||
|
||||
# define register_method(interface, method, callback) \
|
||||
InterfaceAdaptor::_methods[ #method ] = \
|
||||
new DBus::Callback< interface, DBus::Message, const DBus::CallMessage& >(this, & interface :: callback );
|
||||
|
||||
# define connect_signal(interface, signal) \
|
||||
InterfaceProxy::_signals[ #signal ] = \
|
||||
new DBus::Callback< interface, void, const DBus::SignalMessage& >(this, & interface :: method );
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_INTERFACE_H
|
76
include/dbus-c++/introspection.h
Normal file
76
include/dbus-c++/introspection.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_INTROSPECTION_H
|
||||
#define __DBUSXX_INTROSPECTION_H
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
struct IntrospectedArgument
|
||||
{
|
||||
const char* name;
|
||||
const char* type;
|
||||
const bool in;
|
||||
};
|
||||
|
||||
struct IntrospectedMethod
|
||||
{
|
||||
const char* name;
|
||||
const IntrospectedArgument* args;
|
||||
};
|
||||
|
||||
struct IntrospectedInterface
|
||||
{
|
||||
const char* name;
|
||||
const IntrospectedMethod* methods;
|
||||
const IntrospectedMethod* signals;
|
||||
};
|
||||
|
||||
class IntrospectableAdaptor : public InterfaceAdaptor
|
||||
{
|
||||
public:
|
||||
|
||||
IntrospectableAdaptor();
|
||||
|
||||
Message Introspect( const CallMessage& );
|
||||
|
||||
protected:
|
||||
|
||||
IntrospectedInterface* const introspect() const;
|
||||
};
|
||||
|
||||
class IntrospectableProxy : public InterfaceProxy
|
||||
{
|
||||
public:
|
||||
|
||||
IntrospectableProxy();
|
||||
|
||||
std::string Introspect();
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_INTROSPECTION_H
|
305
include/dbus-c++/message.h
Normal file
305
include/dbus-c++/message.h
Normal file
|
@ -0,0 +1,305 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_MESSAGE_H
|
||||
#define __DBUSXX_MESSAGE_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
class Message;
|
||||
class ErrorMessage;
|
||||
class SignalMessage;
|
||||
class ReturnMessage;
|
||||
class Error;
|
||||
class Connection;
|
||||
|
||||
class MessageIter
|
||||
{
|
||||
public:
|
||||
|
||||
MessageIter() {}
|
||||
|
||||
int type();
|
||||
|
||||
bool at_end();
|
||||
|
||||
bool has_next();
|
||||
|
||||
MessageIter& operator ++();
|
||||
|
||||
MessageIter operator ++(int);
|
||||
|
||||
bool append_byte( unsigned char byte );
|
||||
|
||||
unsigned char get_byte();
|
||||
|
||||
bool append_bool( bool b );
|
||||
|
||||
bool get_bool();
|
||||
|
||||
bool append_int16( signed short i );
|
||||
|
||||
signed short get_int16();
|
||||
|
||||
bool append_uint16( unsigned short u );
|
||||
|
||||
unsigned short get_uint16();
|
||||
|
||||
bool append_int32( signed int i );
|
||||
|
||||
signed int get_int32();
|
||||
|
||||
bool append_uint32( unsigned int u );
|
||||
|
||||
unsigned int get_uint32();
|
||||
|
||||
bool append_int64( signed long long i );
|
||||
|
||||
signed long long get_int64();
|
||||
|
||||
bool append_uint64( unsigned long long i );
|
||||
|
||||
unsigned long long get_uint64();
|
||||
|
||||
bool append_double( double d );
|
||||
|
||||
double get_double();
|
||||
|
||||
bool append_string( const char* chars );
|
||||
|
||||
const char* get_string();
|
||||
|
||||
bool append_path( const char* chars );
|
||||
|
||||
const char* get_path();
|
||||
|
||||
bool append_signature( const char* chars );
|
||||
|
||||
const char* get_signature();
|
||||
|
||||
char* signature() const; //returned string must be manually free()'d
|
||||
|
||||
MessageIter recurse();
|
||||
|
||||
bool append_array( char type, const void* ptr, size_t length );
|
||||
|
||||
int array_type();
|
||||
|
||||
int get_array( void* ptr );
|
||||
|
||||
MessageIter new_array( const char* sig );
|
||||
|
||||
bool is_array();
|
||||
|
||||
int array_length();
|
||||
|
||||
MessageIter new_dict_entry();
|
||||
|
||||
bool is_dict();
|
||||
|
||||
MessageIter new_variant( const char* sig );
|
||||
|
||||
MessageIter new_struct( const char* sig );
|
||||
|
||||
void close_container( MessageIter& container );
|
||||
|
||||
Message& msg() const
|
||||
{
|
||||
return *_msg;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
MessageIter(Message& msg) : _msg(&msg) {}
|
||||
|
||||
bool append_basic( int type_id, void* value );
|
||||
|
||||
void get_basic( int type_id, void* ptr );
|
||||
|
||||
private:
|
||||
|
||||
/* I'm sorry, but don't want to include dbus.h in the public api
|
||||
*/
|
||||
unsigned char _iter[sizeof(void*)*3+sizeof(int)*11];
|
||||
|
||||
Message* _msg;
|
||||
|
||||
friend class Message;
|
||||
};
|
||||
|
||||
class Message
|
||||
{
|
||||
public:
|
||||
|
||||
struct Private;
|
||||
|
||||
Message( Private* );
|
||||
|
||||
Message( const Message& m );
|
||||
|
||||
~Message();
|
||||
|
||||
Message copy();
|
||||
|
||||
int type() const;
|
||||
|
||||
int serial() const;
|
||||
|
||||
int reply_serial() const;
|
||||
|
||||
bool reply_serial( int );
|
||||
|
||||
const char* sender() const;
|
||||
|
||||
bool sender( const char* s );
|
||||
|
||||
const char* destination() const;
|
||||
|
||||
bool destination( const char* s );
|
||||
|
||||
bool is_error() const;
|
||||
|
||||
bool is_signal( const char* interface, const char* member ) const;
|
||||
|
||||
MessageIter r_iter() const;
|
||||
|
||||
MessageIter w_iter();
|
||||
|
||||
bool append( int first_type, ... );
|
||||
|
||||
void terminate();
|
||||
|
||||
protected:
|
||||
|
||||
Message();
|
||||
|
||||
protected:
|
||||
|
||||
RefPtrI<Private> _pvt;
|
||||
|
||||
/* classes who need to read `_pvt` directly
|
||||
*/
|
||||
friend class ErrorMessage;
|
||||
friend class ReturnMessage;
|
||||
friend class MessageIter;
|
||||
friend class Error;
|
||||
friend class Connection;
|
||||
};
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
class ErrorMessage : public Message
|
||||
{
|
||||
public:
|
||||
|
||||
ErrorMessage();
|
||||
|
||||
ErrorMessage( const Message&, const char* name, const char* message );
|
||||
|
||||
const char* name() const;
|
||||
|
||||
bool name( const char* n );
|
||||
|
||||
bool operator == ( const ErrorMessage& ) const;
|
||||
};
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
class SignalMessage : public Message
|
||||
{
|
||||
public:
|
||||
|
||||
SignalMessage( const char* name );
|
||||
|
||||
SignalMessage( const char* path, const char* interface, const char* name );
|
||||
|
||||
const char* interface() const;
|
||||
|
||||
bool interface( const char* i );
|
||||
|
||||
const char* member() const;
|
||||
|
||||
bool member( const char* m );
|
||||
|
||||
const char* path() const;
|
||||
|
||||
char** path_split() const;
|
||||
|
||||
bool path( const char* p );
|
||||
|
||||
bool operator == ( const SignalMessage& ) const;
|
||||
};
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
class CallMessage : public Message
|
||||
{
|
||||
public:
|
||||
|
||||
CallMessage();
|
||||
|
||||
CallMessage( const char* dest, const char* path, const char* iface, const char* method );
|
||||
|
||||
const char* interface() const;
|
||||
|
||||
bool interface( const char* i );
|
||||
|
||||
const char* member() const;
|
||||
|
||||
bool member( const char* m );
|
||||
|
||||
const char* path() const;
|
||||
|
||||
char** path_split() const;
|
||||
|
||||
bool path( const char* p );
|
||||
|
||||
const char* signature() const;
|
||||
|
||||
bool operator == ( const CallMessage& ) const;
|
||||
};
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
class ReturnMessage : public Message
|
||||
{
|
||||
public:
|
||||
|
||||
ReturnMessage( const CallMessage& callee );
|
||||
|
||||
const char* signature() const;
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_MESSAGE_H
|
199
include/dbus-c++/object.h
Normal file
199
include/dbus-c++/object.h
Normal file
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_OBJECT_H
|
||||
#define __DBUSXX_OBJECT_H
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include "interface.h"
|
||||
#include "connection.h"
|
||||
#include "message.h"
|
||||
#include "types.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
class Object;
|
||||
|
||||
typedef std::list<Object*> ObjectPList;
|
||||
|
||||
class ObjectAdaptor;
|
||||
|
||||
class ObjectProxy;
|
||||
|
||||
class Object : protected virtual IfaceTracker
|
||||
{
|
||||
protected:
|
||||
|
||||
Object( Connection& conn, const char* path, const char* service );
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Object();
|
||||
|
||||
inline const DBus::Path& path() const;
|
||||
|
||||
inline const std::string& service() const;
|
||||
|
||||
inline const Object* object() const;
|
||||
|
||||
inline Connection& conn();
|
||||
|
||||
private:
|
||||
|
||||
//Object( const Object& );
|
||||
|
||||
virtual bool handle_message( const Message& ) = 0;
|
||||
virtual void register_obj() = 0;
|
||||
virtual void unregister_obj() = 0;
|
||||
|
||||
private:
|
||||
|
||||
Connection _conn;
|
||||
DBus::Path _path;
|
||||
std::string _service;
|
||||
};
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
const Object* Object::object() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
Connection& Object::conn()
|
||||
{
|
||||
return _conn;
|
||||
}
|
||||
|
||||
const DBus::Path& Object::path() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
const std::string& Object::service() const
|
||||
{
|
||||
return _service;
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
class ObjectAdaptor : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
struct Private;
|
||||
|
||||
ObjectAdaptor( Connection& conn, const char* path );
|
||||
|
||||
~ObjectAdaptor();
|
||||
|
||||
void remit_signal( SignalMessage& );
|
||||
|
||||
protected:
|
||||
|
||||
class DeferredReturn
|
||||
{
|
||||
public:
|
||||
|
||||
inline MessageIter& writer();
|
||||
|
||||
inline void* tag();
|
||||
|
||||
private:
|
||||
|
||||
DeferredReturn( Connection& conn, const CallMessage& call, const void* tag );
|
||||
|
||||
Connection _conn;
|
||||
CallMessage _call;
|
||||
MessageIter _writer;
|
||||
ReturnMessage _return;
|
||||
const void* _tag;
|
||||
|
||||
friend class ObjectAdaptor;
|
||||
};
|
||||
|
||||
void return_later( const void* tag );
|
||||
|
||||
void return_now( DeferredReturn* ret );
|
||||
|
||||
void return_error( DeferredReturn* ret, Error& error );
|
||||
|
||||
DeferredReturn* find_return( const void* tag );
|
||||
|
||||
private:
|
||||
|
||||
bool handle_message( const Message& );
|
||||
|
||||
void register_obj();
|
||||
void unregister_obj();
|
||||
|
||||
typedef std::map<const void*, DeferredReturn*> DeferredReturnMap;
|
||||
DeferredReturnMap _deferred_returns;
|
||||
|
||||
friend struct Private;
|
||||
};
|
||||
|
||||
void* ObjectAdaptor::DeferredReturn::tag()
|
||||
{
|
||||
return const_cast<void*>(_tag);
|
||||
}
|
||||
|
||||
MessageIter& ObjectAdaptor::DeferredReturn::writer()
|
||||
{
|
||||
return _writer;
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
class ObjectProxy : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
ObjectProxy( Connection& conn, const char* path, const char* service = "" );
|
||||
|
||||
~ObjectProxy();
|
||||
|
||||
Message rinvoke_method( CallMessage& );
|
||||
|
||||
private:
|
||||
|
||||
bool handle_message( const Message& );
|
||||
|
||||
void register_obj();
|
||||
void unregister_obj();
|
||||
|
||||
private:
|
||||
|
||||
MessageSlot _filtered;
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_OBJECT_H
|
70
include/dbus-c++/pendingcall.h
Normal file
70
include/dbus-c++/pendingcall.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_PENDING_CALL_H
|
||||
#define __DBUSXX_PENDING_CALL_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
class Connection;
|
||||
|
||||
class PendingCall
|
||||
{
|
||||
public:
|
||||
|
||||
struct Private;
|
||||
|
||||
PendingCall( Private* );
|
||||
|
||||
virtual ~PendingCall();
|
||||
|
||||
bool completed();
|
||||
|
||||
void cancel();
|
||||
|
||||
void block();
|
||||
|
||||
void data( void* );
|
||||
|
||||
void* data();
|
||||
|
||||
Slot<void, PendingCall&> slot;
|
||||
|
||||
private:
|
||||
|
||||
PendingCall( const PendingCall& );
|
||||
|
||||
private:
|
||||
|
||||
RefPtrI<Private> _pvt;
|
||||
|
||||
friend struct Private;
|
||||
friend class Connection;
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_PENDING_CALL_H
|
45
include/dbus-c++/refptr_impl.h
Normal file
45
include/dbus-c++/refptr_impl.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_REFPTR_IMPL_H
|
||||
#define __DBUSXX_REFPTR_IMPL_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
template <class T>
|
||||
RefPtrI<T>::RefPtrI( T* ptr )
|
||||
: __ptr(ptr)
|
||||
{}
|
||||
|
||||
template <class T>
|
||||
RefPtrI<T>::~RefPtrI()
|
||||
{
|
||||
if(__cnt.one()) delete __ptr;
|
||||
}
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_REFPTR_IMPL_H
|
72
include/dbus-c++/server.h
Normal file
72
include/dbus-c++/server.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_SERVER_H
|
||||
#define __DBUSXX_SERVER_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "error.h"
|
||||
#include "connection.h"
|
||||
#include "util.h"
|
||||
#include "dispatcher.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
class Server;
|
||||
|
||||
typedef std::list<Server> ServerList;
|
||||
|
||||
class Server
|
||||
{
|
||||
public:
|
||||
|
||||
Server( const char* address );
|
||||
|
||||
Server( const Server& s );
|
||||
|
||||
Dispatcher* setup( Dispatcher* );
|
||||
|
||||
virtual ~Server();
|
||||
|
||||
bool operator == ( const Server& ) const;
|
||||
|
||||
bool listening() const;
|
||||
|
||||
void disconnect();
|
||||
|
||||
struct Private;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void on_new_connection( Connection& c ) = 0;
|
||||
|
||||
private:
|
||||
|
||||
RefPtrI<Private> _pvt;
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_SERVER_H
|
484
include/dbus-c++/types.h
Normal file
484
include/dbus-c++/types.h
Normal file
|
@ -0,0 +1,484 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_TYPES_H
|
||||
#define __DBUSXX_TYPES_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "util.h"
|
||||
#include "message.h"
|
||||
#include "error.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
typedef unsigned char Byte;
|
||||
typedef bool Bool;
|
||||
typedef signed short Int16;
|
||||
typedef unsigned short UInt16;
|
||||
typedef signed int Int32;
|
||||
typedef unsigned int UInt32;
|
||||
typedef signed long long Int64;
|
||||
typedef unsigned long long UInt64;
|
||||
typedef double Double;
|
||||
typedef std::string String;
|
||||
|
||||
struct Path : public std::string
|
||||
{
|
||||
Path() {}
|
||||
Path( const char* c ) : std::string(c) {}
|
||||
Path& operator = ( std::string& s )
|
||||
{
|
||||
std::string::operator = (s);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct Signature : public std::string
|
||||
{
|
||||
Signature() {}
|
||||
Signature( const char* c ) : std::string(c) {}
|
||||
Signature& operator = ( std::string& s )
|
||||
{
|
||||
std::string::operator = (s);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct Invalid {};
|
||||
|
||||
class Variant
|
||||
{
|
||||
public:
|
||||
|
||||
Variant();
|
||||
|
||||
Variant( MessageIter& it );
|
||||
|
||||
Variant& operator = ( const Variant& v );
|
||||
|
||||
const char* signature() const;
|
||||
|
||||
MessageIter iter() const
|
||||
{
|
||||
return _it;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Message _msg;
|
||||
MessageIter _it;
|
||||
mutable Signature _signature;
|
||||
};
|
||||
|
||||
template <typename E>
|
||||
struct Array : public std::vector<E> {};
|
||||
|
||||
template <typename K, typename V>
|
||||
struct Dict : public std::map<K, V>
|
||||
{
|
||||
bool has_key( const K& key ) const
|
||||
{
|
||||
return this->find(key) != this->end();
|
||||
}
|
||||
};
|
||||
|
||||
template <
|
||||
typename T1,
|
||||
typename T2 = Invalid,
|
||||
typename T3 = Invalid,
|
||||
typename T4 = Invalid,
|
||||
typename T5 = Invalid,
|
||||
typename T6 = Invalid,
|
||||
typename T7 = Invalid,
|
||||
typename T8 = Invalid // who needs more than eight?
|
||||
>
|
||||
struct Struct
|
||||
{
|
||||
T1 _1; T2 _2; T3 _3; T4 _4; T5 _5; T6 _6; T7 _7; T8 _8;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct type
|
||||
{
|
||||
static std::string sig()
|
||||
{
|
||||
throw ErrorInvalidArgs("unknown type");
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct type<Byte> { static std::string sig(){ return "y"; } };
|
||||
template <> struct type<Bool> { static std::string sig(){ return "b"; } };
|
||||
template <> struct type<Int16> { static std::string sig(){ return "n"; } };
|
||||
template <> struct type<UInt16> { static std::string sig(){ return "q"; } };
|
||||
template <> struct type<Int32> { static std::string sig(){ return "i"; } };
|
||||
template <> struct type<UInt32> { static std::string sig(){ return "u"; } };
|
||||
template <> struct type<Int64> { static std::string sig(){ return "x"; } };
|
||||
template <> struct type<UInt64> { static std::string sig(){ return "t"; } };
|
||||
template <> struct type<Double> { static std::string sig(){ return "d"; } };
|
||||
template <> struct type<String> { static std::string sig(){ return "s"; } };
|
||||
template <> struct type<Path> { static std::string sig(){ return "o"; } };
|
||||
template <> struct type<Signature> { static std::string sig(){ return "g"; } };
|
||||
template <> struct type<Invalid> { static std::string sig(){ return ""; } };
|
||||
|
||||
template <typename E>
|
||||
struct type< std::vector<E> >
|
||||
{ static std::string sig(){ return "a" + type<E>::sig(); } };
|
||||
|
||||
template <typename K, typename V>
|
||||
struct type< std::map<K,V> >
|
||||
{ static std::string sig(){ return "a{" + type<K>::sig() + type<V>::sig() + "}"; } };
|
||||
|
||||
template <
|
||||
typename T1,
|
||||
typename T2,
|
||||
typename T3,
|
||||
typename T4,
|
||||
typename T5,
|
||||
typename T6,
|
||||
typename T7,
|
||||
typename T8 // who needs more than eight?
|
||||
>
|
||||
struct type< Struct<T1,T2,T3,T4,T5,T6,T7,T8> >
|
||||
{
|
||||
static std::string sig()
|
||||
{
|
||||
return "("
|
||||
+ type<T1>::sig()
|
||||
+ type<T2>::sig()
|
||||
+ type<T3>::sig()
|
||||
+ type<T4>::sig()
|
||||
+ type<T5>::sig()
|
||||
+ type<T6>::sig()
|
||||
+ type<T7>::sig()
|
||||
+ type<T8>::sig()
|
||||
+ ")";
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Invalid& )
|
||||
{
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Byte& val )
|
||||
{
|
||||
iter.append_byte(val);
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Bool& val )
|
||||
{
|
||||
iter.append_bool(val);
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Int16& val )
|
||||
{
|
||||
iter.append_int16(val);
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::UInt16& val )
|
||||
{
|
||||
iter.append_uint16(val);
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Int32& val )
|
||||
{
|
||||
iter.append_int32(val);
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::UInt32& val )
|
||||
{
|
||||
iter.append_uint32(val);
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Int64& val )
|
||||
{
|
||||
iter.append_int64(val);
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::UInt64& val )
|
||||
{
|
||||
iter.append_uint64(val);
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Double& val )
|
||||
{
|
||||
iter.append_double(val);
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::String& val )
|
||||
{
|
||||
iter.append_string(val.c_str());
|
||||
return iter;
|
||||
}
|
||||
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Path& val )
|
||||
{
|
||||
iter.append_path(val.c_str());
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Signature& val )
|
||||
{
|
||||
iter.append_signature(val.c_str());
|
||||
return iter;
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::vector<E>& val )
|
||||
{
|
||||
const std::string sig = DBus::type<E>::sig();
|
||||
DBus::MessageIter ait = iter.new_array(sig.c_str());
|
||||
|
||||
typename std::vector<E>::const_iterator vit;
|
||||
for(vit = val.begin(); vit != val.end(); ++vit)
|
||||
{
|
||||
ait << *vit;
|
||||
}
|
||||
|
||||
iter.close_container(ait);
|
||||
return iter;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::vector<DBus::Byte>& val )
|
||||
{
|
||||
iter.append_array('b', &val.front(), val.size());
|
||||
return iter;
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::map<K,V>& val )
|
||||
{
|
||||
const std::string sig = DBus::type<K>::sig() + DBus::type<V>::sig();
|
||||
DBus::MessageIter ait = iter.new_array(sig.c_str());
|
||||
|
||||
typename std::map<K,V>::const_iterator mit;
|
||||
for(mit = val.begin(); mit != val.end(); ++mit)
|
||||
{
|
||||
DBus::MessageIter eit = ait.new_dict_entry();
|
||||
|
||||
eit << mit->first << mit->second;
|
||||
|
||||
ait.close_container(eit);
|
||||
}
|
||||
|
||||
iter.close_container(ait);
|
||||
return iter;
|
||||
}
|
||||
|
||||
template <
|
||||
typename T1,
|
||||
typename T2,
|
||||
typename T3,
|
||||
typename T4,
|
||||
typename T5,
|
||||
typename T6,
|
||||
typename T7,
|
||||
typename T8
|
||||
>
|
||||
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Struct<T1,T2,T3,T4,T5,T6,T7,T8>& val )
|
||||
{
|
||||
const std::string sig =
|
||||
DBus::type<T1>::sig() + DBus::type<T2>::sig() + DBus::type<T3>::sig() + DBus::type<T4>::sig() +
|
||||
DBus::type<T5>::sig() + DBus::type<T6>::sig() + DBus::type<T7>::sig() + DBus::type<T8>::sig();
|
||||
|
||||
DBus::MessageIter sit = iter.new_struct(sig.c_str());
|
||||
|
||||
sit << val._1 << val._2 << val._3 << val._4 << val._5 << val._6 << val._7 << val._8;
|
||||
|
||||
iter.close_container(sit);
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Variant& val );
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Invalid& )
|
||||
{
|
||||
return iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Byte& val )
|
||||
{
|
||||
val = iter.get_byte();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Bool& val )
|
||||
{
|
||||
val = iter.get_bool();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Int16& val )
|
||||
{
|
||||
val = iter.get_int16();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::UInt16& val )
|
||||
{
|
||||
val = iter.get_uint16();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Int32& val )
|
||||
{
|
||||
val = iter.get_int32();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::UInt32& val )
|
||||
{
|
||||
val = iter.get_uint32();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Int64& val )
|
||||
{
|
||||
val = iter.get_int64();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::UInt64& val )
|
||||
{
|
||||
val = iter.get_uint64();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Double& val )
|
||||
{
|
||||
val = iter.get_double();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::String& val )
|
||||
{
|
||||
val = iter.get_string();
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector<E>& val )
|
||||
{
|
||||
if(!iter.is_array())
|
||||
throw DBus::ErrorInvalidArgs("array expected");
|
||||
|
||||
DBus::MessageIter ait = iter.recurse();
|
||||
|
||||
while(!ait.at_end())
|
||||
{
|
||||
E elem;
|
||||
|
||||
ait >> elem;
|
||||
|
||||
val.push_back(elem);
|
||||
|
||||
++ait;
|
||||
}
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector<DBus::Byte>& val )
|
||||
{
|
||||
if(!iter.is_array())
|
||||
throw DBus::ErrorInvalidArgs("array expected");
|
||||
|
||||
if(iter.array_type() != 'b')
|
||||
throw DBus::ErrorInvalidArgs("byte-array expected");
|
||||
|
||||
val.reserve(iter.array_length());
|
||||
|
||||
iter.get_array(const_cast<DBus::Byte*>(&val.front()));
|
||||
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::map<K,V>& val )
|
||||
{
|
||||
if(!iter.is_dict())
|
||||
throw DBus::ErrorInvalidArgs("dictionary value expected");
|
||||
|
||||
DBus::MessageIter mit = iter.recurse();
|
||||
|
||||
while(!mit.at_end())
|
||||
{
|
||||
K key; V value;
|
||||
|
||||
DBus::MessageIter eit = mit.recurse();
|
||||
|
||||
eit >> key >> value;
|
||||
|
||||
val[key] = value;
|
||||
|
||||
++mit;
|
||||
}
|
||||
|
||||
return ++iter;
|
||||
}
|
||||
|
||||
template <
|
||||
typename T1,
|
||||
typename T2,
|
||||
typename T3,
|
||||
typename T4,
|
||||
typename T5,
|
||||
typename T6,
|
||||
typename T7,
|
||||
typename T8
|
||||
>
|
||||
inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Struct<T1,T2,T3,T4,T5,T6,T7,T8>& val)
|
||||
{
|
||||
DBus::MessageIter sit = iter.recurse();
|
||||
|
||||
sit >> val._1 >> val._2 >> val._3 >> val._4 >> val._5 >> val._6 >> val._7 >> val._8;
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Variant& val );
|
||||
|
||||
#endif//__DBUSXX_TYPES_H
|
||||
|
272
include/dbus-c++/util.h
Normal file
272
include/dbus-c++/util.h
Normal file
|
@ -0,0 +1,272 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_UTIL_H
|
||||
#define __DBUSXX_UTIL_H
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
namespace DBus {
|
||||
|
||||
/*
|
||||
* Very simple reference counting
|
||||
*/
|
||||
|
||||
class RefCnt
|
||||
{
|
||||
public:
|
||||
|
||||
RefCnt()
|
||||
{
|
||||
__ref = new int;
|
||||
(*__ref) = 1;
|
||||
}
|
||||
|
||||
RefCnt( const RefCnt& rc )
|
||||
{
|
||||
__ref = rc.__ref;
|
||||
ref();
|
||||
}
|
||||
|
||||
virtual ~RefCnt()
|
||||
{
|
||||
unref();
|
||||
}
|
||||
|
||||
RefCnt& operator = ( const RefCnt& ref )
|
||||
{
|
||||
ref.ref();
|
||||
unref();
|
||||
__ref = ref.__ref;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool noref() const
|
||||
{
|
||||
return (*__ref) == 0;
|
||||
}
|
||||
|
||||
bool one() const
|
||||
{
|
||||
return (*__ref) == 1;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void ref() const
|
||||
{
|
||||
++ (*__ref);
|
||||
}
|
||||
void unref() const
|
||||
{
|
||||
-- (*__ref);
|
||||
|
||||
if( (*__ref) < 0 )
|
||||
{
|
||||
debug_log("%p: refcount dropped below zero!", __ref);
|
||||
}
|
||||
|
||||
if( noref() )
|
||||
{
|
||||
delete __ref;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
int *__ref;
|
||||
};
|
||||
|
||||
/*
|
||||
* Reference counting pointers (emulate boost::shared_ptr)
|
||||
*/
|
||||
|
||||
template <class T>
|
||||
class RefPtrI // RefPtr to incomplete type
|
||||
{
|
||||
public:
|
||||
|
||||
RefPtrI( T* ptr = 0 );
|
||||
|
||||
~RefPtrI();
|
||||
|
||||
RefPtrI& operator = ( const RefPtrI& ref )
|
||||
{
|
||||
if( this != &ref )
|
||||
{
|
||||
if(__cnt.one()) delete __ptr;
|
||||
|
||||
__ptr = ref.__ptr;
|
||||
__cnt = ref.__cnt;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
T& operator *() const
|
||||
{
|
||||
return *__ptr;
|
||||
}
|
||||
|
||||
T* operator ->() const
|
||||
{
|
||||
if(__cnt.noref()) return 0;
|
||||
|
||||
return __ptr;
|
||||
}
|
||||
|
||||
T* get() const
|
||||
{
|
||||
if(__cnt.noref()) return 0;
|
||||
|
||||
return __ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
T* __ptr;
|
||||
RefCnt __cnt;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class RefPtr
|
||||
{
|
||||
public:
|
||||
|
||||
RefPtr( T* ptr = 0)
|
||||
: __ptr(ptr)
|
||||
{}
|
||||
|
||||
~RefPtr()
|
||||
{
|
||||
if(__cnt.one()) delete __ptr;
|
||||
}
|
||||
|
||||
RefPtr& operator = ( const RefPtr& ref )
|
||||
{
|
||||
if( this != &ref )
|
||||
{
|
||||
if(__cnt.one()) delete __ptr;
|
||||
|
||||
__ptr = ref.__ptr;
|
||||
__cnt = ref.__cnt;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
T& operator *() const
|
||||
{
|
||||
return *__ptr;
|
||||
}
|
||||
|
||||
T* operator ->() const
|
||||
{
|
||||
if(__cnt.noref()) return 0;
|
||||
|
||||
return __ptr;
|
||||
}
|
||||
|
||||
T* get() const
|
||||
{
|
||||
if(__cnt.noref()) return 0;
|
||||
|
||||
return __ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
T* __ptr;
|
||||
RefCnt __cnt;
|
||||
};
|
||||
|
||||
/*
|
||||
* Typed callback template
|
||||
*/
|
||||
|
||||
template <class R, class P>
|
||||
class Callback_Base
|
||||
{
|
||||
public:
|
||||
|
||||
virtual R call( P param ) const = 0;
|
||||
|
||||
virtual ~Callback_Base()
|
||||
{}
|
||||
};
|
||||
|
||||
template <class R, class P>
|
||||
class Slot
|
||||
{
|
||||
public:
|
||||
|
||||
Slot& operator = ( Callback_Base<R,P>* s )
|
||||
{
|
||||
_cb = s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
R operator()( P param ) const
|
||||
{
|
||||
/*if(_cb.get())*/ return _cb->call(param);
|
||||
}
|
||||
|
||||
R call( P param ) const
|
||||
{
|
||||
/*if(_cb.get())*/ return _cb->call(param);
|
||||
}
|
||||
|
||||
bool empty()
|
||||
{
|
||||
return _cb.get() != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
RefPtr< Callback_Base<R,P> > _cb;
|
||||
};
|
||||
|
||||
template <class C, class R, class P>
|
||||
class Callback : public Callback_Base<R,P>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef R (C::*M)(P);
|
||||
|
||||
Callback( C* c, M m )
|
||||
: _c(c), _m(m)
|
||||
{}
|
||||
|
||||
R call( P param ) const
|
||||
{
|
||||
/*if(_c)*/ return (_c->*_m)(param);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
C* _c; M _m;
|
||||
};
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
#endif//__DBUSXX_UTIL_H
|
138
include/dbus-c++/xml.h
Normal file
138
include/dbus-c++/xml.h
Normal file
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
*
|
||||
* D-Bus++ - C++ bindings for DBus
|
||||
*
|
||||
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DBUSXX_XML_H
|
||||
#define __DBUSXX_XML_H
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace DBus {
|
||||
|
||||
namespace Xml {
|
||||
|
||||
class Error : public std::exception
|
||||
{
|
||||
public:
|
||||
|
||||
Error( const char* error, int line, int column );
|
||||
|
||||
~Error() throw()
|
||||
{}
|
||||
|
||||
const char* what() const throw()
|
||||
{
|
||||
return _error.c_str();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::string _error;
|
||||
};
|
||||
|
||||
class Node;
|
||||
|
||||
class Nodes : public std::vector<Node*>
|
||||
{
|
||||
public:
|
||||
|
||||
Nodes operator[]( const std::string& key );
|
||||
|
||||
Nodes select( const std::string& attr, const std::string& value );
|
||||
};
|
||||
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<std::string, std::string> Attributes;
|
||||
|
||||
typedef std::vector<Node> Children;
|
||||
|
||||
std::string name;
|
||||
std::string cdata;
|
||||
Children children;
|
||||
|
||||
Node( std::string& n, Attributes& a )
|
||||
: name(n), _attrs(a)
|
||||
{}
|
||||
|
||||
Node( const char* n, const char** a = NULL );
|
||||
|
||||
Nodes operator[]( const std::string& key );
|
||||
|
||||
std::string get( const std::string& attribute );
|
||||
|
||||
void set( const std::string& attribute, std::string value );
|
||||
|
||||
std::string to_xml() const;
|
||||
|
||||
Node& add( Node child )
|
||||
{
|
||||
children.push_back(child);
|
||||
return children.back();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void _raw_xml( std::string& xml, int& depth ) const;
|
||||
|
||||
Attributes _attrs;
|
||||
};
|
||||
|
||||
class Document
|
||||
{
|
||||
public:
|
||||
|
||||
struct Expat;
|
||||
|
||||
Node* root;
|
||||
|
||||
Document();
|
||||
|
||||
Document( const std::string& xml );
|
||||
|
||||
~Document();
|
||||
|
||||
void from_xml( const std::string& xml );
|
||||
|
||||
std::string to_xml() const;
|
||||
|
||||
private:
|
||||
|
||||
int _depth;
|
||||
};
|
||||
|
||||
} /* namespace Xml */
|
||||
|
||||
} /* namespace DBus */
|
||||
|
||||
std::istream& operator >> ( std::istream&, DBus::Xml::Document& );
|
||||
std::ostream& operator << ( std::ostream&, DBus::Xml::Document& );
|
||||
|
||||
#endif//__DBUSXX_XML_H
|
Loading…
Add table
Add a link
Reference in a new issue