* Enabled the symbol visibility feature from gcc 4, reduces binary size and dynamic loading speed

* A lot of fixes to keep compatibility with older (0.6x) versions of libdbus
* Moved the xml handling code from the library to the code generator
* Rewrote the routine to generate introspection data
* Autojunk cleanup



git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@12019 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
pdurante 2007-07-23 18:31:49 +00:00
parent a8f5e819bd
commit 7c420f87cd
36 changed files with 287 additions and 172 deletions

42
include/dbus-c++/api.h Normal file
View file

@ -0,0 +1,42 @@
/*
*
* D-Bus++ - C++ bindings for D-Bus
*
* Copyright (C) 2005-2007 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_API_H
#define __DBUSXX_API_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef GCC_HASCLASSVISIBILITY
# define DXXAPILOCAL __attribute__ ((visibility("hidden")))
# define DXXAPIPUBLIC __attribute__ ((visibility("default")))
#else
# define DXXAPILOCAL
# define DXXAPIPUBLIC
#endif
#define DXXAPI DXXAPIPUBLIC
#endif//__DBUSXX_API_H

View file

@ -6,6 +6,12 @@
/* DBus supports recursive mutexes (needs DBus >= 0.95) */
#undef DBUS_HAS_RECURSIVE_MUTEX
/* dbus_threads_init_default (needs DBus >= 0.93) */
#undef DBUS_HAS_THREADS_INIT_DEFAULT
/* to enable hidden symbols */
#undef GCC_HASCLASSVISIBILITY
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H

View file

@ -31,6 +31,7 @@
#include <list>
#include "api.h"
#include "types.h"
#include "util.h"
#include "message.h"
@ -47,7 +48,7 @@ typedef std::list<Connection> ConnectionList;
class ObjectAdaptor;
class Dispatcher;
class Connection
class DXXAPI Connection
{
public:
@ -111,7 +112,7 @@ public:
private:
void init();
DXXAPILOCAL void init();
private:

View file

@ -43,7 +43,6 @@
#include "util.h"
#include "dispatcher.h"
#include "eventloop.h"
#include "xml.h"
#include "introspection.h"
#endif//__DBUSXX_DBUS_H

View file

@ -29,11 +29,13 @@
#include "config.h"
#endif
#include "api.h"
namespace DBus {
typedef void (*LogFunction)(const char* format, ...);
extern LogFunction debug_log;
extern DXXAPI LogFunction debug_log;
} /* namespace DBus */

View file

@ -29,11 +29,12 @@
#include "config.h"
#endif
#include "api.h"
#include "connection.h"
namespace DBus {
class Timeout
class DXXAPI Timeout
{
public:
@ -53,14 +54,14 @@ public:
private:
Timeout( const Timeout& );
DXXAPILOCAL Timeout( const Timeout& );
private:
Internal* _int;
};
class Watch
class DXXAPI Watch
{
public:
@ -82,14 +83,14 @@ public:
private:
Watch( const Watch& );
DXXAPILOCAL Watch( const Watch& );
private:
Internal* _int;
};
class Dispatcher
class DXXAPI Dispatcher
{
public:
@ -119,12 +120,12 @@ private:
Connection::PrivatePList _pending_queue;
};
extern Dispatcher* default_dispatcher;
extern DXXAPI Dispatcher* default_dispatcher;
/* classes for multithreading support
*/
class Mutex
class DXXAPI Mutex
{
public:
@ -141,7 +142,7 @@ protected:
Internal* _int;
};
class CondVar
class DXXAPI CondVar
{
public:
@ -181,9 +182,11 @@ typedef bool (*CondVarWaitTimeoutFn)( CondVar* cv, Mutex* mx, int timeout );
typedef void (*CondVarWakeOneFn)( CondVar* cv );
typedef void (*CondVarWakeAllFn)( CondVar* cv );
void _init_threading();
#ifdef DBUS_HAS_THREADS_INIT_DEFAULT
void DXXAPI _init_threading();
#endif//DBUS_HAS_THREADS_INIT_DEFAULT
void _init_threading(
void DXXAPI _init_threading(
MutexNewFn, MutexFreeFn, MutexLockFn, MutexUnlockFn,
CondVarNewFn, CondVarFreeFn, CondVarWaitFn, CondVarWaitTimeoutFn, CondVarWakeOneFn, CondVarWakeAllFn
);

View file

@ -29,6 +29,7 @@
#include "config.h"
#endif
#include "api.h"
#include "util.h"
#include <exception>
@ -38,7 +39,7 @@ namespace DBus {
class Message;
class InternalError;
class Error : public std::exception
class DXXAPI Error : public std::exception
{
public:
@ -50,8 +51,7 @@ public:
Error( Message& );
~Error() throw()
{}
~Error() throw();
const char* what() const throw();
@ -74,210 +74,210 @@ private:
RefPtrI<InternalError> _int;
};
struct ErrorFailed : public Error
struct DXXAPI ErrorFailed : public Error
{
ErrorFailed( const char* message )
: Error("org.freedesktop.DBus.Error.Failed", message)
{}
};
struct ErrorNoMemory : public Error
struct DXXAPI ErrorNoMemory : public Error
{
ErrorNoMemory( const char* message )
: Error("org.freedesktop.DBus.Error.NoMemory", message)
{}
};
struct ErrorServiceUnknown : public Error
struct DXXAPI ErrorServiceUnknown : public Error
{
ErrorServiceUnknown( const char* message )
: Error("org.freedesktop.DBus.Error.ServiceUnknown", message)
{}
};
struct ErrorNameHasNoOwner : public Error
struct DXXAPI ErrorNameHasNoOwner : public Error
{
ErrorNameHasNoOwner( const char* message )
: Error("org.freedesktop.DBus.Error.NameHasNoOwner", message)
{}
};
struct ErrorNoReply : public Error
struct DXXAPI ErrorNoReply : public Error
{
ErrorNoReply( const char* message )
: Error("org.freedesktop.DBus.Error.NoReply", message)
{}
};
struct ErrorIOError : public Error
struct DXXAPI ErrorIOError : public Error
{
ErrorIOError( const char* message )
: Error("org.freedesktop.DBus.Error.IOError", message)
{}
};
struct ErrorBadAddress : public Error
struct DXXAPI ErrorBadAddress : public Error
{
ErrorBadAddress( const char* message )
: Error("org.freedesktop.DBus.Error.BadAddress", message)
{}
};
struct ErrorNotSupported : public Error
struct DXXAPI ErrorNotSupported : public Error
{
ErrorNotSupported( const char* message )
: Error("org.freedesktop.DBus.Error.NotSupported", message)
{}
};
struct ErrorLimitsExceeded : public Error
struct DXXAPI ErrorLimitsExceeded : public Error
{
ErrorLimitsExceeded( const char* message )
: Error("org.freedesktop.DBus.Error.LimitsExceeded", message)
{}
};
struct ErrorAccessDenied : public Error
struct DXXAPI ErrorAccessDenied : public Error
{
ErrorAccessDenied( const char* message )
: Error("org.freedesktop.DBus.Error.AccessDenied", message)
{}
};
struct ErrorAuthFailed : public Error
struct DXXAPI ErrorAuthFailed : public Error
{
ErrorAuthFailed( const char* message )
: Error("org.freedesktop.DBus.Error.AuthFailed", message)
{}
};
struct ErrorNoServer : public Error
struct DXXAPI ErrorNoServer : public Error
{
ErrorNoServer( const char* message )
: Error("org.freedesktop.DBus.Error.NoServer", message)
{}
};
struct ErrorTimeout : public Error
struct DXXAPI ErrorTimeout : public Error
{
ErrorTimeout( const char* message )
: Error("org.freedesktop.DBus.Error.Timeout", message)
{}
};
struct ErrorNoNetwork : public Error
struct DXXAPI ErrorNoNetwork : public Error
{
ErrorNoNetwork( const char* message )
: Error("org.freedesktop.DBus.Error.NoNetwork", message)
{}
};
struct ErrorAddressInUse : public Error
struct DXXAPI ErrorAddressInUse : public Error
{
ErrorAddressInUse( const char* message )
: Error("org.freedesktop.DBus.Error.AddressInUse", message)
{}
};
struct ErrorDisconnected : public Error
struct DXXAPI ErrorDisconnected : public Error
{
ErrorDisconnected( const char* message )
: Error("org.freedesktop.DBus.Error.Disconnected", message)
{}
};
struct ErrorInvalidArgs : public Error
struct DXXAPI ErrorInvalidArgs : public Error
{
ErrorInvalidArgs( const char* message )
: Error("org.freedesktop.DBus.Error.InvalidArgs", message)
{}
};
struct ErrorFileNotFound : public Error
struct DXXAPI ErrorFileNotFound : public Error
{
ErrorFileNotFound( const char* message )
: Error("org.freedesktop.DBus.Error.FileNotFound", message)
{}
};
struct ErrorUnknownMethod : public Error
struct DXXAPI ErrorUnknownMethod : public Error
{
ErrorUnknownMethod( const char* message )
: Error("org.freedesktop.DBus.Error.UnknownMethod", message)
{}
};
struct ErrorTimedOut : public Error
struct DXXAPI ErrorTimedOut : public Error
{
ErrorTimedOut( const char* message )
: Error("org.freedesktop.DBus.Error.TimedOut", message)
{}
};
struct ErrorMatchRuleNotFound : public Error
struct DXXAPI ErrorMatchRuleNotFound : public Error
{
ErrorMatchRuleNotFound( const char* message )
: Error("org.freedesktop.DBus.Error.MatchRuleNotFound", message)
{}
};
struct ErrorMatchRuleInvalid : public Error
struct DXXAPI ErrorMatchRuleInvalid : public Error
{
ErrorMatchRuleInvalid( const char* message )
: Error("org.freedesktop.DBus.Error.MatchRuleInvalid", message)
{}
};
struct ErrorSpawnExecFailed : public Error
struct DXXAPI ErrorSpawnExecFailed : public Error
{
ErrorSpawnExecFailed( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.ExecFailed", message)
{}
};
struct ErrorSpawnForkFailed : public Error
struct DXXAPI ErrorSpawnForkFailed : public Error
{
ErrorSpawnForkFailed( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.ForkFailed", message)
{}
};
struct ErrorSpawnChildExited : public Error
struct DXXAPI ErrorSpawnChildExited : public Error
{
ErrorSpawnChildExited( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.ChildExited", message)
{}
};
struct ErrorSpawnChildSignaled : public Error
struct DXXAPI ErrorSpawnChildSignaled : public Error
{
ErrorSpawnChildSignaled( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.ChildSignaled", message)
{}
};
struct ErrorSpawnFailed : public Error
struct DXXAPI ErrorSpawnFailed : public Error
{
ErrorSpawnFailed( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.Failed", message)
{}
};
struct ErrorInvalidSignature : public Error
struct DXXAPI ErrorInvalidSignature : public Error
{
ErrorInvalidSignature( const char* message )
: Error("org.freedesktop.DBus.Error.InvalidSignature", message)
{}
};
struct ErrorUnixProcessIdUnknown : public Error
struct DXXAPI ErrorUnixProcessIdUnknown : public Error
{
ErrorUnixProcessIdUnknown( const char* message )
: Error("org.freedesktop.DBus.Error.UnixProcessIdUnknown", message)
{}
};
struct ErrorSELinuxSecurityContextUnknown : public Error
struct DXXAPI ErrorSELinuxSecurityContextUnknown : public Error
{
ErrorSELinuxSecurityContextUnknown( const char* message )
: Error("org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown", message)

View file

@ -31,6 +31,7 @@
#include <list>
#include "api.h"
#include "dispatcher.h"
#include "util.h"
@ -38,7 +39,7 @@ namespace DBus {
class EepleMainLoop;
class EepleTimeout
class DXXAPI EepleTimeout
{
public:
@ -78,7 +79,7 @@ friend class EepleMainLoop;
typedef std::list< EepleTimeout* > Timeouts;
class EepleWatch
class DXXAPI EepleWatch
{
public:
@ -118,7 +119,7 @@ friend class EepleMainLoop;
typedef std::list< EepleWatch* > Watches;
class EepleMainLoop
class DXXAPI EepleMainLoop
{
public:
@ -145,7 +146,7 @@ friend class EepleWatch;
class BusDispatcher;
class BusTimeout : public Timeout, public EepleTimeout
class DXXAPI BusTimeout : public Timeout, public EepleTimeout
{
BusTimeout( Timeout::Internal*, BusDispatcher* );
@ -154,7 +155,7 @@ class BusTimeout : public Timeout, public EepleTimeout
friend class BusDispatcher;
};
class BusWatch : public Watch, public EepleWatch
class DXXAPI BusWatch : public Watch, public EepleWatch
{
BusWatch( Watch::Internal*, BusDispatcher* );
@ -163,7 +164,7 @@ class BusWatch : public Watch, public EepleWatch
friend class BusDispatcher;
};
class BusDispatcher : public Dispatcher, public EepleMainLoop
class DXXAPI BusDispatcher : public Dispatcher, public EepleMainLoop
{
public:

View file

@ -31,6 +31,7 @@
#include <glib.h>
#include "api.h"
#include "eventloop.h"
namespace DBus {
@ -39,7 +40,7 @@ namespace Glib {
class BusDispatcher;
class BusTimeout : public Timeout
class DXXAPI BusTimeout : public Timeout
{
private:
@ -63,7 +64,7 @@ private:
friend class BusDispatcher;
};
class BusWatch : public Watch
class DXXAPI BusWatch : public Watch
{
private:
@ -87,7 +88,7 @@ private:
friend class BusDispatcher;
};
class BusDispatcher : public Dispatcher
class DXXAPI BusDispatcher : public Dispatcher
{
public:
BusDispatcher() : _ctx(NULL) {}

View file

@ -31,6 +31,7 @@
#include <string>
#include <map>
#include "api.h"
#include "util.h"
#include "types.h"
@ -39,7 +40,7 @@
namespace DBus {
//todo: this should belong to to properties.h
struct PropertyData
struct DXXAPI PropertyData
{
bool read;
bool write;
@ -57,7 +58,7 @@ class SignalMessage;
typedef std::map<std::string, InterfaceAdaptor*> InterfaceAdaptorTable;
class AdaptorBase
class DXXAPI AdaptorBase
{
public:
@ -84,7 +85,7 @@ class CallMessage;
typedef std::map<std::string, InterfaceProxy*> InterfaceProxyTable;
class ProxyBase
class DXXAPI ProxyBase
{
public:
@ -102,7 +103,7 @@ protected:
InterfaceProxyTable _interfaces;
};
class Interface
class DXXAPI Interface
{
public:
@ -130,7 +131,7 @@ const std::string& Interface::name() const
typedef std::map< std::string, Slot<Message, const CallMessage&> > MethodTable;
class InterfaceAdaptor : public Interface, public virtual AdaptorBase
class DXXAPI InterfaceAdaptor : public Interface, public virtual AdaptorBase
{
public:
@ -160,7 +161,7 @@ protected:
typedef std::map< std::string, Slot<void, const SignalMessage&> > SignalTable;
class InterfaceProxy : public Interface, public virtual ProxyBase
class DXXAPI InterfaceProxy : public Interface, public virtual ProxyBase
{
public:

View file

@ -29,24 +29,25 @@
#include "config.h"
#endif
#include "api.h"
#include "interface.h"
namespace DBus {
struct IntrospectedArgument
struct DXXAPI IntrospectedArgument
{
const char* name;
const char* type;
const bool in;
};
struct IntrospectedMethod
struct DXXAPI IntrospectedMethod
{
const char* name;
const IntrospectedArgument* args;
};
struct IntrospectedProperty
struct DXXAPI IntrospectedProperty
{
const char* name;
const char* type;
@ -54,7 +55,7 @@ struct IntrospectedProperty
const bool write;
};
struct IntrospectedInterface
struct DXXAPI IntrospectedInterface
{
const char* name;
const IntrospectedMethod* methods;
@ -62,7 +63,7 @@ struct IntrospectedInterface
const IntrospectedProperty* properties;
};
class IntrospectableAdaptor : public InterfaceAdaptor
class DXXAPI IntrospectableAdaptor : public InterfaceAdaptor
{
public:
@ -75,7 +76,7 @@ protected:
IntrospectedInterface* const introspect() const;
};
class IntrospectableProxy : public InterfaceProxy
class DXXAPI IntrospectableProxy : public InterfaceProxy
{
public:

View file

@ -32,6 +32,7 @@
#include <string>
#include <map>
#include "api.h"
#include "util.h"
namespace DBus {
@ -43,7 +44,7 @@ class ReturnMessage;
class Error;
class Connection;
class MessageIter
class DXXAPI MessageIter
{
public:
@ -140,11 +141,11 @@ public:
private:
MessageIter(Message& msg) : _msg(&msg) {}
DXXAPILOCAL MessageIter(Message& msg) : _msg(&msg) {}
bool append_basic( int type_id, void* value );
DXXAPILOCAL bool append_basic( int type_id, void* value );
void get_basic( int type_id, void* ptr );
DXXAPILOCAL void get_basic( int type_id, void* ptr );
private:
@ -157,7 +158,7 @@ private:
friend class Message;
};
class Message
class DXXAPI Message
{
public:
@ -221,7 +222,7 @@ friend class Connection;
/*
*/
class ErrorMessage : public Message
class DXXAPI ErrorMessage : public Message
{
public:
@ -239,7 +240,7 @@ public:
/*
*/
class SignalMessage : public Message
class DXXAPI SignalMessage : public Message
{
public:
@ -267,7 +268,7 @@ public:
/*
*/
class CallMessage : public Message
class DXXAPI CallMessage : public Message
{
public:
@ -297,7 +298,7 @@ public:
/*
*/
class ReturnMessage : public Message
class DXXAPI ReturnMessage : public Message
{
public:

View file

@ -32,6 +32,7 @@
#include <string>
#include <list>
#include "api.h"
#include "interface.h"
#include "connection.h"
#include "message.h"
@ -39,7 +40,7 @@
namespace DBus {
class Object
class DXXAPI Object
{
protected:
@ -57,9 +58,9 @@ public:
private:
virtual bool handle_message( const Message& ) = 0;
virtual void register_obj() = 0;
virtual void unregister_obj() = 0;
DXXAPILOCAL virtual bool handle_message( const Message& ) = 0;
DXXAPILOCAL virtual void register_obj() = 0;
DXXAPILOCAL virtual void unregister_obj() = 0;
private:
@ -89,7 +90,7 @@ const std::string& Object::service() const
/*
*/
class Tag
class DXXAPI Tag
{
public:
@ -104,7 +105,7 @@ class ObjectAdaptor;
typedef std::list<ObjectAdaptor*> ObjectAdaptorPList;
class ObjectAdaptor : public Object, public virtual AdaptorBase
class DXXAPI ObjectAdaptor : public Object, public virtual AdaptorBase
{
public:
@ -122,7 +123,7 @@ public:
protected:
class Continuation
class DXXAPI Continuation
{
public:
@ -188,7 +189,7 @@ class ObjectProxy;
typedef std::list<ObjectProxy*> ObjectProxyPList;
class ObjectProxy : public Object, public virtual ProxyBase
class DXXAPI ObjectProxy : public Object, public virtual ProxyBase
{
public:

View file

@ -29,13 +29,14 @@
#include "config.h"
#endif
#include "api.h"
#include "util.h"
namespace DBus {
class Connection;
class PendingCall
class DXXAPI PendingCall
{
public:
@ -59,7 +60,7 @@ public:
private:
PendingCall( const PendingCall& );
DXXAPILOCAL PendingCall( const PendingCall& );
private:

View file

@ -29,6 +29,7 @@
#include "config.h"
#endif
#include "api.h"
#include "types.h"
#include "interface.h"
@ -67,7 +68,7 @@ private:
struct IntrospectedInterface;
class PropertiesAdaptor : public InterfaceAdaptor
class DXXAPI PropertiesAdaptor : public InterfaceAdaptor
{
public:
@ -88,7 +89,7 @@ protected:
IntrospectedInterface* const introspect() const;
};
class PropertiesProxy : public InterfaceProxy
class DXXAPI PropertiesProxy : public InterfaceProxy
{
public:

View file

@ -29,6 +29,7 @@
#include "config.h"
#endif
#include "api.h"
#include "util.h"
namespace DBus {

View file

@ -31,6 +31,7 @@
#include <list>
#include "api.h"
#include "error.h"
#include "connection.h"
#include "util.h"
@ -42,7 +43,7 @@ class Server;
typedef std::list<Server> ServerList;
class Server
class DXXAPI Server
{
public:

View file

@ -33,6 +33,7 @@
#include <vector>
#include <map>
#include "api.h"
#include "util.h"
#include "message.h"
#include "error.h"
@ -50,7 +51,7 @@ typedef unsigned long long UInt64;
typedef double Double;
typedef std::string String;
struct Path : public std::string
struct DXXAPI Path : public std::string
{
Path() {}
Path( const std::string& s ) : std::string(s) {}
@ -62,7 +63,7 @@ struct Path : public std::string
}
};
struct Signature : public std::string
struct DXXAPI Signature : public std::string
{
Signature() {}
Signature( const std::string& s ) : std::string(s) {}
@ -74,9 +75,9 @@ struct Signature : public std::string
}
};
struct Invalid {};
struct DXXAPI Invalid {};
class Variant
class DXXAPI Variant
{
public:
@ -344,7 +345,7 @@ inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Str
return iter;
}
DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Variant& val );
extern DXXAPI DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Variant& val );
/*
*/
@ -507,7 +508,7 @@ inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Struct<T1
return ++iter;
}
DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Variant& val );
extern DXXAPI DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Variant& val );
#endif//__DBUSXX_TYPES_H

View file

@ -29,6 +29,7 @@
#include "config.h"
#endif
#include "api.h"
#include "debug.h"
namespace DBus {
@ -37,7 +38,7 @@ namespace DBus {
* Very simple reference counting
*/
class RefCnt
class DXXAPI RefCnt
{
public:
@ -78,11 +79,11 @@ public:
private:
void ref() const
DXXAPILOCAL void ref() const
{
++ (*__ref);
}
void unref() const
DXXAPILOCAL void unref() const
{
-- (*__ref);

View file

@ -1,142 +0,0 @@
/*
*
* D-Bus++ - C++ bindings for D-Bus
*
* Copyright (C) 2005-2007 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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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