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:
pdurante 2006-09-05 13:36:22 +00:00
commit acfeb85b87
89 changed files with 92818 additions and 0 deletions

4
src/.sconsign Normal file
View file

@ -0,0 +1,4 @@
}q(U message_p.hq(cSCons.Node.FS
BuildInfo
qoq}q(U timestampqJ:ÓDUcsigqU 11d6821bf1a2fc6e208ddb951799f04cqubUdispatcher_p.hq (hoq
}q (hJ :ÓDhU b6bc4f718a90563d8d43e7cab48adb14q ubUconnection_p.hq (hoq}q(hJ:ÓDhU bd0a6f3028a08ea4b19de2336b0b08b1qubUpendingcall_p.hq(hoq}q(hJü9ÓDhU a32b3cffedb99c253266da39949d52e2qubu.

30
src/Makefile.am Normal file
View file

@ -0,0 +1,30 @@
INCLUDES = $(dbus_CFLAGS) $(xml_CFLAGS) -I$(top_srcdir)/include
AM_CPPFLAGS = -DDBUS_API_SUBJECT_TO_CHANGE
HEADER_DIR = $(top_srcdir)/include/dbus-c++
HEADER_FILES = \
$(HEADER_DIR)/config.h \
$(HEADER_DIR)/dbus-c++.h \
$(HEADER_DIR)/types.h \
$(HEADER_DIR)/connection.h \
$(HEADER_DIR)/debug.h \
$(HEADER_DIR)/error.h \
$(HEADER_DIR)/interface.h \
$(HEADER_DIR)/message.h \
$(HEADER_DIR)/dispatcher.h \
$(HEADER_DIR)/eventloop.h \
$(HEADER_DIR)/object.h \
$(HEADER_DIR)/pendingcall.h \
$(HEADER_DIR)/server.h \
$(HEADER_DIR)/debug.h \
$(HEADER_DIR)/util.h \
$(HEADER_DIR)/refptr_impl.h \
$(HEADER_DIR)/xml.h \
$(HEADER_DIR)/introspection.h
lib_includedir=$(includedir)/dbus-c++-0.3/dbus-c++
lib_include_HEADERS = $(HEADER_FILES)
lib_LTLIBRARIES = libdbus-c++-0.3.la
libdbus_c___0_3_la_SOURCES = $(HEADER_FILES) interface.cpp object.cpp introspection.cpp debug.cpp eventloop.cpp xml.cpp types.cpp connection.cpp connection_p.h dispatcher.cpp dispatcher_p.h pendingcall.cpp pendingcall_p.h error.cpp internalerror.h message.cpp message_p.h server.cpp server_p.h
libdbus_c___0_3_la_LIBADD = $(dbus_LIBS) $(xml_LIBS)

534
src/Makefile.in Normal file
View file

@ -0,0 +1,534 @@
# Makefile.in generated by automake 1.9.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = src
DIST_COMMON = $(lib_include_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/dbus-c++/config.h
CONFIG_CLEAN_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(lib_includedir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
libdbus_c___0_3_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1)
am__objects_1 =
am_libdbus_c___0_3_la_OBJECTS = $(am__objects_1) interface.lo \
object.lo introspection.lo debug.lo eventloop.lo xml.lo \
types.lo connection.lo dispatcher.lo pendingcall.lo error.lo \
message.lo server.lo
libdbus_c___0_3_la_OBJECTS = $(am_libdbus_c___0_3_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include/dbus-c++
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \
$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(libdbus_c___0_3_la_SOURCES)
DIST_SOURCES = $(libdbus_c___0_3_la_SOURCES)
lib_includeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(lib_include_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DBUS_DOXYGEN_DOCS_ENABLED_FALSE = @DBUS_DOXYGEN_DOCS_ENABLED_FALSE@
DBUS_DOXYGEN_DOCS_ENABLED_TRUE = @DBUS_DOXYGEN_DOCS_ENABLED_TRUE@
DEBUG_FLAGS = @DEBUG_FLAGS@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DOXYGEN = @DOXYGEN@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
ac_pt_PKG_CONFIG = @ac_pt_PKG_CONFIG@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
dbus_CFLAGS = @dbus_CFLAGS@
dbus_LIBS = @dbus_LIBS@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
xml_CFLAGS = @xml_CFLAGS@
xml_LIBS = @xml_LIBS@
INCLUDES = $(dbus_CFLAGS) $(xml_CFLAGS) -I$(top_srcdir)/include
AM_CPPFLAGS = -DDBUS_API_SUBJECT_TO_CHANGE
HEADER_DIR = $(top_srcdir)/include/dbus-c++
HEADER_FILES = \
$(HEADER_DIR)/config.h \
$(HEADER_DIR)/dbus-c++.h \
$(HEADER_DIR)/types.h \
$(HEADER_DIR)/connection.h \
$(HEADER_DIR)/debug.h \
$(HEADER_DIR)/error.h \
$(HEADER_DIR)/interface.h \
$(HEADER_DIR)/message.h \
$(HEADER_DIR)/dispatcher.h \
$(HEADER_DIR)/eventloop.h \
$(HEADER_DIR)/object.h \
$(HEADER_DIR)/pendingcall.h \
$(HEADER_DIR)/server.h \
$(HEADER_DIR)/debug.h \
$(HEADER_DIR)/util.h \
$(HEADER_DIR)/refptr_impl.h \
$(HEADER_DIR)/xml.h \
$(HEADER_DIR)/introspection.h
lib_includedir = $(includedir)/dbus-c++-0.3/dbus-c++
lib_include_HEADERS = $(HEADER_FILES)
lib_LTLIBRARIES = libdbus-c++-0.3.la
libdbus_c___0_3_la_SOURCES = $(HEADER_FILES) interface.cpp object.cpp introspection.cpp debug.cpp eventloop.cpp xml.cpp types.cpp connection.cpp connection_p.h dispatcher.cpp dispatcher_p.h pendingcall.cpp pendingcall_p.h error.cpp internalerror.h message.cpp message_p.h server.cpp server_p.h
libdbus_c___0_3_la_LIBADD = $(dbus_LIBS) $(xml_LIBS)
all: all-am
.SUFFIXES:
.SUFFIXES: .cpp .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
f=$(am__strip_dir) \
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
else :; fi; \
done
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
@set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
p=$(am__strip_dir) \
echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
$(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
done
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test "$$dir" != "$$p" || dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libdbus-c++-0.3.la: $(libdbus_c___0_3_la_OBJECTS) $(libdbus_c___0_3_la_DEPENDENCIES)
$(CXXLINK) -rpath $(libdir) $(libdbus_c___0_3_la_LDFLAGS) $(libdbus_c___0_3_la_OBJECTS) $(libdbus_c___0_3_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connection.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/debug.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dispatcher.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/error.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eventloop.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interface.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/introspection.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/message.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/object.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pendingcall.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/server.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/types.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xml.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
.cpp.obj:
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.cpp.lo:
@am__fastdepCXX_TRUE@ if $(LTCXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
install-lib_includeHEADERS: $(lib_include_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(lib_includedir)" || $(mkdir_p) "$(DESTDIR)$(lib_includedir)"
@list='$(lib_include_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(lib_includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(lib_includedir)/$$f'"; \
$(lib_includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(lib_includedir)/$$f"; \
done
uninstall-lib_includeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(lib_include_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(lib_includedir)/$$f'"; \
rm -f "$(DESTDIR)$(lib_includedir)/$$f"; \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(mkdir_p) $(distdir)/$(HEADER_DIR)
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(lib_includedir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-libtool distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am: install-lib_includeHEADERS
install-exec-am: install-libLTLIBRARIES
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES \
uninstall-lib_includeHEADERS
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libLTLIBRARIES clean-libtool ctags distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-exec \
install-exec-am install-info install-info-am \
install-libLTLIBRARIES install-lib_includeHEADERS install-man \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
pdf pdf-am ps ps-am tags uninstall uninstall-am \
uninstall-info-am uninstall-libLTLIBRARIES \
uninstall-lib_includeHEADERS
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

360
src/connection.cpp Normal file
View file

@ -0,0 +1,360 @@
/*
*
* 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
*
*/
#include <dbus-c++/debug.h>
#include <dbus-c++/connection.h>
#include <dbus/dbus.h>
#include <string>
#include "internalerror.h"
#include "connection_p.h"
#include "dispatcher_p.h"
#include "message_p.h"
#include "pendingcall_p.h"
using namespace DBus;
Connection::Private::Private( DBusConnection* c )
: conn(c) , dispatcher(0)
{
init();
}
Connection::Private::Private( DBusBusType type )
{
InternalError e;
conn = dbus_bus_get_private(type, e);
if(e) throw Error(e);
init();
}
Connection::Private::~Private()
{
if(dbus_connection_get_is_connected(conn))
{
std::vector<std::string>::iterator i = names.begin();
while(i != names.end())
{
debug_log("%s: releasing bus name %s", dbus_bus_get_unique_name(conn), i->c_str());
dbus_bus_release_name(conn, i->c_str(), NULL);
++i;
}
//dbus_connection_disconnect(conn);
}
dbus_connection_unref(conn);
}
void Connection::Private::init()
{
dbus_connection_ref(conn);
disconn_filter = new Callback<Connection::Private, bool, const Message&>(
this, &Connection::Private::disconn_filter_function
);
dbus_connection_add_filter(conn, message_filter_stub, &disconn_filter, NULL);
dbus_connection_set_dispatch_status_function(conn, dispatch_status_stub, this, 0);
dbus_connection_set_exit_on_disconnect(conn, false); //why was this set to true??
}
bool Connection::Private::do_dispatch()
{
debug_log("dispatching on %p", conn);
return dbus_connection_dispatch(conn) != DBUS_DISPATCH_DATA_REMAINS;
}
void Connection::Private::dispatch_status_stub( DBusConnection* dc, DBusDispatchStatus status, void* data )
{
Private* p = static_cast<Private*>(data);
switch(status)
{
case DBUS_DISPATCH_DATA_REMAINS:
debug_log("some dispatching to do on %p", dc);
p->dispatcher->queue_connection(p);
break;
case DBUS_DISPATCH_COMPLETE:
debug_log("all dispatching done on %p", dc);
break;
case DBUS_DISPATCH_NEED_MEMORY: //uh oh...
debug_log("connection %p needs memory", dc);
break;
}
}
DBusHandlerResult Connection::Private::message_filter_stub( DBusConnection*, DBusMessage* dmsg, void* data )
{
MessageSlot* slot = static_cast<MessageSlot*>(data);
Message msg = Message(new Message::Private(dmsg));
return slot && !slot->empty() && slot->call(msg)
? DBUS_HANDLER_RESULT_HANDLED
: DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
bool Connection::Private::disconn_filter_function( const Message& msg )
{
if(msg.is_signal(DBUS_INTERFACE_LOCAL,"Disconnected"))
{
debug_log("%p disconnected by local bus", conn);
dbus_connection_close(conn);
return true;
}
return false;
}
Connection Connection::SystemBus()
{
return Connection(new Private(DBUS_BUS_SYSTEM));
}
Connection Connection::SessionBus()
{
return Connection(new Private(DBUS_BUS_SESSION));
}
Connection Connection::ActivationBus()
{
return Connection(new Private(DBUS_BUS_STARTER));
}
Connection::Connection( const char* address, bool priv )
{
InternalError e;
DBusConnection* conn = priv
? dbus_connection_open_private(address, e)
: dbus_connection_open(address,e);
if(e) throw Error(e);
_pvt = new Private(conn);
setup(default_dispatcher);
debug_log("connected to %s", address);
}
Connection::Connection( Connection::Private* p )
: _pvt(p)
{
setup(default_dispatcher);
}
Connection::Connection( const Connection& c )
: _pvt(c._pvt)
{
dbus_connection_ref(_pvt->conn);
}
Connection::~Connection()
{
dbus_connection_unref(_pvt->conn);
}
Dispatcher* Connection::setup( Dispatcher* dispatcher )
{
debug_log("registering stubs for connection %p", _pvt->conn);
if(!dispatcher) dispatcher = default_dispatcher;
if(!dispatcher) throw ErrorFailed("no default dispatcher set for new connection");
Dispatcher* prev = _pvt->dispatcher;
_pvt->dispatcher = dispatcher;
dispatcher->queue_connection(_pvt.get());
dbus_connection_set_watch_functions(
_pvt->conn,
Dispatcher::Private::on_add_watch,
Dispatcher::Private::on_rem_watch,
Dispatcher::Private::on_toggle_watch,
dispatcher,
0
);
dbus_connection_set_timeout_functions(
_pvt->conn,
Dispatcher::Private::on_add_timeout,
Dispatcher::Private::on_rem_timeout,
Dispatcher::Private::on_toggle_timeout,
dispatcher,
0
);
return prev;
}
bool Connection::operator == ( const Connection& c ) const
{
return _pvt->conn == c._pvt->conn;
}
bool Connection::connected() const
{
return dbus_connection_get_is_connected(_pvt->conn);
}
void Connection::disconnect()
{
// dbus_connection_disconnect(_pvt->conn); // disappeared in 0.9x
dbus_connection_close(_pvt->conn);
}
bool Connection::unique_name( const char* n )
{
return dbus_bus_set_unique_name(_pvt->conn, n);
}
const char* Connection::unique_name() const
{
return dbus_bus_get_unique_name(_pvt->conn);
}
void Connection::flush()
{
dbus_connection_flush(_pvt->conn);
}
void Connection::add_match( const char* rule )
{
InternalError e;
dbus_bus_add_match(_pvt->conn, rule, e);
debug_log("%s: added match rule %s", unique_name(), rule);
if(e) throw Error(e);
}
void Connection::remove_match( const char* rule )
{
InternalError e;
dbus_bus_remove_match(_pvt->conn, rule, e);
debug_log("%s: removed match rule %s", unique_name(), rule);
if(e) throw Error(e);
}
bool Connection::add_filter( MessageSlot& s )
{
debug_log("%s: adding filter", unique_name());
return dbus_connection_add_filter(_pvt->conn, Private::message_filter_stub, &s, NULL);
}
void Connection::remove_filter( MessageSlot& s )
{
debug_log("%s: removing filter", unique_name());
dbus_connection_remove_filter(_pvt->conn, Private::message_filter_stub, &s);
}
bool Connection::send( const Message& msg, unsigned int* serial )
{
return dbus_connection_send(_pvt->conn, msg._pvt->msg, serial);
}
Message Connection::send_blocking( Message& msg, int timeout )
{
DBusMessage* reply;
InternalError e;
reply = dbus_connection_send_with_reply_and_block(_pvt->conn, msg._pvt->msg, timeout, e);
if(e) throw Error(e);
return Message(new Message::Private(reply));
}
PendingCall Connection::send_async( Message& msg, int timeout )
{
DBusPendingCall* pending;
if(!dbus_connection_send_with_reply(_pvt->conn, msg._pvt->msg, &pending, timeout))
{
throw Error(DBUS_ERROR_NO_MEMORY, "Unable to start asynchronous call");
}
return PendingCall(new PendingCall::Private(pending));
}
void Connection::request_name( const char* name, int flags )
{
InternalError e;
debug_log("%s: registering bus name %s", unique_name(), name);
dbus_bus_request_name(_pvt->conn, name, flags, e); //we deliberately don't check return value
if(e) throw Error(e);
// this->remove_match("destination");
if(name)
{
_pvt->names.push_back(name);
std::string match = "destination='" + _pvt->names.back() + "'";
add_match(match.c_str());
}
}
bool Connection::has_name( const char* name )
{
InternalError e;
bool b = dbus_bus_name_has_owner(_pvt->conn, name, e);
if(e) throw Error(e);
return b;
}
const std::vector<std::string>& Connection::names()
{
return _pvt->names;
}
bool Connection::start_service( const char* name, unsigned long flags )
{
InternalError e;
bool b = dbus_bus_start_service_by_name(_pvt->conn, name, flags, NULL, e);
if(e) throw Error(e);
return b;
}

65
src/connection_p.h Normal file
View file

@ -0,0 +1,65 @@
/*
*
* 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_P_H
#define __DBUSXX_CONNECTION_P_H
#include <dbus-c++/connection.h>
#include <dbus-c++/dispatcher.h>
#include <dbus-c++/refptr_impl.h>
#include <dbus/dbus.h>
#include <string>
namespace DBus {
struct Connection::Private
{
DBusConnection* conn;
std::vector<std::string> names;
Dispatcher* dispatcher;
bool do_dispatch();
MessageSlot disconn_filter;
bool disconn_filter_function( const Message& );
Private( DBusConnection* );
Private( DBusBusType );
~Private();
void init();
static void dispatch_status_stub( DBusConnection*, DBusDispatchStatus, void* );
static DBusHandlerResult message_filter_stub( DBusConnection*, DBusMessage*, void* );
};
} /* namespace DBus */
#endif//__DBUSXX_CONNECTION_P_H

51
src/debug.cpp Normal file
View file

@ -0,0 +1,51 @@
/*
*
* 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
*
*/
#include <dbus-c++/debug.h>
#include <stdarg.h>
#include <cstdio>
#include <stdlib.h>
static void _debug_log_default(const char* format, ...)
{
#ifdef DEBUG
if(getenv("DBUSXX_VERBOSE"))
{
va_list args;
va_start(args, format);
fprintf(stderr, "dbus-c++: ");
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
va_end(args);
}
#endif//DEBUG
}
DBus::LogFunction DBus::debug_log = _debug_log_default;

206
src/dispatcher.cpp Normal file
View file

@ -0,0 +1,206 @@
/*
*
* 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
*
*/
#include <dbus-c++/dispatcher.h>
#include <dbus/dbus.h>
#include "dispatcher_p.h"
#include "connection_p.h"
DBus::Dispatcher* DBus::default_dispatcher = NULL;
using namespace DBus;
Timeout::Timeout( Timeout::Internal* i )
: _int(i)
{
dbus_timeout_set_data((DBusTimeout*)i, this, NULL);
}
int Timeout::interval() const
{
return dbus_timeout_get_interval((DBusTimeout*)_int);
}
bool Timeout::enabled() const
{
return dbus_timeout_get_enabled((DBusTimeout*)_int);
}
bool Timeout::handle()
{
return dbus_timeout_handle((DBusTimeout*)_int);
}
/*
*/
Watch::Watch( Watch::Internal* i )
: _int(i)
{
dbus_watch_set_data((DBusWatch*)i, this, NULL);
}
int Watch::descriptor() const
{
return dbus_watch_get_fd((DBusWatch*)_int);
}
int Watch::flags() const
{
return dbus_watch_get_flags((DBusWatch*)_int);
}
bool Watch::enabled() const
{
return dbus_watch_get_enabled((DBusWatch*)_int);
}
bool Watch::handle( int flags )
{
return dbus_watch_handle((DBusWatch*)_int, flags);
}
/*
*/
dbus_bool_t Dispatcher::Private::on_add_watch( DBusWatch* watch, void* data )
{
Dispatcher* d = static_cast<Dispatcher*>(data);
Watch::Internal* w = reinterpret_cast<Watch::Internal*>(watch);
d->add_watch(w);
return true;
}
void Dispatcher::Private::on_rem_watch( DBusWatch* watch, void* data )
{
Dispatcher* d = static_cast<Dispatcher*>(data);
Watch* w = static_cast<Watch*>(dbus_watch_get_data(watch));
d->rem_watch(w);
}
void Dispatcher::Private::on_toggle_watch( DBusWatch* watch, void* data )
{
Watch* w = static_cast<Watch*>(dbus_watch_get_data(watch));
w->toggle();
}
dbus_bool_t Dispatcher::Private::on_add_timeout( DBusTimeout* timeout, void* data )
{
Dispatcher* d = static_cast<Dispatcher*>(data);
Timeout::Internal* t = reinterpret_cast<Timeout::Internal*>(timeout);
d->add_timeout(t);
return true;
}
void Dispatcher::Private::on_rem_timeout( DBusTimeout* timeout, void* data )
{
Dispatcher* d = static_cast<Dispatcher*>(data);
Timeout* t = static_cast<Timeout*>(dbus_timeout_get_data(timeout));
d->rem_timeout(t);
}
void Dispatcher::Private::on_toggle_timeout( DBusTimeout* timeout, void* data )
{
Timeout* t = static_cast<Timeout*>(dbus_timeout_get_data(timeout));
t->toggle();
}
void Dispatcher::queue_connection( Connection::Private* cp )
{
_pending_queue.push_back(cp);
}
void Dispatcher::dispatch_pending()
{
while(_pending_queue.size() > 0)
{
Connection::PrivatePList::iterator i, j;
i = _pending_queue.begin();
while(i != _pending_queue.end())
{
j = i;
++j;
if((*i)->do_dispatch())
_pending_queue.erase(i);
i = j;
}
}
}
void DBus::_init_threading(
MutexNewFn m1,
MutexFreeFn m2,
MutexLockFn m3,
MutexUnlockFn m4,
CondVarNewFn c1,
CondVarFreeFn c2,
CondVarWaitFn c3,
CondVarWaitTimeoutFn c4,
CondVarWakeOneFn c5,
CondVarWakeAllFn c6
)
{
DBusThreadFunctions functions = {
DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK |
DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK |
DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK |
DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK |
DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK |
DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK |
DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK |
DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK |
DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK|
DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK,
(DBusMutexNewFunction) m1,
(DBusMutexFreeFunction) m2,
(DBusMutexLockFunction) m3,
(DBusMutexUnlockFunction) m4,
(DBusCondVarNewFunction) c1,
(DBusCondVarFreeFunction) c2,
(DBusCondVarWaitFunction) c3,
(DBusCondVarWaitTimeoutFunction) c4,
(DBusCondVarWakeOneFunction) c5,
(DBusCondVarWakeAllFunction) c6
};
dbus_threads_init(&functions);
}

53
src/dispatcher_p.h Normal file
View file

@ -0,0 +1,53 @@
/*
*
* 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_P_H
#define __DBUSXX_DISPATCHER_P_H
#include <dbus-c++/dispatcher.h>
#include <dbus/dbus.h>
#include "internalerror.h"
namespace DBus {
struct Dispatcher::Private
{
static dbus_bool_t on_add_watch( DBusWatch* watch, void* data );
static void on_rem_watch( DBusWatch* watch, void* data );
static void on_toggle_watch( DBusWatch* watch, void* data );
static dbus_bool_t on_add_timeout( DBusTimeout* timeout, void* data );
static void on_rem_timeout( DBusTimeout* timeout, void* data );
static void on_toggle_timeout( DBusTimeout* timeout, void* data );
};
} /* namespace DBus */
#endif//__DBUSXX_DISPATCHER_P_H

82
src/error.cpp Normal file
View file

@ -0,0 +1,82 @@
/*
*
* 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
*
*/
#include <dbus-c++/message.h>
#include <dbus-c++/error.h>
#include <dbus/dbus.h>
#include "message_p.h"
#include "internalerror.h"
using namespace DBus;
/*
*/
Error::Error()
: _int(new InternalError)
{}
Error::Error(InternalError& i)
: _int(new InternalError(i))
{}
Error::Error( const char* name, const char* message )
: _int(new InternalError)
{
set(name, message);
}
Error::Error( Message& m )
: _int(new InternalError)
{
dbus_set_error_from_message(&(_int->error), m._pvt->msg);
}
const char* Error::name()
{
return _int->error.name;
}
const char* Error::message()
{
return _int->error.message;
}
bool Error::is_set()
{
return *(_int);
}
void Error::set( const char* name, const char* message )
{
dbus_set_error_const(&(_int->error), name, message);
}
const char* Error::what() const throw()
{
return _int->error.message;
}

308
src/eventloop.cpp Normal file
View file

@ -0,0 +1,308 @@
/*
*
* 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
*
*/
#include <dbus-c++/eventloop.h>
#include <dbus-c++/debug.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <dbus/dbus.h>
using namespace DBus;
static double millis( timeval tv )
{
return (tv.tv_sec*1000.0 + tv.tv_usec/1000.0);
}
EepleTimeout::EepleTimeout( int interval, bool repeat, EepleMainLoop* ed )
: _enabled(true), _interval(interval), _repeat(repeat), _expiration(0), _data(0), _disp(ed)
{
timeval now;
gettimeofday(&now, NULL);
_expiration = millis(now) + interval;
_disp->_timeouts.push_back(this);
}
EepleTimeout::~EepleTimeout()
{
_disp->_timeouts.remove(this);
}
EepleWatch::EepleWatch( int fd, int flags, EepleMainLoop* ed )
: _enabled(true), _fd(fd), _flags(flags), _state(0), _data(0), _disp(ed)
{
_disp->_watches.push_back(this);
}
EepleWatch::~EepleWatch()
{
_disp->_watches.remove(this);
}
EepleMainLoop::EepleMainLoop()
{
}
EepleMainLoop::~EepleMainLoop()
{
Watches::iterator wi = _watches.begin();
while(wi != _watches.end())
{
Watches::iterator wmp = wi;
++wmp;
delete (*wi);
wi = wmp;
}
Timeouts::iterator ti = _timeouts.begin();
while(ti != _timeouts.end())
{
Timeouts::iterator tmp = ti;
++tmp;
delete (*ti);
ti = tmp;
}
}
void EepleMainLoop::dispatch()
{
int nfd = _watches.size();
pollfd fds[nfd];
Watches::iterator wi = _watches.begin();
for(nfd = 0; wi != _watches.end(); ++wi)
{
if((*wi)->enabled())
{
fds[nfd].fd = (*wi)->descriptor();
fds[nfd].events = (*wi)->flags();
fds[nfd].revents = 0;
++nfd;
}
}
int wait_min = 10000;
Timeouts::iterator ti = _timeouts.begin();
for(;ti != _timeouts.end(); ++ti)
{
if((*ti)->enabled() && (*ti)->interval() < wait_min)
wait_min = (*ti)->interval();
}
//int rfd = poll(fds, nfd, wait_min);
//if(rfd) debug_log("%d descriptors ready");
poll(fds, nfd, wait_min);
timeval now;
gettimeofday(&now, NULL);
double now_millis = millis(now);
ti = _timeouts.begin();
while(ti != _timeouts.end())
{
Timeouts::iterator tmp = ti;
++tmp;
if((*ti)->enabled() && now_millis >= (*ti)->_expiration)
{
(*ti)->expired(*(*ti));
if((*ti)->_repeat)
{
(*ti)->_expiration = now_millis + (*ti)->_interval;
}
}
ti = tmp;
}
for(int j = 0; j < nfd; ++j)
{
for(Watches::iterator wi = _watches.begin(); wi != _watches.end();)
{
Watches::iterator tmp = wi;
++tmp;
if((*wi)->enabled() && (*wi)->_fd == fds[j].fd)
{
if(fds[j].revents)
{
(*wi)->_state = fds[j].revents;
(*wi)->ready(*(*wi));
fds[j].revents = 0;
}
}
wi = tmp;
}
}
}
/*
*/
BusTimeout::BusTimeout( Timeout::Internal* ti, BusDispatcher* bd )
: Timeout(ti), EepleTimeout(Timeout::interval(), true, bd)
{
EepleTimeout::enabled(Timeout::enabled());
}
void BusTimeout::toggle()
{
debug_log("timeout %p toggled (%s)", this, Timeout::enabled() ? "on":"off");
EepleTimeout::enabled(Timeout::enabled());
}
BusWatch::BusWatch( Watch::Internal* wi, BusDispatcher* bd )
: Watch(wi), EepleWatch(Watch::descriptor(), 0, bd)
{
int flags = POLLHUP | POLLERR;
if(Watch::flags() & DBUS_WATCH_READABLE)
flags |= POLLIN;
if(Watch::flags() & DBUS_WATCH_WRITABLE)
flags |= POLLOUT;
EepleWatch::flags(flags);
EepleWatch::enabled(Watch::enabled());
}
void BusWatch::toggle()
{
debug_log("watch %p toggled (%s)", this, Watch::enabled() ? "on":"off");
EepleWatch::enabled(Watch::enabled());
}
void BusDispatcher::enter()
{
debug_log("entering dispatcher %p", this);
_running = true;
while(_running)
{
do_iteration();
}
debug_log("leaving dispatcher %p", this);
}
void BusDispatcher::leave()
{
_running = false;
}
void BusDispatcher::do_iteration()
{
dispatch_pending();
dispatch();
}
Timeout* BusDispatcher::add_timeout( Timeout::Internal* ti )
{
BusTimeout* bt = new BusTimeout(ti, this);
bt->expired = new Callback<BusDispatcher, void, EepleTimeout&>(this, &BusDispatcher::timeout_expired);
bt->data(bt);
debug_log("added timeout %p (%s)", bt, ((Timeout*)bt)->enabled() ? "on":"off");
return bt;
}
void BusDispatcher::rem_timeout( Timeout* t )
{
debug_log("removed timeout %p", t);
delete t;
}
Watch* BusDispatcher::add_watch( Watch::Internal* wi )
{
BusWatch* bw = new BusWatch(wi, this);
bw->ready = new Callback<BusDispatcher, void, EepleWatch&>(this, &BusDispatcher::watch_ready);
bw->data(bw);
debug_log("added watch %p (%s) fd=%d flags=%d",
bw, ((Watch*)bw)->enabled() ? "on":"off", ((Watch*)bw)->descriptor(), ((Watch*)bw)->flags()
);
return bw;
}
void BusDispatcher::rem_watch( Watch* w )
{
debug_log("removed watch %p", w);
delete w;
}
void BusDispatcher::timeout_expired( EepleTimeout& et )
{
debug_log("timeout %p expired", &et);
BusTimeout* timeout = reinterpret_cast<BusTimeout*>(et.data());
timeout->handle();
}
void BusDispatcher::watch_ready( EepleWatch& ew )
{
BusWatch* watch = reinterpret_cast<BusWatch*>(ew.data());
debug_log("watch %p ready, flags=%d state=%d",
watch, ((Watch*)watch)->flags(), watch->state()
);
int flags = 0;
if(watch->state() & POLLIN)
flags |= DBUS_WATCH_READABLE;
if(watch->state() & POLLOUT)
flags |= DBUS_WATCH_WRITABLE;
if(watch->state() & POLLHUP)
flags |= DBUS_WATCH_HANGUP;
if(watch->state() & POLLERR)
flags |= DBUS_WATCH_ERROR;
watch->handle(flags);
}

118
src/interface.cpp Normal file
View file

@ -0,0 +1,118 @@
/*
*
* 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
*
*/
#include <dbus-c++/debug.h>
#include <dbus-c++/interface.h>
#include "internalerror.h"
using namespace DBus;
Message IfaceTracker::rinvoke_method( CallMessage& msg )
{
return ErrorMessage(msg, DBUS_ERROR_NOT_SUPPORTED, "there are no proxies in a InterfaceAdaptor");
}
Interface::Interface( const char* name )
: _name(name)
{
register_interface(name);
}
Interface::~Interface()
{
//unregister_interface(name); //not needed
}
Message Interface::invoke_method( const CallMessage& )
{
throw Error(DBUS_ERROR_NOT_SUPPORTED, "");
}
bool Interface::dispatch_signal( const SignalMessage& )
{
throw Error(DBUS_ERROR_NOT_SUPPORTED, "");
}
void Interface::register_interface( const char* name )
{
debug_log("registering interface %s",name);
_interfaces[name] = this;
}
InterfaceAdaptor::InterfaceAdaptor( const char* name )
: Interface(name)
{}
Message InterfaceAdaptor::invoke_method( const CallMessage& msg )
{
const char* name = msg.member();
MethodTable::iterator mi = _methods.find(name);
if( mi != _methods.end() )
{
return mi->second.call( msg );
}
else
{
return ErrorMessage(msg, DBUS_ERROR_UNKNOWN_METHOD, name);
}
}
void InterfaceAdaptor::emit_signal( const SignalMessage& sig )
{
SignalMessage& sig2 = const_cast<SignalMessage&>(sig);
sig2.interface( iname().c_str() );
remit_signal(sig2);
}
InterfaceProxy::InterfaceProxy( const char* name )
: Interface(name)
{}
bool InterfaceProxy::dispatch_signal( const SignalMessage& msg )
{
const char* name = msg.member();
SignalTable::iterator si = _signals.find(name);
if( si != _signals.end() )
{
si->second.call( msg );
return true;
}
else
{
return false;
}
}
Message InterfaceProxy::invoke_method( const CallMessage& call )
{
CallMessage& call2 = const_cast<CallMessage&>(call);
call2.interface( iname().c_str() );
return rinvoke_method(call2);
}

73
src/internalerror.h Normal file
View file

@ -0,0 +1,73 @@
/*
*
* 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_INTERNALERROR_H
#define __DBUSXX_INTERNALERROR_H
#include <dbus-c++/error.h>
#include <dbus/dbus.h>
namespace DBus {
struct InternalError
{
DBusError error;
InternalError()
{
dbus_error_init(&error);
}
explicit InternalError( DBusError* e )
{
dbus_error_init(&error);
dbus_move_error(e, &error);
}
InternalError(const InternalError& ie)
{
dbus_error_init(&error);
dbus_move_error(const_cast<DBusError*>(&(ie.error)), &error);
}
~InternalError()
{
dbus_error_free(&error);
}
operator DBusError*()
{
return &error;
}
operator bool()
{
return dbus_error_is_set(&error);
}
};
} /* namespace DBus */
#endif//__DBUSXX_INTERNALERROR_H

134
src/introspection.cpp Normal file
View file

@ -0,0 +1,134 @@
/*
*
* 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
*
*/
#include <dbus-c++/introspection.h>
#include <dbus-c++/message.h>
#include <dbus-c++/xml.h>
#include <dbus/dbus.h>
using namespace DBus;
static const char* introspectable_name = "org.freedesktop.DBus.Introspectable";
IntrospectableAdaptor::IntrospectableAdaptor()
: InterfaceAdaptor(introspectable_name)
{
register_method(IntrospectableAdaptor, Introspect, Introspect);
}
Message IntrospectableAdaptor::Introspect( const CallMessage& call )
{
debug_log("requested introspection data");
Xml::Node iroot("node");
InterfaceTable::const_iterator iti;
for(iti = _interfaces.begin(); iti != _interfaces.end(); ++iti)
{
debug_log("introspecting interface %s", iti->first.c_str());
IntrospectedInterface* const intro = iti->second->introspect();
if(intro)
{
Xml::Node& iface = iroot.add(Xml::Node("interface"));
iface.set("name", intro->name);
for(const IntrospectedMethod* m = intro->methods; m->args; ++m)
{
Xml::Node& method = iface.add(Xml::Node("method"));
method.set("name", m->name);
for(const IntrospectedArgument* a = m->args; a->type; ++a)
{
Xml::Node& arg = method.add(Xml::Node("arg"));
if(a->name) arg.set("name", a->name);
arg.set("direction", a->in ? "in" : "out");
arg.set("type", a->type);
}
}
for(const IntrospectedMethod* m = intro->signals; m->args; ++m)
{
Xml::Node& method = iface.add(Xml::Node("signal"));
method.set("name", m->name);
for(const IntrospectedArgument* a = m->args; a->type; ++a)
{
Xml::Node& arg = method.add(Xml::Node("arg"));
if(a->name) arg.set("name", a->name);
arg.set("type", a->type);
}
}
}
}
std::string xml = DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + iroot.to_xml();
ReturnMessage reply(call);
MessageIter wi = reply.w_iter();
wi.append_string(xml.c_str());
return reply;
}
IntrospectedInterface* const IntrospectableAdaptor::introspect() const
{
static IntrospectedArgument Introspect_args[] =
{
{ "data", "s", false },
{ 0, 0, 0 }
};
static IntrospectedMethod Introspectable_methods[] =
{
{ "Introspect", Introspect_args },
{ 0, 0 }
};
static IntrospectedMethod Introspectable_signals[] =
{
{ 0, 0 }
};
static IntrospectedInterface Introspectable_interface =
{
introspectable_name, Introspectable_methods, Introspectable_signals
};
return &Introspectable_interface;
}
IntrospectableProxy::IntrospectableProxy()
: InterfaceProxy(introspectable_name)
{}
std::string IntrospectableProxy::Introspect()
{
DBus::CallMessage call;
call.member("Introspect");
DBus::Message ret = invoke_method(call);
DBus::MessageIter ri = ret.r_iter();
const char* str = ri.get_string();
return str;
}

571
src/message.cpp Normal file
View file

@ -0,0 +1,571 @@
/*
*
* 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
*
*/
#include <dbus-c++/message.h>
#include <dbus/dbus.h>
#include "internalerror.h"
#include "message_p.h"
using namespace DBus;
/*
*/
int MessageIter::type()
{
return dbus_message_iter_get_arg_type((DBusMessageIter*)&_iter);
}
bool MessageIter::at_end()
{
return type() == DBUS_TYPE_INVALID;
}
bool MessageIter::has_next()
{
return dbus_message_iter_has_next((DBusMessageIter*)&_iter);
}
MessageIter& MessageIter::operator ++()
{
dbus_message_iter_next((DBusMessageIter*)&_iter);
return (*this);
}
MessageIter MessageIter::operator ++(int)
{
MessageIter copy(*this);
(*this)++;
return copy;
}
bool MessageIter::append_basic( int type_id, void* value )
{
return dbus_message_iter_append_basic((DBusMessageIter*)&_iter, type_id, value);
}
void MessageIter::get_basic( int type_id, void* ptr )
{
if(type() != type_id)
throw Error(DBUS_ERROR_INVALID_ARGS, "type mismatch");
dbus_message_iter_get_basic((DBusMessageIter*)_iter, ptr);
}
bool MessageIter::append_byte( unsigned char b )
{
return append_basic(DBUS_TYPE_BYTE, &b);
}
unsigned char MessageIter::get_byte()
{
unsigned char b;
get_basic(DBUS_TYPE_BYTE, &b);
return b;
}
bool MessageIter::append_bool( bool b )
{
return append_basic(DBUS_TYPE_BOOLEAN, &b);
}
bool MessageIter::get_bool()
{
bool b;
get_basic(DBUS_TYPE_BOOLEAN, &b);
return b;
}
bool MessageIter::append_int16( signed short i )
{
return append_basic(DBUS_TYPE_INT16, &i);
}
signed short MessageIter::get_int16()
{
signed short i;
get_basic(DBUS_TYPE_INT16, &i);
return i;
}
bool MessageIter::append_uint16( unsigned short u )
{
return append_basic(DBUS_TYPE_UINT16, &u);
}
unsigned short MessageIter::get_uint16()
{
unsigned short u;
get_basic(DBUS_TYPE_UINT16, &u);
return u;
}
bool MessageIter::append_int32( signed int i )
{
return append_basic(DBUS_TYPE_INT32, &i);
}
signed int MessageIter::get_int32()
{
signed int i;
get_basic(DBUS_TYPE_INT32, &i);
return i;
}
bool MessageIter::append_uint32( unsigned int u )
{
return append_basic(DBUS_TYPE_UINT32, &u);
}
unsigned int MessageIter::get_uint32()
{
unsigned int u;
get_basic(DBUS_TYPE_UINT32, &u);
return u;
}
signed long long MessageIter::get_int64()
{
signed long long i;
get_basic(DBUS_TYPE_INT64, &i);
return i;
}
bool MessageIter::append_int64( signed long long i )
{
return append_basic(DBUS_TYPE_INT64, &i);
}
unsigned long long MessageIter::get_uint64()
{
unsigned long long u;
get_basic(DBUS_TYPE_UINT64, &u);
return u;
}
bool MessageIter::append_uint64( unsigned long long u )
{
return append_basic(DBUS_TYPE_UINT64, &u);
}
double MessageIter::get_double()
{
double d;
get_basic(DBUS_TYPE_DOUBLE, &d);
return d;
}
bool MessageIter::append_double( double d )
{
return append_basic(DBUS_TYPE_DOUBLE, &d);
}
bool MessageIter::append_string( const char* chars )
{
return append_basic(DBUS_TYPE_STRING, &chars);
}
const char* MessageIter::get_string()
{
char* chars;
get_basic(DBUS_TYPE_STRING, &chars);
return chars;
}
bool MessageIter::append_path( const char* chars )
{
return append_basic(DBUS_TYPE_OBJECT_PATH, &chars);
}
const char* MessageIter::get_path()
{
char* chars;
get_basic(DBUS_TYPE_OBJECT_PATH, &chars);
return chars;
}
bool MessageIter::append_signature( const char* chars )
{
return append_basic(DBUS_TYPE_SIGNATURE, &chars);
}
const char* MessageIter::get_signature()
{
char* chars;
get_basic(DBUS_TYPE_SIGNATURE, &chars);
return chars;
}
MessageIter MessageIter::recurse()
{
MessageIter iter(msg());
dbus_message_iter_recurse((DBusMessageIter*)&_iter, (DBusMessageIter*)&(iter._iter));
return iter;
}
char* MessageIter::signature() const
{
return dbus_message_iter_get_signature((DBusMessageIter*)&_iter);
}
bool MessageIter::append_array( char type, const void* ptr, size_t length )
{
return dbus_message_iter_append_fixed_array((DBusMessageIter*)&_iter, type, ptr, length);
}
int MessageIter::array_type()
{
return dbus_message_iter_get_element_type((DBusMessageIter*)&_iter);
}
int MessageIter::get_array( void* ptr )
{
int length;
dbus_message_iter_get_fixed_array((DBusMessageIter*)&_iter, ptr, &length);
return length;
}
MessageIter MessageIter::new_array( const char* sig )
{
MessageIter arr(msg());
dbus_message_iter_open_container(
(DBusMessageIter*)&_iter, DBUS_TYPE_ARRAY, sig, (DBusMessageIter*)&(arr._iter)
);
return arr;
}
bool MessageIter::is_array()
{
return dbus_message_iter_get_arg_type((DBusMessageIter*)&_iter) == DBUS_TYPE_ARRAY;
}
int MessageIter::array_length()
{
return dbus_message_iter_get_array_len((DBusMessageIter*)&_iter);
}
MessageIter MessageIter::new_dict_entry()
{
MessageIter ent(msg());
dbus_message_iter_open_container(
(DBusMessageIter*)_iter, DBUS_TYPE_DICT_ENTRY, 0, (DBusMessageIter*)&(ent._iter)
);
return ent;
}
bool MessageIter::is_dict()
{
return is_array() && dbus_message_iter_get_element_type((DBusMessageIter*)_iter) == DBUS_TYPE_DICT_ENTRY;
}
MessageIter MessageIter::new_variant( const char* sig )
{
MessageIter var(msg());
dbus_message_iter_open_container(
(DBusMessageIter*)_iter, DBUS_TYPE_VARIANT, sig, (DBusMessageIter*)&(var._iter)
);
return var;
}
MessageIter MessageIter::new_struct( const char* sig )
{
MessageIter stu(msg());
dbus_message_iter_open_container(
(DBusMessageIter*)_iter, DBUS_TYPE_STRUCT, sig, (DBusMessageIter*)&(stu._iter)
);
return stu;
}
void MessageIter::close_container( MessageIter& container )
{
dbus_message_iter_close_container((DBusMessageIter*)&_iter, (DBusMessageIter*)&(container._iter));
}
/*
*/
Message::Message()
: _pvt(new Private)
{
}
Message::Message( Message::Private* p )
: _pvt(p)
{
if(_pvt->msg) dbus_message_ref(_pvt->msg);
}
Message::Message( const Message& m )
: _pvt(m._pvt)
{
dbus_message_ref(_pvt->msg);
}
Message::~Message()
{
dbus_message_unref(_pvt->msg);
}
Message Message::copy()
{
Private* pvt = new Private(dbus_message_copy(_pvt->msg));
return Message(pvt);
}
bool Message::append( int first_type, ... )
{
va_list vl;
va_start(vl, first_type);
bool b = dbus_message_append_args_valist(_pvt->msg, first_type, vl);
va_end(vl);
return b;
}
void Message::terminate()
{
dbus_message_append_args(_pvt->msg, DBUS_TYPE_INVALID);
}
int Message::type() const
{
return dbus_message_get_type(_pvt->msg);
}
int Message::serial() const
{
return dbus_message_get_serial(_pvt->msg);
}
int Message::reply_serial() const
{
return dbus_message_get_reply_serial(_pvt->msg);
}
bool Message::reply_serial( int s )
{
return dbus_message_set_reply_serial(_pvt->msg, s);
}
const char* Message::sender() const
{
return dbus_message_get_sender(_pvt->msg);
}
bool Message::sender( const char* s )
{
return dbus_message_set_sender(_pvt->msg, s);
}
const char* Message::destination() const
{
return dbus_message_get_destination(_pvt->msg);
}
bool Message::destination( const char* s )
{
return dbus_message_set_destination(_pvt->msg, s);
}
bool Message::is_error() const
{
return type() == DBUS_MESSAGE_TYPE_ERROR;
}
bool Message::is_signal( const char* interface, const char* member ) const
{
return dbus_message_is_signal(_pvt->msg, interface, member);
}
MessageIter Message::w_iter()
{
MessageIter iter(*this);
dbus_message_iter_init_append(_pvt->msg, (DBusMessageIter*)&(iter._iter));
return iter;
}
MessageIter Message::r_iter() const
{
MessageIter iter(const_cast<Message&>(*this));
dbus_message_iter_init(_pvt->msg, (DBusMessageIter*)&(iter._iter));
return iter;
}
/*
*/
ErrorMessage::ErrorMessage()
{
_pvt->msg = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR);
}
ErrorMessage::ErrorMessage( const Message& to_reply, const char* name, const char* message )
{
_pvt->msg = dbus_message_new_error(to_reply._pvt->msg, name, message);
}
bool ErrorMessage::operator == ( const ErrorMessage& m ) const
{
return dbus_message_is_error(_pvt->msg, m.name());
}
const char* ErrorMessage::name() const
{
return dbus_message_get_error_name(_pvt->msg);
}
bool ErrorMessage::name( const char* n )
{
return dbus_message_set_error_name(_pvt->msg, n);
}
/*
*/
SignalMessage::SignalMessage( const char* name )
{
_pvt->msg = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
member(name);
}
SignalMessage::SignalMessage( const char* path, const char* interface, const char* name )
{
_pvt->msg = dbus_message_new_signal(path, interface, name);
}
bool SignalMessage::operator == ( const SignalMessage& m ) const
{
return dbus_message_is_signal(_pvt->msg, m.interface(), m.member());
}
const char* SignalMessage::interface() const
{
return dbus_message_get_interface(_pvt->msg);
}
bool SignalMessage::interface( const char* i )
{
return dbus_message_set_interface(_pvt->msg, i);
}
const char* SignalMessage::member() const
{
return dbus_message_get_member(_pvt->msg);
}
bool SignalMessage::member( const char* m )
{
return dbus_message_set_member(_pvt->msg, m);
}
const char* SignalMessage::path() const
{
return dbus_message_get_path(_pvt->msg);
}
char** SignalMessage::path_split() const
{
char** p;
dbus_message_get_path_decomposed(_pvt->msg, &p); //todo: return as a std::vector ?
return p;
}
bool SignalMessage::path( const char* p )
{
return dbus_message_set_path(_pvt->msg, p);
}
/*
*/
CallMessage::CallMessage()
{
_pvt->msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
}
CallMessage::CallMessage( const char* dest, const char* path, const char* iface, const char* method )
{
_pvt->msg = dbus_message_new_method_call(dest, path, iface, method);
}
bool CallMessage::operator == ( const CallMessage& m ) const
{
return dbus_message_is_method_call(_pvt->msg, m.interface(), m.member());
}
const char* CallMessage::interface() const
{
return dbus_message_get_interface(_pvt->msg);
}
bool CallMessage::interface( const char* i )
{
return dbus_message_set_interface(_pvt->msg, i);
}
const char* CallMessage::member() const
{
return dbus_message_get_member(_pvt->msg);
}
bool CallMessage::member( const char* m )
{
return dbus_message_set_member(_pvt->msg, m);
}
const char* CallMessage::path() const
{
return dbus_message_get_path(_pvt->msg);
}
char** CallMessage::path_split() const
{
char** p;
dbus_message_get_path_decomposed(_pvt->msg, &p);
return p;
}
bool CallMessage::path( const char* p )
{
return dbus_message_set_path(_pvt->msg, p);
}
const char* CallMessage::signature() const
{
return dbus_message_get_signature(_pvt->msg);
}
/*
*/
ReturnMessage::ReturnMessage( const CallMessage& callee )
{
_pvt = new Private(dbus_message_new_method_return(callee._pvt->msg));
}
const char* ReturnMessage::signature() const
{
return dbus_message_get_signature(_pvt->msg);
}

48
src/message_p.h Normal file
View file

@ -0,0 +1,48 @@
/*
*
* 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_P_H
#define __DBUSXX_MESSAGE_P_H
#include <dbus-c++/message.h>
#include <dbus-c++/refptr_impl.h>
#include <dbus/dbus.h>
namespace DBus {
struct Message::Private
{
DBusMessage* msg;
Private() : msg(0)
{}
Private( DBusMessage* m ) : msg(m)
{}
};
} /* namespace DBus */
#endif//__DBUSXX_MESSAGE_P_H

331
src/object.cpp Normal file
View file

@ -0,0 +1,331 @@
/*
*
* 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
*
*/
#include <dbus-c++/debug.h>
#include <dbus-c++/object.h>
#include "internalerror.h"
#include <dbus/dbus.h>
#include "message_p.h"
#include "connection_p.h"
using namespace DBus;
Object::Object( Connection& conn, const char* path, const char* service )
: _conn(conn), _path(path), _service(service ? service : "")
{
}
Object::~Object()
{
}
struct ObjectAdaptor::Private
{
static void unregister_function_stub( DBusConnection*, void* );
static DBusHandlerResult message_function_stub( DBusConnection*, DBusMessage*, void* );
};
static DBusObjectPathVTable _vtable =
{
ObjectAdaptor::Private::unregister_function_stub,
ObjectAdaptor::Private::message_function_stub,
NULL, NULL, NULL, NULL
};
void ObjectAdaptor::Private::unregister_function_stub( DBusConnection* conn, void* data )
{
// XXX: what do we have to do here ?
}
DBusHandlerResult ObjectAdaptor::Private::message_function_stub( DBusConnection*, DBusMessage* dmsg, void* data )
{
ObjectAdaptor* o = static_cast<ObjectAdaptor*>(data);
if( o )
{
Message msg(new Message::Private(dmsg));
debug_log("in object %s", o->path().c_str());
debug_log(" got message #%d from %s to %s",
msg.serial(),
msg.sender(),
msg.destination()
);
return o->handle_message(msg)
? DBUS_HANDLER_RESULT_HANDLED
: DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
else
{
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
}
ObjectAdaptor::ObjectAdaptor( Connection& conn, const char* path )
: Object(conn, path, conn.unique_name())
{
register_obj();
}
ObjectAdaptor::~ObjectAdaptor()
{
unregister_obj();
}
void ObjectAdaptor::register_obj()
{
debug_log("registering local object %s", path().c_str());
if(!dbus_connection_register_object_path(conn()._pvt->conn, path().c_str(), &_vtable, this))
{
throw Error(DBUS_ERROR_NO_MEMORY,"unable to register object path");
}
else
{
InterfaceTable::const_iterator ii = _interfaces.begin();
while( ii != _interfaces.end() )
{
std::string im = "type='method_call',interface='"+ii->first+"'";
conn().add_match(im.c_str());
++ii;
}
}
}
void ObjectAdaptor::unregister_obj()
{
debug_log("unregistering local object %s", path().c_str());
dbus_connection_unregister_object_path(conn()._pvt->conn, path().c_str());
InterfaceTable::const_iterator ii = _interfaces.begin();
while( ii != _interfaces.end() )
{
std::string im = "type='method_call',interface='"+ii->first+"'";
conn().remove_match(im.c_str());
++ii;
}
}
void ObjectAdaptor::remit_signal( SignalMessage& sig )
{
sig.path(path().c_str());
conn().send(sig);
}
struct WontReturnException
{
const void* tag;
};
bool ObjectAdaptor::handle_message( const Message& msg )
{
switch( msg.type() )
{
case DBUS_MESSAGE_TYPE_METHOD_CALL:
{
const CallMessage& cmsg = reinterpret_cast<const CallMessage&>(msg);
const char* member = cmsg.member();
const char* interface = cmsg.interface();
debug_log(" invoking method %s.%s", interface, member);
InterfaceTable::const_iterator ii = _interfaces.find(interface);
if( ii != _interfaces.end() )
{
try
{
Message ret = ii->second->invoke_method(cmsg);
conn().send(ret);
}
catch(Error& e)
{
ErrorMessage em(cmsg, e.name(), e.message());
conn().send(em);
}
catch(WontReturnException& wre)
{
_deferred_returns[wre.tag] = new DeferredReturn(conn(), cmsg, wre.tag);
}
return true;
}
else
{
return false;
}
}
default:
{
return false;
}
}
}
void ObjectAdaptor::return_later( const void* tag )
{
WontReturnException wre = { tag };
throw wre;
}
void ObjectAdaptor::return_now( DeferredReturn* ret )
{
ret->_conn.send(ret->_return);
DeferredReturnMap::iterator di = _deferred_returns.find(ret->_tag);
delete di->second;
_deferred_returns.erase(di);
}
void ObjectAdaptor::return_error( DeferredReturn* ret, Error& error )
{
ret->_conn.send(ErrorMessage(ret->_call, error.name(), error.message()));
DeferredReturnMap::iterator di = _deferred_returns.find(ret->_tag);
delete di->second;
_deferred_returns.erase(di);
}
ObjectAdaptor::DeferredReturn* ObjectAdaptor::find_return( const void* tag )
{
DeferredReturnMap::iterator di = _deferred_returns.find(tag);
return di != _deferred_returns.end() ? di->second : NULL;
}
ObjectAdaptor::DeferredReturn::DeferredReturn( Connection& conn, const CallMessage& call, const void* tag )
: _conn(conn), _call(call), _return(_call), _tag(tag)
{
_writer = _return.w_iter(); //todo: verify
}
/*
*/
ObjectProxy::ObjectProxy( Connection& conn, const char* path, const char* service )
: Object(conn, path, service)
{
register_obj();
}
ObjectProxy::~ObjectProxy()
{
unregister_obj();
}
void ObjectProxy::register_obj()
{
debug_log("registering remote object %s", path().c_str());
_filtered = new Callback<ObjectProxy, bool, const Message&>(this, &ObjectProxy::handle_message);
conn().add_filter(_filtered);
InterfaceTable::const_iterator ii = _interfaces.begin();
while( ii != _interfaces.end() )
{
std::string im = "type='signal',interface='"+ii->first+"'";
conn().add_match(im.c_str());
++ii;
}
// conn().add_match("type='signal'");
// conn().add_match("type='method_call'");
}
void ObjectProxy::unregister_obj()
{
debug_log("unregistering remote object %s", path().c_str());
InterfaceTable::const_iterator ii = _interfaces.begin();
while( ii != _interfaces.end() )
{
std::string im = "type='signal',interface='"+ii->first+"'";
conn().remove_match(im.c_str());
++ii;
}
// conn().remove_match("type='method_call'");
// conn().remove_match("type='signal'");
conn().remove_filter(_filtered);
}
Message ObjectProxy::rinvoke_method( CallMessage& call )
{
call.path(path().c_str());
call.destination(service().c_str());
return conn().send_blocking(call, 2000);
}
bool ObjectProxy::handle_message( const Message& msg )
{
switch( msg.type() )
{
case DBUS_MESSAGE_TYPE_SIGNAL:
{
const SignalMessage& smsg = reinterpret_cast<const SignalMessage&>(msg);
const char* interface = smsg.interface();
const char* member = smsg.member();
debug_log("filtered signal %s(in %s) from remote object %s", member, interface, msg.sender());
InterfaceTable::const_iterator ii = _interfaces.find(interface);
if( ii != _interfaces.end() )
{
return ii->second->dispatch_signal(smsg);
}
else
{
return false;
}
}
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
{
debug_log("filtered method return from remote object %s", msg.sender());
//TODO:
return false;
}
case DBUS_MESSAGE_TYPE_ERROR:
{
debug_log("filtered error from remote object %s", msg.sender());
//TODO:
return false;
}
default:
{
return false;
}
}
}

105
src/pendingcall.cpp Normal file
View file

@ -0,0 +1,105 @@
/*
*
* 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
*
*/
#include <dbus-c++/pendingcall.h>
#include <dbus/dbus.h>
#include "internalerror.h"
#include "pendingcall_p.h"
using namespace DBus;
PendingCall::Private::Private( DBusPendingCall* pc )
: call(pc), dataslot(-1)
{
if(!dbus_pending_call_allocate_data_slot(&dataslot))
{
throw Error(DBUS_ERROR_NO_MEMORY, "Unable to allocate data slot");
}
}
void PendingCall::Private::notify_stub( DBusPendingCall* dpc, void* data )
{
PendingCall* pc = static_cast<PendingCall*>(data);
pc->slot(*pc);
}
PendingCall::Private::~Private()
{
if(dataslot != -1)
{
dbus_pending_call_allocate_data_slot(&dataslot);
}
}
PendingCall::PendingCall( PendingCall::Private* p )
: _pvt(p)
{
if(!dbus_pending_call_set_notify(_pvt->call, Private::notify_stub, this, NULL))
{
throw Error(DBUS_ERROR_NO_MEMORY, "Unable to initialize pending call");
}
}
PendingCall::PendingCall( const PendingCall& c )
: _pvt(c._pvt)
{
dbus_pending_call_ref(_pvt->call);
}
PendingCall::~PendingCall()
{
dbus_pending_call_unref(_pvt->call);
}
bool PendingCall::completed()
{
return dbus_pending_call_get_completed(_pvt->call);
}
void PendingCall::cancel()
{
dbus_pending_call_cancel(_pvt->call);
}
void PendingCall::block()
{
dbus_pending_call_block(_pvt->call);
}
void PendingCall::data( void* p )
{
if(!dbus_pending_call_set_data(_pvt->call, _pvt->dataslot, p, NULL))
{
throw Error(DBUS_ERROR_NO_MEMORY, "Unable to initialize data slot");
}
}
void* PendingCall::data()
{
return dbus_pending_call_get_data(_pvt->call, _pvt->dataslot);
}

49
src/pendingcall_p.h Normal file
View file

@ -0,0 +1,49 @@
/*
*
* 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_P_H
#define __DBUSXX_PENDING_CALL_P_H
#include <dbus-c++/pendingcall.h>
#include <dbus-c++/refptr_impl.h>
#include <dbus/dbus.h>
namespace DBus {
struct PendingCall::Private
{
DBusPendingCall* call;
int dataslot;
Private( DBusPendingCall* );
~Private();
static void notify_stub( DBusPendingCall* dpc, void* data );
};
} /* namespace DBus */
#endif//__DBUSXX_PENDING_CALL_P_H

115
src/server.cpp Normal file
View file

@ -0,0 +1,115 @@
/*
*
* 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
*
*/
#include <dbus-c++/debug.h>
#include <dbus-c++/server.h>
#include "internalerror.h"
#include "server_p.h"
#include "connection_p.h"
#include "dispatcher_p.h"
using namespace DBus;
Server::Private::Private( DBusServer* s )
: server(s)
{
dbus_server_set_new_connection_function(server, on_new_conn_cb, this, NULL);
}
void Server::Private::on_new_conn_cb( DBusServer* server, DBusConnection* conn, void* data )
{
//Private* p = static_cast<Private*>(data);
//m->on_new_connection(nc); //TODO
Connection nc(new Connection::Private(conn));
debug_log("incoming connection");
}
Server::Server( const char* address )
{
InternalError e;
DBusServer* server = dbus_server_listen(address, e);
if(e) throw Error(e);
_pvt = new Private(server);
}
Server::Server( const Server& s )
: _pvt(s._pvt)
{
dbus_server_ref(_pvt->server);
}
Server::~Server()
{
dbus_server_unref(_pvt->server);
}
Dispatcher* Server::setup( Dispatcher* dispatcher )
{
debug_log("registering stubs for server %p", _pvt->server);
Dispatcher* prev = _pvt->dispatcher;
dbus_server_set_watch_functions(
_pvt->server,
Dispatcher::Private::on_add_watch,
Dispatcher::Private::on_rem_watch,
Dispatcher::Private::on_toggle_watch,
dispatcher,
0
);
dbus_server_set_timeout_functions(
_pvt->server,
Dispatcher::Private::on_add_timeout,
Dispatcher::Private::on_rem_timeout,
Dispatcher::Private::on_toggle_timeout,
dispatcher,
0
);
_pvt->dispatcher = dispatcher;
return prev;
}
bool Server::operator == ( const Server& s ) const
{
return _pvt->server == s._pvt->server;
}
bool Server::listening() const
{
return dbus_server_get_is_connected(_pvt->server);
}
void Server::disconnect()
{
dbus_server_disconnect(_pvt->server);
}

49
src/server_p.h Normal file
View file

@ -0,0 +1,49 @@
/*
*
* 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_P_H
#define __DBUSXX_SERVER_P_H
#include <dbus-c++/server.h>
#include <dbus-c++/dispatcher.h>
#include <dbus-c++/refptr_impl.h>
#include <dbus/dbus.h>
namespace DBus {
struct Server::Private
{
DBusServer* server;
Dispatcher* dispatcher;
Private( DBusServer* );
static void on_new_conn_cb( DBusServer* server, DBusConnection* conn, void* data );
};
} /* namespace DBus */
#endif//__DBUSXX_SERVER_P_H

177
src/types.cpp Normal file
View file

@ -0,0 +1,177 @@
/*
*
* 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
*
*/
#include <dbus-c++/types.h>
#include <dbus-c++/object.h>
#include <dbus/dbus.h>
#include <stdarg.h>
#include "message_p.h"
#include "internalerror.h"
using namespace DBus;
Variant::Variant()
: _msg(CallMessage()), // dummy message used as temporary storage for variant data
_it(_msg.w_iter())
{
}
Variant::Variant( MessageIter& it )
: _msg(it.msg()),
_it(it.recurse())
{
}
Variant& Variant::operator = ( const Variant& v )
{
if(&v != this)
{
_msg = v._msg;
_it = v._it;
_signature = v._signature;
}
return *this;
}
const char* Variant::signature() const
{
char* sigbuf = _it.signature();
_signature = sigbuf;
free(sigbuf);
return _signature.c_str();
}
MessageIter& operator << ( MessageIter& iter, const Variant& val )
{
const char* sig = val.signature();
MessageIter rit = val.iter();
MessageIter wit = iter.new_variant(sig);
for(size_t i = 0; i < strlen(sig); ++i)
{
switch(sig[i])
{
case 'b':
{
Bool b; rit >> b; wit << b;
break;
}
case 'y':
{
Byte y; rit >> y; wit << y;
break;
}
case 'n':
{
Int16 n; rit >> n; wit << n;
break;
}
case 'q':
{
UInt16 q; rit >> q; wit << q;
break;
}
case 'i':
{
Int32 i; rit >> i; wit << i;
break;
}
case 'u':
{
UInt32 u; rit >> u; wit << u;
break;
}
case 'x':
{
Int64 x; rit >> x; wit << x;
break;
}
case 't':
{
UInt64 t; rit >> t; wit << t;
break;
}
case 'd':
{
Double d; rit >> d; wit << d;
break;
}
case 's':
{
String s; rit >> s; wit << s;
break;
}
case 'o':
{
Path o; rit >> o; wit << o;
break;
}
case 'g':
{
Signature g; rit >> g; wit << g;
break;
}
case 'a':
{
break;
}
case '(':
{
break;
}
case ')':
{
break;
}
case '{':
{
break;
}
case '}':
{
break;
}
}
}
//TODO: implement marshaling of compound types
iter.close_container(wit);
return iter;
}
MessageIter& operator >> ( MessageIter& iter, Variant& val )
{
//TODO: check if iter really points to a variant
val = Variant(iter);
return ++iter;
}

314
src/xml.cpp Normal file
View file

@ -0,0 +1,314 @@
/*
*
* 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
*
*/
#include <dbus-c++/xml.h>
#include <dbus-c++/debug.h>
#include <expat.h>
std::istream& operator >> ( std::istream& in, DBus::Xml::Document& doc )
{
std::stringbuf xmlbuf;
in.get(xmlbuf, '\0');
doc.from_xml(xmlbuf.str());
return in;
}
std::ostream& operator << ( std::ostream& out, const DBus::Xml::Document& doc )
{
return out << doc.to_xml();
}
using namespace DBus;
using namespace DBus::Xml;
Error::Error( const char* error, int line, int column )
{
std::ostringstream estream;
estream << "line " << line << ", column " << column << ": " << error;
_error = estream.str();
}
Node::Node( const char* n, const char** a )
: name(n)
{
if(a)
for(int i = 0; a[i]; i += 2)
{
_attrs[a[i]] = a[i+1];
//debug_log("xml:\t%s = %s", a[i], a[i+1]);
}
}
Nodes Nodes::operator[]( const std::string& key )
{
Nodes result;
for(iterator i = begin(); i != end(); ++i)
{
Nodes part = (**i)[key];
result.insert(result.end(), part.begin(), part.end());
}
return result;
}
Nodes Nodes::select( const std::string& attr, const std::string& value )
{
Nodes result;
for(iterator i = begin(); i != end(); ++i)
{
if((*i)->get(attr) == value)
result.insert(result.end(), *i);
}
return result;
}
Nodes Node::operator[]( const std::string& key )
{
Nodes result;
if(key.length() == 0) return result;
for(Children::iterator i = children.begin(); i != children.end(); ++i)
{
if(i->name == key)
result.push_back(&(*i));
}
return result;
}
std::string Node::get( const std::string& attribute )
{
if(_attrs.find(attribute) != _attrs.end())
return _attrs[attribute];
else
return "";
}
void Node::set( const std::string& attribute, std::string value )
{
if(value.length())
_attrs[attribute] = value;
else
_attrs.erase(value);
}
std::string Node::to_xml() const
{
std::string xml;
int depth = 0;
_raw_xml(xml, depth);
return xml;
}
void Node::_raw_xml( std::string& xml, int& depth ) const
{
xml.append(depth*2, ' ');
xml.append("<"+name);
for(Attributes::const_iterator i = _attrs.begin(); i != _attrs.end(); ++i)
{
xml.append(" "+i->first+"=\""+i->second+"\"");
}
if(cdata.length() == 0 && children.size() == 0)
{
xml.append("/>\n");
}
else
{
xml.append(">");
if(cdata.length())
{
xml.append(cdata);
}
if(children.size())
{
xml.append("\n");
depth++;
for(Children::const_iterator i = children.begin(); i != children.end(); ++i)
{
i->_raw_xml(xml, depth);
}
depth--;
xml.append(depth*2, ' ');
}
xml.append("</"+name+">\n");
}
}
Document::Document()
: root(0), _depth(0)
{
}
Document::Document( const std::string& xml )
: root(0), _depth(0)
{
from_xml(xml);
}
Document::~Document()
{
delete root;
}
struct Document::Expat
{
static void start_doctype_decl_handler(
void* data, const XML_Char* name, const XML_Char* sysid, const XML_Char* pubid, int has_internal_subset
);
static void end_doctype_decl_handler( void* data );
static void start_element_handler( void *data, const XML_Char *name, const XML_Char **atts );
static void character_data_handler( void *data, const XML_Char* chars, int len );
static void end_element_handler( void *data, const XML_Char *name );
};
void Document::from_xml( const std::string& xml )
{
_depth = 0;
delete root;
root = 0;
XML_Parser parser = XML_ParserCreate("UTF-8");
XML_SetUserData(parser, this);
XML_SetDoctypeDeclHandler(
parser,
Document::Expat::start_doctype_decl_handler,
Document::Expat::end_doctype_decl_handler
);
XML_SetElementHandler(
parser,
Document::Expat::start_element_handler,
Document::Expat::end_element_handler
);
XML_SetCharacterDataHandler(
parser,
Document::Expat::character_data_handler
);
XML_Status status = XML_Parse(parser, xml.c_str(), xml.length(), true);
if(status == XML_STATUS_ERROR)
{
const char* error = XML_ErrorString(XML_GetErrorCode(parser));
int line = XML_GetCurrentLineNumber(parser);
int column = XML_GetCurrentColumnNumber(parser);
XML_ParserFree(parser);
throw Error(error, line, column);
}
else
{
XML_ParserFree(parser);
}
}
std::string Document::to_xml() const
{
return root->to_xml();
}
void Document::Expat::start_doctype_decl_handler(
void* data, const XML_Char* name, const XML_Char* sysid, const XML_Char* pubid, int has_internal_subset
)
{
}
void Document::Expat::end_doctype_decl_handler( void* data )
{
}
void Document::Expat::start_element_handler( void *data, const XML_Char *name, const XML_Char **atts )
{
Document* doc = (Document*)data;
//debug_log("xml:%d -> %s", doc->_depth, name);
if(!doc->root)
{
doc->root = new Node(name, atts);
}
else
{
Node::Children* cld = &(doc->root->children);
for(int i = 1; i < doc->_depth; ++i)
{
cld = &(cld->back().children);
}
cld->push_back(Node(name, atts));
//std::cerr << doc->to_xml() << std::endl;
}
doc->_depth++;
}
void Document::Expat::character_data_handler( void *data, const XML_Char* chars, int len )
{
Document* doc = (Document*)data;
Node* nod = doc->root;
for(int i = 1; i < doc->_depth; ++i)
{
nod = &(nod->children.back());
}
int x, y;
x = 0;
y = len-1;
while(isspace(chars[y]) && y > 0) --y;
while(isspace(chars[x]) && x < y) ++x;
nod->cdata = std::string(chars, x, y+1);
}
void Document::Expat::end_element_handler( void *data, const XML_Char *name )
{
Document* doc = (Document*)data;
//debug_log("xml:%d <- %s", doc->_depth, name);
doc->_depth--;
}