* Remove all bindings

This commit is contained in:
John (J5) Palmieri 2006-07-14 16:20:12 +00:00
parent 5efe8e7f1d
commit a929c9a3b4
328 changed files with 16 additions and 124017 deletions

View file

@ -49,7 +49,7 @@ WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = dbus glib
INPUT = dbus
FILE_PATTERNS = *.c *.h
RECURSIVE = YES
#EXCLUDE = test

View file

@ -1,56 +1,15 @@
if HAVE_GLIB
GLIB_SUBDIR=glib
GLIB_PC=dbus-glib-1.pc
endif
if HAVE_QT
QT_SUBDIR=qt
QT_PC=dbus-qt4-1.pc
endif
if HAVE_QT3
QT3_SUBDIR=qt3
endif
if DBUS_USE_GCJ
GCJ_SUBDIR=gcj
endif
if DBUS_USE_CSC
MONO_SUBDIR=mono
MONO_PC=dbus-sharp.pc
endif
if HAVE_PYTHON
PYTHON_SUBDIR=python
endif
## really we should require gcj/mcs/python also but since they are
## annoying to install, we don't for now
dist-local:
if test -z "$(QT_SUBDIR)" || test -z "$(GLIB_SUBDIR)" ; then \
echo "You have to build with Qt and GLib to make dist" ; \
fi
SUBDIRS=dbus bus doc $(GLIB_SUBDIR) $(GCJ_SUBDIR) $(MONO_SUBDIR) $(QT_SUBDIR) $(QT3_SUBDIR) $(PYTHON_SUBDIR) tools test
DIST_SUBDIRS=dbus bus doc glib qt qt3 gcj mono python tools test
SUBDIRS=dbus bus doc tools test
DIST_SUBDIRS=dbus bus doc tools test
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = dbus-1.pc $(GLIB_PC) $(QT_PC) $(MONO_PC)
pkgconfig_DATA = dbus-1.pc
DISTCLEANFILES = \
dbus-1.pc \
$(GLIB_PC) \
$(QT_PC) \
$(MONO_PC)
dbus-1.pc
EXTRA_DIST = \
HACKING \
dbus-1.pc.in \
dbus-glib-1.pc.in \
dbus-qt4-1.pc.in \
dbus-sharp.pc.in
dbus-1.pc.in
all-local: Doxyfile
@ -61,7 +20,7 @@ clean-gcov:
clean-bbg:
find -name "*.bbg" -o -name "*.bb" | xargs rm || true
GCOV_DIRS=dbus bus $(GLIB_SUBDIR) $(QT_SUBDIR)
GCOV_DIRS=dbus bus
## .PHONY so it always rebuilds it
.PHONY: coverage-report.txt

View file

@ -46,13 +46,6 @@ AC_PROG_CXX
AC_ISC_POSIX
AC_HEADER_STDC
AC_ARG_ENABLE(qt, AS_HELP_STRING([--enable-qt],[enable Qt-friendly client library]),enable_qt=$enableval,enable_qt=auto)
AC_ARG_ENABLE(qt-debug, AS_HELP_STRING([--enable-qt-debug],[enable Qt-friendly client library, linked to debug Qt libraries]),enable_qt_debug=$enableval,enable_qt_debug=no)
AC_ARG_WITH(qt_moc, AS_HELP_STRING([--with-qt-moc=<path>],[moc for Qt]))
AC_ARG_ENABLE(qt3, AS_HELP_STRING([--enable-qt3],[enable Qt3-friendly client library]),enable_qt3=$enableval,enable_qt3=auto)
AC_ARG_WITH(qt3_moc, AS_HELP_STRING([--with-qt3-moc=<path>],[moc for Qt3]))
AC_ARG_ENABLE(glib, AS_HELP_STRING([--enable-glib],[enable GLib-friendly client library]),enable_glib=$enableval,enable_glib=auto)
AC_ARG_ENABLE(gtk, AS_HELP_STRING([--enable-gtk],[enable GTK-requiring executables]),enable_gtk=$enableval,enable_gtk=auto)
AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests],[enable unit test code]),enable_tests=$enableval,enable_tests=$USE_MAINTAINER_MODE)
AC_ARG_ENABLE(ansi, AS_HELP_STRING([--enable-ansi],[enable -ansi -pedantic gcc flags]),enable_ansi=$enableval,enable_ansi=no)
AC_ARG_ENABLE(verbose-mode, AS_HELP_STRING([--enable-verbose-mode],[support verbose debug mode]),enable_verbose_mode=$enableval,enable_verbose_mode=$USE_MAINTAINER_MODE)
@ -62,10 +55,6 @@ AC_ARG_ENABLE(xml-docs, AS_HELP_STRING([--enable-xml-docs],[build XML documentat
AC_ARG_ENABLE(doxygen-docs, AS_HELP_STRING([--enable-doxygen-docs],[build DOXYGEN documentation (requires Doxygen)]),enable_doxygen_docs=$enableval,enable_doxygen_docs=auto)
AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov],[compile with coverage profiling instrumentation (gcc only)]),enable_gcov=$enableval,enable_gcov=no)
AC_ARG_ENABLE(abstract-sockets, AS_HELP_STRING([--enable-abstract-sockets],[use abstract socket namespace (linux only)]),enable_abstract_sockets=$enableval,enable_abstract_sockets=auto)
AC_ARG_ENABLE(gcj, AS_HELP_STRING([--enable-gcj],[build gcj bindings]),enable_gcj=$enableval,enable_gcj=no)
AC_ARG_ENABLE(mono, AS_HELP_STRING([--enable-mono],[build mono bindings]),enable_mono=$enableval,enable_mono=no)
AC_ARG_ENABLE(mono_docs, AS_HELP_STRING([--enable-mono-docs],[build mono docs]),enable_mono_docs=$enableval,enable_mono_docs=no)
AC_ARG_ENABLE(python, AS_HELP_STRING([--enable-python],[build python bindings]),enable_python=$enableval,enable_python=auto)
AC_ARG_ENABLE(selinux, AS_HELP_STRING([--enable-selinux],[build with SELinux support]),enable_selinux=$enableval,enable_selinux=auto)
AC_ARG_ENABLE(dnotify, AS_HELP_STRING([--enable-dnotify],[build with dnotify support (linux only)]),enable_dnotify=$enableval,enable_dnotify=auto)
AC_ARG_ENABLE(console-owner-file, AS_HELP_STRING([--enable-console-owner-file],[enable console owner file]),enable_console_owner_file=$enableval,enable_console_owner_file=auto)
@ -190,142 +179,8 @@ else
fi
fi
#### can't use AM_PROG_GCJ since it fails fatally if no gcj found
AC_CHECK_PROGS(GCJ, gcj, gcj)
if test -z "$GCJ" ; then
have_gcj=no
else
# Needs to be here so libtool wont get confused
AM_PROG_GCJ
have_gcj=yes
if test "x${GCJFLAGS-unset}" = xunset; then
GCJFLAGS="-g -O2 -Wall"
fi
AC_SUBST(GCJFLAGS)
fi
if test x$enable_gcj = xauto ; then
if test x$have_gcj = xno ; then
enable_gcj=no
else
enable_gcj=yes
fi
fi
if test x$enable_gcj = xyes; then
if test x$have_gcj = xno ; then
AC_MSG_ERROR([Building gcj explicitly required, but gcj not found])
else
AC_CHECK_PROGS(JAR, gcj-jar fastjar jar)
fi
fi
AM_CONDITIONAL(DBUS_USE_GCJ, test x$enable_gcj = xyes)
AM_PROG_LIBTOOL
#### Look for mono
MONO_REQUIRED_VERSION=0.95
AC_SUBST(MONO_REQUIRED_VERSION)
PKG_CHECK_MODULES(MONO_DEPENDENCY, mono >= $MONO_REQUIRED_VERSION, have_mono=true, have_mono=false)
if test "x$enable_mono" = "xyes"; then
if test "x$have_mono" = "xfalse"; then
AC_MSG_ERROR([Mono was not found])
fi
fi
if test "x$have_mono" = "xtrue"; then
if test `uname -s` = "Darwin"; then
AC_PATH_PROG(RUNTIME, mint, no)
AC_PATH_PROG(CSC, mcs, no)
LIB_PREFIX=
LIB_SUFFIX=.dylib
else
AC_PATH_PROG(RUNTIME, mono, no)
AC_PATH_PROG(CSC, mcs, no)
LIB_PREFIX=.so
LIB_SUFFIX=
fi
else
AC_PATH_PROG(CSC, csc.exe, no)
RUNTIME=
LIB_PREFIX=
LIB_SUFFIX=.dylib
fi
if test x$enable_mono = xyes; then
if test x$have_mcs = xno ; then
AC_MSG_ERROR([Building Mono bindings explicitly required, but mcs compiler not found])
fi
### Test for GACUTIL
AC_PATH_PROG(GACUTIL, gacutil, no)
if test "x$GACUTIL" = "xno" ; then
AC_MSG_ERROR([No gacutil tool found])
fi
AC_SUBST(GACUTIL)
fi
if test x$enable_mono = xauto ; then
if test x$CSC = xno ; then
enable_mono=no
else
### Test for GACUTIL
AC_PATH_PROG(GACUTIL, gacutil, no)
if test "x$GACUTIL" = "xno" ; then
enable_mono=no
else
enable_mono=yes
fi
fi
fi
AC_SUBST(RUNTIME)
AC_SUBST(CSC)
AC_SUBST(GACUTIL)
AC_SUBST(LIB_PREFIX)
AC_SUBST(LIB_SUFFIX)
AM_CONDITIONAL(DBUS_USE_CSC, test x$enable_mono = xyes)
#### Look for monodoc
MONODOC_REQUIRED_VERSION=0.16
AC_SUBST(MONODOC_REQUIRED_VERSION)
PKG_CHECK_MODULES(MONODOC_DEPENDENCY, monodoc >= $MONODOC_REQUIRED_VERSION, have_monodoc=yes, have_monodoc=no)
if test x$enable_mono_docs = xyes; then
if test x$have_monodoc = xno ; then
AC_MSG_ERROR([Building Mono docs explicitly required, but monodoc not found])
else
AC_PATH_PROG(MONODOC, monodoc, no)
if test x$MONODOC = xno; then
AC_MSG_ERROR([Building Mono docs explicitly required, but monodoc not found])
fi
fi
fi
if test x$enable_mono_docs = xauto ; then
if test x$have_monodoc = xno ; then
enable_mono_docs=no
MONODOC=
else
AC_PATH_PROG(MONODOC, monodoc, no)
if test x$MONODOC = xno; then
enable_mono_docs=no
MONODOC=
else
enable_mono_docs=yes
fi
fi
fi
AC_SUBST(MONODOC)
AM_CONDITIONAL(ENABLE_MONODOC, test "x$enable_mono_docs" = "xyes")
changequote(,)dnl
# let ourselves use our own unstable API
CPPFLAGS="-DDBUS_API_SUBJECT_TO_CHANGE=1 $CPPFLAGS"
@ -885,230 +740,6 @@ DBUS_TEST_LIBS=
AC_SUBST(DBUS_TEST_CFLAGS)
AC_SUBST(DBUS_TEST_LIBS)
# Glib detection
PKG_CHECK_MODULES(DBUS_GLIB, gobject-2.0 >= 2.4, have_glib=yes, have_glib=no)
PKG_CHECK_MODULES(DBUS_GLIB_THREADS, gthread-2.0 >= 2.4, have_glib_threads=yes, have_glib_threads=no)
if test x$have_glib = xno ; then
AC_MSG_WARN([GLib development libraries not found])
fi
if test x$enable_glib = xyes; then
if test x$have_glib = xno; then
AC_MSG_ERROR([GLib explicitly required, and GLib development libraries not found])
fi
fi
if test x$enable_glib = xno; then
have_glib=no;
fi
AM_CONDITIONAL(HAVE_GLIB, test x$have_glib = xyes)
AM_CONDITIONAL(HAVE_GLIB_THREADS, test x$have_glib_threads = xyes)
if test x$have_glib = xyes; then
GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0`
else
GLIB_GENMARSHAL=glib-not-enabled-so-there-is-no-genmarshal
fi
AC_SUBST(GLIB_GENMARSHAL)
dnl GLib flags
AC_SUBST(DBUS_GLIB_CFLAGS)
AC_SUBST(DBUS_GLIB_LIBS)
AC_SUBST(DBUS_GLIB_THREADS_LIBS)
DBUS_GLIB_TOOL_CFLAGS=$XML_CFLAGS
DBUS_GLIB_TOOL_LIBS="$XML_LIBS $INTLLIBS"
AC_SUBST(DBUS_GLIB_TOOL_CFLAGS)
AC_SUBST(DBUS_GLIB_TOOL_LIBS)
# GTK detection
if test x$have_glib = xno ; then
AC_MSG_WARN([Can't use GTK+ since GLib not enabled])
have_gtk=no
else
PKG_CHECK_MODULES(DBUS_GTK, gtk+-2.0 >= 2.4, have_gtk=yes, have_gtk=no)
PKG_CHECK_MODULES(DBUS_GTK_THREADS, gtk+-2.0 >= 2.4 gthread-2.0, have_gtk_threads=yes, have_gtk_threads=no)
fi
if test x$have_gtk = xno ; then
AC_MSG_WARN([GTK+ development libraries not found])
fi
if test x$enable_gtk = xyes; then
if test x$have_gtk = xno; then
AC_MSG_ERROR([GTK+ explicitly required, and GTK+ development libraries not found])
fi
fi
if test x$enable_gtk = xno; then
have_gtk=no;
fi
AM_CONDITIONAL(HAVE_GTK, test x$have_gtk = xyes)
dnl Gtk flags
AC_SUBST(DBUS_GTK_CFLAGS)
AC_SUBST(DBUS_GTK_LIBS)
AC_SUBST(DBUS_GTK_THREADS_CFLAGS)
AC_SUBST(DBUS_GTK_THREADS_LIBS)
dnl Qt3 detection
if test -z "$with_qt3_moc" ; then
AC_PATH_PROG(QT3_MOC, moc, no)
else
QT3_MOC=$with_qt3_moc
AC_SUBST(QT3_MOC)
fi
have_qt3=no
AC_MSG_CHECKING([for qglobal.h])
if test -n "$QTDIR" -a -f "$QTDIR/include/qglobal.h"; then
have_qt3=yes
DBUS_QT3_CXXFLAGS="-I$QTDIR/include"
else
for dir in "${prefix}/include/qt" "/usr/include/qt-3.1" "/usr/include/qt3" "/usr/include/qt" "/usr/lib/qt/include" "/usr/lib/qt-3.1/include"; do
if test -f "$dir/qglobal.h"; then
have_qt3=yes
DBUS_QT3_CXXFLAGS="-I$dir"
DBUS_QT3_LIBS="-L$QTDIR/lib -lqt-mt"
fi
done
fi
if test x$have_qt3 = xyes; then
AC_MSG_RESULT([found])
else
AC_MSG_RESULT([not found])
fi
if test x$have_qt3 = xno; then
AC_MSG_WARN([Qt3 development libraries not found])
fi
if test x$enable_qt3 = xyes; then
if test x$have_qt3 = xno; then
AC_MSG_ERROR([Qt3 integration explicitly required, and Qt3 libraries not found])
fi
fi
if test x$enable_qt3 = xno; then
have_qt3=no;
fi
AM_CONDITIONAL(HAVE_QT3, test x$have_qt3 = xyes)
dnl Qt3 flags
AC_SUBST(DBUS_QT3_CXXFLAGS)
AC_SUBST(DBUS_QT3_LIBS)
dnl Qt4 detection
AC_MSG_CHECKING([if we want to link to Qt debugging libraries])
qt_suffix=
if test x$enable_qt_debug = xyes; then
qt_suffix=_debug
AC_MSG_RESULT([debug])
else
AC_MSG_RESULT([release])
fi
if test x$enable_qt = xno; then
have_qt=no
have_qt_gui=no
have_qtest=no
else
QT_CORE=QtCore$qt_suffix
QT_XML=QtXml$qt_suffix
QT_GUI=QtGui$qt_suffix
QT_TESTLIB=QtTest$qt_suffix
min_qt_version=4.1.3
AC_SUBST(QT_CORE)
AC_SUBST(QT_XML)
PKG_CHECK_MODULES([DBUS_QT],
[$QT_CORE >= $min_qt_version $QT_XML >= $min_qt_version],
have_qt=yes,
have_qt=no)
fi
dnl Check for moc too
if test x$have_qt = xyes ; then
AC_MSG_CHECKING([for moc])
if test -z "$with_qt_moc" ; then
QT_MOC=`$PKG_CONFIG --variable=exec_prefix $QT_CORE`
QT_MOC=${QT_MOC}/bin/moc
else
QT_MOC=$with_qt_moc
fi
if test -x "$QT_MOC"; then
AC_MSG_RESULT([found, $QT_MOC])
else
AC_MSG_RESULT([not found])
AC_MSG_WARN([moc not found; disabling Qt])
have_qt=no
fi
fi
if test x$have_qt = xno ; then
if test x$enable_qt = xyes; then
AC_MSG_ERROR([Qt integration explicitly required, and Qt libraries not found])
fi
have_qt=no
else
dnl Qt4 flags
AC_SUBST(DBUS_QT_CFLAGS)
AC_SUBST(DBUS_QT_LIBS)
AC_SUBST(QT_MOC)
dnl QTestLib detection
PKG_CHECK_MODULES([DBUS_QTESTLIB],
[$QT_TESTLIB >= 4.1.0],
have_qtest=yes,
have_qtest=no)
if test x$have_qtest = xno ; then
AC_MSG_WARN([Qt Unit Test library not found])
fi
if test x$have_qt = xno; then
have_qtest=no
fi
AC_SUBST(DBUS_QTESTLIB_CFLAGS)
AC_SUBST(DBUS_QTESTLIB_LIBS)
dnl QtGui detection
PKG_CHECK_MODULES([DBUS_QT_GUI], [$QT_GUI >= $min_qt_version],
have_qt_gui=yes,
have_qt_gui=no)
if test x$have_qt_gui = xyes ; then
AC_MSG_CHECKING([for uic])
QT_UIC=`$PKG_CONFIG --variable=exec_prefix $QT_GUI`/bin/uic
if test -x "$QT_UIC" ; then
AC_MSG_RESULT([found, $QT_UIC])
else
AC_MSG_RESULT([not found, disabling Qt Gui])
have_qt_gui=no
fi
fi
AC_SUBST(DBUS_QT_GUI_CFLAGS)
AC_SUBST(DBUS_QT_GUI_LIBS)
AC_SUBST(QT_UIC)
fi
AM_CONDITIONAL(HAVE_QT, test x$have_qt = xyes)
AM_CONDITIONAL(HAVE_QT_GUI, test x$have_qt_gui = xyes)
AM_CONDITIONAL(HAVE_QTESTLIB, test x$have_qtest = xyes)
### X11 detection
AC_PATH_XTRA
@ -1343,8 +974,6 @@ AC_SUBST(TEST_$1)
TEST_PATH(SERVICE_DIR, data/valid-service-files)
TEST_PATH(SERVICE_BINARY, test-service)
TEST_PATH(SHELL_SERVICE_BINARY, test-shell-service)
TEST_PATH(GLIB_SERVICE_BINARY, glib/test-service-glib)
TEST_PATH(PYTHON_SERVICE_BINARY, python/test-service.py)
TEST_PATH(EXIT_BINARY, test-exit)
TEST_PATH(SEGFAULT_BINARY, test-segfault)
TEST_PATH(SLEEP_FOREVER_BINARY, test-sleep-forever)
@ -1377,51 +1006,6 @@ fi
AC_DEFINE_UNQUOTED(DBUS_SESSION_SOCKET_DIR, "$DBUS_SESSION_SOCKET_DIR", [Where per-session bus puts its sockets])
AC_SUBST(DBUS_SESSION_SOCKET_DIR)
# Detect if we can build Python bindings (need python, python headers, and pyrex)
if test x$enable_python = xno; then
have_python=no
else
have_python_version=2.4
AC_MSG_NOTICE([Checking to see if we can build Python bindings])
have_python=no
AM_PATH_PYTHON()
if test -z "$PYTHON" ; then
AC_MSG_WARN([Python not found])
else
AC_MSG_CHECKING([whether $PYTHON version >= $have_python_version])
AM_PYTHON_CHECK_VERSION([$PYTHON], [$have_python_version],
[have_python_version="yes"],
[have_python_version="too old"])
AC_MSG_RESULT($have_python_version)
AC_CHECK_PROGS(PYREX, pyrexc)
if test -z "$PYREX" ; then
have_pyrex=no
else
have_pyrex=yes
fi
AM_CHECK_PYTHON_HEADERS(have_python_headers=yes,have_python_headers=no)
if test x$have_pyrex = xyes -a x$have_python_headers = xyes -a "x$have_python_version" = xyes ; then
have_python=yes
fi
fi
if test x$have_python = xno ; then
if test x$enable_python = xyes ; then
AC_MSG_ERROR([Building python explicitly requested, but can't build python bindings because either Pyrex, Python headers or a suitable Python version was not found])
else
AC_MSG_WARN([Couldn't find either Pyrex, the Python headers or a suitable version of Python, not building Python bindings])
fi
fi
fi
AM_CONDITIONAL(HAVE_PYTHON, test x$have_python = xyes)
AC_OUTPUT([
Doxyfile
dbus/dbus-arch-deps.h
@ -1432,49 +1016,21 @@ bus/rc.messagebus
bus/dbus-daemon.1
Makefile
dbus/Makefile
glib/Makefile
glib/examples/Makefile
glib/examples/statemachine/Makefile
python/Makefile
python/examples/Makefile
qt/Makefile
qt/dbus/Makefile
qt/src/Makefile
qt/tools/Makefile
qt/examples/Makefile
qt3/Makefile
gcj/Makefile
gcj/org/Makefile
gcj/org/freedesktop/Makefile
gcj/org/freedesktop/dbus/Makefile
mono/Makefile
mono/AssemblyInfo.cs
mono/dbus-sharp.dll.config
mono/example/Makefile
mono/doc/Makefile
bus/Makefile
tools/Makefile
test/Makefile
test/glib/Makefile
test/python/Makefile
test/qt/Makefile
test/name-test/Makefile
doc/Makefile
dbus-1.pc
dbus-glib-1.pc
dbus-sharp.pc
dbus-qt4-1.pc
test/data/valid-config-files/debug-allow-all.conf
test/data/valid-config-files/debug-allow-all-sha1.conf
test/data/valid-service-files/debug-echo.service
test/data/valid-service-files/debug-segfault.service
test/data/valid-service-files/debug-glib.service
test/data/valid-service-files/debug-shell-echo-success.service
test/data/valid-service-files/debug-shell-echo-fail.service
test/data/valid-service-files/debug-python.service
])
### FIXME it's bizarre that have_qt and have_glib are used
### FIXME it's bizarre that have_qt
### instead of enable_ - should fix things so that enable
### is always whether it's enabled, and have is always whether
### it was found.
@ -1502,26 +1058,6 @@ echo "
Doxygen: ${DOXYGEN}
xmlto: ${XMLTO}"
if test x$enable_gcj = xyes ; then
echo \
" gcj: ${GCJ}
gcjflags: ${GCJFLAGS}
jar: ${JAR}"
else
echo \
" gcj: (not enabled)"
fi
if test x$enable_mono = xyes ; then
echo \
" csc: ${CSC}
"
else
echo \
" csc: (not enabled)
"
fi
echo "
Maintainer mode: ${USE_MAINTAINER_MODE}
gcc coverage profiling: ${enable_gcov}
@ -1529,14 +1065,8 @@ echo "
Building verbose mode: ${enable_verbose_mode}
Building assertions: ${enable_asserts}
Building checks: ${enable_checks}
Building Qt4 bindings: ${have_qt}
Building Qt3 bindings: ${have_qt3}
Building GLib bindings: ${have_glib}
Building Python bindings: ${have_python}
Building SELinux support: ${have_selinux}
Building dnotify support: ${have_dnotify}
Building Mono bindings: ${enable_mono}
Building Mono docs: ${enable_mono_docs}
Building GTK+ tools: ${have_gtk}
Building X11 code: ${enable_x11}
Building Doxygen docs: ${enable_doxygen_docs}

View file

@ -1,12 +0,0 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: dbus-glib
Description: GLib integration for the free desktop message bus
Version: @VERSION@
Requires: dbus-1 glib-2.0
Libs: -L${libdir} -ldbus-glib-1

View file

@ -1,20 +1,6 @@
INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) -DDBUS_COMPILATION
if HAVE_GLIB
DBUS_GLIB_BUILT_INCLUDES= \
dbus-glib-error-enum.h
GLIB_INCLUDES= \
dbus-glib.h \
dbus-glib-lowlevel.h \
$(DBUS_GLIB_BUILT_INCLUDES)
dbus-glib-error-enum.h: dbus-protocol.h make-dbus-glib-error-enum.sh
$(srcdir)/make-dbus-glib-error-enum.sh $(srcdir)/dbus-protocol.h $@
endif
dbusincludedir=$(includedir)/dbus-1.0/dbus
dbusarchincludedir=$(libdir)/dbus-1.0/include/dbus
@ -35,8 +21,7 @@ dbusinclude_HEADERS= \
dbus-shared.h \
dbus-signature.h \
dbus-threads.h \
dbus-types.h \
$(GLIB_INCLUDES)
dbus-types.h
dbusarchinclude_HEADERS= \
@ -158,9 +143,8 @@ libdbus_convenience_la_SOURCES= \
$(DBUS_UTIL_SOURCES)
BUILT_SOURCES=$(dbusarchinclude_HEADERS) $(DBUS_GLIB_BUILT_INCLUDES)
EXTRA_DIST=dbus-arch-deps.h.in make-dbus-glib-error-enum.sh
CLEANFILES=$(DBUS_GLIB_BUILT_INCLUDES)
BUILT_SOURCES=$(dbusarchinclude_HEADERS)
EXTRA_DIST=dbus-arch-deps.h.in
## this library is the same as libdbus, but exports all the symbols
## and is only used for static linking within the dbus package.

View file

@ -1,72 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-glib-lowlevel.h GLib integration details that require dbus/dbus.h
*
* Copyright (C) 2002, 2003 CodeFactory AB
* Copyright (C) 2003, 2004 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GLIB_LOWLEVEL_H
#define DBUS_GLIB_LOWLEVEL_H
#include <dbus/dbus-glib.h>
#include <dbus/dbus.h>
G_BEGIN_DECLS
void dbus_set_g_error (GError **gerror,
DBusError *derror);
#define DBUS_TYPE_CONNECTION (dbus_connection_get_g_type ())
#define DBUS_TYPE_MESSAGE (dbus_message_get_g_type ())
#define DBUS_TYPE_PENDING_CALL (dbus_pending_call_get_g_type ())
GType dbus_connection_get_g_type (void) G_GNUC_CONST;
GType dbus_message_get_g_type (void) G_GNUC_CONST;
GType dbus_pending_call_get_g_type (void) G_GNUC_CONST;
void dbus_connection_setup_with_g_main (DBusConnection *connection,
GMainContext *context);
void dbus_server_setup_with_g_main (DBusServer *server,
GMainContext *context);
void dbus_g_proxy_send (DBusGProxy *proxy,
DBusMessage *message,
dbus_uint32_t *client_serial);
DBusConnection* dbus_g_connection_get_connection (DBusGConnection *gconnection);
DBusMessage* dbus_g_message_get_message (DBusGMessage *gmessage);
/* dbus_g_pending_call_get_pending_call() deliberately skipped for now;
* not sure it makes sense to use any of the DBusPendingCall functions
* on the wrapped pending call (once we have the right exported
* g-functions anyhow)
*/
gchar* dbus_g_method_get_sender (DBusGMethodInvocation *context);
DBusMessage* dbus_g_method_get_reply (DBusGMethodInvocation *context);
void dbus_g_method_send_reply (DBusGMethodInvocation *context,
DBusMessage *reply);
G_END_DECLS
#endif /* DBUS_GLIB_LOWLEVEL_H */

View file

@ -1,256 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-glib.h GLib integration
*
* Copyright (C) 2002, 2003 CodeFactory AB
* Copyright (C) 2003, 2004 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GLIB_H
#define DBUS_GLIB_H
#include <glib-object.h>
#include <dbus/dbus-shared.h>
G_BEGIN_DECLS
#define DBUS_INSIDE_DBUS_GLIB_H 1
/**
* Convert to DBusConnection with dbus_g_connection_get_connection() in dbus-glib-lowlevel.h
*/
typedef struct _DBusGConnection DBusGConnection;
/**
* Convert to DBusMessage with dbus_g_message_get_message() in dbus-glib-lowlevel.h
*/
typedef struct _DBusGMessage DBusGMessage;
#define DBUS_TYPE_G_CONNECTION (dbus_g_connection_get_g_type ())
#define DBUS_TYPE_G_MESSAGE (dbus_g_message_get_g_type ())
GType dbus_g_connection_get_g_type (void) G_GNUC_CONST;
GType dbus_g_message_get_g_type (void) G_GNUC_CONST;
DBusGConnection* dbus_g_connection_ref (DBusGConnection *connection);
void dbus_g_connection_unref (DBusGConnection *connection);
DBusGMessage* dbus_g_message_ref (DBusGMessage *message);
void dbus_g_message_unref (DBusGMessage *message);
void dbus_g_connection_flush (DBusGConnection *connection);
GQuark dbus_g_error_quark (void);
#define DBUS_GERROR dbus_g_error_quark ()
typedef enum
{
#include <dbus/dbus-glib-error-enum.h>
} DBusGError;
gboolean dbus_g_error_has_name (GError *error,
const char *name);
const char * dbus_g_error_get_name (GError *error);
void dbus_g_thread_init (void);
DBusGConnection* dbus_g_connection_open (const gchar *address,
GError **error);
DBusGConnection* dbus_g_bus_get (DBusBusType type,
GError **error);
typedef struct _DBusGObjectInfo DBusGObjectInfo;
typedef struct _DBusGMethodInfo DBusGMethodInfo;
/**
* Object typically generated by dbus-binding-tool that
* stores a mapping from introspection data to a
* function pointer for a C method to be invoked.
*/
struct _DBusGMethodInfo
{
GCallback function; /**< C method to invoke */
GClosureMarshal marshaller; /**< Marshaller to invoke method */
int data_offset; /**< Offset into the introspection data */
};
/**
* Introspection data for a GObject, normally autogenerated by
* a tool such as dbus-binding-tool.
*/
struct _DBusGObjectInfo
{
int format_version; /**< Allows us to change the rest of this struct
* by adding DBusGObjectInfo2, DBusGObjectInfo3, etc.
*/
const DBusGMethodInfo *method_infos; /**< Array of method pointers */
int n_method_infos; /**< Length of the infos array */
const char *data; /**< Introspection data */
const char *exported_signals; /**< Exported signals */
const char *exported_properties; /**< Exported properties */
};
void dbus_g_object_type_install_info (GType object_type,
const DBusGObjectInfo *info);
void dbus_g_error_domain_register (GQuark domain,
const char * default_iface,
GType code_enum);
void dbus_g_connection_register_g_object (DBusGConnection *connection,
const char *at_path,
GObject *object);
GObject * dbus_g_connection_lookup_g_object (DBusGConnection *connection,
const char *at_path);
#ifdef DBUS_COMPILATION
#include "glib/dbus-gtype-specialized.h"
#else
#include <dbus/dbus-gtype-specialized.h>
#endif
/* definitions for some basic array types */
#define DBUS_TYPE_G_BOOLEAN_ARRAY (dbus_g_type_get_collection ("GArray", G_TYPE_BOOLEAN))
#define DBUS_TYPE_G_UCHAR_ARRAY (dbus_g_type_get_collection ("GArray", G_TYPE_UCHAR))
#define DBUS_TYPE_G_UINT_ARRAY (dbus_g_type_get_collection ("GArray", G_TYPE_UINT))
#define DBUS_TYPE_G_INT_ARRAY (dbus_g_type_get_collection ("GArray", G_TYPE_INT))
#define DBUS_TYPE_G_UINT64_ARRAY (dbus_g_type_get_collection ("GArray", G_TYPE_UINT64))
#define DBUS_TYPE_G_INT64_ARRAY (dbus_g_type_get_collection ("GArray", G_TYPE_INT64))
#define DBUS_TYPE_G_OBJECT_ARRAY (dbus_g_type_get_collection ("GPtrArray", G_TYPE_OBJECT))
#define DBUS_TYPE_G_STRING_STRING_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
GType dbus_g_object_path_get_g_type (void) G_GNUC_CONST;
#define DBUS_TYPE_G_OBJECT_PATH (dbus_g_object_path_get_g_type ())
void dbus_g_object_register_marshaller (GClosureMarshal marshaller,
GType rettype,
...);
void dbus_g_object_register_marshaller_array(GClosureMarshal marshaller,
GType rettype,
guint n_types,
const GType* types);
typedef struct _DBusGProxy DBusGProxy;
typedef struct _DBusGProxyClass DBusGProxyClass;
#define DBUS_TYPE_G_PROXY (dbus_g_proxy_get_type ())
#define DBUS_G_PROXY(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), DBUS_TYPE_G_PROXY, DBusGProxy))
#define DBUS_G_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUS_TYPE_G_PROXY, DBusGProxyClass))
#define DBUS_IS_G_PROXY(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), DBUS_TYPE_G_PROXY))
#define DBUS_IS_G_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUS_TYPE_G_PROXY))
#define DBUS_G_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUS_TYPE_G_PROXY, DBusGProxyClass))
struct _DBusGProxy
{
GObject parent;
};
struct _DBusGProxyClass
{
GObjectClass parent_class; /**< Parent class */
};
typedef struct _DBusGProxyCall DBusGProxyCall;
typedef void (* DBusGProxyCallNotify) (DBusGProxy *proxy,
DBusGProxyCall *call_id,
void *user_data);
GType dbus_g_proxy_get_type (void) G_GNUC_CONST;
DBusGProxy* dbus_g_proxy_new_for_name (DBusGConnection *connection,
const char *name,
const char *path,
const char *interface);
DBusGProxy* dbus_g_proxy_new_for_name_owner (DBusGConnection *connection,
const char *name,
const char *path,
const char *interface,
GError **error);
DBusGProxy* dbus_g_proxy_new_from_proxy (DBusGProxy *proxy,
const char *interface,
const char *path_name);
DBusGProxy* dbus_g_proxy_new_for_peer (DBusGConnection *connection,
const char *path_name,
const char *interface_name);
void dbus_g_proxy_set_interface (DBusGProxy *proxy,
const char *interface_name);
void dbus_g_proxy_add_signal (DBusGProxy *proxy,
const char *signal_name,
GType first_type,
...);
void dbus_g_proxy_connect_signal (DBusGProxy *proxy,
const char *signal_name,
GCallback handler,
void *data,
GClosureNotify free_data_func);
void dbus_g_proxy_disconnect_signal (DBusGProxy *proxy,
const char *signal_name,
GCallback handler,
void *data);
gboolean dbus_g_proxy_call (DBusGProxy *proxy,
const char *method,
GError **error,
GType first_arg_type,
...);
void dbus_g_proxy_call_no_reply (DBusGProxy *proxy,
const char *method,
GType first_arg_type,
...);
DBusGProxyCall * dbus_g_proxy_begin_call (DBusGProxy *proxy,
const char *method,
DBusGProxyCallNotify notify,
gpointer data,
GDestroyNotify destroy,
GType first_arg_type,
...);
gboolean dbus_g_proxy_end_call (DBusGProxy *proxy,
DBusGProxyCall *call,
GError **error,
GType first_arg_type,
...);
void dbus_g_proxy_cancel_call (DBusGProxy *proxy,
DBusGProxyCall *call);
const char* dbus_g_proxy_get_path (DBusGProxy *proxy);
const char* dbus_g_proxy_get_bus_name (DBusGProxy *proxy);
const char* dbus_g_proxy_get_interface (DBusGProxy *proxy);
typedef struct _DBusGMethodInvocation DBusGMethodInvocation;
void dbus_g_method_return (DBusGMethodInvocation *context, ...);
void dbus_g_method_return_error (DBusGMethodInvocation *context, GError *error);
/* Probably possible to replace this with a closure */
typedef struct {
GCallback cb;
gpointer userdata;
} DBusGAsyncData;
#undef DBUS_INSIDE_DBUS_GLIB_H
G_END_DECLS
#endif /* DBUS_GLIB_H */

View file

@ -1,25 +0,0 @@
#!/bin/sh
SRC=$1
DEST=$2
die()
{
echo $1 1>&2
/bin/rm $DEST.tmp
exit 1
}
cat $SRC | grep '#define DBUS_ERROR' | sed -e 's/#define //g' | \
sed -e 's/".*//g' | sed -e 's/DBUS_ERROR/DBUS_GERROR/g' | sed -e 's/ *$/,/g' > $DEST.tmp
if ! test -s $DEST.tmp ; then
die "$DEST.tmp is empty, something went wrong, see any preceding error message"
fi
echo "DBUS_GERROR_REMOTE_EXCEPTION" >> $DEST.tmp
echo "#ifndef DBUS_INSIDE_DBUS_GLIB_H" >> $DEST.tmp
echo '#error "' "$DEST" 'may only be included by dbus-glib.h"' >> $DEST.tmp
echo "#endif" >> $DEST.tmp
mv $DEST.tmp $DEST || die "could not move $DEST.tmp to $DEST"

View file

@ -1,6 +0,0 @@
.deps
.libs
Makefile
Makefile.in
dbus-1.jar
test-message

View file

@ -1,18 +0,0 @@
SUBDIRS=org
CLEANFILES=dbus-1.jar
dbus-1.jar:
-@rm -f dbus-1.jar
find org -type d -o -type f -name '*.class' | \
sed -e '/\/\./d' | \
$(JAR) cfM0E@ $@
jardir = $(datadir)/java
jar_DATA = dbus-1.jar
noinst_PROGRAMS = test-message
test_message_SOURCES = TestMessage.java
test_message_LDFLAGS = --main=TestMessage
test_message_LDADD = $(top_builddir)/gcj/org/freedesktop/dbus/libdbus-gcj-1.la

View file

@ -1,8 +0,0 @@
import org.freedesktop.dbus.Message;
public class TestMessage {
public static void main (String[] args) {
Message msg = new Message ("test", "bla");
}
}

View file

@ -1,3 +0,0 @@
Makefile
Makefile.in

View file

@ -1 +0,0 @@
SUBDIRS=freedesktop

View file

@ -1,2 +0,0 @@
Makefile
Makefile.in

View file

@ -1 +0,0 @@
SUBDIRS=dbus

View file

@ -1,9 +0,0 @@
Makefile
Makefile.in
.deps
.libs
*.la
*.class
*.lo
*.h

View file

@ -1,57 +0,0 @@
INCLUDES= \
-I$(top_srcdir) \
-I$(top_builddir)/gcj/org/freedesktop/dbus \
$(DBUS_CLIENT_CFLAGS)
GCJH = gcjh
lib_LTLIBRARIES = libdbus-gcj-1.la
MOSTLYCLEANFILES = $(generated_headers) $(java_class_files)
java_sources = \
Message.java
native_sources = \
natMessage.cc
generated_headers = $(java_sources:.java=.h)
java_class_files = $(java_sources:.java=.class)
native_object_files = $(native_sources:.cc=.lo)
java_object_files = $(java_sources:.java=.lo)
.class.h:
$(GCJH) $(basename $<)
.java.class:
$(GCJ) -C $< -d ../../..
.cc.lo:
$(LIBTOOL) --mode=compile $(CXX) $(INCLUDES) $(CXXFLAGS) $(CPPFLAGS) -c -o '$@' '$<'
.java.lo:
$(LIBTOOL) --mode=compile $(GCJ) $(INCLUDES) $(GCJ_FLAGS) -c -o '$@' '$<'
libdbus_gcj_1_la_SOURCES =
libdbus_gcj_1_la_DEPENDENCIES = \
$(generated_headers) \
$(native_object_files) \
$(java_object_files) \
$(java_class_files)
libdbus_gcj_1_la_LDFLAGS = -no-undefined
libdbus_gcj_1_la_LIBADD = \
$(native_object_files) \
$(java_object_files)
EXTRA_libdbus_gcj_1_la_SOURCES = \
$(native_sources) \
$(java_sources)
libdbus_gcj_1_la_LINK = $(LIBTOOL) --tag=GCJ --mode=link $(GCJ) -L$(here) $(JC1FLAGS) $(LDFLAGS) -o $@

View file

@ -1,13 +0,0 @@
package org.freedesktop.dbus;
import gnu.gcj.RawData;
public class Message {
private RawData message;
public Message (String name, String destService) {
this.message = dbus_message_new (name, destService);
}
private static native RawData dbus_message_new (String name, String destService);
}

View file

@ -1,20 +0,0 @@
// This file was created by `gcjh -stubs'. -*- c++ -*-
//
// This file is intended to give you a head start on implementing native
// methods using CNI.
// Be aware: running `gcjh -stubs ' once more for this class may
// overwrite any edits you have made to this file.
#include <Message.h>
#include <gcj/cni.h>
#include <java/lang/UnsupportedOperationException.h>
#include <dbus/dbus.h>
::gnu::gcj::RawData *
org::freedesktop::dbus::Message::dbus_message_new (::java::lang::String *, ::java::lang::String *)
{
throw new ::java::lang::UnsupportedOperationException (JvNewStringLatin1 ("org::freedesktop::dbus::Message::dbus_message_new (::java::lang::String *, ::java::lang::String *) not implemented"));
}

View file

@ -1,105 +0,0 @@
SUBDIRS = . examples
INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) $(DBUS_GLIB_TOOL_CFLAGS) -DDBUS_COMPILATION=1 -DDBUS_LOCALEDIR=\"$(prefix)/@DATADIRNAME@/locale\"
lib_LTLIBRARIES=libdbus-glib-1.la
dbus-glib-error-switch.h: $(top_srcdir)/dbus/dbus-protocol.h make-dbus-glib-error-switch.sh
$(LIBTOOL) --mode=execute $(srcdir)/make-dbus-glib-error-switch.sh $(top_srcdir)/dbus/dbus-protocol.h $@
BUILT_SOURCES = dbus-glib-error-switch.h
CLEANFILES = $(BUILT_SOURCES)
DBUS_GLIB_INTERNALS = \
dbus-gtype-specialized.c \
dbus-gutils.c \
dbus-gutils.h \
dbus-gsignature.c \
dbus-gsignature.h \
dbus-gvalue.h \
dbus-gvalue-utils.c \
dbus-gvalue-utils.h
libdbus_glib_1_la_SOURCES = \
dbus-glib-error-switch.h \
dbus-glib.c \
dbus-gmain.c \
dbus-gmarshal.c \
dbus-gmarshal.h \
dbus-gobject.c \
dbus-gobject.h \
dbus-gproxy.c \
dbus-gtest.c \
dbus-gtest.h \
dbus-gvalue.c \
dbus-gvalue.h \
dbus-gthread.c \
$(DBUS_GLIB_INTERNALS)
libdbus_glib_HEADERS = \
dbus-gtype-specialized.h
libdbus_glibdir = $(includedir)/dbus-1.0/dbus
libdbus_glib_1_la_LIBADD= $(top_builddir)/dbus/libdbus-1.la $(DBUS_GLIB_LIBS)
## don't export symbols that start with "_" (we use this
## convention for internal symbols)
libdbus_glib_1_la_LDFLAGS= -export-symbols-regex "^[^_].*" -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -no-undefined
# convenience lib used here and by dbus-viewer
noinst_LTLIBRARIES=libdbus-gtool.la
libdbus_gtool_la_SOURCES = $(DBUS_GLIB_INTERNALS) \
dbus-gidl.c \
dbus-gidl.h \
dbus-gloader-expat.c \
dbus-gparser.c \
dbus-gparser.h
libdbus_gtool_la_LIBADD = libdbus-glib-1.la
bin_PROGRAMS=dbus-binding-tool
dbus_binding_tool_SOURCES = \
dbus-binding-tool-glib.h \
dbus-binding-tool-glib.c \
dbus-glib-tool.h \
dbus-glib-tool.c
dbus_binding_tool_LDADD= libdbus-gtool.la $(DBUS_GLIB_LIBS) -lexpat
## we just rebuilt these manually and check them into cvs; easier than
## convincing automake/make to do this properly
regenerate-built-sources:
@GLIB_GENMARSHAL@ --prefix=_dbus_g_marshal dbus-gmarshal.list --header > dbus-gmarshal.h && \
echo '#include "dbus-gmarshal.h"' > dbus-gmarshal.c && \
@GLIB_GENMARSHAL@ --prefix=_dbus_g_marshal dbus-gmarshal.list --body >> dbus-gmarshal.c
EXTRA_DIST=dbus-gmarshal.list make-dbus-glib-error-switch.sh
if DBUS_BUILD_TESTS
## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we
## build even when not doing "make check"
noinst_PROGRAMS= $(TESTS)
## note that TESTS has special meaning (stuff to use in make check)
## so if adding tests not to be run in make check, don't add them to
## TESTS
TESTS_ENVIRONMENT=DBUS_TEST_DATA=$(top_builddir)/test/data DBUS_TEST_HOMEDIR=$(top_builddir)/dbus
TESTS=dbus-glib-test
## FIXME we aren't running dbus-glib-tool --self-test
dbus_glib_test_SOURCES= \
dbus-gtest-main.c
dbus_glib_test_LDADD= $(top_builddir)/glib/libdbus-glib-1.la
else
### not building tests
TESTS=
endif

File diff suppressed because it is too large Load diff

View file

@ -1,40 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-binding-tool-output-glib.h prototypes for glib output
*
* Copyright (C) 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it bwill be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_BINDING_TOOL_OUTPUT_GLIB_H
#define DBUS_BINDING_TOOL_OUTPUT_GLIB_H
G_BEGIN_DECLS
#define DBUS_GLIB_ANNOTATION_C_SYMBOL "org.freedesktop.DBus.GLib.CSymbol"
#define DBUS_GLIB_ANNOTATION_CLIENT_C_SYMBOL "org.freedesktop.DBus.GLib.ClientCSymbol"
#define DBUS_GLIB_ANNOTATION_ASYNC "org.freedesktop.DBus.GLib.Async"
#define DBUS_GLIB_ANNOTATION_CONST "org.freedesktop.DBus.GLib.Const"
#define DBUS_GLIB_ANNOTATION_RETURNVAL "org.freedesktop.DBus.GLib.ReturnVal"
#define DBUS_GLIB_ANNOTATION_NOREPLY "org.freedesktop.DBus.Method.NoReply"
gboolean dbus_binding_tool_output_glib_client (BaseInfo *info, GIOChannel *channel, gboolean ignore_unsupported, GError **error);
gboolean dbus_binding_tool_output_glib_server (BaseInfo *info, GIOChannel *channel, const char *prefix, GError **error);
G_END_DECLS
#endif

View file

@ -1,788 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gidl.c data structure describing an interface, to be generated from IDL
* or something
*
* Copyright (C) 2003, 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "dbus-gidl.h"
#ifndef DOXYGEN_SHOULD_SKIP_THIS
struct BaseInfo
{
unsigned int refcount : 28;
unsigned int type : 4;
char *name;
};
struct NodeInfo
{
BaseInfo base;
GSList *interfaces;
GSList *nodes;
};
struct InterfaceInfo
{
BaseInfo base;
GHashTable *annotations;
/* Since we have BaseInfo now these could be one list */
GSList *methods;
GSList *signals;
GSList *properties;
};
struct MethodInfo
{
BaseInfo base;
GHashTable *annotations;
GSList *args;
};
struct SignalInfo
{
BaseInfo base;
GSList *args;
};
struct PropertyInfo
{
BaseInfo base;
char *type;
PropertyAccessFlags access;
};
struct ArgInfo
{
BaseInfo base;
char *type;
ArgDirection direction;
GHashTable *annotations;
};
static void
get_hash_key (gpointer key, gpointer value, gpointer data)
{
GSList **list = data;
*list = g_slist_prepend (*list, key);
}
static GSList *
get_hash_keys (GHashTable *table)
{
GSList *ret = NULL;
g_hash_table_foreach (table, get_hash_key, &ret);
return ret;
}
BaseInfo *
base_info_ref (BaseInfo *info)
{
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (info->refcount > 0, NULL);
info->refcount += 1;
return info;
}
static void
base_info_free (void *ptr)
{
BaseInfo *info;
info = ptr;
g_free (info->name);
g_free (info);
}
void
base_info_unref (BaseInfo *info)
{
g_return_if_fail (info != NULL);
g_return_if_fail (info->refcount > 0);
/* This is sort of bizarre, BaseInfo was tacked on later */
switch (info->type)
{
case INFO_TYPE_NODE:
node_info_unref ((NodeInfo*) info);
break;
case INFO_TYPE_INTERFACE:
interface_info_unref ((InterfaceInfo*) info);
break;
case INFO_TYPE_SIGNAL:
signal_info_unref ((SignalInfo*) info);
break;
case INFO_TYPE_METHOD:
method_info_unref ((MethodInfo*) info);
break;
case INFO_TYPE_PROPERTY:
property_info_unref ((PropertyInfo*) info);
break;
case INFO_TYPE_ARG:
arg_info_unref ((ArgInfo*) info);
break;
}
}
InfoType
base_info_get_type (BaseInfo *info)
{
return info->type;
}
const char*
base_info_get_name (BaseInfo *info)
{
return info->name;
}
void
base_info_set_name (BaseInfo *info,
const char *name)
{
char *old;
old = info->name;
info->name = g_strdup (name);
g_free (old);
}
GType
base_info_get_gtype (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static ("BaseInfo",
(GBoxedCopyFunc) base_info_ref,
(GBoxedFreeFunc) base_info_unref);
return our_type;
}
static void
free_interface_list (GSList **interfaces_p)
{
GSList *tmp;
tmp = *interfaces_p;
while (tmp != NULL)
{
interface_info_unref (tmp->data);
tmp = tmp->next;
}
g_slist_free (*interfaces_p);
*interfaces_p = NULL;
}
static void
free_node_list (GSList **nodes_p)
{
GSList *tmp;
tmp = *nodes_p;
while (tmp != NULL)
{
node_info_unref (tmp->data);
tmp = tmp->next;
}
g_slist_free (*nodes_p);
*nodes_p = NULL;
}
static void
free_method_list (GSList **methods_p)
{
GSList *tmp;
tmp = *methods_p;
while (tmp != NULL)
{
method_info_unref (tmp->data);
tmp = tmp->next;
}
g_slist_free (*methods_p);
*methods_p = NULL;
}
static void
free_signal_list (GSList **signals_p)
{
GSList *tmp;
tmp = *signals_p;
while (tmp != NULL)
{
signal_info_unref (tmp->data);
tmp = tmp->next;
}
g_slist_free (*signals_p);
*signals_p = NULL;
}
static void
free_property_list (GSList **props_p)
{
GSList *tmp;
tmp = *props_p;
while (tmp != NULL)
{
property_info_unref (tmp->data);
tmp = tmp->next;
}
g_slist_free (*props_p);
*props_p = NULL;
}
NodeInfo*
node_info_new (const char *name)
{
NodeInfo *info;
/* name can be NULL */
info = g_new0 (NodeInfo, 1);
info->base.refcount = 1;
info->base.name = g_strdup (name);
info->base.type = INFO_TYPE_NODE;
return info;
}
NodeInfo *
node_info_ref (NodeInfo *info)
{
info->base.refcount += 1;
return info;
}
void
node_info_unref (NodeInfo *info)
{
info->base.refcount -= 1;
if (info->base.refcount == 0)
{
free_interface_list (&info->interfaces);
free_node_list (&info->nodes);
base_info_free (info);
}
}
const char*
node_info_get_name (NodeInfo *info)
{
return info->base.name;
}
GSList*
node_info_get_interfaces (NodeInfo *info)
{
return info->interfaces;
}
void
node_info_add_interface (NodeInfo *info,
InterfaceInfo *interface)
{
interface_info_ref (interface);
info->interfaces = g_slist_append (info->interfaces, interface);
}
GSList*
node_info_get_nodes (NodeInfo *info)
{
return info->nodes;
}
void
node_info_add_node (NodeInfo *info,
NodeInfo *node)
{
node_info_ref (node);
info->nodes = g_slist_append (info->nodes, node);
}
void
node_info_replace_node (NodeInfo *info,
NodeInfo *old_child,
NodeInfo *new_child)
{
GSList *link;
node_info_ref (new_child); /* before unref old_child in case they are the same */
link = g_slist_find (info->nodes, old_child);
g_assert (link != NULL);
node_info_unref (old_child);
link->data = new_child;
}
InterfaceInfo*
interface_info_new (const char *name)
{
InterfaceInfo *info;
info = g_new0 (InterfaceInfo, 1);
info->base.refcount = 1;
info->base.name = g_strdup (name);
info->base.type = INFO_TYPE_INTERFACE;
info->annotations = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
return info;
}
InterfaceInfo *
interface_info_ref (InterfaceInfo *info)
{
info->base.refcount += 1;
return info;
}
void
interface_info_unref (InterfaceInfo *info)
{
info->base.refcount -= 1;
if (info->base.refcount == 0)
{
g_hash_table_destroy (info->annotations);
free_method_list (&info->methods);
free_signal_list (&info->signals);
free_property_list (&info->properties);
base_info_free (info);
}
}
const char*
interface_info_get_name (InterfaceInfo *info)
{
return info->base.name;
}
GSList *
interface_info_get_annotations (InterfaceInfo *info)
{
return get_hash_keys (info->annotations);
}
const char*
interface_info_get_annotation (InterfaceInfo *info,
const char *name)
{
return g_hash_table_lookup (info->annotations, name);
}
GSList*
interface_info_get_methods (InterfaceInfo *info)
{
return info->methods;
}
GSList*
interface_info_get_signals (InterfaceInfo *info)
{
return info->signals;
}
GSList*
interface_info_get_properties (InterfaceInfo *info)
{
return info->properties;
}
void
interface_info_add_annotation (InterfaceInfo *info,
const char *name,
const char *value)
{
g_hash_table_insert (info->annotations,
g_strdup (name),
g_strdup (value));
}
void
interface_info_add_method (InterfaceInfo *info,
MethodInfo *method)
{
method_info_ref (method);
info->methods = g_slist_append (info->methods, method);
}
void
interface_info_add_signal (InterfaceInfo *info,
SignalInfo *signal)
{
signal_info_ref (signal);
info->signals = g_slist_append (info->signals, signal);
}
void
interface_info_add_property (InterfaceInfo *info,
PropertyInfo *property)
{
property_info_ref (property);
info->properties = g_slist_append (info->properties, property);
}
static void
free_arg_list (GSList **args_p)
{
GSList *tmp;
tmp = *args_p;
while (tmp != NULL)
{
ArgInfo *ai = tmp->data;
g_assert (ai->base.type == INFO_TYPE_ARG);
arg_info_unref (tmp->data);
tmp = tmp->next;
}
g_slist_free (*args_p);
*args_p = NULL;
}
MethodInfo*
method_info_new (const char *name)
{
MethodInfo *info;
info = g_new0 (MethodInfo, 1);
info->base.refcount = 1;
info->base.name = g_strdup (name);
info->base.type = INFO_TYPE_METHOD;
info->annotations = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
return info;
}
MethodInfo *
method_info_ref (MethodInfo *info)
{
info->base.refcount += 1;
return info;
}
void
method_info_unref (MethodInfo *info)
{
info->base.refcount -= 1;
if (info->base.refcount == 0)
{
g_hash_table_destroy (info->annotations);
free_arg_list (&info->args);
base_info_free (info);
}
}
const char*
method_info_get_name (MethodInfo *info)
{
return info->base.name;
}
GSList *
method_info_get_annotations (MethodInfo *info)
{
return get_hash_keys (info->annotations);
}
const char*
method_info_get_annotation (MethodInfo *info,
const char *name)
{
return g_hash_table_lookup (info->annotations, name);
}
GSList*
method_info_get_args (MethodInfo *info)
{
return info->args;
}
int
method_info_get_n_args (MethodInfo *info)
{
return g_slist_length (info->args);
}
static int
args_sort_by_direction (const void *a,
const void *b)
{
const ArgInfo *arg_a = a;
const ArgInfo *arg_b = b;
if (arg_a->direction == arg_b->direction)
return 0;
else if (arg_a->direction == ARG_IN)
return -1; /* in is less than out */
else
return 1;
}
void
method_info_add_annotation (MethodInfo *info,
const char *name,
const char *value)
{
g_hash_table_insert (info->annotations,
g_strdup (name),
g_strdup (value));
}
void
method_info_add_arg (MethodInfo *info,
ArgInfo *arg)
{
arg_info_ref (arg);
info->args = g_slist_append (info->args, arg);
/* Keep "in" args sorted before "out" and otherwise maintain
* stable order (g_slist_sort is stable, at least in sufficiently
* new glib)
*/
info->args = g_slist_sort (info->args, args_sort_by_direction);
}
SignalInfo*
signal_info_new (const char *name)
{
SignalInfo *info;
info = g_new0 (SignalInfo, 1);
info->base.refcount = 1;
info->base.name = g_strdup (name);
info->base.type = INFO_TYPE_SIGNAL;
return info;
}
SignalInfo *
signal_info_ref (SignalInfo *info)
{
info->base.refcount += 1;
return info;
}
void
signal_info_unref (SignalInfo *info)
{
info->base.refcount -= 1;
if (info->base.refcount == 0)
{
free_arg_list (&info->args);
base_info_free (info);
}
}
const char*
signal_info_get_name (SignalInfo *info)
{
return info->base.name;
}
GSList*
signal_info_get_args (SignalInfo *info)
{
return info->args;
}
int
signal_info_get_n_args (SignalInfo *info)
{
return g_slist_length (info->args);
}
void
signal_info_add_arg (SignalInfo *info,
ArgInfo *arg)
{
g_assert (arg->direction == ARG_OUT);
arg_info_ref (arg);
info->args = g_slist_append (info->args, arg);
/* signal args don't need sorting since only "out" is allowed */
}
PropertyInfo*
property_info_new (const char *name,
const char *type,
PropertyAccessFlags access)
{
PropertyInfo *info;
info = g_new0 (PropertyInfo, 1);
info->base.refcount = 1;
info->base.name = g_strdup (name);
info->base.type = INFO_TYPE_PROPERTY;
info->type = g_strdup (type);
info->access = access;
return info;
}
PropertyInfo*
property_info_ref (PropertyInfo *info)
{
info->base.refcount += 1;
return info;
}
void
property_info_unref (PropertyInfo *info)
{
info->base.refcount -= 1;
if (info->base.refcount == 0)
{
g_free (info->type);
base_info_free (info);
}
}
const char*
property_info_get_name (PropertyInfo *info)
{
return info->base.name;
}
const char *
property_info_get_type (PropertyInfo *info)
{
return info->type;
}
PropertyAccessFlags
property_info_get_access (PropertyInfo *info)
{
return info->access;
}
ArgInfo*
arg_info_new (const char *name,
ArgDirection direction,
const char *type)
{
ArgInfo *info;
info = g_new0 (ArgInfo, 1);
info->base.refcount = 1;
info->base.type = INFO_TYPE_ARG;
/* name can be NULL */
info->base.name = g_strdup (name);
info->direction = direction;
info->type = g_strdup (type);
info->annotations = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
return info;
}
ArgInfo *
arg_info_ref (ArgInfo *info)
{
info->base.refcount += 1;
return info;
}
void
arg_info_unref (ArgInfo *info)
{
info->base.refcount -= 1;
if (info->base.refcount == 0)
{
g_hash_table_destroy (info->annotations);
g_free (info->type);
base_info_free (info);
}
}
const char*
arg_info_get_name (ArgInfo *info)
{
return info->base.name;
}
const char *
arg_info_get_type (ArgInfo *info)
{
return info->type;
}
ArgDirection
arg_info_get_direction (ArgInfo *info)
{
return info->direction;
}
GSList*
arg_info_get_annotations (ArgInfo *info)
{
return get_hash_keys (info->annotations);
}
const char*
arg_info_get_annotation (ArgInfo *info,
const char *annotation)
{
return g_hash_table_lookup (info->annotations, annotation);
}
void
arg_info_add_annotation (ArgInfo *info,
const char *name,
const char *value)
{
g_hash_table_insert (info->annotations,
g_strdup (name),
g_strdup (value));
}
#ifdef DBUS_BUILD_TESTS
/**
* @ingroup DBusGIDL
* Unit test for GLib IDL internals
* @returns #TRUE on success.
*/
gboolean
_dbus_gidl_test (void)
{
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

View file

@ -1,158 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gidl.h data structure describing an interface, to be generated from IDL
* or something
*
* Copyright (C) 2003 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GLIB_IDL_H
#define DBUS_GLIB_IDL_H
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#include <dbus/dbus.h>
#include <glib-object.h>
G_BEGIN_DECLS
typedef struct BaseInfo BaseInfo;
typedef struct NodeInfo NodeInfo;
typedef struct InterfaceInfo InterfaceInfo;
typedef struct MethodInfo MethodInfo;
typedef struct SignalInfo SignalInfo;
typedef struct PropertyInfo PropertyInfo;
typedef struct ArgInfo ArgInfo;
typedef enum
{
ARG_INVALID = -1,
ARG_IN,
ARG_OUT
} ArgDirection;
typedef enum
{
PROPERTY_READ = 1 << 0,
PROPERTY_WRITE = 1 << 1
} PropertyAccessFlags;
typedef enum
{
INFO_TYPE_NODE,
INFO_TYPE_INTERFACE,
INFO_TYPE_METHOD,
INFO_TYPE_SIGNAL,
INFO_TYPE_ARG,
INFO_TYPE_PROPERTY
} InfoType;
BaseInfo* base_info_ref (BaseInfo *info);
void base_info_unref (BaseInfo *info);
InfoType base_info_get_type (BaseInfo *info);
const char* base_info_get_name (BaseInfo *info);
void base_info_set_name (BaseInfo *info,
const char *name);
GType base_info_get_gtype (void);
#define BASE_INFO_TYPE (base_info_get_gtype ())
NodeInfo* node_info_new (const char *name);
NodeInfo* node_info_ref (NodeInfo *info);
void node_info_unref (NodeInfo *info);
const char* node_info_get_name (NodeInfo *info);
GSList* node_info_get_interfaces (NodeInfo *info);
GSList* node_info_get_nodes (NodeInfo *info);
void node_info_add_interface (NodeInfo *info,
InterfaceInfo *interface);
void node_info_add_node (NodeInfo *info,
NodeInfo *child);
void node_info_replace_node (NodeInfo *info,
NodeInfo *old_child,
NodeInfo *new_child);
InterfaceInfo* interface_info_new (const char *name);
InterfaceInfo* interface_info_ref (InterfaceInfo *info);
void interface_info_unref (InterfaceInfo *info);
const char* interface_info_get_name (InterfaceInfo *info);
GSList* interface_info_get_annotations(InterfaceInfo *info);
const char* interface_info_get_annotation (InterfaceInfo*info,
const char *annotation);
GSList* interface_info_get_methods (InterfaceInfo *info);
GSList* interface_info_get_signals (InterfaceInfo *info);
GSList* interface_info_get_properties (InterfaceInfo *info);
void interface_info_add_annotation (InterfaceInfo *info,
const char *name,
const char *value);
void interface_info_add_method (InterfaceInfo *info,
MethodInfo *method);
void interface_info_add_signal (InterfaceInfo *info,
SignalInfo *signal);
void interface_info_add_property (InterfaceInfo *info,
PropertyInfo *property);
MethodInfo* method_info_new (const char *name);
MethodInfo* method_info_ref (MethodInfo *info);
void method_info_unref (MethodInfo *info);
const char* method_info_get_name (MethodInfo *info);
GSList* method_info_get_annotations (MethodInfo *info);
const char* method_info_get_annotation (MethodInfo *info,
const char *annotation);
void method_info_add_annotation (MethodInfo *info,
const char *name,
const char *value);
GSList* method_info_get_args (MethodInfo *info);
void method_info_add_arg (MethodInfo *info,
ArgInfo *arg);
int method_info_get_n_args (MethodInfo *info);
SignalInfo* signal_info_new (const char *name);
SignalInfo* signal_info_ref (SignalInfo *info);
void signal_info_unref (SignalInfo *info);
const char* signal_info_get_name (SignalInfo *info);
GSList* signal_info_get_args (SignalInfo *info);
void signal_info_add_arg (SignalInfo *info,
ArgInfo *arg);
int signal_info_get_n_args (SignalInfo *info);
PropertyInfo* property_info_new (const char *name,
const char *type,
PropertyAccessFlags access);
PropertyInfo* property_info_ref (PropertyInfo *info);
void property_info_unref (PropertyInfo *info);
const char* property_info_get_name (PropertyInfo *info);
const char* property_info_get_type (PropertyInfo *info);
PropertyAccessFlags property_info_get_access (PropertyInfo *info);
ArgInfo* arg_info_new (const char *name,
ArgDirection direction,
const char *type);
ArgInfo* arg_info_ref (ArgInfo *info);
void arg_info_unref (ArgInfo *info);
const char* arg_info_get_name (ArgInfo *info);
const char* arg_info_get_type (ArgInfo *info);
ArgDirection arg_info_get_direction (ArgInfo *info);
GSList* arg_info_get_annotations (ArgInfo *info);
const char* arg_info_get_annotation (ArgInfo *info,
const char *annotation);
void arg_info_add_annotation (ArgInfo *info,
const char *name,
const char *value);
G_END_DECLS
#endif /* DBUS_GLIB_IDL_H */
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

View file

@ -1,489 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-glib-tool.c Tool used by apps using glib bindings
*
* Copyright (C) 2003, 2004 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include "dbus-gidl.h"
#include "dbus-gparser.h"
#include "dbus-gutils.h"
#include "dbus-glib-tool.h"
#include "dbus-binding-tool-glib.h"
#include <locale.h>
#include <libintl.h>
#define _(x) dgettext (GETTEXT_PACKAGE, x)
#define N_(x) x
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <string.h>
#include <time.h>
#ifdef DBUS_BUILD_TESTS
static void run_all_tests (const char *test_data_dir);
#endif
typedef enum {
DBUS_BINDING_OUTPUT_NONE,
DBUS_BINDING_OUTPUT_PRETTY,
DBUS_BINDING_OUTPUT_GLIB_SERVER,
DBUS_BINDING_OUTPUT_GLIB_CLIENT
} DBusBindingOutputMode;
static void
indent (int depth)
{
depth *= 2; /* 2-space indent */
while (depth > 0)
{
putc (' ', stdout);
--depth;
}
}
static void pretty_print (BaseInfo *base,
int depth);
static void
pretty_print_list (GSList *list,
int depth)
{
GSList *tmp;
tmp = list;
while (tmp != NULL)
{
pretty_print (tmp->data, depth);
tmp = tmp->next;
}
}
static void
pretty_print (BaseInfo *base,
int depth)
{
InfoType t;
const char *name;
t = base_info_get_type (base);
name = base_info_get_name (base);
indent (depth);
switch (t)
{
case INFO_TYPE_NODE:
{
NodeInfo *n = (NodeInfo*) base;
if (name == NULL)
printf (_("<anonymous node> {\n"));
else
printf (_("node \"%s\" {\n"), name);
pretty_print_list (node_info_get_interfaces (n), depth + 1);
pretty_print_list (node_info_get_nodes (n), depth + 1);
indent (depth);
printf ("}\n");
}
break;
case INFO_TYPE_INTERFACE:
{
InterfaceInfo *i = (InterfaceInfo*) base;
GSList *annotations, *elt;
g_assert (name != NULL);
printf (_("interface \"%s\" {\n"), name);
annotations = interface_info_get_annotations (i);
for (elt = annotations; elt; elt = elt->next)
{
const char *name = elt->data;
const char *value = interface_info_get_annotation (i, name);
printf (_(" (binding \"%s\": \"%s\") "),
name, value);
}
g_slist_free (annotations);
pretty_print_list (interface_info_get_methods (i), depth + 1);
pretty_print_list (interface_info_get_signals (i), depth + 1);
pretty_print_list (interface_info_get_properties (i), depth + 1);
indent (depth);
printf ("}\n");
}
break;
case INFO_TYPE_METHOD:
{
MethodInfo *m = (MethodInfo*) base;
GSList *annotations, *elt;
g_assert (name != NULL);
annotations = method_info_get_annotations (m);
printf (_("method \"%s\""), name);
for (elt = annotations; elt; elt = elt->next)
{
const char *name = elt->data;
const char *value = method_info_get_annotation (m, name);
printf (_(" (annotation \"%s\": \"%s\") "),
name, value);
}
g_slist_free (annotations);
pretty_print_list (method_info_get_args (m), depth + 1);
indent (depth);
printf (")\n");
}
break;
case INFO_TYPE_SIGNAL:
{
SignalInfo *s = (SignalInfo*) base;
g_assert (name != NULL);
printf (_("signal \"%s\" (\n"), name);
pretty_print_list (signal_info_get_args (s), depth + 1);
indent (depth);
printf (")\n");
}
break;
case INFO_TYPE_PROPERTY:
{
PropertyInfo *a = (PropertyInfo*) base;
const char *pt = property_info_get_type (a);
PropertyAccessFlags acc = property_info_get_access (a);
printf ("%s%s %s",
acc & PROPERTY_READ ? "read" : "",
acc & PROPERTY_WRITE ? "write" : "",
pt);
if (name)
printf (" %s\n", name);
else
printf ("\n");
}
break;
case INFO_TYPE_ARG:
{
ArgInfo *a = (ArgInfo*) base;
const char *at = arg_info_get_type (a);
ArgDirection d = arg_info_get_direction (a);
printf ("%s %s",
d == ARG_IN ? "in" : "out",
at);
if (name)
printf (" %s\n", name);
else
printf ("\n");
}
break;
}
}
GQuark
dbus_binding_tool_error_quark (void)
{
static GQuark quark = 0;
if (!quark)
quark = g_quark_from_static_string ("dbus_binding_tool_error");
return quark;
}
static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
static void
lose (const char *str, ...)
{
va_list args;
va_start (args, str);
vfprintf (stderr, str, args);
fputc ('\n', stderr);
va_end (args);
exit (1);
}
static void
lose_gerror (const char *prefix, GError *error)
{
lose ("%s: %s", prefix, error->message);
}
static void
usage (int ecode)
{
fprintf (stderr, "dbus-binding-tool [--version] [--help] --mode=[pretty|glib-server|glib-client] [--ignore-unsupported] [--force] [--output=FILE] [--prefix=SYMBOL_PREFIX]\n");
exit (ecode);
}
static void
version (void)
{
printf ("D-BUS Binding Tool %s\n"
"Copyright (C) 2003-2005 Red Hat, Inc.\n"
"This is free software; see the source for copying conditions.\n"
"There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
VERSION);
exit (0);
}
int
main (int argc, char **argv)
{
const char *output_file;
const char *prefix;
char *output_file_tmp;
int i;
GSList *files;
DBusBindingOutputMode outputmode;
gboolean end_of_args;
GSList *tmp;
GIOChannel *channel;
GError *error;
time_t newest_src;
struct stat srcbuf;
struct stat targetbuf;
gboolean force;
gboolean ignore_unsupported;
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, DBUS_LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
g_type_init ();
outputmode = DBUS_BINDING_OUTPUT_NONE;
end_of_args = FALSE;
files = NULL;
output_file = NULL;
prefix = "";
ignore_unsupported = FALSE;
force = FALSE;
i = 1;
while (i < argc)
{
const char *arg = argv[i];
if (!end_of_args)
{
if (strcmp (arg, "--help") == 0 ||
strcmp (arg, "-h") == 0 ||
strcmp (arg, "-?") == 0)
usage (0);
else if (strcmp (arg, "--version") == 0)
version ();
else if (strcmp (arg, "--force") == 0)
force = TRUE;
#ifdef DBUS_BUILD_TESTS
else if (strcmp (arg, "--self-test") == 0)
run_all_tests (NULL);
#endif /* DBUS_BUILD_TESTS */
else if (strncmp (arg, "--mode=", 7) == 0)
{
const char *mode = arg + 7;
if (!strcmp (mode, "pretty"))
outputmode = DBUS_BINDING_OUTPUT_PRETTY;
else if (!strcmp (mode, "glib-server"))
outputmode = DBUS_BINDING_OUTPUT_GLIB_SERVER;
else if (!strcmp (mode, "glib-client"))
outputmode = DBUS_BINDING_OUTPUT_GLIB_CLIENT;
else
usage (1);
}
else if (strcmp (arg, "--ignore-unsupported") == 0)
ignore_unsupported = TRUE;
else if (strncmp (arg, "--output=", 9) == 0)
{
output_file = arg + 9;
}
else if (strncmp (arg, "--prefix=", 9) == 0)
{
prefix = arg + 9;
}
else if (arg[0] == '-' &&
arg[1] == '-' &&
arg[2] == '\0')
end_of_args = TRUE;
else if (arg[0] == '-')
{
usage (1);
}
else
{
files = g_slist_prepend (files, (char*) arg);
}
}
else
files = g_slist_prepend (files, (char*) arg);
++i;
}
error = NULL;
files = g_slist_reverse (files);
if (output_file && !force)
{
newest_src = 0;
for (tmp = files; tmp != NULL; tmp = tmp->next)
{
const char *filename;
filename = tmp->data;
if (stat (filename, &srcbuf) < 0)
lose ("Couldn't stat %s: %s", filename, g_strerror (errno));
if (srcbuf.st_mtime > newest_src)
newest_src = srcbuf.st_mtime;
}
if (stat (output_file, &targetbuf) > 0
&& targetbuf.st_mtime >= newest_src)
exit (0);
}
if (output_file)
{
output_file_tmp = g_strconcat (output_file, ".tmp", NULL);
if (!(channel = g_io_channel_new_file (output_file_tmp, "w", &error)))
lose_gerror (_("Couldn't open temporary file"), error);
}
else
{
channel = g_io_channel_unix_new (fileno (stdout));
output_file_tmp = NULL; /* silence gcc */
}
if (!g_io_channel_set_encoding (channel, NULL, &error))
lose_gerror (_("Couldn't set channel encoding to NULL"), error);
for (tmp = files; tmp != NULL; tmp = tmp->next)
{
NodeInfo *node;
GError *error;
const char *filename;
filename = tmp->data;
error = NULL;
node = description_load_from_file (filename,
&error);
if (node == NULL)
{
lose_gerror (_("Unable to load \"%s\""), error);
}
else
{
switch (outputmode)
{
case DBUS_BINDING_OUTPUT_PRETTY:
pretty_print ((BaseInfo*) node, 0);
break;
case DBUS_BINDING_OUTPUT_GLIB_SERVER:
if (!dbus_binding_tool_output_glib_server ((BaseInfo *) node, channel, prefix, &error))
lose_gerror (_("Compilation failed"), error);
break;
case DBUS_BINDING_OUTPUT_GLIB_CLIENT:
if (!dbus_binding_tool_output_glib_client ((BaseInfo *) node, channel, ignore_unsupported, &error))
lose_gerror (_("Compilation failed"), error);
break;
case DBUS_BINDING_OUTPUT_NONE:
break;
}
}
if (node)
node_info_unref (node);
}
if (g_io_channel_shutdown (channel, TRUE, &error) != G_IO_STATUS_NORMAL)
lose_gerror (_("Failed to shutdown IO channel"), error);
g_io_channel_unref (channel);
if (output_file)
{
if (rename (output_file_tmp, output_file) < 0)
lose ("Failed to rename %s to %s: %s", output_file_tmp, output_file,
g_strerror (errno));
g_free (output_file_tmp);
}
return 0;
}
#ifdef DBUS_BUILD_TESTS
static void
test_die (const char *failure)
{
lose ("Unit test failed: %s", failure);
}
/**
* @ingroup DBusGTool
* Unit test for GLib utility tool
* @returns #TRUE on success.
*/
static gboolean
_dbus_gtool_test (const char *test_data_dir)
{
return TRUE;
}
static void
run_all_tests (const char *test_data_dir)
{
if (test_data_dir == NULL)
test_data_dir = g_getenv ("DBUS_TEST_DATA");
if (test_data_dir != NULL)
printf ("Test data in %s\n", test_data_dir);
else
printf ("No test data!\n");
printf ("%s: running binding tests\n", "dbus-binding-tool");
if (!_dbus_gtool_test (test_data_dir))
test_die ("gtool");
printf ("%s: completed successfully\n", "dbus-binding-tool");
}
#endif /* DBUS_BUILD_TESTS */

View file

@ -1,38 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-glib-tool.h: Definitions used internally by binding tool
*
* Copyright (C) 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_BINDING_TOOL_H
#define DBUS_BINDING_TOOL_H
#include <glib/gquark.h>
typedef enum
{
DBUS_BINDING_TOOL_ERROR_UNSUPPORTED_CONVERSION,
DBUS_BINDING_TOOL_ERROR_INVALID_ANNOTATION
} DBusBindingToolError;
#define DBUS_BINDING_TOOL_ERROR dbus_binding_tool_error_quark ()
GQuark dbus_binding_tool_error_quark (void);
#endif

View file

@ -1,304 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-glib.c General GLib binding stuff
*
* Copyright (C) 2004 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "dbus-gtest.h"
#include "dbus-gutils.h"
#include "dbus-gobject.h"
#include <string.h>
#include <libintl.h>
#define _(x) dgettext (GETTEXT_PACKAGE, x)
#define N_(x) x
/**
* @addtogroup DBusGLib
* @{
*/
/**
* Blocks until outgoing calls and signal emissions have been sent.
*
* @param connection the connection to flush
*/
void
dbus_g_connection_flush (DBusGConnection *connection)
{
dbus_connection_flush (DBUS_CONNECTION_FROM_G_CONNECTION (connection));
}
/**
* Increment refcount on a #DBusGConnection
*
* @param gconnection the connection to ref
* @returns the connection that was ref'd
*/
DBusGConnection*
dbus_g_connection_ref (DBusGConnection *gconnection)
{
DBusConnection *c;
c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
dbus_connection_ref (c);
return gconnection;
}
/**
* Decrement refcount on a #DBusGConnection
*
* @param gconnection the connection to unref
*/
void
dbus_g_connection_unref (DBusGConnection *gconnection)
{
DBusConnection *c;
c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
dbus_connection_unref (c);
}
/**
* Increment refcount on a #DBusGMessage
*
* @param gmessage the message to ref
* @returns the message that was ref'd
*/
DBusGMessage*
dbus_g_message_ref (DBusGMessage *gmessage)
{
DBusMessage *c;
c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
dbus_message_ref (c);
return gmessage;
}
/**
* Decrement refcount on a #DBusGMessage
*
* @param gmessage the message to unref
*/
void
dbus_g_message_unref (DBusGMessage *gmessage)
{
DBusMessage *c;
c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
dbus_message_unref (c);
}
/**
* The implementation of DBUS_GERROR error domain. See documentation
* for GError in GLib reference manual.
*
* @returns the error domain quark for use with GError
*/
GQuark
dbus_g_error_quark (void)
{
static GQuark quark = 0;
if (quark == 0)
quark = g_quark_from_static_string ("g-exec-error-quark");
return quark;
}
/**
* Determine whether D-BUS error name for a remote exception matches
* the given name. This function is intended to be invoked on a
* GError returned from an invocation of a remote method, e.g. via
* dbus_g_proxy_end_call. It will silently return FALSE for errors
* which are not remote D-BUS exceptions (i.e. with a domain other
* than DBUS_GERROR or a code other than
* DBUS_GERROR_REMOTE_EXCEPTION).
*
* @param error the GError given from the remote method
* @param name the D-BUS error name
* @param msg the D-BUS error detailed message
* @returns TRUE iff the remote error has the given name
*/
gboolean
dbus_g_error_has_name (GError *error, const char *name)
{
g_return_val_if_fail (error != NULL, FALSE);
if (error->domain != DBUS_GERROR
|| error->code != DBUS_GERROR_REMOTE_EXCEPTION)
return FALSE;
return !strcmp (dbus_g_error_get_name (error), name);
}
/**
* Return the D-BUS name for a remote exception.
* This function may only be invoked on a GError returned from an
* invocation of a remote method, e.g. via dbus_g_proxy_end_call.
* Moreover, you must ensure that the error's domain is DBUS_GERROR,
* and the code is DBUS_GERROR_REMOTE_EXCEPTION.
*
* @param error the GError given from the remote method
* @param name the D-BUS error name
* @param msg the D-BUS error detailed message
* @returns the D-BUS error name
*/
const char *
dbus_g_error_get_name (GError *error)
{
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail (error->domain == DBUS_GERROR, NULL);
g_return_val_if_fail (error->code == DBUS_GERROR_REMOTE_EXCEPTION, NULL);
return error->message + strlen (error->message) + 1;
}
/**
* Get the GLib type ID for a DBusConnection boxed type.
*
* @returns GLib type
*/
GType
dbus_connection_get_g_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static ("DBusConnection",
(GBoxedCopyFunc) dbus_connection_ref,
(GBoxedFreeFunc) dbus_connection_unref);
return our_type;
}
/**
* Get the GLib type ID for a DBusMessage boxed type.
*
* @returns GLib type
*/
GType
dbus_message_get_g_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static ("DBusMessage",
(GBoxedCopyFunc) dbus_message_ref,
(GBoxedFreeFunc) dbus_message_unref);
return our_type;
}
/**
* Get the GLib type ID for a DBusGConnection boxed type.
*
* @returns GLib type
*/
GType
dbus_g_connection_get_g_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static ("DBusGConnection",
(GBoxedCopyFunc) dbus_g_connection_ref,
(GBoxedFreeFunc) dbus_g_connection_unref);
return our_type;
}
/**
* Get the GLib type ID for a DBusGMessage boxed type.
*
* @returns GLib type
*/
GType
dbus_g_message_get_g_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static ("DBusGMessage",
(GBoxedCopyFunc) dbus_g_message_ref,
(GBoxedFreeFunc) dbus_g_message_unref);
return our_type;
}
/**
* Get the DBusConnection corresponding to this DBusGConnection.
* The return value does not have its refcount incremented.
*
* @returns DBusConnection
*/
DBusConnection*
dbus_g_connection_get_connection (DBusGConnection *gconnection)
{
return DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
}
/**
* Get the DBusMessage corresponding to this DBusGMessage.
* The return value does not have its refcount incremented.
*
* @returns DBusMessage
*/
DBusMessage*
dbus_g_message_get_message (DBusGMessage *gmessage)
{
return DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
}
/** @} */ /* end of public API */
#ifdef DBUS_BUILD_TESTS
/**
* @ingroup DBusGLibInternals
* Unit test for general glib stuff
* @returns #TRUE on success.
*/
gboolean
_dbus_glib_test (const char *test_data_dir)
{
DBusError err;
GError *gerror = NULL;
dbus_error_init (&err);
dbus_set_error_const (&err, DBUS_ERROR_NO_MEMORY, "Out of memory!");
dbus_set_g_error (&gerror, &err);
g_assert (gerror != NULL);
g_assert (gerror->domain == DBUS_GERROR);
g_assert (gerror->code == DBUS_GERROR_NO_MEMORY);
g_assert (!strcmp (gerror->message, "Out of memory!"));
dbus_error_init (&err);
g_clear_error (&gerror);
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */

View file

@ -1,266 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gloader-expat.c expat XML loader
*
* Copyright (C) 2003 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "dbus-gparser.h"
#include <expat.h>
#include <string.h>
static void*
expat_g_malloc (size_t sz)
{
return g_malloc (sz);
}
static void*
expat_g_realloc (void *mem, size_t sz)
{
return g_realloc (mem, sz);
}
static XML_Memory_Handling_Suite memsuite =
{
expat_g_malloc,
expat_g_realloc,
g_free
};
/**
* Context for Expat parser for introspection data.
*/
typedef struct
{
Parser *parser; /**< The parser for the introspection data */
const char *filename; /**< The filename being loaded */
GString *content; /**< The content of the current element */
GError **error; /**< Error return location */
gboolean failed; /**< True if parse has failed */
} ExpatParseContext;
static dbus_bool_t
process_content (ExpatParseContext *context)
{
if (context->failed)
return FALSE;
if (context->content->len > 0)
{
if (!parser_content (context->parser,
context->content->str,
context->content->len,
context->error))
{
context->failed = TRUE;
return FALSE;
}
g_string_set_size (context->content, 0);
}
return TRUE;
}
static void
expat_StartElementHandler (void *userData,
const XML_Char *name,
const XML_Char **atts)
{
ExpatParseContext *context = userData;
int i;
char **names;
char **values;
/* Expat seems to suck and can't abort the parse if we
* throw an error. Expat 2.0 is supposed to fix this.
*/
if (context->failed)
return;
if (!process_content (context))
return;
/* "atts" is key, value, key, value, NULL */
for (i = 0; atts[i] != NULL; ++i)
; /* nothing */
g_assert (i % 2 == 0);
names = g_new0 (char *, i / 2 + 1);
values = g_new0 (char *, i / 2 + 1);
i = 0;
while (atts[i] != NULL)
{
g_assert (i % 2 == 0);
names [i / 2] = (char*) atts[i];
values[i / 2] = (char*) atts[i+1];
i += 2;
}
if (!parser_start_element (context->parser,
name,
(const char **) names,
(const char **) values,
context->error))
{
g_free (names);
g_free (values);
context->failed = TRUE;
return;
}
g_free (names);
g_free (values);
}
static void
expat_EndElementHandler (void *userData,
const XML_Char *name)
{
ExpatParseContext *context = userData;
if (!process_content (context))
return;
if (!parser_end_element (context->parser,
name,
context->error))
{
context->failed = TRUE;
return;
}
}
/* s is not 0 terminated. */
static void
expat_CharacterDataHandler (void *userData,
const XML_Char *s,
int len)
{
ExpatParseContext *context = userData;
if (context->failed)
return;
g_string_append_len (context->content,
s, len);
}
NodeInfo*
description_load_from_file (const char *filename,
GError **error)
{
char *contents;
gsize len;
NodeInfo *nodes;
contents = NULL;
if (!g_file_get_contents (filename, &contents, &len, error))
return NULL;
nodes = description_load_from_string (contents, len, error);
g_free (contents);
return nodes;
}
NodeInfo*
description_load_from_string (const char *str,
int len,
GError **error)
{
XML_Parser expat;
ExpatParseContext context;
NodeInfo *nodes;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (len < 0)
len = strlen (str);
expat = NULL;
context.parser = NULL;
context.error = error;
context.failed = FALSE;
expat = XML_ParserCreate_MM ("UTF-8", &memsuite, NULL);
if (expat == NULL)
g_error ("No memory to create XML parser\n");
context.parser = parser_new ();
context.content = g_string_new (NULL);
XML_SetUserData (expat, &context);
XML_SetElementHandler (expat,
expat_StartElementHandler,
expat_EndElementHandler);
XML_SetCharacterDataHandler (expat,
expat_CharacterDataHandler);
if (!XML_Parse (expat, str, len, TRUE))
{
if (context.error != NULL &&
*context.error == NULL)
{
enum XML_Error e;
e = XML_GetErrorCode (expat);
if (e == XML_ERROR_NO_MEMORY)
g_error ("Not enough memory to parse XML document");
else
g_set_error (error,
G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
"Error in D-BUS description XML, line %d, column %d: %s\n",
XML_GetCurrentLineNumber (expat),
XML_GetCurrentColumnNumber (expat),
XML_ErrorString (e));
}
goto failed;
}
if (context.failed)
goto failed;
if (!parser_finished (context.parser, error))
goto failed;
XML_ParserFree (expat);
g_string_free (context.content, TRUE);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
nodes = parser_get_nodes (context.parser);
node_info_ref (nodes);
parser_unref (context.parser);
return nodes;
failed:
g_return_val_if_fail (error == NULL || *error != NULL, NULL);
g_string_free (context.content, TRUE);
if (expat)
XML_ParserFree (expat);
if (context.parser)
parser_unref (context.parser);
return NULL;
}

View file

@ -1,814 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gmain.c GLib main loop integration
*
* Copyright (C) 2002, 2003 CodeFactory AB
* Copyright (C) 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "dbus-gtest.h"
#include "dbus-gutils.h"
#include "dbus-gvalue.h"
#include "dbus-gobject.h"
#include "dbus-gvalue-utils.h"
#include "dbus-gsignature.h"
#include <string.h>
#include <libintl.h>
#define _(x) dgettext (GETTEXT_PACKAGE, x)
#define N_(x) x
/**
* @defgroup DBusGLib GLib bindings
* @brief API for using D-BUS with GLib
*
* libdbus proper is a low-level API, these GLib bindings wrap libdbus
* with a much higher-level approach. The higher level approach is
* possible because GLib defines a main loop, an object/type system,
* and an out-of-memory handling policy (it exits the program).
* See http://www.gtk.org for GLib information.
*
* To manipulate remote objects, use #DBusGProxy.
*/
/**
* @defgroup DBusGLibInternals GLib bindings implementation details
* @ingroup DBusInternals
* @brief Implementation details of GLib bindings
*
* @{
*/
/**
* A GSource subclass for dispatching DBusConnection messages.
* We need this on top of the IO handlers, because sometimes
* there are messages to dispatch queued up but no IO pending.
*/
typedef struct
{
GSource source; /**< the parent GSource */
DBusConnection *connection; /**< the connection to dispatch */
} DBusGMessageQueue;
static gboolean message_queue_prepare (GSource *source,
gint *timeout);
static gboolean message_queue_check (GSource *source);
static gboolean message_queue_dispatch (GSource *source,
GSourceFunc callback,
gpointer user_data);
static const GSourceFuncs message_queue_funcs = {
message_queue_prepare,
message_queue_check,
message_queue_dispatch,
NULL
};
static gboolean
message_queue_prepare (GSource *source,
gint *timeout)
{
DBusConnection *connection = ((DBusGMessageQueue *)source)->connection;
*timeout = -1;
return (dbus_connection_get_dispatch_status (connection) == DBUS_DISPATCH_DATA_REMAINS);
}
static gboolean
message_queue_check (GSource *source)
{
return FALSE;
}
static gboolean
message_queue_dispatch (GSource *source,
GSourceFunc callback,
gpointer user_data)
{
DBusConnection *connection = ((DBusGMessageQueue *)source)->connection;
dbus_connection_ref (connection);
/* Only dispatch once - we don't want to starve other GSource */
dbus_connection_dispatch (connection);
dbus_connection_unref (connection);
return TRUE;
}
typedef struct
{
GMainContext *context; /**< the main context */
GSList *ios; /**< all IOHandler */
GSList *timeouts; /**< all TimeoutHandler */
DBusConnection *connection; /**< NULL if this is really for a server not a connection */
GSource *message_queue_source; /**< DBusGMessageQueue */
} ConnectionSetup;
typedef struct
{
ConnectionSetup *cs;
GSource *source;
DBusWatch *watch;
} IOHandler;
typedef struct
{
ConnectionSetup *cs;
GSource *source;
DBusTimeout *timeout;
} TimeoutHandler;
static dbus_int32_t connection_slot = -1;
static dbus_int32_t server_slot = -1;
static ConnectionSetup*
connection_setup_new (GMainContext *context,
DBusConnection *connection)
{
ConnectionSetup *cs;
cs = g_new0 (ConnectionSetup, 1);
g_assert (context != NULL);
cs->context = context;
g_main_context_ref (cs->context);
if (connection)
{
cs->connection = connection;
cs->message_queue_source = g_source_new (&message_queue_funcs,
sizeof (DBusGMessageQueue));
((DBusGMessageQueue*)cs->message_queue_source)->connection = connection;
g_source_attach (cs->message_queue_source, cs->context);
}
return cs;
}
static void
io_handler_source_finalized (gpointer data)
{
IOHandler *handler;
handler = data;
if (handler->watch)
dbus_watch_set_data (handler->watch, NULL, NULL);
g_free (handler);
}
static void
io_handler_destroy_source (void *data)
{
IOHandler *handler;
handler = data;
if (handler->source)
{
GSource *source = handler->source;
handler->source = NULL;
handler->cs->ios = g_slist_remove (handler->cs->ios, handler);
g_source_destroy (source);
g_source_unref (source);
}
}
static void
io_handler_watch_freed (void *data)
{
IOHandler *handler;
handler = data;
handler->watch = NULL;
io_handler_destroy_source (handler);
}
static gboolean
io_handler_dispatch (GIOChannel *source,
GIOCondition condition,
gpointer data)
{
IOHandler *handler;
guint dbus_condition = 0;
DBusConnection *connection;
handler = data;
connection = handler->cs->connection;
if (connection)
dbus_connection_ref (connection);
if (condition & G_IO_IN)
dbus_condition |= DBUS_WATCH_READABLE;
if (condition & G_IO_OUT)
dbus_condition |= DBUS_WATCH_WRITABLE;
if (condition & G_IO_ERR)
dbus_condition |= DBUS_WATCH_ERROR;
if (condition & G_IO_HUP)
dbus_condition |= DBUS_WATCH_HANGUP;
/* Note that we don't touch the handler after this, because
* dbus may have disabled the watch and thus killed the
* handler.
*/
dbus_watch_handle (handler->watch, dbus_condition);
handler = NULL;
if (connection)
dbus_connection_unref (connection);
return TRUE;
}
static void
connection_setup_add_watch (ConnectionSetup *cs,
DBusWatch *watch)
{
guint flags;
GIOCondition condition;
GIOChannel *channel;
IOHandler *handler;
if (!dbus_watch_get_enabled (watch))
return;
g_assert (dbus_watch_get_data (watch) == NULL);
flags = dbus_watch_get_flags (watch);
condition = G_IO_ERR | G_IO_HUP;
if (flags & DBUS_WATCH_READABLE)
condition |= G_IO_IN;
if (flags & DBUS_WATCH_WRITABLE)
condition |= G_IO_OUT;
handler = g_new0 (IOHandler, 1);
handler->cs = cs;
handler->watch = watch;
channel = g_io_channel_unix_new (dbus_watch_get_fd (watch));
handler->source = g_io_create_watch (channel, condition);
g_source_set_callback (handler->source, (GSourceFunc) io_handler_dispatch, handler,
io_handler_source_finalized);
g_source_attach (handler->source, cs->context);
cs->ios = g_slist_prepend (cs->ios, handler);
dbus_watch_set_data (watch, handler, io_handler_watch_freed);
g_io_channel_unref (channel);
}
static void
connection_setup_remove_watch (ConnectionSetup *cs,
DBusWatch *watch)
{
IOHandler *handler;
handler = dbus_watch_get_data (watch);
if (handler == NULL)
return;
io_handler_destroy_source (handler);
}
static void
timeout_handler_source_finalized (gpointer data)
{
TimeoutHandler *handler;
handler = data;
if (handler->timeout)
dbus_timeout_set_data (handler->timeout, NULL, NULL);
g_free (handler);
}
static void
timeout_handler_destroy_source (void *data)
{
TimeoutHandler *handler;
handler = data;
if (handler->source)
{
GSource *source = handler->source;
handler->source = NULL;
handler->cs->timeouts = g_slist_remove (handler->cs->timeouts, handler);
g_source_destroy (source);
g_source_unref (source);
}
}
static void
timeout_handler_timeout_freed (void *data)
{
TimeoutHandler *handler;
handler = data;
handler->timeout = NULL;
timeout_handler_destroy_source (handler);
}
static gboolean
timeout_handler_dispatch (gpointer data)
{
TimeoutHandler *handler;
handler = data;
dbus_timeout_handle (handler->timeout);
return TRUE;
}
static void
connection_setup_add_timeout (ConnectionSetup *cs,
DBusTimeout *timeout)
{
TimeoutHandler *handler;
if (!dbus_timeout_get_enabled (timeout))
return;
g_assert (dbus_timeout_get_data (timeout) == NULL);
handler = g_new0 (TimeoutHandler, 1);
handler->cs = cs;
handler->timeout = timeout;
handler->source = g_timeout_source_new (dbus_timeout_get_interval (timeout));
g_source_set_callback (handler->source, timeout_handler_dispatch, handler,
timeout_handler_source_finalized);
g_source_attach (handler->source, handler->cs->context);
cs->timeouts = g_slist_prepend (cs->timeouts, handler);
dbus_timeout_set_data (timeout, handler, timeout_handler_timeout_freed);
}
static void
connection_setup_remove_timeout (ConnectionSetup *cs,
DBusTimeout *timeout)
{
TimeoutHandler *handler;
handler = dbus_timeout_get_data (timeout);
if (handler == NULL)
return;
timeout_handler_destroy_source (handler);
}
static void
connection_setup_free (ConnectionSetup *cs)
{
while (cs->ios)
io_handler_destroy_source (cs->ios->data);
while (cs->timeouts)
timeout_handler_destroy_source (cs->timeouts->data);
if (cs->message_queue_source)
{
GSource *source;
source = cs->message_queue_source;
cs->message_queue_source = NULL;
g_source_destroy (source);
g_source_unref (source);
}
g_main_context_unref (cs->context);
g_free (cs);
}
static dbus_bool_t
add_watch (DBusWatch *watch,
gpointer data)
{
ConnectionSetup *cs;
cs = data;
connection_setup_add_watch (cs, watch);
return TRUE;
}
static void
remove_watch (DBusWatch *watch,
gpointer data)
{
ConnectionSetup *cs;
cs = data;
connection_setup_remove_watch (cs, watch);
}
static void
watch_toggled (DBusWatch *watch,
void *data)
{
/* Because we just exit on OOM, enable/disable is
* no different from add/remove
*/
if (dbus_watch_get_enabled (watch))
add_watch (watch, data);
else
remove_watch (watch, data);
}
static dbus_bool_t
add_timeout (DBusTimeout *timeout,
void *data)
{
ConnectionSetup *cs;
cs = data;
if (!dbus_timeout_get_enabled (timeout))
return TRUE;
connection_setup_add_timeout (cs, timeout);
return TRUE;
}
static void
remove_timeout (DBusTimeout *timeout,
void *data)
{
ConnectionSetup *cs;
cs = data;
connection_setup_remove_timeout (cs, timeout);
}
static void
timeout_toggled (DBusTimeout *timeout,
void *data)
{
/* Because we just exit on OOM, enable/disable is
* no different from add/remove
*/
if (dbus_timeout_get_enabled (timeout))
add_timeout (timeout, data);
else
remove_timeout (timeout, data);
}
static void
wakeup_main (void *data)
{
ConnectionSetup *cs = data;
g_main_context_wakeup (cs->context);
}
/* Move to a new context */
static ConnectionSetup*
connection_setup_new_from_old (GMainContext *context,
ConnectionSetup *old)
{
GSList *tmp;
ConnectionSetup *cs;
g_assert (old->context != context);
cs = connection_setup_new (context, old->connection);
tmp = old->ios;
while (tmp != NULL)
{
IOHandler *handler = tmp->data;
connection_setup_add_watch (cs, handler->watch);
tmp = tmp->next;
}
tmp = old->timeouts;
while (tmp != NULL)
{
TimeoutHandler *handler = tmp->data;
connection_setup_add_timeout (cs, handler->timeout);
tmp = tmp->next;
}
return cs;
}
/** @} */ /* End of GLib bindings internals */
/** @addtogroup DBusGLib
* @{
*/
/**
* Sets the watch and timeout functions of a #DBusConnection
* to integrate the connection with the GLib main loop.
* Pass in #NULL for the #GMainContext unless you're
* doing something specialized.
*
* If called twice for the same context, does nothing the second
* time. If called once with context A and once with context B,
* context B replaces context A as the context monitoring the
* connection.
*
* @param connection the connection
* @param context the #GMainContext or #NULL for default context
*/
void
dbus_connection_setup_with_g_main (DBusConnection *connection,
GMainContext *context)
{
ConnectionSetup *old_setup;
ConnectionSetup *cs;
/* FIXME we never free the slot, so its refcount just keeps growing,
* which is kind of broken.
*/
dbus_connection_allocate_data_slot (&connection_slot);
if (connection_slot < 0)
goto nomem;
if (context == NULL)
context = g_main_context_default ();
cs = NULL;
old_setup = dbus_connection_get_data (connection, connection_slot);
if (old_setup != NULL)
{
if (old_setup->context == context)
return; /* nothing to do */
cs = connection_setup_new_from_old (context, old_setup);
/* Nuke the old setup */
dbus_connection_set_data (connection, connection_slot, NULL, NULL);
old_setup = NULL;
}
if (cs == NULL)
cs = connection_setup_new (context, connection);
if (!dbus_connection_set_data (connection, connection_slot, cs,
(DBusFreeFunction)connection_setup_free))
goto nomem;
if (!dbus_connection_set_watch_functions (connection,
add_watch,
remove_watch,
watch_toggled,
cs, NULL))
goto nomem;
if (!dbus_connection_set_timeout_functions (connection,
add_timeout,
remove_timeout,
timeout_toggled,
cs, NULL))
goto nomem;
dbus_connection_set_wakeup_main_function (connection,
wakeup_main,
cs, NULL);
return;
nomem:
g_error ("Not enough memory to set up DBusConnection for use with GLib");
}
/**
* Sets the watch and timeout functions of a #DBusServer
* to integrate the server with the GLib main loop.
* In most cases the context argument should be #NULL.
*
* If called twice for the same context, does nothing the second
* time. If called once with context A and once with context B,
* context B replaces context A as the context monitoring the
* connection.
*
* @param server the server
* @param context the #GMainContext or #NULL for default
*/
void
dbus_server_setup_with_g_main (DBusServer *server,
GMainContext *context)
{
ConnectionSetup *old_setup;
ConnectionSetup *cs;
/* FIXME we never free the slot, so its refcount just keeps growing,
* which is kind of broken.
*/
dbus_server_allocate_data_slot (&server_slot);
if (server_slot < 0)
goto nomem;
if (context == NULL)
context = g_main_context_default ();
cs = NULL;
old_setup = dbus_server_get_data (server, server_slot);
if (old_setup != NULL)
{
if (old_setup->context == context)
return; /* nothing to do */
cs = connection_setup_new_from_old (context, old_setup);
/* Nuke the old setup */
dbus_server_set_data (server, server_slot, NULL, NULL);
old_setup = NULL;
}
if (cs == NULL)
cs = connection_setup_new (context, NULL);
if (!dbus_server_set_data (server, server_slot, cs,
(DBusFreeFunction)connection_setup_free))
goto nomem;
if (!dbus_server_set_watch_functions (server,
add_watch,
remove_watch,
watch_toggled,
cs, NULL))
goto nomem;
if (!dbus_server_set_timeout_functions (server,
add_timeout,
remove_timeout,
timeout_toggled,
cs, NULL))
goto nomem;
return;
nomem:
g_error ("Not enough memory to set up DBusServer for use with GLib");
}
/**
* Returns a connection to the given address.
*
* (Internally, calls dbus_connection_open() then calls
* dbus_connection_setup_with_g_main() on the result.)
*
* @param address address of the connection to open
* @param error address where an error can be returned.
* @returns a DBusConnection
*/
DBusGConnection*
dbus_g_connection_open (const gchar *address,
GError **error)
{
DBusConnection *connection;
DBusError derror;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
_dbus_g_value_types_init ();
dbus_error_init (&derror);
connection = dbus_connection_open (address, &derror);
if (connection == NULL)
{
dbus_set_g_error (error, &derror);
dbus_error_free (&derror);
return NULL;
}
/* does nothing if it's already been done */
dbus_connection_setup_with_g_main (connection, NULL);
return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
}
/**
* Returns a connection to the given bus. The connection is a global variable
* shared with other callers of this function.
*
* (Internally, calls dbus_bus_get() then calls
* dbus_connection_setup_with_g_main() on the result.)
*
* @param type bus type
* @param error address where an error can be returned.
* @returns a DBusConnection
*/
DBusGConnection*
dbus_g_bus_get (DBusBusType type,
GError **error)
{
DBusConnection *connection;
DBusError derror;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
_dbus_g_value_types_init ();
dbus_error_init (&derror);
connection = dbus_bus_get (type, &derror);
if (connection == NULL)
{
dbus_set_g_error (error, &derror);
dbus_error_free (&derror);
return NULL;
}
/* does nothing if it's already been done */
dbus_connection_setup_with_g_main (connection, NULL);
return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
}
/** @} */ /* end of public API */
#ifdef DBUS_BUILD_TESTS
/**
* @ingroup DBusGLibInternals
* Unit test for GLib main loop integration
* @returns #TRUE on success.
*/
gboolean
_dbus_gmain_test (const char *test_data_dir)
{
GType type;
GType rectype;
g_type_init ();
_dbus_g_value_types_init ();
rectype = dbus_g_type_get_collection ("GArray", G_TYPE_UINT);
g_assert (rectype != G_TYPE_INVALID);
g_assert (!strcmp (g_type_name (rectype), "GArray_guint_"));
type = _dbus_gtype_from_signature ("au", TRUE);
g_assert (type == rectype);
rectype = dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING);
g_assert (rectype != G_TYPE_INVALID);
g_assert (!strcmp (g_type_name (rectype), "GHashTable_gchararray+gchararray_"));
type = _dbus_gtype_from_signature ("a{ss}", TRUE);
g_assert (type == rectype);
type = _dbus_gtype_from_signature ("o", FALSE);
g_assert (type == DBUS_TYPE_G_OBJECT_PATH);
type = _dbus_gtype_from_signature ("o", TRUE);
g_assert (type == DBUS_TYPE_G_OBJECT_PATH);
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */

View file

@ -1,89 +0,0 @@
#include "dbus-gmarshal.h"
#include <glib-object.h>
#ifdef G_ENABLE_DEBUG
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
#define g_marshal_value_peek_char(v) g_value_get_char (v)
#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)
#define g_marshal_value_peek_int(v) g_value_get_int (v)
#define g_marshal_value_peek_uint(v) g_value_get_uint (v)
#define g_marshal_value_peek_long(v) g_value_get_long (v)
#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)
#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)
#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)
#define g_marshal_value_peek_enum(v) g_value_get_enum (v)
#define g_marshal_value_peek_flags(v) g_value_get_flags (v)
#define g_marshal_value_peek_float(v) g_value_get_float (v)
#define g_marshal_value_peek_double(v) g_value_get_double (v)
#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)
#define g_marshal_value_peek_param(v) g_value_get_param (v)
#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)
#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)
#define g_marshal_value_peek_object(v) g_value_get_object (v)
#else /* !G_ENABLE_DEBUG */
/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
* Do not access GValues directly in your code. Instead, use the
* g_value_get_*() functions
*/
#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int
#define g_marshal_value_peek_char(v) (v)->data[0].v_int
#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint
#define g_marshal_value_peek_int(v) (v)->data[0].v_int
#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint
#define g_marshal_value_peek_long(v) (v)->data[0].v_long
#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong
#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64
#define g_marshal_value_peek_enum(v) (v)->data[0].v_long
#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong
#define g_marshal_value_peek_float(v) (v)->data[0].v_float
#define g_marshal_value_peek_double(v) (v)->data[0].v_double
#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
#endif /* !G_ENABLE_DEBUG */
/* NONE:STRING,STRING,STRING (dbus-gmarshal.list:1) */
void
_dbus_g_marshal_VOID__STRING_STRING_STRING (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__STRING_STRING_STRING) (gpointer data1,
gpointer arg_1,
gpointer arg_2,
gpointer arg_3,
gpointer data2);
register GMarshalFunc_VOID__STRING_STRING_STRING callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
g_return_if_fail (n_param_values == 4);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_VOID__STRING_STRING_STRING) (marshal_data ? marshal_data : cc->callback);
callback (data1,
g_marshal_value_peek_string (param_values + 1),
g_marshal_value_peek_string (param_values + 2),
g_marshal_value_peek_string (param_values + 3),
data2);
}

View file

@ -1,21 +0,0 @@
#ifndef ___dbus_g_marshal_MARSHAL_H__
#define ___dbus_g_marshal_MARSHAL_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* NONE:STRING,STRING,STRING (dbus-gmarshal.list:1) */
extern void _dbus_g_marshal_VOID__STRING_STRING_STRING (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
#define _dbus_g_marshal_NONE__STRING_STRING_STRING _dbus_g_marshal_VOID__STRING_STRING_STRING
G_END_DECLS
#endif /* ___dbus_g_marshal_MARSHAL_H__ */

View file

@ -1 +0,0 @@
NONE:STRING,STRING,STRING

File diff suppressed because it is too large Load diff

View file

@ -1,43 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gobject.h: common functions used to map between D-BUS and GObject
*
* Copyright (C) 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GLIB_OBJECT_H
#define DBUS_GLIB_OBJECT_H
#include <dbus/dbus.h>
#include <dbus/dbus-signature.h>
#include <glib.h>
#include "dbus/dbus-glib.h"
G_BEGIN_DECLS
const char * _dbus_gobject_get_path (GObject *obj);
GClosureMarshal _dbus_gobject_lookup_marshaller (GType rettype,
guint n_params,
const GType *param_types);
G_END_DECLS
#endif

View file

@ -1,881 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gparser.c parse DBus description files
*
* Copyright (C) 2003, 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "dbus-gparser.h"
#include "dbus/dbus-glib-lowlevel.h"
#include "dbus-gidl.h"
#include "dbus-gobject.h"
#include "dbus/dbus-signature.h"
#include <string.h>
#include <libintl.h>
#define _(x) gettext ((x))
#define N_(x) x
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#define ELEMENT_IS(name) (strcmp (element_name, (name)) == 0)
typedef struct
{
const char *name;
const char **retloc;
} LocateAttr;
static gboolean
locate_attributes (const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error,
const char *first_attribute_name,
const char **first_attribute_retloc,
...)
{
va_list args;
const char *name;
const char **retloc;
int n_attrs;
#define MAX_ATTRS 24
LocateAttr attrs[MAX_ATTRS];
gboolean retval;
int i;
g_return_val_if_fail (first_attribute_name != NULL, FALSE);
g_return_val_if_fail (first_attribute_retloc != NULL, FALSE);
retval = TRUE;
n_attrs = 1;
attrs[0].name = first_attribute_name;
attrs[0].retloc = first_attribute_retloc;
*first_attribute_retloc = NULL;
va_start (args, first_attribute_retloc);
name = va_arg (args, const char*);
retloc = va_arg (args, const char**);
while (name != NULL)
{
g_return_val_if_fail (retloc != NULL, FALSE);
g_assert (n_attrs < MAX_ATTRS);
attrs[n_attrs].name = name;
attrs[n_attrs].retloc = retloc;
n_attrs += 1;
*retloc = NULL;
name = va_arg (args, const char*);
retloc = va_arg (args, const char**);
}
va_end (args);
if (!retval)
return retval;
i = 0;
while (attribute_names[i])
{
int j;
gboolean found;
found = FALSE;
j = 0;
while (j < n_attrs)
{
if (strcmp (attrs[j].name, attribute_names[i]) == 0)
{
retloc = attrs[j].retloc;
if (*retloc != NULL)
{
g_set_error (error,
G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Attribute \"%s\" repeated twice on the same <%s> element"),
attrs[j].name, element_name);
retval = FALSE;
goto out;
}
*retloc = attribute_values[i];
found = TRUE;
}
++j;
}
if (!found)
{
g_set_error (error,
G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Attribute \"%s\" is invalid on <%s> element in this context"),
attribute_names[i], element_name);
retval = FALSE;
goto out;
}
++i;
}
out:
return retval;
}
#if 0
static gboolean
check_no_attributes (const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error)
{
if (attribute_names[0] != NULL)
{
g_set_error (error,
G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Attribute \"%s\" is invalid on <%s> element in this context"),
attribute_names[0], element_name);
return FALSE;
}
return TRUE;
}
#endif
struct Parser
{
int refcount;
NodeInfo *result; /* Filled in when we pop the last node */
GSList *node_stack;
InterfaceInfo *interface;
MethodInfo *method;
SignalInfo *signal;
PropertyInfo *property;
ArgInfo *arg;
gboolean in_annotation;
};
Parser*
parser_new (void)
{
Parser *parser;
parser = g_new0 (Parser, 1);
parser->refcount = 1;
return parser;
}
Parser *
parser_ref (Parser *parser)
{
parser->refcount += 1;
return parser;
}
void
parser_unref (Parser *parser)
{
parser->refcount -= 1;
if (parser->refcount == 0)
{
if (parser->result)
node_info_unref (parser->result);
g_free (parser);
}
}
gboolean
parser_check_doctype (Parser *parser,
const char *doctype,
GError **error)
{
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (strcmp (doctype, "node") != 0)
{
g_set_error (error,
G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
"D-BUS description file has the wrong document type %s, use node or interface",
doctype);
return FALSE;
}
else
return TRUE;
}
static gboolean
parse_node (Parser *parser,
const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error)
{
const char *name;
NodeInfo *node;
if (parser->interface ||
parser->method ||
parser->signal ||
parser->property ||
parser->arg ||
parser->in_annotation)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Can't put <%s> element here"),
element_name);
return FALSE;
}
name = NULL;
if (!locate_attributes (element_name, attribute_names,
attribute_values, error,
"name", &name,
NULL))
return FALSE;
/* Only the root node can have no name */
if (parser->node_stack != NULL && name == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"name", element_name);
return FALSE;
}
/* Root element name must be absolute */
if (parser->node_stack == NULL && name && *name != '/')
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute on <%s> element must be an absolute object path, \"%s\" not OK"),
"name", element_name, name);
return FALSE;
}
/* Other element names must not be absolute */
if (parser->node_stack != NULL && name && *name == '/')
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute on <%s> element must not be an absolute object path, \"%s\" starts with /"),
"name", element_name, name);
return FALSE;
}
node = node_info_new (name);
if (parser->node_stack != NULL)
{
node_info_add_node (parser->node_stack->data,
node);
}
parser->node_stack = g_slist_prepend (parser->node_stack,
node);
return TRUE;
}
static gboolean
parse_interface (Parser *parser,
const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error)
{
const char *name;
InterfaceInfo *iface;
NodeInfo *top;
if (parser->interface ||
parser->method ||
parser->signal ||
parser->property ||
parser->arg ||
parser->in_annotation ||
(parser->node_stack == NULL))
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Can't put <%s> element here"),
element_name);
return FALSE;
}
name = NULL;
if (!locate_attributes (element_name, attribute_names,
attribute_values, error,
"name", &name,
NULL))
return FALSE;
if (name == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"name", element_name);
return FALSE;
}
top = parser->node_stack->data;
iface = interface_info_new (name);
node_info_add_interface (top, iface);
interface_info_unref (iface);
parser->interface = iface;
return TRUE;
}
static gboolean
parse_method (Parser *parser,
const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error)
{
const char *name;
MethodInfo *method;
if (parser->interface == NULL ||
parser->node_stack == NULL ||
parser->method ||
parser->signal ||
parser->property ||
parser->in_annotation ||
parser->arg)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Can't put <%s> element here"),
element_name);
return FALSE;
}
name = NULL;
if (!locate_attributes (element_name, attribute_names,
attribute_values, error,
"name", &name,
NULL))
return FALSE;
if (name == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"name", element_name);
return FALSE;
}
method = method_info_new (name);
interface_info_add_method (parser->interface, method);
method_info_unref (method);
parser->method = method;
return TRUE;
}
static gboolean
parse_signal (Parser *parser,
const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error)
{
const char *name;
SignalInfo *signal;
if (parser->interface == NULL ||
parser->node_stack == NULL ||
parser->signal ||
parser->method ||
parser->property ||
parser->in_annotation ||
parser->arg)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Can't put <%s> element here"),
element_name);
return FALSE;
}
name = NULL;
if (!locate_attributes (element_name, attribute_names,
attribute_values, error,
"name", &name,
NULL))
return FALSE;
if (name == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"name", element_name);
return FALSE;
}
signal = signal_info_new (name);
interface_info_add_signal (parser->interface, signal);
signal_info_unref (signal);
parser->signal = signal;
return TRUE;
}
static gboolean
validate_signature (const char *str,
const char *element_name,
GError **error)
{
DBusError derror;
dbus_error_init (&derror);
if (!dbus_signature_validate (str, &derror))
{
dbus_set_g_error (error, &derror);
return FALSE;
}
return TRUE;
}
static gboolean
parse_property (Parser *parser,
const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error)
{
const char *name;
const char *access;
const char *type;
PropertyInfo *property;
PropertyAccessFlags access_flags;
if (parser->interface == NULL ||
parser->node_stack == NULL ||
parser->signal ||
parser->method ||
parser->property ||
parser->in_annotation ||
parser->arg)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Can't put <%s> element here"),
element_name);
return FALSE;
}
name = NULL;
if (!locate_attributes (element_name, attribute_names,
attribute_values, error,
"name", &name,
"access", &access,
"type", &type,
NULL))
return FALSE;
if (name == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"name", element_name);
return FALSE;
}
if (access == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"access", element_name);
return FALSE;
}
if (type == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"type", element_name);
return FALSE;
}
if (!validate_signature (type, element_name, error))
return FALSE;
access_flags = 0;
if (strcmp (access, "readwrite") == 0)
access_flags = PROPERTY_READ | PROPERTY_WRITE;
else if (strcmp (access, "read") == 0)
access_flags = PROPERTY_READ;
else if (strcmp (access, "write") == 0)
access_flags = PROPERTY_WRITE;
else
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("access=\"%s\" must have value readwrite, read, or write on %s\n"),
access, element_name);
return FALSE;
}
property = property_info_new (name, type, access_flags);
interface_info_add_property (parser->interface, property);
property_info_unref (property);
parser->property = property;
return TRUE;
}
static gboolean
parse_arg (Parser *parser,
const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error)
{
const char *name;
const char *type;
const char *direction;
ArgDirection dir;
ArgInfo *arg;
char *generated_name;
if (!(parser->method || parser->signal) ||
parser->node_stack == NULL ||
parser->property ||
parser->in_annotation ||
parser->arg)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Can't put <%s> element here"),
element_name);
return FALSE;
}
name = NULL;
if (!locate_attributes (element_name, attribute_names,
attribute_values, error,
"name", &name,
"type", &type,
"direction", &direction,
NULL))
return FALSE;
/* name can be null for args */
if (type == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"type", element_name);
return FALSE;
}
if (direction == NULL)
{
/* methods default to in, signal to out */
if (parser->method)
direction = "in";
else if (parser->signal)
direction = "out";
else
g_assert_not_reached ();
}
dir = ARG_INVALID;
if (strcmp (direction, "in") == 0)
dir = ARG_IN;
else if (strcmp (direction, "out") == 0)
dir = ARG_OUT;
if (dir == ARG_INVALID ||
(parser->signal && dir == ARG_IN))
{
if (parser->signal)
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Signals must have direction=\"out\" (just omit the direction attribute)"));
else
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute on <%s> has value \"in\" or \"out\""),
"direction", element_name);
return FALSE;
}
if (!validate_signature (type, element_name, error))
return FALSE;
generated_name = NULL;
if (name == NULL)
generated_name = g_strdup_printf ("arg%d",
parser->method ?
method_info_get_n_args (parser->method) :
signal_info_get_n_args (parser->signal));
arg = arg_info_new (name ? name : generated_name, dir, type);
if (parser->method)
method_info_add_arg (parser->method, arg);
else if (parser->signal)
signal_info_add_arg (parser->signal, arg);
else
g_assert_not_reached ();
g_free (generated_name);
arg_info_unref (arg);
parser->arg = arg;
return TRUE;
}
static gboolean
parse_annotation (Parser *parser,
const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error)
{
const char *name;
const char *value;
if (!(parser->method || parser->interface || parser->arg) ||
parser->node_stack == NULL ||
parser->signal ||
parser->property ||
parser->in_annotation)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Can't put <%s> element here"),
element_name);
return FALSE;
}
name = NULL;
if (!locate_attributes (element_name, attribute_names,
attribute_values, error,
"name", &name,
"value", &value,
NULL))
return FALSE;
if (name == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"name", element_name);
return FALSE;
}
if (value == NULL)
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("\"%s\" attribute required on <%s> element "),
"value", element_name);
return FALSE;
}
if (parser->arg)
arg_info_add_annotation (parser->arg, name, value);
else if (parser->method)
method_info_add_annotation (parser->method, name, value);
else if (parser->interface)
interface_info_add_annotation (parser->interface, name, value);
else
g_assert_not_reached ();
parser->in_annotation = TRUE;
return TRUE;
}
gboolean
parser_start_element (Parser *parser,
const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error)
{
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (ELEMENT_IS ("node"))
{
if (!parse_node (parser, element_name, attribute_names,
attribute_values, error))
return FALSE;
}
else if (ELEMENT_IS ("interface"))
{
if (!parse_interface (parser, element_name, attribute_names,
attribute_values, error))
return FALSE;
}
else if (ELEMENT_IS ("method"))
{
if (!parse_method (parser, element_name, attribute_names,
attribute_values, error))
return FALSE;
}
else if (ELEMENT_IS ("signal"))
{
if (!parse_signal (parser, element_name, attribute_names,
attribute_values, error))
return FALSE;
}
else if (ELEMENT_IS ("property"))
{
if (!parse_property (parser, element_name, attribute_names,
attribute_values, error))
return FALSE;
}
else if (ELEMENT_IS ("arg"))
{
if (!parse_arg (parser, element_name, attribute_names,
attribute_values, error))
return FALSE;
}
else if (ELEMENT_IS ("annotation"))
{
if (!parse_annotation (parser, element_name, attribute_names,
attribute_values, error))
return FALSE;
}
else
{
g_set_error (error, G_MARKUP_ERROR,
G_MARKUP_ERROR_PARSE,
_("Element <%s> not recognized"),
element_name);
}
return TRUE;
}
gboolean
parser_end_element (Parser *parser,
const char *element_name,
GError **error)
{
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (ELEMENT_IS ("interface"))
{
parser->interface = NULL;
}
else if (ELEMENT_IS ("method"))
{
parser->method = NULL;
}
else if (ELEMENT_IS ("signal"))
{
parser->signal = NULL;
}
else if (ELEMENT_IS ("property"))
{
parser->property = NULL;
}
else if (ELEMENT_IS ("arg"))
{
parser->arg = NULL;
}
else if (ELEMENT_IS ("annotation"))
{
parser->in_annotation = FALSE;
}
else if (ELEMENT_IS ("node"))
{
NodeInfo *top;
g_assert (parser->node_stack != NULL);
top = parser->node_stack->data;
parser->node_stack = g_slist_remove (parser->node_stack,
top);
if (parser->node_stack == NULL)
parser->result = top; /* We are done, store the result */
}
else
g_assert_not_reached (); /* should have had an error on start_element */
return TRUE;
}
gboolean
parser_content (Parser *parser,
const char *content,
int len,
GError **error)
{
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
/* FIXME check that it's all whitespace */
return TRUE;
}
gboolean
parser_finished (Parser *parser,
GError **error)
{
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return TRUE;
}
NodeInfo*
parser_get_nodes (Parser *parser)
{
return parser->result;
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

View file

@ -1,65 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gparser.h parse DBus description files
*
* Copyright (C) 2003 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GLIB_PARSER_H
#define DBUS_GLIB_PARSER_H
#include <dbus/dbus.h>
#include <glib.h>
#include "dbus-gidl.h"
G_BEGIN_DECLS
typedef struct Parser Parser;
Parser* parser_new (void);
Parser* parser_ref (Parser *parser);
void parser_unref (Parser *parser);
gboolean parser_check_doctype (Parser *parser,
const char *doctype,
GError **error);
gboolean parser_start_element (Parser *parser,
const char *element_name,
const char **attribute_names,
const char **attribute_values,
GError **error);
gboolean parser_end_element (Parser *parser,
const char *element_name,
GError **error);
gboolean parser_content (Parser *parser,
const char *content,
int len,
GError **error);
gboolean parser_finished (Parser *parser,
GError **error);
NodeInfo* description_load_from_file (const char *filename,
GError **error);
NodeInfo* description_load_from_string (const char *str,
int len,
GError **error);
NodeInfo* parser_get_nodes (Parser *parser);
G_END_DECLS
#endif /* DBUS_GLIB_GPARSER_H */

File diff suppressed because it is too large Load diff

View file

@ -1,210 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gsignature.c Mapping from dbus type signatures to GType
*
* Copyright (C) 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "config.h"
#include "dbus-gtest.h"
#include "dbus-gsignature.h"
#include "dbus-gvalue-utils.h"
#include <string.h>
#include <glib.h>
#define MAP_BASIC(d_t, g_t) \
case DBUS_TYPE_##d_t: \
return G_TYPE_##g_t;
static GType
typecode_to_gtype (int type)
{
switch (type)
{
MAP_BASIC (BOOLEAN, BOOLEAN);
MAP_BASIC (BYTE, UCHAR);
MAP_BASIC (INT16, INT);
MAP_BASIC (INT32, INT);
MAP_BASIC (UINT16, UINT);
MAP_BASIC (UINT32, UINT);
MAP_BASIC (INT64, INT64);
MAP_BASIC (UINT64, UINT64);
MAP_BASIC (DOUBLE, DOUBLE);
MAP_BASIC (STRING, STRING);
default:
return G_TYPE_INVALID;
}
}
#undef MAP_BASIC
static gboolean
dbus_typecode_maps_to_basic (int typecode)
{
return typecode_to_gtype (typecode) != G_TYPE_INVALID;
}
GType
_dbus_gtype_from_basic_typecode (int typecode)
{
g_assert (dbus_type_is_basic (typecode));
g_assert (dbus_typecode_maps_to_basic (typecode));
return typecode_to_gtype (typecode);
}
static GType
signature_iter_to_g_type_dict (const DBusSignatureIter *subiter, gboolean is_client)
{
DBusSignatureIter iter;
GType key_gtype;
GType value_gtype;
g_assert (dbus_signature_iter_get_current_type (subiter) == DBUS_TYPE_DICT_ENTRY);
dbus_signature_iter_recurse (subiter, &iter);
key_gtype = _dbus_gtype_from_signature_iter (&iter, is_client);
if (key_gtype == G_TYPE_INVALID)
return G_TYPE_INVALID;
dbus_signature_iter_next (&iter);
value_gtype = _dbus_gtype_from_signature_iter (&iter, is_client);
if (value_gtype == G_TYPE_INVALID)
return G_TYPE_INVALID;
if (!_dbus_gtype_is_valid_hash_key (key_gtype)
|| !_dbus_gtype_is_valid_hash_value (value_gtype))
/* Later we need to return DBUS_TYPE_G_VALUE */
return G_TYPE_INVALID;
return dbus_g_type_get_map ("GHashTable", key_gtype, value_gtype);
}
static GType
signature_iter_to_g_type_array (DBusSignatureIter *iter, gboolean is_client)
{
GType elt_gtype;
elt_gtype = _dbus_gtype_from_signature_iter (iter, is_client);
if (elt_gtype == G_TYPE_INVALID)
return G_TYPE_INVALID;
if (elt_gtype == G_TYPE_OBJECT)
return DBUS_TYPE_G_OBJECT_ARRAY;
if (elt_gtype == G_TYPE_STRING)
return G_TYPE_STRV;
if (_dbus_g_type_is_fixed (elt_gtype))
return dbus_g_type_get_collection ("GArray", elt_gtype);
else if (g_type_is_a (elt_gtype, G_TYPE_OBJECT)
|| g_type_is_a (elt_gtype, G_TYPE_BOXED))
return dbus_g_type_get_collection ("GPtrArray", elt_gtype);
/* Later we need to return DBUS_TYPE_G_VALUE */
return G_TYPE_INVALID;
}
static GType
signature_iter_to_g_type_struct (DBusSignatureIter *iter, gboolean is_client)
{
GArray *types;
GType ret;
types = g_array_new (FALSE, FALSE, sizeof (GType));
do
{
GType curtype;
curtype = _dbus_gtype_from_signature_iter (iter, is_client);
g_array_append_val (types, curtype);
}
while (dbus_signature_iter_next (iter));
ret = dbus_g_type_get_structv ("GValueArray", types->len, (GType*) types->data);
g_array_free (types, TRUE);
return ret;
}
GType
_dbus_gtype_from_signature_iter (DBusSignatureIter *iter, gboolean is_client)
{
int current_type;
current_type = dbus_signature_iter_get_current_type (iter);
/* TODO: handle type 0? */
if (dbus_typecode_maps_to_basic (current_type))
return _dbus_gtype_from_basic_typecode (current_type);
else if (current_type == DBUS_TYPE_OBJECT_PATH)
return DBUS_TYPE_G_OBJECT_PATH;
else
{
DBusSignatureIter subiter;
g_assert (dbus_type_is_container (current_type));
if (current_type == DBUS_TYPE_VARIANT)
return G_TYPE_VALUE;
dbus_signature_iter_recurse (iter, &subiter);
if (current_type == DBUS_TYPE_ARRAY)
{
int elt_type = dbus_signature_iter_get_current_type (&subiter);
if (elt_type == DBUS_TYPE_DICT_ENTRY)
return signature_iter_to_g_type_dict (&subiter, is_client);
else
return signature_iter_to_g_type_array (&subiter, is_client);
}
else if (current_type == DBUS_TYPE_STRUCT)
{
return signature_iter_to_g_type_struct (&subiter, is_client);
}
else
{
g_assert_not_reached ();
return G_TYPE_INVALID;
}
}
}
GType
_dbus_gtype_from_signature (const char *signature, gboolean is_client)
{
DBusSignatureIter iter;
dbus_signature_iter_init (&iter, signature);
return _dbus_gtype_from_signature_iter (&iter, is_client);
}
GArray *
_dbus_gtypes_from_arg_signature (const char *argsig, gboolean is_client)
{
GArray *ret;
int current_type;
DBusSignatureIter sigiter;
ret = g_array_new (FALSE, FALSE, sizeof (GType));
dbus_signature_iter_init (&sigiter, argsig);
while ((current_type = dbus_signature_iter_get_current_type (&sigiter)) != DBUS_TYPE_INVALID)
{
GType curtype;
curtype = _dbus_gtype_from_signature_iter (&sigiter, is_client);
g_array_append_val (ret, curtype);
dbus_signature_iter_next (&sigiter);
}
return ret;
}

View file

@ -1,19 +0,0 @@
#ifndef DBUS_GOBJECT_SIGNATURE_H
#define DBUS_GOBJECT_SIGNATURE_H
#include <dbus/dbus.h>
#include <dbus/dbus-signature.h>
#include <glib.h>
GType _dbus_gtype_from_basic_typecode (int typecode);
GType _dbus_gtype_from_signature (const char *signature,
gboolean is_client);
GType _dbus_gtype_from_signature_iter (DBusSignatureIter *sigiter,
gboolean is_client);
GArray * _dbus_gtypes_from_arg_signature (const char *signature,
gboolean is_client);
#endif

View file

@ -1,51 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gtest-main.c Program to run all libdbus-glib tests
*
* Copyright (C) 2003 Red Hat Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#ifdef DBUS_BUILD_TESTS
#include "dbus-gtest.h"
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int
main (int argc,
char **argv)
{
const char *test_data_dir;
setlocale(LC_ALL, "");
if (argc > 1)
test_data_dir = argv[1];
else
test_data_dir = NULL;
dbus_glib_internal_do_not_use_run_tests (test_data_dir);
return 0;
}
#endif

View file

@ -1,92 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-test.c Program to run all tests
*
* Copyright (C) 2002, 2003 Red Hat Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include "dbus-gtest.h"
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#ifdef DBUS_BUILD_TESTS
static void
die (const char *failure)
{
fprintf (stderr, "Unit test failed: %s\n", failure);
exit (1);
}
#endif /* DBUS_BUILD_TESTS */
/**
* An exported symbol to be run in order to execute
* unit tests. Should not be used by
* any app other than our test app, this symbol
* won't exist in some builds of the library.
* (with --enable-tests=no)
*
* @param test_data_dir the directory with test data (test/data normally)
*/
void
dbus_glib_internal_do_not_use_run_tests (const char *test_data_dir)
{
#ifdef DBUS_BUILD_TESTS
if (test_data_dir == NULL)
test_data_dir = g_getenv ("DBUS_TEST_DATA");
if (test_data_dir != NULL)
printf ("Test data in %s\n", test_data_dir);
else
printf ("No test data!\n");
g_type_init ();
printf ("%s: running GValue util tests\n", "dbus-glib-test");
if (!_dbus_gvalue_utils_test (test_data_dir))
die ("gvalue utils");
printf ("%s: running GValue tests\n", "dbus-glib-test");
if (!_dbus_gvalue_test (test_data_dir))
die ("gvalue utils");
printf ("%s: running glib tests\n", "dbus-glib-test");
if (!_dbus_glib_test (test_data_dir))
die ("glib");
printf ("%s: running utils tests\n", "dbus-glib-test");
if (!_dbus_gutils_test (test_data_dir))
die ("gutils");
printf ("%s: running mainloop integration tests\n", "dbus-glib-test");
if (!_dbus_gmain_test (test_data_dir))
die ("gmain");
printf ("%s: running GObject tests\n", "dbus-glib-test");
if (!_dbus_gobject_test (test_data_dir))
die ("gobject");
printf ("%s: completed successfully\n", "dbus-glib-test");
#else
printf ("Not compiled with unit tests, not running any\n");
#endif
}

View file

@ -1,38 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gtest.h Declarations of test functions.
*
* Copyright (C) 2003 Red Hat Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GLIB_TEST_H
#define DBUS_GLIB_TEST_H
#include <dbus/dbus-glib.h>
gboolean _dbus_gmain_test (const char *test_data_dir);
gboolean _dbus_gobject_test (const char *test_data_dir);
gboolean _dbus_gutils_test (const char *test_data_dir);
gboolean _dbus_glib_test (const char *test_data_dir);
gboolean _dbus_gvalue_test (const char *test_data_dir);
gboolean _dbus_gvalue_utils_test (const char *test_data_dir);
void dbus_glib_internal_do_not_use_run_tests (const char *test_data_dir);
#endif /* DBUS_GLIB_TEST_H */

View file

@ -1,179 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gthread.c GThread integration
*
* Copyright (C) 2002 CodeFactory AB
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* #define G_DEBUG_LOCKS 1 */
#include <glib.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
/** @addtogroup DBusGLibInternals
* @{
*/
static DBusMutex * dbus_gmutex_new (void);
static void dbus_gmutex_free (DBusMutex *mutex);
static dbus_bool_t dbus_gmutex_lock (DBusMutex *mutex);
static dbus_bool_t dbus_gmutex_unlock (DBusMutex *mutex);
static DBusCondVar* dbus_gcondvar_new (void);
static void dbus_gcondvar_free (DBusCondVar *cond);
static void dbus_gcondvar_wait (DBusCondVar *cond,
DBusMutex *mutex);
static dbus_bool_t dbus_gcondvar_wait_timeout (DBusCondVar *cond,
DBusMutex *mutex,
int timeout_msec);
static void dbus_gcondvar_wake_one (DBusCondVar *cond);
static void dbus_gcondvar_wake_all (DBusCondVar *cond);
static const 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,
dbus_gmutex_new,
dbus_gmutex_free,
dbus_gmutex_lock,
dbus_gmutex_unlock,
dbus_gcondvar_new,
dbus_gcondvar_free,
dbus_gcondvar_wait,
dbus_gcondvar_wait_timeout,
dbus_gcondvar_wake_one,
dbus_gcondvar_wake_all
};
static DBusMutex *
dbus_gmutex_new (void)
{
GMutex *mutex;
mutex = g_mutex_new ();
return (DBusMutex *)mutex;
}
static void
dbus_gmutex_free (DBusMutex *mutex)
{
g_mutex_free ((GMutex *)mutex);
}
static dbus_bool_t
dbus_gmutex_lock (DBusMutex *mutex)
{
g_mutex_lock ((GMutex *)mutex);
return TRUE;
}
static dbus_bool_t
dbus_gmutex_unlock (DBusMutex *mutex)
{
g_mutex_unlock ((GMutex *)mutex);
return TRUE;
}
static DBusCondVar*
dbus_gcondvar_new (void)
{
return (DBusCondVar*)g_cond_new ();
}
static void
dbus_gcondvar_free (DBusCondVar *cond)
{
g_cond_free ((GCond *)cond);
}
static void
dbus_gcondvar_wait (DBusCondVar *cond,
DBusMutex *mutex)
{
g_cond_wait ((GCond *)cond, (GMutex *)mutex);
}
static dbus_bool_t
dbus_gcondvar_wait_timeout (DBusCondVar *cond,
DBusMutex *mutex,
int timeout_msec)
{
GTimeVal now;
g_get_current_time (&now);
now.tv_sec += timeout_msec / 1000;
now.tv_usec += (timeout_msec % 1000) * 1000;
if (now.tv_usec > G_USEC_PER_SEC)
{
now.tv_sec += 1;
now.tv_usec -= G_USEC_PER_SEC;
}
return g_cond_timed_wait ((GCond *)cond, (GMutex *)mutex, &now);
}
static void
dbus_gcondvar_wake_one (DBusCondVar *cond)
{
g_cond_signal ((GCond *)cond);
}
static void
dbus_gcondvar_wake_all (DBusCondVar *cond)
{
g_cond_broadcast ((GCond *)cond);
}
/** @} End of internals */
/** @addtogroup DBusGLib
* @{
*/
/**
* Initializes the D-BUS thread system to use
* GLib threads. This function may only be called
* once and must be called prior to calling any
* other function in the D-BUS API.
*/
void
dbus_g_thread_init (void)
{
if (!g_thread_supported ())
g_error ("g_thread_init() must be called before dbus_threads_init()");
dbus_threads_init (&functions);
}
/** @} end of public API */

View file

@ -1,31 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gtool-test.h Declarations of test functions for dbus-glib-tool.
*
* Copyright (C) 2003 Red Hat Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GLIB_TOOL_TEST_H
#define DBUS_GLIB_TOOL_TEST_H
#include <dbus/dbus-glib.h>
gboolean _dbus_gtool_test (const char *test_data_dir);
#endif /* DBUS_GLIB_TEST_H */

View file

@ -1,778 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gtype-specialized.c: Non-DBus-specific functions for specialized GTypes
*
* Copyright (C) 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "dbus-gtype-specialized.h"
#include <glib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>
typedef enum {
DBUS_G_SPECTYPE_COLLECTION,
DBUS_G_SPECTYPE_MAP,
DBUS_G_SPECTYPE_STRUCT
} DBusGTypeSpecializedType;
typedef struct {
DBusGTypeSpecializedType type;
const DBusGTypeSpecializedVtable *vtable;
} DBusGTypeSpecializedContainer;
typedef struct {
guint num_types;
GType *types;
const DBusGTypeSpecializedContainer *klass;
} DBusGTypeSpecializedData;
static GHashTable /* char * -> data* */ *specialized_containers;
static GQuark
specialized_type_data_quark ()
{
static GQuark quark;
if (!quark)
quark = g_quark_from_static_string ("DBusGTypeSpecializedData");
return quark;
}
void
dbus_g_type_specialized_init (void)
{
specialized_containers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
}
static gboolean
specialized_types_is_initialized (void)
{
return specialized_containers != NULL;
}
static DBusGTypeSpecializedData *
lookup_specialization_data (GType type)
{
return g_type_get_qdata (type, specialized_type_data_quark ());
}
/* Copied from gboxed.c */
static void
proxy_value_init (GValue *value)
{
value->data[0].v_pointer = NULL;
}
/* Adapted from gboxed.c */
static void
proxy_value_free (GValue *value)
{
if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
{
DBusGTypeSpecializedData *data;
GType type;
type = G_VALUE_TYPE (value);
data = lookup_specialization_data (type);
g_assert (data != NULL);
if (data->klass->vtable->free_func)
{
data->klass->vtable->free_func (type, value->data[0].v_pointer);
}
else
{
g_assert (data->klass->vtable->simple_free_func != NULL);
data->klass->vtable->simple_free_func (value->data[0].v_pointer);
}
}
}
/* Adapted from gboxed.c */
static void
proxy_value_copy (const GValue *src_value,
GValue *dest_value)
{
if (src_value->data[0].v_pointer)
{
DBusGTypeSpecializedData *data;
GType type;
type = G_VALUE_TYPE (src_value);
data = lookup_specialization_data (type);
g_assert (data != NULL);
dest_value->data[0].v_pointer = data->klass->vtable->copy_func (type, src_value->data[0].v_pointer);
}
else
dest_value->data[0].v_pointer = src_value->data[0].v_pointer;
}
/* Copied from gboxed.c */
static gpointer
proxy_value_peek_pointer (const GValue *value)
{
return value->data[0].v_pointer;
}
/* Adapted from gboxed.c */
static gchar*
proxy_collect_value (GValue *value,
guint n_collect_values,
GTypeCValue *collect_values,
guint collect_flags)
{
DBusGTypeSpecializedData *data;
GType type;
type = G_VALUE_TYPE (value);
data = lookup_specialization_data (type);
if (!collect_values[0].v_pointer)
value->data[0].v_pointer = NULL;
else
{
if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
{
value->data[0].v_pointer = collect_values[0].v_pointer;
value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
}
else
{
value->data[0].v_pointer = data->klass->vtable->copy_func (type, collect_values[0].v_pointer);
}
}
return NULL;
}
/* Adapted from gboxed.c */
static gchar*
proxy_lcopy_value (const GValue *value,
guint n_collect_values,
GTypeCValue *collect_values,
guint collect_flags)
{
gpointer *boxed_p = collect_values[0].v_pointer;
if (!boxed_p)
return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
if (!value->data[0].v_pointer)
*boxed_p = NULL;
else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
*boxed_p = value->data[0].v_pointer;
else
{
DBusGTypeSpecializedData *data;
GType type;
type = G_VALUE_TYPE (value);
data = lookup_specialization_data (type);
*boxed_p = data->klass->vtable->copy_func (type, value->data[0].v_pointer);
}
return NULL;
}
static char *
build_specialization_name (const char *prefix, guint num_types, GType *types)
{
GString *fullname;
guint i;
fullname = g_string_new (prefix);
g_string_append_c (fullname, '_');
for (i=0; i < num_types; i++)
{
if (i!=0)
g_string_append_c (fullname, '+');
g_string_append (fullname, g_type_name (types[i]));
}
g_string_append_c (fullname, '_');
return g_string_free (fullname, FALSE);
}
static void
register_container (const char *name,
DBusGTypeSpecializedType type,
const DBusGTypeSpecializedVtable *vtable)
{
DBusGTypeSpecializedContainer *klass;
klass = g_new0 (DBusGTypeSpecializedContainer, 1);
klass->type = type;
klass->vtable = vtable;
g_hash_table_insert (specialized_containers, g_strdup (name), klass);
}
void
dbus_g_type_register_collection (const char *name,
const DBusGTypeSpecializedCollectionVtable *vtable,
guint flags)
{
g_return_if_fail (specialized_types_is_initialized ());
register_container (name, DBUS_G_SPECTYPE_COLLECTION, (const DBusGTypeSpecializedVtable*) vtable);
}
void
dbus_g_type_register_map (const char *name,
const DBusGTypeSpecializedMapVtable *vtable,
guint flags)
{
g_return_if_fail (specialized_types_is_initialized ());
register_container (name, DBUS_G_SPECTYPE_MAP, (const DBusGTypeSpecializedVtable*) vtable);
}
void
dbus_g_type_register_struct (const char *name,
const DBusGTypeSpecializedStructVtable *vtable,
guint flags)
{
g_return_if_fail (specialized_types_is_initialized ());
register_container (name, DBUS_G_SPECTYPE_STRUCT, (const DBusGTypeSpecializedVtable*) vtable);
}
const DBusGTypeSpecializedMapVtable* dbus_g_type_map_peek_vtable (GType map_type)
{
DBusGTypeSpecializedData *data;
g_return_val_if_fail (dbus_g_type_is_map(map_type), NULL);
data = lookup_specialization_data (map_type);
g_assert (data != NULL);
return (DBusGTypeSpecializedMapVtable *)(data->klass->vtable);
}
const DBusGTypeSpecializedCollectionVtable* dbus_g_type_collection_peek_vtable (GType collection_type)
{
DBusGTypeSpecializedData *data;
g_return_val_if_fail (dbus_g_type_is_collection(collection_type), NULL);
data = lookup_specialization_data (collection_type);
g_assert (data != NULL);
return (DBusGTypeSpecializedCollectionVtable *)(data->klass->vtable);
}
const DBusGTypeSpecializedStructVtable* dbus_g_type_struct_peek_vtable (GType struct_type)
{
DBusGTypeSpecializedData *data;
g_return_val_if_fail (dbus_g_type_is_struct (struct_type), NULL);
data = lookup_specialization_data (struct_type);
g_assert (data != NULL);
return (DBusGTypeSpecializedStructVtable *)(data->klass->vtable);
}
static GType
register_specialized_instance (const DBusGTypeSpecializedContainer *klass,
char *name,
guint num_types,
GType *types)
{
GType ret;
static const GTypeValueTable vtable =
{
proxy_value_init,
proxy_value_free,
proxy_value_copy,
proxy_value_peek_pointer,
"p",
proxy_collect_value,
"p",
proxy_lcopy_value,
};
static const GTypeInfo derived_info =
{
0, /* class_size */
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
0, /* instance_size */
0, /* n_preallocs */
NULL, /* instance_init */
&vtable, /* value_table */
};
ret = g_type_register_static (G_TYPE_BOXED, name, &derived_info, 0);
/* install proxy functions upon successfull registration */
if (ret != G_TYPE_INVALID)
{
DBusGTypeSpecializedData *data;
data = g_new0 (DBusGTypeSpecializedData, 1);
data->num_types = num_types;
data->types = g_memdup (types, sizeof (GType) * num_types);
data->klass = klass;
g_type_set_qdata (ret, specialized_type_data_quark (), data);
}
return ret;
}
static GType
lookup_or_register_specialized (const char *container,
guint num_types,
GType *types)
{
GType ret;
char *name;
const DBusGTypeSpecializedContainer *klass;
g_return_val_if_fail (specialized_types_is_initialized (), G_TYPE_INVALID);
klass = g_hash_table_lookup (specialized_containers, container);
g_return_val_if_fail (klass != NULL, G_TYPE_INVALID);
name = build_specialization_name (container, num_types, types);
ret = g_type_from_name (name);
if (ret == G_TYPE_INVALID)
{
/* Take ownership of name */
ret = register_specialized_instance (klass, name,
num_types,
types);
}
else
g_free (name);
return ret;
}
GType
dbus_g_type_get_collection (const char *container,
GType specialization)
{
return lookup_or_register_specialized (container, 1, &specialization);
}
GType
dbus_g_type_get_map (const char *container,
GType key_specialization,
GType value_specialization)
{
GType types[2] = {key_specialization, value_specialization};
return lookup_or_register_specialized (container, 2, types);
}
GType
dbus_g_type_get_structv (const char *container,
guint num_items,
GType *types)
{
return lookup_or_register_specialized (container, num_items, types);
}
GType
dbus_g_type_get_struct (const char *container,
GType first_type,
...)
{
GArray *types;
GType curtype, ret;
va_list args;
va_start (args, first_type);
types = g_array_new (FALSE, FALSE, sizeof (GType));
curtype = first_type;
while (curtype != G_TYPE_INVALID)
{
g_array_append_val (types, curtype);
curtype = va_arg (args, GType);
}
va_end (args);
ret = lookup_or_register_specialized (container, types->len,
(GType *) types->data);
g_array_free (types, TRUE);
return ret;
}
gboolean
dbus_g_type_is_collection (GType gtype)
{
DBusGTypeSpecializedData *data;
data = lookup_specialization_data (gtype);
if (data == NULL)
return FALSE;
return data->klass->type == DBUS_G_SPECTYPE_COLLECTION;
}
gboolean
dbus_g_type_is_map (GType gtype)
{
DBusGTypeSpecializedData *data;
data = lookup_specialization_data (gtype);
if (data == NULL)
return FALSE;
return data->klass->type == DBUS_G_SPECTYPE_MAP;
}
gboolean
dbus_g_type_is_struct (GType gtype)
{
DBusGTypeSpecializedData *data;
data = lookup_specialization_data (gtype);
if (data == NULL)
return FALSE;
return data->klass->type == DBUS_G_SPECTYPE_STRUCT;
}
static GType
get_specialization_index (GType gtype, guint i)
{
DBusGTypeSpecializedData *data;
data = lookup_specialization_data (gtype);
if (i < data->num_types)
return data->types[i];
else
return G_TYPE_INVALID;
}
GType
dbus_g_type_get_collection_specialization (GType gtype)
{
g_return_val_if_fail (dbus_g_type_is_collection (gtype), G_TYPE_INVALID);
return get_specialization_index (gtype, 0);
}
GType
dbus_g_type_get_map_key_specialization (GType gtype)
{
g_return_val_if_fail (dbus_g_type_is_map (gtype), G_TYPE_INVALID);
return get_specialization_index (gtype, 0);
}
GType
dbus_g_type_get_map_value_specialization (GType gtype)
{
g_return_val_if_fail (dbus_g_type_is_map (gtype), G_TYPE_INVALID);
return get_specialization_index (gtype, 1);
}
GType
dbus_g_type_get_struct_member_type (GType gtype, guint index)
{
g_return_val_if_fail (dbus_g_type_is_struct (gtype), G_TYPE_INVALID);
return get_specialization_index (gtype, index);
}
guint
dbus_g_type_get_struct_size (GType gtype)
{
DBusGTypeSpecializedData *data;
g_return_val_if_fail (dbus_g_type_is_struct (gtype), G_TYPE_INVALID);
data = lookup_specialization_data (gtype);
return data->num_types;
}
gpointer
dbus_g_type_specialized_construct (GType type)
{
DBusGTypeSpecializedData *data;
g_return_val_if_fail (specialized_types_is_initialized (), FALSE);
data = lookup_specialization_data (type);
g_return_val_if_fail (data != NULL, FALSE);
return data->klass->vtable->constructor (type);
}
gboolean
dbus_g_type_collection_get_fixed (GValue *value,
gpointer *data_ret,
guint *len_ret)
{
DBusGTypeSpecializedData *data;
GType gtype;
g_return_val_if_fail (specialized_types_is_initialized (), FALSE);
g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), FALSE);
gtype = G_VALUE_TYPE (value);
data = lookup_specialization_data (gtype);
g_return_val_if_fail (data != NULL, FALSE);
return ((DBusGTypeSpecializedCollectionVtable *) (data->klass->vtable))->fixed_accessor (gtype,
g_value_get_boxed (value),
data_ret, len_ret);
}
void
dbus_g_type_collection_value_iterate (const GValue *value,
DBusGTypeSpecializedCollectionIterator iterator,
gpointer user_data)
{
DBusGTypeSpecializedData *data;
GType gtype;
g_return_if_fail (specialized_types_is_initialized ());
g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
gtype = G_VALUE_TYPE (value);
data = lookup_specialization_data (gtype);
g_return_if_fail (data != NULL);
((DBusGTypeSpecializedCollectionVtable *) data->klass->vtable)->iterator (gtype,
g_value_get_boxed (value),
iterator, user_data);
}
typedef struct {
GValue *val;
GType specialization_type;
DBusGTypeSpecializedData *specdata;
} DBusGTypeSpecializedAppendContextReal;
void
dbus_g_type_specialized_init_append (GValue *value, DBusGTypeSpecializedAppendContext *ctx)
{
DBusGTypeSpecializedAppendContextReal *realctx = (DBusGTypeSpecializedAppendContextReal *) ctx;
GType gtype;
DBusGTypeSpecializedData *specdata;
g_return_if_fail (specialized_types_is_initialized ());
g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
gtype = G_VALUE_TYPE (value);
specdata = lookup_specialization_data (gtype);
g_return_if_fail (specdata != NULL);
g_return_if_fail (specdata->num_types != 0);
realctx->val = value;
realctx->specialization_type = specdata->types[0];
realctx->specdata = specdata;
}
void
dbus_g_type_specialized_collection_append (DBusGTypeSpecializedAppendContext *ctx,
GValue *elt)
{
DBusGTypeSpecializedAppendContextReal *realctx = (DBusGTypeSpecializedAppendContextReal *) ctx;
((DBusGTypeSpecializedCollectionVtable *) realctx->specdata->klass->vtable)->append_func (ctx, elt);
}
void
dbus_g_type_specialized_collection_end_append (DBusGTypeSpecializedAppendContext *ctx)
{
DBusGTypeSpecializedAppendContextReal *realctx = (DBusGTypeSpecializedAppendContextReal *) ctx;
if (((DBusGTypeSpecializedCollectionVtable *) realctx->specdata->klass->vtable)->end_append_func != NULL)
((DBusGTypeSpecializedCollectionVtable *) realctx->specdata->klass->vtable)->end_append_func (ctx);
}
void
dbus_g_type_specialized_map_append (DBusGTypeSpecializedAppendContext *ctx,
GValue *key,
GValue *val)
{
DBusGTypeSpecializedAppendContextReal *realctx = (DBusGTypeSpecializedAppendContextReal *) ctx;
((DBusGTypeSpecializedMapVtable *) realctx->specdata->klass->vtable)->append_func (ctx, key, val);
}
void
dbus_g_type_map_value_iterate (const GValue *value,
DBusGTypeSpecializedMapIterator iterator,
gpointer user_data)
{
DBusGTypeSpecializedData *data;
GType gtype;
g_return_if_fail (specialized_types_is_initialized ());
g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
gtype = G_VALUE_TYPE (value);
data = lookup_specialization_data (gtype);
g_return_if_fail (data != NULL);
((DBusGTypeSpecializedMapVtable *) data->klass->vtable)->iterator (gtype,
g_value_get_boxed (value),
iterator, user_data);
}
gboolean
dbus_g_type_struct_get_member (const GValue *value,
guint index,
GValue *dest)
{
DBusGTypeSpecializedData *data;
GType gtype;
g_return_val_if_fail (specialized_types_is_initialized (), FALSE);
g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), FALSE);
gtype = G_VALUE_TYPE (value);
data = lookup_specialization_data (gtype);
g_return_val_if_fail (data != NULL, FALSE);
return ((DBusGTypeSpecializedStructVtable *) (data->klass->vtable))->get_member(gtype,
g_value_get_boxed (value),
index, dest);
}
gboolean
dbus_g_type_struct_set_member (GValue *value,
guint index,
const GValue *src)
{
DBusGTypeSpecializedData *data;
GType gtype;
g_return_val_if_fail (specialized_types_is_initialized (), FALSE);
g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), FALSE);
gtype = G_VALUE_TYPE (value);
data = lookup_specialization_data (gtype);
g_return_val_if_fail (data != NULL, FALSE);
return ((DBusGTypeSpecializedStructVtable *) (data->klass->vtable))->set_member(gtype,
g_value_get_boxed (value),
index, src);
}
/**
* dbus_g_type_struct_get:
* @value: a GValue containing a DBusGTypeStruct type
* @member: struct member to get
* @...: location in which to return the value of this member,
* followed optionally by more member/return locations pairs, followed by
* by G_MAXUINT
*
* Collects the selected values of this struct into the return locations
* provided.
*
* Returns: FALSE on failure
*/
gboolean
dbus_g_type_struct_get (const GValue *value,
guint first_member,
...)
{
va_list var_args;
GType type;
guint size,i;
gchar *error;
GValue val = {0,};
g_return_val_if_fail (dbus_g_type_is_struct (G_VALUE_TYPE (value)), FALSE);
va_start (var_args, first_member);
size = dbus_g_type_get_struct_size (G_VALUE_TYPE (value));
i = first_member;
while (i != G_MAXUINT)
{
if (i >= size)
goto error;
type = dbus_g_type_get_struct_member_type (G_VALUE_TYPE (value),i);
g_value_init (&val, type);
dbus_g_type_struct_get_member (value, i, &val);
G_VALUE_LCOPY (&val, var_args, 0, &error);
if (error)
{
g_warning ("%s, %s", G_STRFUNC, error);
g_free (error);
g_value_unset (&val);
goto error;
}
g_value_unset (&val);
i = va_arg (var_args, guint);
}
va_end (var_args);
return TRUE;
error:
va_end (var_args);
return FALSE;
}
/**
* dbus_g_type_struct_set:
* @value: a GValue containing a DBusGTypeStruct type
* @member: struct member to set
* @...: value for the first member, followed optionally by
* more member/value pairs, followed by G_MAXUINT
*
* Sets the selected members of the struct in @value.
*
* Returns: FALSE on failure
*/
gboolean
dbus_g_type_struct_set (GValue *value,
guint first_member,
...)
{
va_list var_args;
GType type;
guint size,i;
gchar *error;
GValue val = {0,};
g_return_val_if_fail (dbus_g_type_is_struct (G_VALUE_TYPE (value)), FALSE);
va_start (var_args, first_member);
size = dbus_g_type_get_struct_size (G_VALUE_TYPE (value));
i = first_member;
while (i != G_MAXUINT)
{
if (i >= size)
goto error;
type = dbus_g_type_get_struct_member_type (G_VALUE_TYPE (value),i);
g_value_init (&val, type);
G_VALUE_COLLECT (&val, var_args, 0, &error);
if (error)
{
g_warning ("%s, %s", G_STRFUNC, error);
g_free (error);
g_value_unset (&val);
goto error;
}
dbus_g_type_struct_set_member (value, i, &val);
g_value_unset (&val);
i = va_arg (var_args, guint);
}
va_end (var_args);
return TRUE;
error:
va_end (var_args);
return FALSE;
}

View file

@ -1,176 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gtype-specialized.h: Non-DBus-specific functions for specialized GTypes
*
* Copyright (C) 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GOBJECT_TYPE_SPECIALIZED_H
#define DBUS_GOBJECT_TYPE_SPECIALIZED_H
#include <glib.h>
#include <glib-object.h>
G_BEGIN_DECLS
GType dbus_g_type_get_collection (const char *container,
GType specialization);
GType dbus_g_type_get_map (const char *container,
GType key_specialization,
GType value_specialization);
GType dbus_g_type_get_structv (const char *container,
guint num_items,
GType *types);
GType dbus_g_type_get_struct (const char *container,
GType first_type,
...);
gboolean dbus_g_type_is_collection (GType gtype);
gboolean dbus_g_type_is_map (GType gtype);
gboolean dbus_g_type_is_struct (GType gtype);
GType dbus_g_type_get_collection_specialization (GType gtype);
GType dbus_g_type_get_map_key_specialization (GType gtype);
GType dbus_g_type_get_map_value_specialization (GType gtype);
GType dbus_g_type_get_struct_member_type (GType gtype,
guint index);
guint dbus_g_type_get_struct_size (GType gtype);
typedef void (*DBusGTypeSpecializedCollectionIterator) (const GValue *val,
gpointer user_data);
typedef void (*DBusGTypeSpecializedMapIterator) (const GValue *key_val,
const GValue *value_val,
gpointer user_data);
gpointer dbus_g_type_specialized_construct (GType type);
typedef struct {
/* public */
GValue *val;
GType specialization_type;
/* padding */
gpointer b;
guint c;
gpointer d;
} DBusGTypeSpecializedAppendContext;
void dbus_g_type_specialized_init_append (GValue *val, DBusGTypeSpecializedAppendContext *ctx);
void dbus_g_type_specialized_collection_append (DBusGTypeSpecializedAppendContext *ctx, GValue *elt);
void dbus_g_type_specialized_collection_end_append (DBusGTypeSpecializedAppendContext *ctx);
void dbus_g_type_specialized_map_append (DBusGTypeSpecializedAppendContext *ctx,
GValue *key,
GValue *val);
gboolean dbus_g_type_collection_get_fixed (GValue *value,
gpointer *data,
guint *len);
void dbus_g_type_collection_value_iterate (const GValue *value,
DBusGTypeSpecializedCollectionIterator iterator,
gpointer user_data);
void dbus_g_type_map_value_iterate (const GValue *value,
DBusGTypeSpecializedMapIterator iterator,
gpointer user_data);
gboolean dbus_g_type_struct_get_member (const GValue *value,
guint index,
GValue *dest);
gboolean dbus_g_type_struct_set_member (GValue *value,
guint index,
const GValue *src);
gboolean dbus_g_type_struct_get (const GValue *value,
guint member,
...);
gboolean dbus_g_type_struct_set (GValue *value,
guint member,
...);
typedef gpointer (*DBusGTypeSpecializedConstructor) (GType type);
typedef void (*DBusGTypeSpecializedFreeFunc) (GType type, gpointer val);
typedef gpointer (*DBusGTypeSpecializedCopyFunc) (GType type, gpointer src);
typedef struct {
DBusGTypeSpecializedConstructor constructor;
DBusGTypeSpecializedFreeFunc free_func;
DBusGTypeSpecializedCopyFunc copy_func;
GDestroyNotify simple_free_func; /* for type-independent freeing if possible */
gpointer padding2;
gpointer padding3;
} DBusGTypeSpecializedVtable;
typedef gboolean (*DBusGTypeSpecializedCollectionFixedAccessorFunc) (GType type, gpointer instance, gpointer *values, guint *len);
typedef void (*DBusGTypeSpecializedCollectionIteratorFunc) (GType type, gpointer instance, DBusGTypeSpecializedCollectionIterator iterator, gpointer user_data);
typedef void (*DBusGTypeSpecializedCollectionAppendFunc) (DBusGTypeSpecializedAppendContext *ctx, GValue *val);
typedef void (*DBusGTypeSpecializedCollectionEndAppendFunc) (DBusGTypeSpecializedAppendContext *ctx);
typedef struct {
DBusGTypeSpecializedVtable base_vtable;
DBusGTypeSpecializedCollectionFixedAccessorFunc fixed_accessor;
DBusGTypeSpecializedCollectionIteratorFunc iterator;
DBusGTypeSpecializedCollectionAppendFunc append_func;
DBusGTypeSpecializedCollectionEndAppendFunc end_append_func;
} DBusGTypeSpecializedCollectionVtable;
typedef void (*DBusGTypeSpecializedMapIteratorFunc) (GType type, gpointer instance, DBusGTypeSpecializedMapIterator iterator, gpointer user_data);
typedef void (*DBusGTypeSpecializedMapAppendFunc) (DBusGTypeSpecializedAppendContext *ctx, GValue *key, GValue *val);
typedef struct {
DBusGTypeSpecializedVtable base_vtable;
DBusGTypeSpecializedMapIteratorFunc iterator;
DBusGTypeSpecializedMapAppendFunc append_func;
} DBusGTypeSpecializedMapVtable;
typedef gboolean (*DBusGTypeSpecializedStructGetMember) (GType type, gpointer instance, guint member, GValue *ret_value);
typedef gboolean (*DBusGTypeSpecializedStructSetMember) (GType type, gpointer instance, guint member, const GValue *new_value);
typedef struct {
DBusGTypeSpecializedVtable base_vtable;
DBusGTypeSpecializedStructGetMember get_member;
DBusGTypeSpecializedStructSetMember set_member;
} DBusGTypeSpecializedStructVtable;
void dbus_g_type_specialized_init (void);
void dbus_g_type_register_collection (const char *name,
const DBusGTypeSpecializedCollectionVtable *vtable,
guint flags);
void dbus_g_type_register_map (const char *name,
const DBusGTypeSpecializedMapVtable *vtable,
guint flags);
const DBusGTypeSpecializedMapVtable* dbus_g_type_map_peek_vtable (GType map_type);
const DBusGTypeSpecializedCollectionVtable* dbus_g_type_collection_peek_vtable (GType collection_type);
void dbus_g_type_register_struct (const char *name,
const DBusGTypeSpecializedStructVtable *vtable,
guint flags);
const DBusGTypeSpecializedMapVtable* dbus_g_type_map_peek_vtable (GType map_type);
const DBusGTypeSpecializedCollectionVtable* dbus_g_type_collection_peek_vtable (GType collection_type);
const DBusGTypeSpecializedStructVtable* dbus_g_type_struct_peek_vtable (GType struct_type);
G_END_DECLS
#endif

View file

@ -1,130 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gutils.c Utils shared between convenience lib and installed lib
*
* Copyright (C) 2003 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include "dbus-gutils.h"
#include "dbus-gtest.h"
#include <string.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
char**
_dbus_gutils_split_path (const char *path)
{
int len;
char **split;
int n_components;
int i, j, comp;
len = strlen (path);
n_components = 0;
if (path[1] != '\0') /* if not "/" */
{
i = 0;
while (i < len)
{
if (path[i] == '/')
n_components += 1;
++i;
}
}
split = g_new0 (char*, n_components + 1);
comp = 0;
if (n_components == 0)
i = 1;
else
i = 0;
while (comp < n_components)
{
if (path[i] == '/')
++i;
j = i;
while (j < len && path[j] != '/')
++j;
/* Now [i, j) is the path component */
g_assert (i < j);
g_assert (path[i] != '/');
g_assert (j == len || path[j] == '/');
split[comp] = g_strndup (&path[i], j - i + 1);
split[comp][j-i] = '\0';
++comp;
i = j;
}
g_assert (i == len);
return split;
}
char*
_dbus_gutils_wincaps_to_uscore (const char *caps)
{
const char *p;
GString *str;
str = g_string_new (NULL);
p = caps;
while (*p)
{
if (g_ascii_isupper (*p))
{
if (str->len > 0 &&
(str->len < 2 || str->str[str->len-2] != '_'))
g_string_append_c (str, '_');
g_string_append_c (str, g_ascii_tolower (*p));
}
else
{
g_string_append_c (str, *p);
}
++p;
}
return g_string_free (str, FALSE);
}
#ifdef DBUS_BUILD_TESTS
/**
* @ingroup DBusGLibInternals
* Unit test for GLib utils internals
* @returns #TRUE on success.
*/
gboolean
_dbus_gutils_test (const char *test_data_dir)
{
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

View file

@ -1,57 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gutils.h Utils shared between convenience lib and installed lib
*
* Copyright (C) 2003 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GLIB_UTILS_H
#define DBUS_GLIB_UTILS_H
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#include <dbus/dbus.h>
#include <glib-object.h>
G_BEGIN_DECLS
char **_dbus_gutils_split_path (const char *path);
char *_dbus_gutils_wincaps_to_uscore (const char *uscore);
/* These munge the pointer to enforce that a plain cast won't work,
* accessor functions must be used; i.e. to ensure the ABI
* reflects our encapsulation.
*/
#define _DBUS_POINTER_SHIFT(p) ((void*) (((char*)p) + sizeof (void*)))
#define _DBUS_POINTER_UNSHIFT(p) ((void*) (((char*)p) - sizeof (void*)))
#define DBUS_CONNECTION_FROM_G_CONNECTION(x) ((DBusConnection*) _DBUS_POINTER_UNSHIFT(x))
#define DBUS_MESSAGE_FROM_G_MESSAGE(x) ((DBusMessage*) _DBUS_POINTER_UNSHIFT(x))
#define DBUS_PENDING_CALL_FROM_G_PENDING_CALL(x) ((DBusPendingCall*) _DBUS_POINTER_UNSHIFT(x))
#define DBUS_G_CONNECTION_FROM_CONNECTION(x) ((DBusGConnection*) _DBUS_POINTER_SHIFT(x))
#define DBUS_G_MESSAGE_FROM_MESSAGE(x) ((DBusGMessage*) _DBUS_POINTER_SHIFT(x))
#define DBUS_G_PENDING_CALL_FROM_PENDING_CALL(x) ((DBusGPendingCall*) _DBUS_POINTER_SHIFT(x))
G_END_DECLS
#endif /* DBUS_GLIB_UTILS_H */
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

File diff suppressed because it is too large Load diff

View file

@ -1,73 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gvalue-utils.h: Non-DBus-specific functions related to GType/GValue
*
* Copyright (C) 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_GOBJECT_VALUE_UTILS_H
#define DBUS_GOBJECT_VALUE_UTILS_H
#include <glib.h>
#include <glib-object.h>
G_BEGIN_DECLS
void _dbus_g_type_specialized_builtins_init (void);
gboolean _dbus_g_type_is_fixed (GType gtype);
guint _dbus_g_type_fixed_get_size (GType gtype);
gboolean _dbus_gvalue_set_from_pointer (GValue *value,
gconstpointer storage);
typedef void (*DBusGHashValueForeachFunc) (GValue * key, GValue *val, gpointer data);
void _dbus_g_hash_table_value_foreach (GHashTable *table,
GType hash_type,
DBusGHashValueForeachFunc func,
gpointer data);
void _dbus_g_hash_table_insert_values (GHashTable *table,
GValue *key_val,
GValue *value_val);
void _dbus_g_hash_table_insert_steal_values (GHashTable *table,
GValue *key_val,
GValue *value_val);
gboolean _dbus_gtype_is_valid_hash_key (GType type);
gboolean _dbus_gtype_is_valid_hash_value (GType type);
GHashFunc _dbus_g_hash_func_from_gtype (GType gtype);
GEqualFunc _dbus_g_hash_equal_from_gtype (GType gtype);
GDestroyNotify _dbus_g_hash_free_from_gtype (GType gtype);
gboolean _dbus_gvalue_store (GValue *value,
gpointer storage);
gboolean _dbus_gvalue_take (GValue *value,
GTypeCValue *cvalue);
gboolean _dbus_gtype_can_signal_error (GType gtype);
gboolean _dbus_gvalue_signals_error (const GValue *value);
G_END_DECLS
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,43 +0,0 @@
#ifndef DBUS_GOBJECT_VALUE_H
#define DBUS_GOBJECT_VALUE_H
#include <dbus/dbus.h>
#include <dbus/dbus-signature.h>
#include <glib.h>
#include <glib-object.h>
#include "dbus/dbus-glib.h"
G_BEGIN_DECLS
typedef struct {
DBusGConnection *gconnection;
DBusGProxy *proxy;
} DBusGValueMarshalCtx;
void _dbus_g_value_types_init (void);
char * _dbus_gtype_to_signature (GType type);
char * _dbus_gvalue_to_signature (const GValue *val);
gboolean _dbus_gvalue_demarshal (DBusGValueMarshalCtx *context,
DBusMessageIter *iter,
GValue *value,
GError **error);
gboolean _dbus_gvalue_demarshal_variant (DBusGValueMarshalCtx *context,
DBusMessageIter *iter,
GValue *value,
GError **error);
GValueArray * _dbus_gvalue_demarshal_message (DBusGValueMarshalCtx *context,
DBusMessage *message,
guint n_params,
const GType *types,
GError **error);
gboolean _dbus_gvalue_marshal (DBusMessageIter *iter,
const GValue *value);
G_END_DECLS
#endif /* DBUS_GOBJECT_VALUE_H */

View file

@ -1,17 +0,0 @@
.deps
.libs
Makefile
Makefile.in
*.lo
*.la
example-client
example-service
example-service-glue.h
example-signal-recipient
example-signal-emitter
example-signal-emitter-glue.h
run-with-tmp-session-bus.conf
*.bb
*.bbg
*.da
*.gcov

View file

@ -1,38 +0,0 @@
SUBDIRS = . statemachine
INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) -DDBUS_COMPILATION
## Makefile.am bits for sample client/server pair
noinst_PROGRAMS= example-client example-service
example_client_SOURCES= example-client.c
example_client_LDADD= $(top_builddir)/glib/libdbus-glib-1.la
example_service_SOURCES= example-service.c
example_service_LDADD= $(top_builddir)/glib/libdbus-glib-1.la
BUILT_SOURCES = example-service-glue.h
example-service-glue.h: example-service.xml
$(LIBTOOL) --mode=execute $(top_builddir)/glib/dbus-binding-tool --prefix=some_object --mode=glib-server --output=example-service-glue.h $(srcdir)/example-service.xml
## Makefile.am bits for another client/server pair
noinst_PROGRAMS += example-signal-recipient example-signal-emitter
example_signal_recipient_SOURCES= example-signal-recipient.c
example_signal_recipient_LDADD= $(top_builddir)/glib/libdbus-glib-1.la
example_signal_emitter_SOURCES= example-signal-emitter.c
example_signal_emitter_LDADD= $(top_builddir)/glib/libdbus-glib-1.la
BUILT_SOURCES += example-signal-emitter-glue.h
example-signal-emitter-glue.h: example-signal-emitter.xml
$(LIBTOOL) --mode=execute $(top_builddir)/glib/dbus-binding-tool --prefix=test_object --mode=glib-server --output=example-signal-emitter-glue.h $(srcdir)/example-signal-emitter.xml
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = example-service.xml example-signal-emitter.xml

View file

@ -1,121 +0,0 @@
#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <stdlib.h>
static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
static void
lose (const char *str, ...)
{
va_list args;
va_start (args, str);
vfprintf (stderr, str, args);
fputc ('\n', stderr);
va_end (args);
exit (1);
}
static void
lose_gerror (const char *prefix, GError *error)
{
lose ("%s: %s", prefix, error->message);
}
static void
print_hash_value (gpointer key, gpointer val, gpointer data)
{
printf ("%s -> %s\n", (char *) key, (char *) val);
}
int
main (int argc, char **argv)
{
DBusGConnection *bus;
DBusGProxy *remote_object;
DBusGProxy *remote_object_introspectable;
GError *error = NULL;
char **reply_list;
char **reply_ptr;
GValueArray *hello_reply_struct;
GHashTable *hello_reply_dict;
char *introspect_data;
guint i;
g_type_init ();
{
GLogLevelFlags fatal_mask;
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
g_log_set_always_fatal (fatal_mask);
}
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!bus)
lose_gerror ("Couldn't connect to session bus", error);
remote_object = dbus_g_proxy_new_for_name (bus,
"org.designfu.SampleService",
"/SomeObject",
"org.designfu.SampleInterface");
if (!dbus_g_proxy_call (remote_object, "HelloWorld", &error,
G_TYPE_STRING, "Hello from example-client.c!", G_TYPE_INVALID,
G_TYPE_STRV, &reply_list, G_TYPE_INVALID))
lose_gerror ("Failed to complete HelloWorld", error);
if (!dbus_g_proxy_call (remote_object, "GetTuple", &error,
G_TYPE_INVALID,
G_TYPE_VALUE_ARRAY, &hello_reply_struct, G_TYPE_INVALID))
lose_gerror ("Failed to complete GetTuple", error);
if (!dbus_g_proxy_call (remote_object, "GetDict", &error,
G_TYPE_INVALID,
DBUS_TYPE_G_STRING_STRING_HASHTABLE, &hello_reply_dict, G_TYPE_INVALID))
lose_gerror ("Failed to complete GetDict", error);
printf ("reply_list: ");
for (reply_ptr = reply_list; *reply_ptr; reply_ptr++)
printf ("\"%s\" ", *reply_ptr);
printf ("\n");
g_strfreev (reply_list);
for (i = 0; i < hello_reply_struct->n_values; i++)
{
GValue strval = { 0, };
g_value_init (&strval, G_TYPE_STRING);
if (!g_value_transform (g_value_array_get_nth (hello_reply_struct, i), &strval))
g_value_set_static_string (&strval, "(couldn't transform to string)");
g_print ("%s: %s\n", g_type_name (G_VALUE_TYPE (g_value_array_get_nth (hello_reply_struct, i))),
g_value_get_string (&strval));
}
g_value_array_free (hello_reply_struct);
printf ("\n");
g_hash_table_foreach (hello_reply_dict, print_hash_value, NULL);
g_hash_table_destroy (hello_reply_dict);
remote_object_introspectable = dbus_g_proxy_new_for_name (bus,
"org.designfu.SampleService",
"/SomeObject",
"org.freedesktop.DBus.Introspectable");
if (!dbus_g_proxy_call (remote_object_introspectable, "Introspect", &error,
G_TYPE_INVALID,
G_TYPE_STRING, &introspect_data, G_TYPE_INVALID))
lose_gerror ("Failed to complete Introspect", error);
printf ("%s", introspect_data);
g_free (introspect_data);
g_object_unref (G_OBJECT (remote_object_introspectable));
g_object_unref (G_OBJECT (remote_object));
exit(0);
}

View file

@ -1,153 +0,0 @@
#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <stdlib.h>
static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
static void
lose (const char *str, ...)
{
va_list args;
va_start (args, str);
vfprintf (stderr, str, args);
fputc ('\n', stderr);
va_end (args);
exit (1);
}
static void
lose_gerror (const char *prefix, GError *error)
{
lose ("%s: %s", prefix, error->message);
}
typedef struct SomeObject SomeObject;
typedef struct SomeObjectClass SomeObjectClass;
GType some_object_get_type (void);
struct SomeObject
{
GObject parent;
};
struct SomeObjectClass
{
GObjectClass parent;
};
#define SOME_TYPE_OBJECT (some_object_get_type ())
#define SOME_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), SOME_TYPE_OBJECT, SomeObject))
#define SOME_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOME_TYPE_OBJECT, SomeObjectClass))
#define SOME_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), SOME_TYPE_OBJECT))
#define SOME_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SOME_TYPE_OBJECT))
#define SOME_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOME_TYPE_OBJECT, SomeObjectClass))
G_DEFINE_TYPE(SomeObject, some_object, G_TYPE_OBJECT)
gboolean some_object_hello_world (SomeObject *obj, const char *hello_message, char ***ret, GError **error);
gboolean some_object_get_tuple (SomeObject *obj, GValueArray **ret, GError **error);
gboolean some_object_get_dict (SomeObject *obj, GHashTable **ret, GError **error);
#include "example-service-glue.h"
static void
some_object_init (SomeObject *obj)
{
}
static void
some_object_class_init (SomeObjectClass *klass)
{
}
gboolean
some_object_hello_world (SomeObject *obj, const char *hello_message, char ***ret, GError **error)
{
printf ("%s\n", hello_message);
*ret = g_new (char *, 3);
(*ret)[0] = g_strdup ("Hello");
(*ret)[1] = g_strdup (" from example-service.c");
(*ret)[2] = NULL;
return TRUE;
}
gboolean
some_object_get_tuple (SomeObject *obj, GValueArray **ret, GError **error)
{
*ret = g_value_array_new (6);
g_value_array_prepend (*ret, NULL);
g_value_init (g_value_array_get_nth (*ret, 0), G_TYPE_STRING);
g_value_set_string (g_value_array_get_nth (*ret, 0), "hello");
g_value_array_prepend (*ret, NULL);
g_value_init (g_value_array_get_nth (*ret, 0), G_TYPE_UINT);
g_value_set_uint (g_value_array_get_nth (*ret, 0), 42);
return TRUE;
}
gboolean
some_object_get_dict (SomeObject *obj, GHashTable **ret, GError **error)
{
*ret = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (*ret, "first", "Hello Dict");
g_hash_table_insert (*ret, "second", " from example-service.c");
return TRUE;
}
int
main (int argc, char **argv)
{
DBusGConnection *bus;
DBusGProxy *bus_proxy;
GError *error = NULL;
SomeObject *obj;
GMainLoop *mainloop;
guint request_name_result;
g_type_init ();
{
GLogLevelFlags fatal_mask;
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
g_log_set_always_fatal (fatal_mask);
}
dbus_g_object_type_install_info (SOME_TYPE_OBJECT, &dbus_glib_some_object_object_info);
mainloop = g_main_loop_new (NULL, FALSE);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!bus)
lose_gerror ("Couldn't connect to session bus", error);
bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");
if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
G_TYPE_STRING, "org.designfu.SampleService",
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &request_name_result,
G_TYPE_INVALID))
lose_gerror ("Failed to acquire org.designfu.SampleService", error);
obj = g_object_new (SOME_TYPE_OBJECT, NULL);
dbus_g_connection_register_g_object (bus, "/SomeObject", G_OBJECT (obj));
printf ("service running\n");
g_main_loop_run (mainloop);
exit (0);
}

View file

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/">
<interface name="org.designfu.SampleInterface">
<method name="HelloWorld">
<arg type="s"/>
<arg type="as" direction="out"/>
</method>
<method name="GetTuple">
<arg type="(ss)" direction="out" />
</method>
<method name="GetDict">
<arg type="a{ss}" direction="out"/>
</method>
</interface>
</node>

View file

@ -1,132 +0,0 @@
#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <stdlib.h>
static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
static void
lose (const char *str, ...)
{
va_list args;
va_start (args, str);
vfprintf (stderr, str, args);
fputc ('\n', stderr);
va_end (args);
exit (1);
}
static void
lose_gerror (const char *prefix, GError *error)
{
lose ("%s: %s", prefix, error->message);
}
typedef struct TestObject TestObject;
typedef struct TestObjectClass TestObjectClass;
GType test_object_get_type (void);
struct TestObject
{
GObject parent;
};
struct TestObjectClass
{
GObjectClass parent;
};
enum
{
HELLO_SIGNAL,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
#define TEST_TYPE_OBJECT (test_object_get_type ())
#define TEST_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TEST_TYPE_OBJECT, TestObject))
#define TEST_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_OBJECT, TestObjectClass))
#define TEST_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TEST_TYPE_OBJECT))
#define TEST_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_OBJECT))
#define TEST_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_OBJECT, TestObjectClass))
G_DEFINE_TYPE(TestObject, test_object, G_TYPE_OBJECT)
gboolean test_object_emit_hello_signal (TestObject *obj, GError **error);
#include "example-signal-emitter-glue.h"
static void
test_object_init (TestObject *obj)
{
}
static void
test_object_class_init (TestObjectClass *klass)
{
signals[HELLO_SIGNAL] =
g_signal_new ("hello_signal",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
0,
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
}
gboolean
test_object_emit_hello_signal (TestObject *obj, GError **error)
{
g_signal_emit (obj, signals[HELLO_SIGNAL], 0, "Hello");
return TRUE;
}
int
main (int argc, char **argv)
{
DBusGConnection *bus;
DBusGProxy *bus_proxy;
GError *error = NULL;
TestObject *obj;
GMainLoop *mainloop;
guint request_name_result;
g_type_init ();
dbus_g_object_type_install_info (TEST_TYPE_OBJECT, &dbus_glib_test_object_object_info);
mainloop = g_main_loop_new (NULL, FALSE);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!bus)
lose_gerror ("Couldn't connect to session bus", error);
bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");
if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
G_TYPE_STRING, "org.designfu.TestService",
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &request_name_result,
G_TYPE_INVALID))
lose_gerror ("Failed to acquire org.designfu.TestService", error);
obj = g_object_new (TEST_TYPE_OBJECT, NULL);
dbus_g_connection_register_g_object (bus, "/org/designfu/TestService/object", G_OBJECT (obj));
printf ("test service running\n");
g_main_loop_run (mainloop);
exit (0);
}

View file

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/">
<interface name="org.designfu.TestService">
<method name="emitHelloSignal">
</method>
<!-- Mark the signal as exported -->
<signal name="HelloSignal"/>
</interface>
</node>

View file

@ -1,102 +0,0 @@
#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <stdlib.h>
static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
static void
lose (const char *str, ...)
{
va_list args;
va_start (args, str);
vfprintf (stderr, str, args);
fputc ('\n', stderr);
va_end (args);
exit (1);
}
static void
lose_gerror (const char *prefix, GError *error)
{
lose ("%s: %s", prefix, error->message);
}
static gboolean
emit_signal (gpointer arg)
{
DBusGProxy *proxy = arg;
dbus_g_proxy_call_no_reply (proxy, "emitHelloSignal", G_TYPE_INVALID);
return TRUE;
}
static void
hello_signal_handler (DBusGProxy *proxy, const char *hello_string, gpointer user_data)
{
printf ("Received signal and it says: %s\n", hello_string);
}
int
main (int argc, char **argv)
{
DBusGConnection *bus;
DBusGProxy *remote_object;
GError *error = NULL;
GMainLoop *mainloop;
g_type_init ();
mainloop = g_main_loop_new (NULL, FALSE);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!bus)
lose_gerror ("Couldn't connect to session bus", error);
/* We use _for_name_owner in order to track this particular service
* instance, which lets us receive signals.
*/
remote_object = dbus_g_proxy_new_for_name (bus,
"org.designfu.TestService",
"/org/designfu/TestService/object",
"org.designfu.TestService");
if (!remote_object)
lose_gerror ("Failed to get name owner", error);
/* IMPORTANT:
*
* Note because this signal's signature is VOID__STRING, we do not
* need to register a marshaller, since there is a builtin one.
* However for other signatures, you must generate a marshaller,
* then call dbus_g_object_register_marshaller. It would look like
* this:
*
* dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID);
*
*/
/* Tell DBus what the type signature of the signal callback is; this
* allows us to sanity-check incoming messages before invoking the
* callback. You need to do this once for each proxy you create,
* not every time you want to connect to the signal.
*/
dbus_g_proxy_add_signal (remote_object, "HelloSignal", G_TYPE_STRING, G_TYPE_INVALID);
/* Actually connect to the signal. Note you can call
* dbus_g_proxy_connect_signal multiple times for one invocation of
* dbus_g_proxy_add_signal.
*/
dbus_g_proxy_connect_signal (remote_object, "HelloSignal", G_CALLBACK (hello_signal_handler),
NULL, NULL);
g_timeout_add (2000, emit_signal, remote_object);
g_main_loop_run (mainloop);
exit (0);
}

View file

@ -1,16 +0,0 @@
.deps
.libs
Makefile
Makefile.in
*.lo
*.la
statemachine-client
statemachine-server
statemachine-glue.h
statemachine-server-glue.h
run-with-tmp-session-bus.conf
sm-marshal.[ch]
*.bb
*.bbg
*.da
*.gcov

View file

@ -1,35 +0,0 @@
INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) $(DBUS_GTK_THREADS_CFLAGS) -DDBUS_COMPILATION
## Makefile.am bits for sample client/server pair
noinst_PROGRAMS= statemachine-server
if HAVE_GTK
noinst_PROGRAMS += statemachine-client
endif
EXTRA_DIST = statemachine.h statemachine-server.h sm-marshal.list statemachine-server.xml statemachine.xml
statemachine_server_SOURCES= statemachine-server.c sm-marshal.c statemachine.c
statemachine_server_LDADD= $(top_builddir)/glib/libdbus-glib-1.la
statemachine_client_SOURCES= statemachine-client.c sm-marshal.c statemachine.h
statemachine_client_LDADD= $(top_builddir)/glib/libdbus-glib-1.la $(DBUS_GTK_THREADS_LIBS)
BUILT_SOURCES = statemachine-server-glue.h statemachine-glue.h
statemachine-server-glue.h: statemachine-server.xml
$(LIBTOOL) --mode=execute $(top_builddir)/glib/dbus-binding-tool --prefix=sm_server --mode=glib-server --output=$@ $<
statemachine-glue.h: statemachine.xml
$(LIBTOOL) --mode=execute $(top_builddir)/glib/dbus-binding-tool --prefix=sm_object --mode=glib-server --output=$@ $<
sm-marshal.c: Makefile sm-marshal.list
@GLIB_GENMARSHAL@ --prefix=sm_marshal $(srcdir)/sm-marshal.list --header --body > $@.tmp && mv $@.tmp $@
sm-marshal.h: Makefile sm-marshal.list
@GLIB_GENMARSHAL@ --prefix=sm_marshal $(srcdir)/sm-marshal.list --header > $@.tmp && mv $@.tmp $@
BUILT_SOURCES += sm-marshal.c sm-marshal.h
CLEANFILES = $(BUILT_SOURCES)

View file

@ -1 +0,0 @@
VOID:STRING,BOXED

View file

@ -1,662 +0,0 @@
#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "sm-marshal.h"
static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
static void
lose (const char *str, ...)
{
va_list args;
GtkWidget *dialog;
char *text;
va_start (args, str);
text = g_strdup_vprintf (str, args);
va_end (args);
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"%s",
text);
gtk_dialog_run (GTK_DIALOG (dialog));
g_free (text);
exit (1);
}
static void
lose_gerror (const char *prefix, GError *error)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"%s",
prefix);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s",
error->message);
gtk_dialog_run (GTK_DIALOG (dialog));
exit (1);
}
typedef struct
{
char *name;
char *state;
gdouble progress;
DBusGProxy *proxy;
DBusGProxyCall *get_progress_call;
} MachineInfo;
typedef struct
{
GtkWindow *window;
GtkWidget *view;
GtkTreeModel *store;
DBusGConnection *bus;
DBusGProxy *server_proxy;
GSList *pending_creation_calls;
DBusGProxyCall *get_machines_call;
} ClientState;
static gboolean
proxy_to_iter (GtkTreeModel *model, DBusGProxy *proxy, GtkTreeIter *iter)
{
if (!gtk_tree_model_get_iter_first (model, iter))
return FALSE;
do {
MachineInfo *info;
gtk_tree_model_get (model, iter, 0, &info, -1);
if (info->proxy == proxy)
return TRUE;
} while (gtk_tree_model_iter_next (model, iter));
return FALSE;
}
static void
signal_row_change (ClientState *state, GtkTreeIter *iter)
{
GtkTreePath *path;
path = gtk_tree_model_get_path (state->store, iter);
gtk_tree_model_row_changed (state->store, path, iter);
gtk_tree_path_free (path);
}
static void
get_machine_info_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer data)
{
GtkTreeIter iter;
ClientState *state = data;
GError *error = NULL;
char *name, *statename;
MachineInfo *info;
if (!dbus_g_proxy_end_call (proxy, call, &error,
G_TYPE_STRING, &name,
G_TYPE_STRING, &statename,
G_TYPE_INVALID))
lose_gerror ("Couldn't complete GetInfo", error);
if (!proxy_to_iter (state->store, proxy, &iter))
g_assert_not_reached ();
gtk_tree_model_get (state->store, &iter, 0, &info, -1);
g_free (info->name);
info->name = name;
g_free (info->state);
info->state = statename;
signal_row_change (state, &iter);
}
static void
set_proxy_acquisition_progress (ClientState *state,
DBusGProxy *proxy,
double progress)
{
MachineInfo *info;
GtkTreeIter iter;
if (!proxy_to_iter (state->store, proxy, &iter))
g_assert_not_reached ();
gtk_tree_model_get (state->store, &iter, 0, &info, -1);
/* Ignore machines in unknown state */
if (!info->state)
return;
if (strcmp (info->state, "Acquired"))
lose ("Got AcquisitionProgress signal in bad state %s",
info->state);
g_print ("Got acquisition progress change for %p (%s) to %f\n", proxy, info->name ? info->name : "(unknown)", progress);
info->progress = progress;
signal_row_change (state, &iter);
}
static void
proxy_acquisition_changed_cb (DBusGProxy *proxy,
double progress,
gpointer user_data)
{
set_proxy_acquisition_progress (user_data, proxy, progress);
}
static void
get_acquiring_progress_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
GError *error = NULL;
MachineInfo *info;
GtkTreeIter iter;
ClientState *state = user_data;
gdouble progress;
if (!proxy_to_iter (state->store, proxy, &iter))
g_assert_not_reached ();
gtk_tree_model_get (state->store, &iter, 0, &info, -1);
g_assert (info->get_progress_call == call);
if (!dbus_g_proxy_end_call (proxy, call, &error,
G_TYPE_DOUBLE, &progress, G_TYPE_INVALID))
lose_gerror ("Failed to complete GetAcquiringProgress call", error);
info->get_progress_call = NULL;
set_proxy_acquisition_progress (state, proxy, progress);
}
static void
proxy_state_changed_cb (DBusGProxy *proxy,
const char *statename,
gpointer user_data)
{
MachineInfo *info;
GtkTreeIter iter;
ClientState *state = user_data;
if (!proxy_to_iter (state->store, proxy, &iter))
g_assert_not_reached ();
gtk_tree_model_get (state->store, &iter, 0, &info, -1);
g_print ("Got state change for %p (%s) to %s\n", proxy, info->name ? info->name : "(unknown)", statename);
g_free (info->state);
info->state = g_strdup (statename);
if (!strcmp (info->state, "Acquired"))
{
g_print ("Starting GetAcquiringProgress call for %p\n", info->proxy);
if (info->get_progress_call != NULL)
{
dbus_g_proxy_cancel_call (info->proxy, info->get_progress_call);
info->get_progress_call = NULL;
}
info->get_progress_call =
dbus_g_proxy_begin_call (info->proxy, "GetAcquiringProgress",
get_acquiring_progress_cb,
state, NULL,
G_TYPE_INVALID);
}
else
info->progress = 0.0;
signal_row_change (state, &iter);
}
static void
add_machine (ClientState *state,
const char *name,
const char *mstate,
const char *path)
{
MachineInfo *info;
GtkTreeIter iter;
info = g_new0 (MachineInfo, 1);
info->name = g_strdup (name);
info->state = g_strdup (mstate);
info->progress = 0.0;
info->proxy = dbus_g_proxy_new_for_name (state->bus,
"com.example.StateServer",
path,
"com.example.StateMachine");
if (!info->state)
{
g_print ("Starting GetInfo call for %p\n", info->proxy);
dbus_g_proxy_begin_call (info->proxy, "GetInfo",
get_machine_info_cb,
state, NULL,
G_TYPE_INVALID);
}
/* Watch for state changes */
dbus_g_proxy_add_signal (info->proxy, "StateChanged",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (info->proxy,
"StateChanged",
G_CALLBACK (proxy_state_changed_cb),
state,
NULL);
dbus_g_proxy_add_signal (info->proxy, "AcquisitionProgress",
G_TYPE_DOUBLE, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (info->proxy,
"AcquisitionProgress",
G_CALLBACK (proxy_acquisition_changed_cb),
state,
NULL);
gtk_list_store_prepend (GTK_LIST_STORE (state->store), &iter);
gtk_list_store_set (GTK_LIST_STORE (state->store), &iter, 0, info, -1);
}
static void
machine_created_cb (DBusGProxy *proxy,
const char *name,
const char *path,
gpointer data)
{
ClientState *state = data;
add_machine (state, name, NULL, path);
}
static void
server_destroyed_cb (DBusGProxy *proxy, gpointer data)
{
g_print ("Server terminated!\n");
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"State Machine server has exited");
gtk_dialog_run (GTK_DIALOG (dialog));
exit (1);
}
static void
window_destroyed_cb (GtkWidget *window, gpointer data)
{
gtk_main_quit ();
}
static void
create_machine_completed_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer data)
{
GError *error = NULL;
ClientState *state = data;
if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID))
{
/* Ignore NameInUse errors */
if (dbus_g_error_has_name (error, "com.example.StateServer.NameInUse"))
;
else
lose_gerror ("Failed to create new state machine", error);
}
g_print ("machine created successfully\n");
state->pending_creation_calls = g_slist_remove (state->pending_creation_calls, call);
}
static void
send_create_machine (ClientState *state)
{
DBusGProxyCall *call;
char *name;
gint n_children;
n_children = gtk_tree_model_iter_n_children (state->store, NULL);
name = g_strdup_printf ("machine%d", n_children);
g_print ("Invoking CreateMachine(%s)\n", name);
call = dbus_g_proxy_begin_call (state->server_proxy, "CreateMachine",
create_machine_completed_cb,
state, NULL,
G_TYPE_STRING, name, G_TYPE_INVALID);
g_free (name);
state->pending_creation_calls = g_slist_prepend (state->pending_creation_calls, call);
}
static void
do_a_state_change (ClientState *state)
{
gint index;
GtkTreeIter iter;
gint n_children;
MachineInfo *info;
n_children = gtk_tree_model_iter_n_children (state->store, NULL);
if (n_children == 0)
{
g_print ("No machines yet, not doing a state switch\n");
return;
}
index = g_random_int_range (0, n_children);
gtk_tree_model_iter_nth_child (state->store, &iter, NULL, index);
gtk_tree_model_get (state->store, &iter, 0, &info, -1);
if (!info->state)
{
g_print ("Machine not yet in known state, skipping state switch\n");
return;
}
if (!strcmp (info->state, "Shutdown"))
{
g_print ("Sending Start request to machine %s\n", info->name);
dbus_g_proxy_call_no_reply (info->proxy, "Start", G_TYPE_INVALID);
}
else if (!strcmp (info->state, "Loading"))
{
g_print ("Sending Reacquire request to machine %s\n", info->name);
dbus_g_proxy_call_no_reply (info->proxy, "Reacquire", G_TYPE_INVALID);
}
else
{
g_print ("Sending Shutdown request to machine %s\n", info->name);
dbus_g_proxy_call_no_reply (info->proxy, "Shutdown", G_TYPE_INVALID);
}
}
static gboolean
do_something_random_2 (gpointer data)
{
ClientState *state = data;
do_a_state_change (state);
g_timeout_add (g_random_int_range (2000, 5000), do_something_random_2, state);
return FALSE;
}
static gboolean
do_something_random (gpointer data)
{
ClientState *state = data;
gint n_children;
switch (g_random_int_range (0, 3))
{
case 0:
send_create_machine (state);
break;
case 1:
case 2:
do_a_state_change (state);
break;
default:
g_assert_not_reached ();
}
n_children = gtk_tree_model_iter_n_children (state->store, NULL);
if (n_children >= 5)
{
g_print ("MAX children reached, switching to state changes only\n");
g_timeout_add (g_random_int_range (500, 3000), do_something_random_2, state);
}
else
g_timeout_add (g_random_int_range (500, 3000), do_something_random, state);
return FALSE;
}
static void
set_cell_name (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
MachineInfo *info;
gtk_tree_model_get (tree_model, iter, 0, &info, -1);
g_object_set (cell, "text", info->name ? info->name : "", NULL);
}
static gint
sort_by_name (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer user_data)
{
MachineInfo *info_a, *info_b;
gtk_tree_model_get (model, a, 0, &info_a, -1);
gtk_tree_model_get (model, b, 0, &info_b, -1);
return strcmp (info_a->name ? info_a->name : "",
info_b ? info_b->name : "");
}
static void
set_cell_state (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
MachineInfo *info;
gtk_tree_model_get (tree_model, iter, 0, &info, -1);
g_object_set (cell, "text", info->state ? info->state : "", NULL);
}
static gint
sort_by_state (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer user_data)
{
MachineInfo *info_a, *info_b;
gtk_tree_model_get (model, a, 0, &info_a, -1);
gtk_tree_model_get (model, b, 0, &info_b, -1);
return strcmp (info_a->state ? info_a->state : "",
info_b ? info_b->state : "");
}
static void
set_cell_progress (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
MachineInfo *info;
gtk_tree_model_get (tree_model, iter, 0, &info, -1);
g_object_set (cell, "value", (int) (info->progress * 100), NULL);
}
static gint
sort_by_progress (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer user_data)
{
MachineInfo *info_a, *info_b;
gtk_tree_model_get (model, a, 0, &info_a, -1);
gtk_tree_model_get (model, b, 0, &info_b, -1);
return info_a->progress > info_b->progress ? 1 : -1;
}
static void
get_machines_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer data)
{
GError *error = NULL;
ClientState *state = data;
GPtrArray *objs;
guint i;
GtkWidget *scrolledwin;
GtkTreeViewColumn *col;
GtkCellRenderer *rend;
g_assert (call == state->get_machines_call);
if (!dbus_g_proxy_end_call (proxy, call, &error,
dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH),
&objs,
G_TYPE_INVALID))
lose_gerror ("Failed to get current machine list", error);
gtk_container_remove (GTK_CONTAINER (state->window),
gtk_bin_get_child (GTK_BIN (state->window)));
scrolledwin = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwin);
state->store = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_POINTER));
state->view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (state->store));
gtk_widget_show (state->view);
gtk_container_add (GTK_CONTAINER (scrolledwin), state->view);
gtk_container_add (GTK_CONTAINER (state->window), scrolledwin);
rend = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (_("Name"),
rend,
NULL);
gtk_tree_view_column_set_cell_data_func (col, rend, set_cell_name, NULL, NULL);
gtk_tree_view_column_set_resizable (col, TRUE);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (state->store),
0, sort_by_name, NULL, NULL);
gtk_tree_view_column_set_sort_column_id (col, 0);
gtk_tree_view_append_column (GTK_TREE_VIEW (state->view), col);
rend = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (_("State"),
rend,
NULL);
gtk_tree_view_column_set_cell_data_func (col, rend, set_cell_state, NULL, NULL);
gtk_tree_view_column_set_resizable (col, TRUE);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (state->store),
0, sort_by_state, NULL, NULL);
gtk_tree_view_column_set_sort_column_id (col, 0);
gtk_tree_view_append_column (GTK_TREE_VIEW (state->view), col);
rend = gtk_cell_renderer_progress_new ();
col = gtk_tree_view_column_new_with_attributes (_("Progress"),
rend,
NULL);
gtk_tree_view_column_set_cell_data_func (col, rend, set_cell_progress, NULL, NULL);
gtk_tree_view_column_set_resizable (col, TRUE);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (state->store),
0, sort_by_progress, NULL, NULL);
gtk_tree_view_column_set_sort_column_id (col, 0);
gtk_tree_view_append_column (GTK_TREE_VIEW (state->view), col);
for (i = 0; i < objs->len; i++)
{
add_machine (state, NULL, NULL, g_ptr_array_index (objs, i));
g_free (g_ptr_array_index (objs, i));
}
g_ptr_array_free (objs, TRUE);
g_idle_add (do_something_random, state);
}
int
main (int argc, char **argv)
{
DBusGConnection *bus;
DBusGProxy *server;
GError *error = NULL;
ClientState state;
GtkWidget *label;
gtk_init (&argc, &argv);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
state.window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
gtk_window_set_resizable (GTK_WINDOW (state.window), TRUE);
g_signal_connect (G_OBJECT (state.window), "destroy",
G_CALLBACK (window_destroyed_cb),
&state);
gtk_window_set_title (GTK_WINDOW (state.window), _("D-BUS State Machine Demo"));
gtk_window_set_default_size (GTK_WINDOW (state.window), 320, 240);
label = gtk_label_new ("");
gtk_label_set_markup (GTK_LABEL (label), "<b>Loading...</b>");
gtk_widget_show (label);
gtk_container_add (GTK_CONTAINER (state.window), label);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!bus)
lose_gerror ("Couldn't connect to session bus", error);
state.bus = bus;
server = dbus_g_proxy_new_for_name_owner (bus,
"com.example.StateServer",
"/com/example/StateServer",
"com.example.StateMachineServer",
&error);
if (!server)
lose_gerror ("Couldn't find \"com.example.StateServer\"", error);
state.server_proxy = server;
g_signal_connect (server, "destroy",
G_CALLBACK (server_destroyed_cb),
&state);
dbus_g_object_register_marshaller (sm_marshal_VOID__STRING_BOXED,
G_TYPE_NONE, G_TYPE_STRING,
DBUS_TYPE_G_OBJECT_PATH);
dbus_g_proxy_add_signal (server, "MachineCreated", G_TYPE_STRING, DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (server, "MachineCreated",
G_CALLBACK (machine_created_cb),
&state, NULL);
state.get_machines_call = dbus_g_proxy_begin_call (server, "GetMachines",
get_machines_cb, &state, NULL,
G_TYPE_INVALID);
gtk_widget_show (GTK_WIDGET (state.window));
gtk_main ();
g_object_unref (G_OBJECT (server));
exit(0);
}

View file

@ -1,229 +0,0 @@
#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <stdlib.h>
#include "statemachine.h"
#include "sm-marshal.h"
#include "statemachine-server.h"
enum
{
PROP_O,
PROP_BUS
};
enum
{
MACHINE_CREATED,
LAST_SIGNAL
};
static guint sm_server_signals[LAST_SIGNAL] = { 0 };
static void sm_server_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void sm_server_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE(SMServer, sm_server, G_TYPE_OBJECT)
#include "statemachine-server-glue.h"
#include "statemachine-glue.h"
static void
sm_server_init (SMServer *obj)
{
obj->machines = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
}
static void
sm_server_class_init (SMServerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = sm_server_set_property;
object_class->get_property = sm_server_get_property;
g_object_class_install_property (object_class,
PROP_BUS,
g_param_spec_boxed ("bus",
"bus",
"bus",
DBUS_TYPE_G_CONNECTION,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
sm_server_signals[MACHINE_CREATED] =
g_signal_new ("machine-created",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
0,
NULL, NULL,
sm_marshal_VOID__STRING_BOXED,
G_TYPE_NONE, 2, G_TYPE_STRING, DBUS_TYPE_G_OBJECT_PATH);
}
static void
sm_server_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SMServer *server = SM_SERVER (object);
switch (prop_id)
{
case PROP_BUS:
server->bus = g_value_get_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
sm_server_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SMServer *server = SM_SERVER (object);
switch (prop_id)
{
case PROP_BUS:
g_value_set_boxed (value, server->bus);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
machine_state_changed_cb (SMObject *obj, const char *state, gpointer data)
{
char *name;
g_object_get (obj, "name", &name, NULL);
g_print ("Machine %s switching to state %s\n", name, state);
g_free (name);
}
static void
machine_acquisition_changed_cb (SMObject *obj, gdouble progress, gpointer data)
{
char *name;
g_object_get (obj, "name", &name, NULL);
g_print ("Machine %s got progress %f\n", name, progress);
g_free (name);
}
gboolean
sm_server_create_machine (SMServer *server, const char *name, GError **error)
{
SMObject *machine;
char *path;
machine = g_hash_table_lookup (server->machines, name);
if (machine != NULL)
{
g_set_error (error,
SM_ERROR,
SM_ERROR_NAME_IN_USE,
"Statemachine name \"%s\" is already in use",
name);
return FALSE;
}
machine = g_object_new (SM_TYPE_OBJECT, "name", name, NULL);
path = g_strdup_printf ("/com/example/StateMachines/%s", name);
dbus_g_connection_register_g_object (server->bus, path, G_OBJECT (machine));
g_hash_table_insert (server->machines, g_strdup (name), machine);
g_print ("Created state machine with name %s at %s\n", name, path);
g_signal_connect_object (machine, "state-changed",
G_CALLBACK (machine_state_changed_cb),
NULL, 0);
g_signal_connect_object (machine, "acquisition-progress",
G_CALLBACK (machine_acquisition_changed_cb),
NULL, 0);
g_signal_emit (server, sm_server_signals[MACHINE_CREATED], 0, name, path);
return TRUE;
}
static void
add_machine_to_ptr_array (gpointer key, gpointer val, gpointer data)
{
const char *name = key;
/* SMObject *sm = val; */
GPtrArray *ptrarray = data;
g_ptr_array_add (ptrarray, g_strdup_printf ("/com/example/StateMachines/%s",
name));
}
gboolean
sm_server_get_machines (SMServer *server, GPtrArray **machines, GError **error)
{
*machines = g_ptr_array_new ();
g_hash_table_foreach (server->machines, add_machine_to_ptr_array, *machines);
return TRUE;
}
int
main (int argc, char **argv)
{
DBusGConnection *bus;
DBusGProxy *bus_proxy;
GError *error = NULL;
SMServer *server;
GMainLoop *mainloop;
guint request_name_result;
g_type_init ();
dbus_g_object_type_install_info (SM_TYPE_SERVER, &dbus_glib_sm_server_object_info);
dbus_g_object_type_install_info (SM_TYPE_OBJECT, &dbus_glib_sm_object_object_info);
dbus_g_error_domain_register (SM_ERROR, NULL, SM_TYPE_ERROR);
mainloop = g_main_loop_new (NULL, FALSE);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!bus)
g_critical ("Couldn't connect to session bus: %s\n", error->message);
bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");
if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
G_TYPE_STRING, "com.example.StateServer",
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &request_name_result,
G_TYPE_INVALID))
g_critical ("Couldn't acquire com.example.StateServer: %s\n", error->message);
server = g_object_new (SM_TYPE_SERVER, "bus", bus, NULL);
dbus_g_connection_register_g_object (bus, "/com/example/StateServer", G_OBJECT (server));
g_print ("StateMachine server initialized\n");
g_main_loop_run (mainloop);
exit (0);
}

View file

@ -1,37 +0,0 @@
#ifndef _SM_SERVER_H
#define _SM_SERVER_H
#include "statemachine.h"
#include <dbus/dbus-glib.h>
typedef struct SMServer SMServer;
typedef struct SMServerClass SMServerClass;
struct SMServer
{
GObject parent;
/* Private */
DBusGConnection *bus;
GHashTable *machines;
};
struct SMServerClass
{
GObjectClass parent;
};
#define SM_TYPE_SERVER (sm_server_get_type ())
#define SM_SERVER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), SM_TYPE_SERVER, SMServer))
#define SM_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SM_TYPE_SERVER, SMServerClass))
#define SM_IS_SERVER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), SM_TYPE_SERVER))
#define SM_IS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SM_TYPE_SERVER))
#define SM_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SM_TYPE_SERVER, SMServerClass))
GType sm_server_get_type (void);
gboolean sm_server_create_machine (SMServer *server, const char *name, GError **error);
gboolean sm_server_get_machines (SMServer *server, GPtrArray **machines, GError **error);
#endif

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/">
<interface name="com.example.StateMachineServer">
<method name="CreateMachine">
<arg type="s" name="name" direction="in"/>
</method>
<method name="GetMachines">
<arg type="ao" direction="out"/>
</method>
<signal name="MachineCreated"/>
</interface>
</node>

View file

@ -1,353 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "statemachine.h"
static void clear_pending_tasks (SMObject *object);
static void state_change (SMObject *object, SMObjectState new_state);
static void sm_object_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void sm_object_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
enum
{
PROP_0,
PROP_NAME,
};
enum
{
STATE_CHANGED,
ACQUISITION_FAILED,
ACQUISITION_PROGRESS,
LAST_SIGNAL
};
static guint sm_object_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE(SMObject, sm_object, G_TYPE_OBJECT)
static void
sm_object_init (SMObject *obj)
{
obj->state = SM_OBJECT_STATE_SHUTDOWN;
}
static void
sm_object_class_init (SMObjectClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
object_class->set_property = sm_object_set_property;
object_class->get_property = sm_object_get_property;
g_object_class_install_property (object_class,
PROP_NAME,
g_param_spec_string ("name",
"name",
"name",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
sm_object_signals[STATE_CHANGED] =
g_signal_new ("state-changed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
0,
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
sm_object_signals[ACQUISITION_PROGRESS] =
g_signal_new ("acquisition-progress",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
0,
NULL, NULL,
g_cclosure_marshal_VOID__DOUBLE,
G_TYPE_NONE, 1, G_TYPE_DOUBLE);
sm_object_signals[ACQUISITION_FAILED] =
g_signal_new ("acquisition-failed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
0,
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
/* This should really be standard. */
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
GQuark
sm_error_quark (void)
{
static GQuark ret = 0;
if (!ret)
ret = g_quark_from_static_string ("SMObjectErrorQuark");
return ret;
}
GType
sm_object_state_get_type (void)
{
static GType etype = 0;
if (etype == 0)
{
static const GEnumValue values[] =
{
ENUM_ENTRY (SM_OBJECT_STATE_SHUTDOWN, "Shutdown"),
ENUM_ENTRY (SM_OBJECT_STATE_INITIALIZED, "Loading"),
ENUM_ENTRY (SM_OBJECT_STATE_ACQUIRED, "Acquired"),
ENUM_ENTRY (SM_OBJECT_STATE_OPERATING, "Operating"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("SMObjectState", values);
}
return etype;
}
GType
sm_error_get_type (void)
{
static GType etype = 0;
if (etype == 0)
{
static const GEnumValue values[] =
{
ENUM_ENTRY (SM_ERROR_INVALID_STATE, "InvalidState"),
ENUM_ENTRY (SM_ERROR_NAME_IN_USE, "NameInUse"),
{ 0, 0, 0 }
};
g_assert (SM_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
etype = g_enum_register_static ("SMError", values);
}
return etype;
}
static void
sm_object_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SMObject *sm = SM_OBJECT (object);
switch (prop_id)
{
case PROP_NAME:
sm->name = g_strdup (g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
sm_object_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SMObject *sm= SM_OBJECT (object);
switch (prop_id)
{
case PROP_NAME:
g_value_set_string (value, sm->name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static const char *
state_to_string (SMObjectState state)
{
GEnumValue *value;
GEnumClass *prop_class;
const char *ret;
prop_class = g_type_class_ref (SM_TYPE_OBJECT_STATE);
value = g_enum_get_value (prop_class, state);
ret = value->value_nick;
g_type_class_unref (prop_class);
return ret;
}
static void
queue_task (SMObject *object, guint delay, GSourceFunc func)
{
guint id;
id = g_timeout_add (delay, func, object);
object->pending_tasks = g_slist_prepend (object->pending_tasks, GUINT_TO_POINTER (id));
}
static gboolean
idle_state_change (gpointer data)
{
SMObject *object = data;
g_print ("doing idle state change for %s to %s\n",
object->name, state_to_string (object->requested_state));
state_change (object, object->requested_state);
return FALSE;
}
static gboolean
idle_further_acquire (gpointer data)
{
SMObject *object = data;
g_print ("doing idle acquisition for machine %s\n", object->name);
object->acquisition_progress += g_random_double_range (0.20, 0.7);
if (object->acquisition_progress > 1.0)
{
object->acquisition_progress = 1.0;
return FALSE;
}
else
{
g_signal_emit (object, sm_object_signals[ACQUISITION_PROGRESS], 0, object->acquisition_progress);
return TRUE;
}
}
static void
clear_pending_tasks (SMObject *object)
{
GSList *tmp;
for (tmp = object->pending_tasks; tmp; tmp = tmp->next)
g_source_remove (GPOINTER_TO_UINT (tmp->data));
g_slist_free (object->pending_tasks);
object->pending_tasks = NULL;
}
static void
state_change (SMObject *object, SMObjectState new_state)
{
g_signal_emit (object, sm_object_signals[STATE_CHANGED], 0,
state_to_string (new_state));
clear_pending_tasks (object);
if (new_state == SM_OBJECT_STATE_ACQUIRED)
{
object->acquisition_progress = 0.0;
queue_task (object, 1000, idle_further_acquire);
}
else if (new_state == SM_OBJECT_STATE_INITIALIZED)
{
if (g_random_int_range (0, 2) == 0)
{
object->requested_state = SM_OBJECT_STATE_ACQUIRED;
queue_task (object, 3000, idle_state_change);
}
}
object->state = new_state;
}
gboolean
sm_object_get_info (SMObject *object, char **name, char **state, GError **error)
{
*name= g_strdup (object->name);
*state = g_strdup (state_to_string (object->state));
return TRUE;
}
gboolean
sm_object_start (SMObject *object, GError **error)
{
if (object->state != SM_OBJECT_STATE_SHUTDOWN)
{
g_set_error (error,
SM_ERROR,
SM_ERROR_INVALID_STATE,
"%s",
"Can't start from non-shutdown state");
return FALSE;
}
state_change (object, SM_OBJECT_STATE_INITIALIZED);
return TRUE;
}
gboolean
sm_object_shutdown (SMObject *object, GError **error)
{
if (object->state == SM_OBJECT_STATE_SHUTDOWN)
{
g_set_error (error,
SM_ERROR,
SM_ERROR_INVALID_STATE,
"%s",
"Can't shutdown from shutdown state");
return FALSE;
}
state_change (object, SM_OBJECT_STATE_SHUTDOWN);
return TRUE;
}
gboolean
sm_object_reinitialize (SMObject *object, GError **error)
{
if (object->state != SM_OBJECT_STATE_ACQUIRED
&& object->state != SM_OBJECT_STATE_OPERATING)
{
g_set_error (error,
SM_ERROR,
SM_ERROR_INVALID_STATE,
"Can't reinitialize from state %d",
object->state);
return FALSE;
}
state_change (object, SM_OBJECT_STATE_INITIALIZED);
return TRUE;
}
gboolean
sm_object_reacquire (SMObject *object, GError **error)
{
if (object->state == SM_OBJECT_STATE_ACQUIRED)
{
g_set_error (error,
SM_ERROR,
SM_ERROR_INVALID_STATE,
"Can't reacquire from state %d",
object->state);
return FALSE;
}
state_change (object, SM_OBJECT_STATE_ACQUIRED);
return TRUE;
}
gboolean
sm_object_get_acquiring_progress (SMObject *object, gdouble *out, GError **error)
{
if (object->state != SM_OBJECT_STATE_ACQUIRED)
{
g_set_error (error,
SM_ERROR,
SM_ERROR_INVALID_STATE,
"Can't get progress from state %d",
object->state);
return FALSE;
}
*out = object->acquisition_progress;
return TRUE;
}

View file

@ -1,77 +0,0 @@
#ifndef _SM_OBJECT_H
#define _SM_OBJECT_H
#include <glib.h>
#include <glib-object.h>
GQuark sm_error_quark (void);
#define SM_ERROR (sm_error_quark ())
typedef enum
{
SM_ERROR_INVALID_STATE = 0,
SM_ERROR_NAME_IN_USE,
SM_NUM_ERRORS
} SMError;
GType sm_error_get_type (void);
#define SM_TYPE_ERROR (sm_error_get_type ())
typedef enum
{
SM_OBJECT_STATE_SHUTDOWN = 0,
SM_OBJECT_STATE_INITIALIZED,
SM_OBJECT_STATE_ACQUIRED,
SM_OBJECT_STATE_OPERATING,
SM_OBJECT_NUM_STATES
} SMObjectState;
GType sm_object_state_get_type (void);
#define SM_TYPE_OBJECT_STATE (sm_object_state_get_type ())
typedef struct SMObject SMObject;
typedef struct SMObjectClass SMObjectClass;
struct SMObject
{
GObject parent;
/* Private */
char *name;
SMObjectState state;
double acquisition_progress;
GSList /* guint */ *pending_tasks;
SMObjectState requested_state;
};
struct SMObjectClass
{
GObjectClass parent;
};
#define SM_TYPE_OBJECT (sm_object_get_type ())
#define SM_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), SM_TYPE_OBJECT, SMObject))
#define SM_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SM_TYPE_OBJECT, SMObjectClass))
#define SM_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), SM_TYPE_OBJECT))
#define SM_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SM_TYPE_OBJECT))
#define SM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SM_TYPE_OBJECT, SMObjectClass))
GType sm_object_get_type (void);
gboolean sm_object_get_info (SMObject *object, char **name, char **state, GError **error);
gboolean sm_object_start (SMObject *object, GError **error);
gboolean sm_object_shutdown (SMObject *object, GError **error);
gboolean sm_object_reinitialize (SMObject *object, GError **error);
gboolean sm_object_reacquire (SMObject *object, GError **error);
gboolean sm_object_get_acquiring_progress (SMObject *object, gdouble *out, GError **error);
#endif

View file

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/">
<interface name="com.example.StateMachine">
<method name="GetInfo">
<arg type="s" name="name" direction="out"/>
<arg type="s" name="state" direction="out"/>
</method>
<method name="Start">
</method>
<method name="Shutdown">
</method>
<method name="Reinitialize">
</method>
<method name="Reacquire">
</method>
<method name="GetAcquiringProgress">
<arg type="d" direction="out"/>
</method>
<!-- Mark the signals as exported -->
<signal name="StateChanged"/>
<signal name="AcquisitionFailed"/>
<signal name="AcquisitionProgress"/>
</interface>
</node>

View file

@ -1,29 +0,0 @@
#!/bin/sh
SRC=$1
DEST=$2
die()
{
echo $1 1>&2
/bin/rm $DEST.tmp
exit 1
}
echo 'static gint' > $DEST.tmp
echo 'dbus_error_to_gerror_code (const char *derr)' >> $DEST.tmp
echo '{' >> $DEST.tmp
echo ' if (0) ; ' >> $DEST.tmp
cat $SRC | grep '#define DBUS_ERROR' | sed -e 's/#define //g' | \
sed -e 's/".*//g' | \
(while read line; do \
echo ' else if (!strcmp (derr, ' "$line" ' )) '; \
echo ' return ' `echo $line | sed -e 's/DBUS_ERROR/DBUS_GERROR/g'` ';'; \
done; \
) >> $DEST.tmp
echo ' else' >> $DEST.tmp
echo ' return DBUS_GERROR_REMOTE_EXCEPTION;' >> $DEST.tmp
echo '}' >> $DEST.tmp
mv $DEST.tmp $DEST || die "could not move $DEST.tmp to $DEST"

View file

@ -1,17 +0,0 @@
.deps
.libs
Makefile
Makefile.in
*.lo
*.la
*.bb
*.bbg
*.gcov
*.da
.dbus-keyrings
*.dll
*.exe
test-dbus-sharp
AssemblyInfo.cs
dbus-sharp.dll.config

View file

@ -1,327 +0,0 @@
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
namespace DBus
{
// Holds the arguments of a message. Provides methods for appending
// arguments and to assist in matching .NET types with D-BUS types.
public class Arguments : IEnumerable, IDisposable
{
// Must follow sizeof(DBusMessageIter)
internal static readonly int DBusMessageIterSize = Marshal.SizeOf (typeof(_DBusMessageIter));
private static Hashtable dbusTypes = null;
private Message message;
private IntPtr appenderIter;
private IEnumerator enumerator = null;
internal Arguments (Message message)
{
this.appenderIter = Marshal.AllocCoTaskMem(DBusMessageIterSize);
this.message = message;
}
private void Dispose (bool disposing)
{
Marshal.FreeCoTaskMem(appenderIter);
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
~Arguments()
{
Dispose (false);
}
// Checks the suitability of a D-BUS type for supporting a .NET
// type.
public static bool Suits(Type dbusType, Type type)
{
object [] pars = new object[1];
pars[0] = type;
return (bool) dbusType.InvokeMember("Suits", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, pars, null);
}
// Find a suitable match for the given .NET type or throw an
// exception if one can't be found.
public static Type MatchType(Type type)
{
foreach(Type dbusType in DBusTypes.Values) {
if (Suits(dbusType, type)) {
return dbusType;
}
}
throw new ApplicationException("No suitable DBUS type found for type '" + type + "'");
}
// The D-BUS types.
public static Hashtable DBusTypes {
get
{
if (dbusTypes == null) {
dbusTypes = new Hashtable();
foreach (Type type in Assembly.GetAssembly(typeof(DBusType.IDBusType)).GetTypes()) {
if (type != typeof(DBusType.IDBusType) && typeof(DBusType.IDBusType).IsAssignableFrom(type)) {
dbusTypes.Add(GetCode(type), type);
}
}
}
return dbusTypes;
}
}
// Append an argument
public void Append(DBusType.IDBusType dbusType)
{
dbusType.Append(appenderIter);
}
// Append an argument of the specified type
private void AppendType(Type type, object val)
{
object [] pars = new Object[2];
pars[0] = val;
pars[1] = message.Service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(MatchType(type), pars);
Append(dbusType);
}
// Append the results of a method call
public void AppendResults(MethodInfo method, object retVal, object [] parameters)
{
InitAppending();
if (method.ReturnType != typeof(void)) {
AppendType(method.ReturnType, retVal);
}
for (int i = 0; i < method.GetParameters().Length; i++) {
ParameterInfo par = method.GetParameters()[i];
if (par.IsOut || par.ParameterType.ToString().EndsWith("&")) {
// It's an OUT or INOUT parameter.
AppendType(par.ParameterType.UnderlyingSystemType, parameters[i]);
}
}
}
// Get the parameters
public object[] GetParameters(MethodInfo method)
{
ParameterInfo[] pars = method.GetParameters();
ArrayList paramList = new ArrayList();
enumerator = GetEnumerator();
foreach (ParameterInfo par in pars) {
if (!par.IsOut) {
// It's an IN or INOUT paramter.
enumerator.MoveNext();
DBusType.IDBusType dbusType = (DBusType.IDBusType) enumerator.Current;
paramList.Add(dbusType.Get(par.ParameterType));
} else {
// It's an OUT so just create a parameter for it
object var = null;
paramList.Add(var);
}
}
return paramList.ToArray();
}
// Parse the IN & REF parameters to a method and return the types in a list.
public static object[] ParseInParameters(MethodInfo method)
{
ArrayList types = new ArrayList();
ParameterInfo[] pars = method.GetParameters();
foreach (ParameterInfo par in pars) {
if (!par.IsOut) {
types.Add(MatchType(par.ParameterType));
}
}
return types.ToArray();
}
// Parse the OUT & REF parameters to a method and return the types in a list.
public static object[] ParseOutParameters(MethodInfo method)
{
ArrayList types = new ArrayList();
ParameterInfo[] pars = method.GetParameters();
foreach (ParameterInfo par in pars) {
if (par.IsOut || par.ParameterType.ToString().EndsWith("&")) {
types.Add(MatchType(par.ParameterType));
}
}
return types.ToArray();
}
// Get the appropriate constructor for a D-BUS type
public static ConstructorInfo GetDBusTypeConstructor(Type dbusType, Type type)
{
Type constructorType;
if (type.IsArray)
constructorType = typeof (System.Array);
else if (type.IsEnum)
constructorType = Enum.GetUnderlyingType (type);
else
constructorType = type.UnderlyingSystemType;
ConstructorInfo constructor = dbusType.GetConstructor(new Type[] {constructorType, typeof(Service)});
if (constructor == null)
throw new ArgumentException("There is no valid constructor for '" + dbusType + "' from type '" + type + "'");
return constructor;
}
// Get the type code for a given D-BUS type
public static char GetCode(Type dbusType)
{
return (char) dbusType.InvokeMember("Code", BindingFlags.Static | BindingFlags.GetField, null, null, null);
}
// Get the type code for a given D-BUS type as a string
public static string GetCodeAsString (Type dbusType)
{
return GetCode (dbusType).ToString ();
}
// Get a complete method signature
public override string ToString()
{
IntPtr iter = Marshal.AllocCoTaskMem(DBusMessageIterSize);
string key = "";
// Iterate through the parameters getting the type codes to a string
bool notEmpty = dbus_message_iter_init(message.RawMessage, iter);
if (notEmpty) {
do {
char code = (char) dbus_message_iter_get_arg_type(iter);
if (code == '\0')
return key;
key += code;
} while (dbus_message_iter_next(iter));
}
Marshal.FreeCoTaskMem(iter);
return key;
}
// Move to the next parameter
public DBusType.IDBusType GetNext()
{
enumerator.MoveNext();
return (DBusType.IDBusType) enumerator.Current;
}
// Begin appending
public void InitAppending()
{
dbus_message_iter_init_append(message.RawMessage, appenderIter);
}
// Get the enumerator
public IEnumerator GetEnumerator()
{
return new ArgumentsEnumerator(this);
}
[StructLayout(LayoutKind.Sequential)]
private class _DBusMessageIter
{
IntPtr dummy1;
IntPtr dummy2;
int dummy3;
int dummy4;
int dummy5;
int dummy6;
int dummy7;
int dummy8;
int dummy9;
int dummy10;
int dummy11;
int pad1;
int pad2;
IntPtr pad3;
}
private class ArgumentsEnumerator : IEnumerator
{
private Arguments arguments;
private bool started = false;
private bool notEmpty = false;
private IntPtr iter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
public ArgumentsEnumerator(Arguments arguments)
{
this.arguments = arguments;
Reset();
}
~ArgumentsEnumerator()
{
Marshal.FreeCoTaskMem(iter);
}
public bool MoveNext()
{
if (started) {
return dbus_message_iter_next(iter);
} else {
started = true;
return notEmpty;
}
}
public void Reset()
{
notEmpty = dbus_message_iter_init(arguments.message.RawMessage, iter);
started = false;
}
public object Current
{
get
{
object [] pars = new Object[2];
pars[0] = iter;
pars[1] = arguments.message.Service;
Type type = (Type) DBusTypes[(char) dbus_message_iter_get_arg_type(iter)];
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(type, pars);
return dbusType;
}
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_init_append(IntPtr rawMessage, IntPtr iter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_has_next(IntPtr iter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_next(IntPtr iter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_init(IntPtr rawMessage, IntPtr iter);
[DllImport("dbus-1")]
private extern static int dbus_message_iter_get_arg_type(IntPtr iter);
}
}

View file

@ -1,6 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly:AssemblyVersion("@VERSION@")]
[assembly:AssemblyDelaySign(false)]
[assembly:AssemblyKeyFile("@srcdir@/dbus-sharp.snk")]

View file

@ -1,54 +0,0 @@
namespace DBus
{
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
public class Bus
{
// Keep in sync with C
private enum BusType
{
Session = 0,
System = 1,
Activation = 2
}
// Don't allow instantiation
private Bus () { }
public static Connection GetSessionBus()
{
return GetBus(BusType.Session);
}
public static Connection GetSystemBus()
{
return GetBus(BusType.System);
}
private static Connection GetBus(BusType busType)
{
Error error = new Error();
error.Init();
IntPtr rawConnection = dbus_bus_get((int) busType, ref error);
if (rawConnection != IntPtr.Zero) {
Connection connection = Connection.Wrap(rawConnection);
connection.SetupWithMain();
dbus_connection_unref(rawConnection);
return connection;
} else {
throw new DBusException(error);
}
}
[DllImport ("dbus-1")]
private extern static IntPtr dbus_bus_get (int which, ref Error error);
[DllImport ("dbus-1")]
private extern static void dbus_connection_unref (IntPtr ptr);
}
}

View file

@ -1,37 +0,0 @@
namespace DBus
{
using System;
public delegate void NameOwnerChangedHandler (string name,
string oldOwner,
string newOwner);
[Interface ("org.freedesktop.DBus")]
public abstract class BusDriver
{
[Method]
public abstract string[] ListNames ();
[Method]
public abstract string GetNameOwner (string name);
[Method]
public abstract UInt32 GetConnectionUnixUser (string connectionName);
[Signal]
public virtual event NameOwnerChangedHandler NameOwnerChanged;
static public BusDriver New (Connection connection)
{
Service service;
service = Service.Get (connection, "org.freedesktop.DBus");
BusDriver driver;
driver = (BusDriver) service.GetObject (typeof (BusDriver), "/org/freedesktop/DBus");
return driver;
}
}
}

View file

@ -1,354 +0,0 @@
namespace DBus
{
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Collections;
public delegate int DBusHandleMessageFunction (IntPtr rawConnection,
IntPtr rawMessage,
IntPtr userData);
internal delegate void DBusObjectPathUnregisterFunction(IntPtr rawConnection,
IntPtr userData);
internal delegate int DBusObjectPathMessageFunction(IntPtr rawConnection,
IntPtr rawMessage,
IntPtr userData);
[StructLayout (LayoutKind.Sequential)]
internal struct DBusObjectPathVTable
{
public DBusObjectPathUnregisterFunction unregisterFunction;
public DBusObjectPathMessageFunction messageFunction;
public IntPtr padding1;
public IntPtr padding2;
public IntPtr padding3;
public IntPtr padding4;
public DBusObjectPathVTable(DBusObjectPathUnregisterFunction unregisterFunction,
DBusObjectPathMessageFunction messageFunction)
{
this.unregisterFunction = unregisterFunction;
this.messageFunction = messageFunction;
this.padding1 = IntPtr.Zero;
this.padding2 = IntPtr.Zero;
this.padding3 = IntPtr.Zero;
this.padding4 = IntPtr.Zero;
}
}
public class Connection : IDisposable
{
/// <summary>
/// A pointer to the underlying Connection structure
/// </summary>
private IntPtr rawConnection;
/// <summary>
/// The current slot number
/// </summary>
private static int slot = -1;
private int timeout = -1;
private ArrayList filters = new ArrayList (); // of DBusHandleMessageFunction
private ArrayList matches = new ArrayList (); // of string
private Hashtable object_paths = new Hashtable (); // key: string value: DBusObjectPathVTable
internal Connection(IntPtr rawConnection)
{
RawConnection = rawConnection;
}
public Connection(string address)
{
// the assignment bumps the refcount
Error error = new Error();
error.Init();
RawConnection = dbus_connection_open(address, ref error);
if (RawConnection != IntPtr.Zero) {
dbus_connection_unref(RawConnection);
} else {
throw new DBusException(error);
}
SetupWithMain();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose (bool disposing)
{
if (disposing && RawConnection != IntPtr.Zero)
{
dbus_connection_disconnect(rawConnection);
RawConnection = IntPtr.Zero; // free the native object
}
}
public void Flush()
{
dbus_connection_flush(RawConnection);
}
public void SetupWithMain()
{
dbus_connection_setup_with_g_main(RawConnection, IntPtr.Zero);
}
~Connection ()
{
Dispose (false);
}
internal static Connection Wrap(IntPtr rawConnection)
{
if (slot > -1) {
// Maybe we already have a Connection object associated with
// this rawConnection then return it
IntPtr rawThis = dbus_connection_get_data (rawConnection, slot);
if (rawThis != IntPtr.Zero && ((GCHandle)rawThis).Target == typeof(DBus.Connection)) {
return (DBus.Connection) ((GCHandle)rawThis).Target;
}
}
// If it doesn't exist then create a new connection around it
return new Connection(rawConnection);
}
public void AddFilter (DBusHandleMessageFunction func)
{
if (!dbus_connection_add_filter (RawConnection,
func,
IntPtr.Zero,
IntPtr.Zero))
throw new OutOfMemoryException ();
this.filters.Add (func);
}
public void RemoveFilter (DBusHandleMessageFunction func)
{
dbus_connection_remove_filter (RawConnection, func, IntPtr.Zero);
this.filters.Remove (func);
}
public void AddMatch (string match_rule)
{
dbus_bus_add_match (RawConnection, match_rule, IntPtr.Zero);
this.matches.Add (match_rule);
}
public void RemoveMatch (string match_rule)
{
dbus_bus_remove_match (RawConnection, match_rule, IntPtr.Zero);
this.matches.Remove (match_rule);
}
internal void RegisterObjectPath (string path, DBusObjectPathVTable vtable)
{
if (!dbus_connection_register_object_path (RawConnection, path, ref vtable, IntPtr.Zero))
throw new OutOfMemoryException ();
this.object_paths[path] = vtable;
}
internal void UnregisterObjectPath (string path)
{
dbus_connection_unregister_object_path (RawConnection, path);
this.object_paths.Remove (path);
}
public string UniqueName
{
get
{
return Marshal.PtrToStringAnsi (dbus_bus_get_unique_name (RawConnection));
}
}
public int Timeout
{
get
{
return this.timeout;
}
set
{
this.timeout = value;
}
}
private int Slot
{
get
{
if (slot == -1)
{
// We need to initialize the slot
if (!dbus_connection_allocate_data_slot (ref slot))
throw new OutOfMemoryException ();
Debug.Assert (slot >= 0);
}
return slot;
}
}
internal IntPtr RawConnection
{
get
{
return rawConnection;
}
set
{
if (value == rawConnection)
return;
if (rawConnection != IntPtr.Zero)
{
// Remove our callbacks from this connection
foreach (DBusHandleMessageFunction func in this.filters)
dbus_connection_remove_filter (rawConnection, func, IntPtr.Zero);
foreach (string match_rule in this.matches)
dbus_bus_remove_match (rawConnection, match_rule, IntPtr.Zero);
foreach (string path in this.object_paths.Keys)
dbus_connection_unregister_object_path (rawConnection, path);
// Get the reference to this
IntPtr rawThis = dbus_connection_get_data (rawConnection, Slot);
Debug.Assert (rawThis != IntPtr.Zero);
// Blank over the reference
dbus_connection_set_data (rawConnection, Slot, IntPtr.Zero, IntPtr.Zero);
// Free the reference
((GCHandle) rawThis).Free();
// Unref the connection
dbus_connection_unref(rawConnection);
}
this.rawConnection = value;
if (rawConnection != IntPtr.Zero)
{
GCHandle rawThis;
dbus_connection_ref (rawConnection);
// We store a weak reference to the C# object on the C object
rawThis = GCHandle.Alloc (this, GCHandleType.WeakTrackResurrection);
dbus_connection_set_data(rawConnection, Slot, (IntPtr) rawThis, IntPtr.Zero);
// Add the callbacks to this new connection
foreach (DBusHandleMessageFunction func in this.filters)
dbus_connection_add_filter (rawConnection, func, IntPtr.Zero, IntPtr.Zero);
foreach (string match_rule in this.matches)
dbus_bus_add_match (rawConnection, match_rule, IntPtr.Zero);
foreach (string path in this.object_paths.Keys) {
DBusObjectPathVTable vtable = (DBusObjectPathVTable) this.object_paths[path];
dbus_connection_register_object_path (rawConnection, path, ref vtable, IntPtr.Zero);
}
}
else
{
this.filters.Clear ();
this.matches.Clear ();
this.object_paths.Clear ();
}
}
}
[DllImport("dbus-glib-1")]
private extern static void dbus_connection_setup_with_g_main(IntPtr rawConnection,
IntPtr rawContext);
[DllImport ("dbus-1")]
private extern static IntPtr dbus_connection_open (string address, ref Error error);
[DllImport ("dbus-1")]
private extern static void dbus_connection_unref (IntPtr ptr);
[DllImport ("dbus-1")]
private extern static void dbus_connection_ref (IntPtr ptr);
[DllImport ("dbus-1")]
private extern static bool dbus_connection_allocate_data_slot (ref int slot);
[DllImport ("dbus-1")]
private extern static void dbus_connection_free_data_slot (ref int slot);
[DllImport ("dbus-1")]
private extern static bool dbus_connection_set_data (IntPtr ptr,
int slot,
IntPtr data,
IntPtr free_data_func);
[DllImport ("dbus-1")]
private extern static void dbus_connection_flush (IntPtr ptr);
[DllImport ("dbus-1")]
private extern static IntPtr dbus_connection_get_data (IntPtr ptr,
int slot);
[DllImport ("dbus-1")]
private extern static void dbus_connection_disconnect (IntPtr ptr);
[DllImport ("dbus-1")]
private extern static IntPtr dbus_bus_get_unique_name (IntPtr ptr);
[DllImport("dbus-1")]
private extern static bool dbus_connection_add_filter(IntPtr rawConnection,
DBusHandleMessageFunction filter,
IntPtr userData,
IntPtr freeData);
[DllImport("dbus-1")]
private extern static void dbus_connection_remove_filter(IntPtr rawConnection,
DBusHandleMessageFunction filter,
IntPtr userData);
[DllImport("dbus-1")]
private extern static void dbus_bus_add_match(IntPtr rawConnection,
string rule,
IntPtr erro);
[DllImport("dbus-1")]
private extern static void dbus_bus_remove_match(IntPtr rawConnection,
string rule,
IntPtr erro);
[DllImport ("dbus-1")]
private extern static bool dbus_connection_register_object_path (IntPtr rawConnection,
string path,
ref DBusObjectPathVTable vTable,
IntPtr userData);
[DllImport ("dbus-1")]
private extern static void dbus_connection_unregister_object_path (IntPtr rawConnection,
string path);
}
}

View file

@ -1,12 +0,0 @@
namespace DBus
{
using System;
using System.Runtime.InteropServices;
public class DBusException : ApplicationException
{
internal DBusException (Error error) : base (error.Message) {
error.Free();
}
}
}

View file

@ -1,172 +0,0 @@
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// Array.
/// </summary>
public class Array : IDBusType
{
public const char Code = 'a';
private System.Array val;
private ArrayList elements;
private Type elementType;
private Service service = null;
private Array()
{
}
public Array(System.Array val, Service service)
{
this.val = val;
this.elementType = Arguments.MatchType(val.GetType().GetElementType());
this.service = service;
}
public Array(IntPtr iter, Service service)
{
this.service = service;
IntPtr arrayIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
int elementTypeCode = dbus_message_iter_get_element_type (iter);
dbus_message_iter_recurse (iter, arrayIter);
this.elementType = (Type) Arguments.DBusTypes [(char) elementTypeCode];
elements = new ArrayList ();
if (dbus_message_iter_get_arg_type (arrayIter) != 0) {
do {
object [] pars = new Object[2];
pars[0] = arrayIter;
pars[1] = service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
elements.Add(dbusType);
} while (dbus_message_iter_next(arrayIter));
}
Marshal.FreeCoTaskMem(arrayIter);
}
public string GetElementCodeAsString ()
{
string ret = System.String.Empty;
Type t = val.GetType ().GetElementType ();
while (true) {
ret += Arguments.GetCodeAsString (Arguments.MatchType(t));
if (t.IsArray)
t = t.GetElementType ();
else
break;
}
return ret;
}
public void Append(IntPtr iter)
{
IntPtr arrayIter = Marshal.AllocCoTaskMem (Arguments.DBusMessageIterSize);
if (!dbus_message_iter_open_container (iter,
(int) Code, GetElementCodeAsString(),
arrayIter)) {
throw new ApplicationException("Failed to append array argument: " + val);
}
foreach (object element in this.val) {
object [] pars = new Object[2];
pars[0] = element;
pars[1] = this.service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
dbusType.Append(arrayIter);
}
if (!dbus_message_iter_close_container (iter, arrayIter)) {
throw new ApplicationException ("Failed to append array argument: " + val);
}
Marshal.FreeCoTaskMem (arrayIter);
}
public static bool Suits(System.Type type)
{
Type type2 = type.GetElementType ();
if (type.IsArray || (type2 != null && type2.IsArray)) {
return true;
}
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_Ref);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Castclass, type);
if (!isReturn) {
generator.Emit(OpCodes.Stind_Ref);
}
}
public object Get()
{
throw new ArgumentException("Cannot call Get on an Array without specifying type.");
}
public object Get(System.Type type)
{
if (type.IsArray)
type = type.GetElementType ();
if (Arguments.Suits(elementType, type.UnderlyingSystemType)) {
this.val = System.Array.CreateInstance(type.UnderlyingSystemType, elements.Count);
int i = 0;
foreach (DBusType.IDBusType element in elements) {
this.val.SetValue(element.Get(type.UnderlyingSystemType), i++);
}
} else {
throw new ArgumentException("Cannot cast DBus.Type.Array to type '" + type.ToString() + "'");
}
return this.val;
}
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_open_container (IntPtr iter,
int containerType,
string elementType,
IntPtr subIter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_close_container (IntPtr iter,
IntPtr subIter);
[DllImport("dbus-1")]
private extern static int dbus_message_iter_get_element_type(IntPtr iter);
[DllImport("dbus-1")]
private extern static int dbus_message_iter_get_arg_type(IntPtr iter);
[DllImport("dbus-1")]
private extern static void dbus_message_iter_recurse(IntPtr iter, IntPtr subIter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_next(IntPtr iter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_has_next (IntPtr iter);
}
}

View file

@ -1,86 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// Boolean
/// </summary>
public class Boolean : IDBusType
{
public const char Code = 'b';
private System.Boolean val;
private Boolean()
{
}
public Boolean(System.Boolean val, Service service)
{
this.val = val;
}
public Boolean(IntPtr iter, Service service)
{
dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append BOOLEAN argument:" + val);
}
public static bool Suits(System.Type type)
{
switch (type.ToString()) {
case "System.Boolean":
case "System.Boolean&":
return true;
}
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_I1);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Unbox, type);
generator.Emit(OpCodes.Ldind_I1);
if (!isReturn) {
generator.Emit(OpCodes.Stind_I1);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
switch (type.ToString()) {
case "System.Boolean":
case "System.Boolean&":
return this.val;
default:
throw new ArgumentException("Cannot cast DBus.Type.Boolean to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out bool value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref bool value);
}
}

View file

@ -1,105 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// Byte
/// </summary>
public class Byte : IDBusType
{
public const char Code = 'y';
private System.Byte val;
private Byte()
{
}
public Byte(System.Byte val, Service service)
{
this.val = val;
}
public Byte(System.Char val, Service service)
{
this.val = (byte) val;
}
public Byte(IntPtr iter, Service service)
{
dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append BYTE argument:" + val);
}
public static bool Suits(System.Type type)
{
if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.Byte)) {
return true;
}
switch (type.ToString()) {
case "System.Byte":
case "System.Byte&":
case "System.Char":
case "System.Char&":
return true;
}
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_U1);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Unbox, type);
generator.Emit(OpCodes.Ldind_U1);
if (!isReturn) {
generator.Emit(OpCodes.Stind_I1);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
if (type.IsEnum) {
return Enum.ToObject(type, this.val);
}
switch (type.ToString()) {
case "System.Byte":
case "System.Byte&":
return this.val;
case "System.Char":
case "System.Char&":
char charVal = (char) this.val;
return charVal;
default:
throw new ArgumentException("Cannot cast DBus.Type.Byte to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out byte value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref byte value);
}
}

View file

@ -1,148 +0,0 @@
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// Dict.
/// </summary>
public class Dict : IDBusType
{
public const char Code = 'm';
private Hashtable val;
private Dict()
{
}
public Dict(IDictionary val, Service service)
{
this.val = new Hashtable();
foreach (DictionaryEntry entry in val) {
this.val.Add(entry.Key, entry.Value);
}
}
public Dict(IntPtr iter, Service service)
{
IntPtr dictIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
bool notEmpty = dbus_message_iter_init_dict_iterator(iter, dictIter);
this.val = new Hashtable();
if (notEmpty) {
do {
string key = dbus_message_iter_get_dict_key(dictIter);
// Get the argument type and get the value
Type elementType = (Type) DBus.Arguments.DBusTypes[(char) dbus_message_iter_get_arg_type(dictIter)];
object [] pars = new Object[2];
pars[0] = dictIter;
pars[1] = service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
this.val.Add(key, dbusType);
} while (dbus_message_iter_next(dictIter));
}
Marshal.FreeCoTaskMem(dictIter);
}
public void Append(IntPtr iter)
{
IntPtr dictIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
if (!dbus_message_iter_append_dict(iter,
dictIter)) {
throw new ApplicationException("Failed to append DICT argument:" + val);
}
foreach (DictionaryEntry entry in this.val) {
if (!dbus_message_iter_append_dict_key(dictIter, (string) entry.Key)) {
throw new ApplicationException("Failed to append DICT key:" + entry.Key);
}
// Get the element type
Type elementType = Arguments.MatchType(entry.Value.GetType());
object [] pars = new Object[1];
pars[0] = entry.Value;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
dbusType.Append(dictIter);
}
Marshal.FreeCoTaskMem(dictIter);
}
public static bool Suits(System.Type type)
{
if (typeof(IDictionary).IsAssignableFrom(type)) {
return true;
}
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_Ref);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Castclass, type);
if (!isReturn) {
generator.Emit(OpCodes.Stind_Ref);
}
}
public object Get()
{
return Get(typeof(Hashtable));
}
public object Get(System.Type type)
{
IDictionary retVal;
if (Suits(type)) {
retVal = (IDictionary) Activator.CreateInstance(type, new object[0]);
foreach (DictionaryEntry entry in this.val) {
retVal.Add(entry.Key, ((IDBusType) entry.Value).Get());
}
} else {
throw new ArgumentException("Cannot cast DBus.Type.Dict to type '" + type.ToString() + "'");
}
return retVal;
}
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_init_dict_iterator(IntPtr iter,
IntPtr dictIter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_dict(IntPtr iter,
IntPtr dictIter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_has_next(IntPtr iter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_next(IntPtr iter);
[DllImport("dbus-1")]
private extern static string dbus_message_iter_get_dict_key (IntPtr dictIter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_dict_key (IntPtr dictIter,
string value);
[DllImport("dbus-1")]
private extern static int dbus_message_iter_get_arg_type(IntPtr iter);
}
}

View file

@ -1,86 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// IEEE 754 double
/// </summary>
public class Double : IDBusType
{
public const char Code = 'd';
private System.Double val;
private Double()
{
}
public Double(System.Double val, Service service)
{
this.val = val;
}
public Double(IntPtr iter, Service service)
{
dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append DOUBLE argument:" + val);
}
public static bool Suits(System.Type type)
{
switch (type.ToString()) {
case "System.Double":
case "System.Double&":
return true;
}
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_R8);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Unbox, type);
generator.Emit(OpCodes.Ldind_R8);
if (!isReturn) {
generator.Emit(OpCodes.Stind_R8);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
switch (type.ToString()) {
case "System.Double":
case "System.Double&":
return this.val;
default:
throw new ArgumentException("Cannot cast DBus.Type.Double to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out double value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref double value);
}
}

View file

@ -1,16 +0,0 @@
using System;
namespace DBus.DBusType
{
/// <summary>
/// Base class for DBusTypes
/// </summary>
public interface IDBusType
{
object Get();
object Get(System.Type type);
void Append(IntPtr iter);
}
}

View file

@ -1,93 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// 16-bit integer.
/// </summary>
public class Int16 : IDBusType
{
public const char Code = 'n';
private System.Int16 val;
private Int16()
{
}
public Int16(System.Int16 val, Service service)
{
this.val = val;
}
public Int16(IntPtr iter, Service service)
{
dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append INT16 argument:" + val);
}
public static bool Suits(System.Type type)
{
if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.Int16)) {
return true;
}
switch (type.ToString()) {
case "System.Int16":
case "System.Int16&":
return true; }
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_I2);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Unbox, type);
generator.Emit(OpCodes.Ldind_I2);
if (!isReturn) {
generator.Emit(OpCodes.Stind_I2);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
if (type.IsEnum) {
return Enum.ToObject(type, this.val);
}
switch (type.ToString()) {
case "System.Int16":
case "System.Int16&":
return this.val;
default:
throw new ArgumentException("Cannot cast DBus.Type.Int16 to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.Int16 value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.Int16 value);
}
}

View file

@ -1,93 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// 32-bit integer.
/// </summary>
public class Int32 : IDBusType
{
public const char Code = 'i';
private System.Int32 val;
private Int32()
{
}
public Int32(System.Int32 val, Service service)
{
this.val = val;
}
public Int32(IntPtr iter, Service service)
{
dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append INT32 argument:" + val);
}
public static bool Suits(System.Type type)
{
if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.Int32)) {
return true;
}
switch (type.ToString()) {
case "System.Int32":
case "System.Int32&":
return true; }
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_I4);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Unbox, type);
generator.Emit(OpCodes.Ldind_I4);
if (!isReturn) {
generator.Emit(OpCodes.Stind_I4);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
if (type.IsEnum) {
return Enum.ToObject(type, this.val);
}
switch (type.ToString()) {
case "System.Int32":
case "System.Int32&":
return this.val;
default:
throw new ArgumentException("Cannot cast DBus.Type.Int32 to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.Int32 value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.Int32 value);
}
}

View file

@ -1,94 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// 64-bit integer.
/// </summary>
public class Int64 : IDBusType
{
public const char Code = 'x';
private System.Int64 val;
private Int64()
{
}
public Int64(System.Int64 val, Service service)
{
this.val = val;
}
public Int64(IntPtr iter, Service service)
{
dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append INT64 argument:" + val);
}
public static bool Suits(System.Type type)
{
if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.Int64)) {
return true;
}
switch (type.ToString()) {
case "System.Int64":
case "System.Int64&":
return true;
}
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_I8);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Unbox, type);
generator.Emit(OpCodes.Ldind_I8);
if (!isReturn) {
generator.Emit(OpCodes.Stind_I8);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
if (type.IsEnum) {
return Enum.ToObject(type, this.val);
}
switch (type.ToString()) {
case "System.Int64":
case "System.Int64&":
return this.val;
default:
throw new ArgumentException("Cannot cast DBus.Type.Int64 to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.Int64 value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.Int64 value);
}
}

View file

@ -1,107 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// An object path.
/// </summary>
public class ObjectPath : IDBusType
{
public const char Code = 'o';
private string path = null;
private object val = null;
private Service service = null;
private ObjectPath()
{
}
public ObjectPath(object val, Service service)
{
this.val = val;
this.service = service;
}
public ObjectPath(IntPtr iter, Service service)
{
IntPtr raw;
dbus_message_iter_get_basic (iter, out raw);
this.path = Marshal.PtrToStringAnsi (raw);
this.service = service;
}
private string Path
{
get {
if (this.path == null && this.val != null) {
Handler handler = this.service.GetHandler(this.val);
this.path = handler.Path;
}
return this.path;
}
}
public void Append(IntPtr iter)
{
IntPtr marshalVal = Marshal.StringToHGlobalAnsi (Path);
bool success = dbus_message_iter_append_basic (iter, (int) Code, ref marshalVal);
Marshal.FreeHGlobal (marshalVal);
if (!success)
throw new ApplicationException("Failed to append OBJECT_PATH argument:" + val);
}
public static bool Suits(System.Type type)
{
object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), false);
if (attributes.Length == 1) {
return true;
} else {
return false;
}
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_Ref);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Castclass, type);
if (!isReturn) {
generator.Emit(OpCodes.Stind_Ref);
}
}
public object Get()
{
throw new ArgumentException("Cannot call Get on an ObjectPath without specifying type.");
}
public object Get(System.Type type)
{
try {
return this.service.GetObject(type, Path);
} catch(Exception ex) {
throw new ArgumentException("Cannot cast object pointed to by Object Path to type '" + type.ToString() + "': " + ex);
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out IntPtr path);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref IntPtr path);
}
}

View file

@ -1,95 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// A string.
/// </summary>
public class String : IDBusType
{
public const char Code = 's';
private string val;
private String()
{
}
public String(string val, Service service)
{
this.val = val;
}
public String(IntPtr iter, Service service)
{
IntPtr raw;
dbus_message_iter_get_basic (iter, out raw);
this.val = Marshal.PtrToStringAnsi (raw);
}
public void Append(IntPtr iter)
{
IntPtr marshalVal = Marshal.StringToHGlobalAnsi (val);
bool success = dbus_message_iter_append_basic (iter, (int) Code, ref marshalVal);
Marshal.FreeHGlobal (marshalVal);
if (!success)
throw new ApplicationException("Failed to append STRING argument:" + val);
}
public static bool Suits(System.Type type)
{
switch (type.ToString()) {
case "System.String":
case "System.String&":
return true;
}
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_Ref);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Castclass, type);
if (!isReturn) {
generator.Emit(OpCodes.Stind_Ref);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
switch (type.ToString())
{
case "System.String":
case "System.String&":
return this.val;
default:
throw new ArgumentException("Cannot cast DBus.Type.String to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out IntPtr value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref IntPtr value);
}
}

View file

@ -1,93 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// 16-bit integer.
/// </summary>
public class UInt16 : IDBusType
{
public const char Code = 'q';
private System.UInt16 val;
private UInt16()
{
}
public UInt16(System.UInt16 val, Service service)
{
this.val = val;
}
public UInt16(IntPtr iter, Service service)
{
dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append INT16 argument:" + val);
}
public static bool Suits(System.Type type)
{
if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.UInt16)) {
return true;
}
switch (type.ToString()) {
case "System.UInt16":
case "System.UInt16&":
return true; }
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_U2);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Unbox, type);
generator.Emit(OpCodes.Ldind_U2);
if (!isReturn) {
generator.Emit(OpCodes.Stind_I2);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
if (type.IsEnum) {
return Enum.ToObject(type, this.val);
}
switch (type.ToString()) {
case "System.UInt16":
case "System.UInt16&":
return this.val;
default:
throw new ArgumentException("Cannot cast DBus.Type.UInt16 to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt16 value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt16 value);
}
}

View file

@ -1,95 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// 32-bit unsigned integer.
/// </summary>
public class UInt32 : IDBusType
{
public const char Code = 'u';
private System.UInt32 val;
private UInt32()
{
}
public UInt32(System.UInt32 val, Service service)
{
this.val = val;
}
public UInt32(IntPtr iter, Service service)
{
dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append UINT32 argument:" + val);
}
public static bool Suits(System.Type type)
{
if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.UInt32)) {
return true;
}
switch (type.ToString()) {
case "System.UInt32":
case "System.UInt32&":
return true;
}
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_U4);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Unbox, type);
generator.Emit(OpCodes.Ldind_U4);
if (!isReturn) {
generator.Emit(OpCodes.Stind_I4);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
if (type.IsEnum) {
return Enum.ToObject(type, this.val);
}
switch (type.ToString())
{
case "System.UInt32":
case "System.UInt32&":
return this.val;
default:
throw new ArgumentException("Cannot cast DBus.Type.UInt32 to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt32 value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt32 value);
}
}

View file

@ -1,95 +0,0 @@
using System;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using DBus;
namespace DBus.DBusType
{
/// <summary>
/// 64-bit unsigned integer.
/// </summary>
public class UInt64 : IDBusType
{
public const char Code = 't';
private System.UInt64 val;
private UInt64()
{
}
public UInt64(System.UInt64 val, Service service)
{
this.val = val;
}
public UInt64(IntPtr iter, Service service)
{
dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append UINT64 argument:" + val);
}
public static bool Suits(System.Type type)
{
if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.UInt64)) {
return true;
}
switch (type.ToString()) {
case "System.UInt64":
case "System.UInt64&":
return true;
}
return false;
}
public static void EmitMarshalIn(ILGenerator generator, Type type)
{
if (type.IsByRef) {
generator.Emit(OpCodes.Ldind_I8);
}
}
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
{
generator.Emit(OpCodes.Unbox, type);
generator.Emit(OpCodes.Ldind_I8);
if (!isReturn) {
generator.Emit(OpCodes.Stind_I8);
}
}
public object Get()
{
return this.val;
}
public object Get(System.Type type)
{
if (type.IsEnum) {
return Enum.ToObject(type, this.val);
}
switch (type.ToString())
{
case "System.UInt64":
case "System.UInt64&":
return this.val;
default:
throw new ArgumentException("Cannot cast DBus.Type.UInt64 to type '" + type.ToString() + "'");
}
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt64 value);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt64 value);
}
}

View file

@ -1,60 +0,0 @@
namespace DBus
{
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
// FIXME add code to verify that size of DBus.Error
// matches the C code.
[StructLayout (LayoutKind.Sequential)]
internal struct Error
{
internal IntPtr name;
internal IntPtr message;
private int dummies;
private IntPtr padding1;
public void Init()
{
dbus_error_init(ref this);
}
public void Free()
{
dbus_error_free(ref this);
}
public string Message
{
get
{
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(message);
}
}
public string Name
{
get
{
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name);
}
}
public bool IsSet
{
get
{
return (name != IntPtr.Zero);
}
}
[DllImport ("dbus-1", EntryPoint="dbus_error_init")]
private extern static void dbus_error_init (ref Error error);
[DllImport ("dbus-1", EntryPoint="dbus_error_free")]
private extern static void dbus_error_free (ref Error error);
}
}

View file

@ -1,45 +0,0 @@
namespace DBus
{
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
public class ErrorMessage : Message
{
public ErrorMessage() : base(MessageType.Error)
{
}
internal ErrorMessage(IntPtr rawMessage, Service service) : base(rawMessage, service)
{
}
public ErrorMessage(Service service) : base(MessageType.Error, service)
{
}
public new string Name
{
get {
if (this.name == null) {
this.name = Marshal.PtrToStringAnsi(dbus_message_get_error_name(RawMessage));
}
return this.name;
}
set {
if (value != this.name) {
dbus_message_set_error_name(RawMessage, value);
this.name = value;
}
}
}
[DllImport("dbus-1")]
private extern static bool dbus_message_set_error_name(IntPtr rawMessage, string name);
[DllImport("dbus-1")]
private extern static IntPtr dbus_message_get_error_name(IntPtr rawMessage);
}
}

View file

@ -1,172 +0,0 @@
namespace DBus
{
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Reflection;
using System.Collections;
internal enum Result
{
Handled = 0,
NotYetHandled = 1,
NeedMemory = 2
}
internal class Handler
{
private string path = null;
private Introspector introspector = null;
private object handledObject = null;
private DBusObjectPathVTable vTable;
private Connection connection;
private Service service;
// We need to hold extra references to these callbacks so that they don't
// get garbage collected before they are called back into from unmanaged
// code.
private DBusObjectPathUnregisterFunction unregister_func;
private DBusObjectPathMessageFunction message_func;
public Handler(object handledObject,
string path,
Service service)
{
Service = service;
Connection = service.Connection;
HandledObject = handledObject;
this.path = path;
// Create the vTable and register the path
this.unregister_func = new DBusObjectPathUnregisterFunction (Unregister_Called);
this.message_func = new DBusObjectPathMessageFunction (Message_Called);
vTable = new DBusObjectPathVTable (this.unregister_func, this.message_func);
Connection.RegisterObjectPath (Path, vTable);
RegisterSignalHandlers();
}
private void RegisterSignalHandlers()
{
ProxyBuilder proxyBuilder = new ProxyBuilder(Service, HandledObject.GetType(), Path);
foreach (DictionaryEntry interfaceEntry in this.introspector.InterfaceProxies) {
InterfaceProxy interfaceProxy = (InterfaceProxy) interfaceEntry.Value;
foreach (DictionaryEntry signalEntry in interfaceProxy.Signals) {
EventInfo eventE = (EventInfo) signalEntry.Value;
Delegate del = Delegate.CreateDelegate(eventE.EventHandlerType, proxyBuilder.GetSignalProxy(), "Proxy_" + eventE.Name);
eventE.AddEventHandler(HandledObject, del);
}
}
}
public object HandledObject
{
get {
return this.handledObject;
}
set {
this.handledObject = value;
// Register the methods
this.introspector = Introspector.GetIntrospector(value.GetType());
}
}
public void Unregister_Called(IntPtr rawConnection,
IntPtr userData)
{
if (service != null) {
service.UnregisterObject(HandledObject);
}
path = null;
}
private int Message_Called(IntPtr rawConnection,
IntPtr rawMessage,
IntPtr userData)
{
Message message = Message.Wrap(rawMessage, Service);
Result res = Result.NotYetHandled;
switch (message.Type) {
case Message.MessageType.MethodCall:
res = HandleMethod ((MethodCall) message);
break;
case Message.MessageType.Signal:
// We're not interested in signals here because we're the ones
// that generate them!
break;
}
message.Dispose ();
return (int) res;
}
private Result HandleMethod(MethodCall methodCall)
{
methodCall.Service = service;
InterfaceProxy interfaceProxy = this.introspector.GetInterface(methodCall.InterfaceName);
if (interfaceProxy == null || !interfaceProxy.HasMethod(methodCall.Key)) {
// No such interface here.
return Result.NotYetHandled;
}
MethodInfo method = interfaceProxy.GetMethod(methodCall.Key);
Message.Push (methodCall);
// Now call the method. FIXME: Error handling
object [] args = methodCall.Arguments.GetParameters(method);
object retVal = method.Invoke(this.handledObject, args);
Message.Pop ();
// Create the reply and send it
MethodReturn methodReturn = new MethodReturn(methodCall);
methodReturn.Arguments.AppendResults(method, retVal, args);
methodReturn.Send();
return Result.Handled;
}
internal string Path
{
get
{
return path;
}
}
internal Connection Connection
{
get
{
return connection;
}
set
{
this.connection = value;
}
}
public Service Service
{
get
{
return service;
}
set
{
this.service = value;
}
}
}
}

View file

@ -1,23 +0,0 @@
using System;
namespace DBus
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public class InterfaceAttribute : Attribute
{
private string interfaceName;
public InterfaceAttribute(string interfaceName)
{
this.interfaceName = interfaceName;
}
public string InterfaceName
{
get
{
return this.interfaceName;
}
}
}
}

View file

@ -1,121 +0,0 @@
namespace DBus
{
using System;
using System.Collections;
using System.Reflection;
internal class InterfaceProxy
{
private static Hashtable interfaceProxies = new Hashtable();
private Hashtable methods = null;
private Hashtable signals = null;
private string interfaceName;
private InterfaceProxy(Type type)
{
object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), true);
InterfaceAttribute interfaceAttribute = (InterfaceAttribute) attributes[0];
this.interfaceName = interfaceAttribute.InterfaceName;
AddMethods(type);
AddSignals(type);
}
// Add all the events with Signal attributes
private void AddSignals(Type type)
{
this.signals = new Hashtable();
foreach (EventInfo signal in type.GetEvents(BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.DeclaredOnly)) {
object[] attributes = signal.GetCustomAttributes(typeof(SignalAttribute), false);
if (attributes.GetLength(0) > 0) {
MethodInfo invoke = signal.EventHandlerType.GetMethod("Invoke");
signals.Add(signal.Name + " " + GetSignature(invoke), signal);
}
}
}
// Add all the methods with Method attributes
private void AddMethods(Type type)
{
this.methods = new Hashtable();
foreach (MethodInfo method in type.GetMethods(BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.DeclaredOnly)) {
object[] attributes = method.GetCustomAttributes(typeof(MethodAttribute), false);
if (attributes.GetLength(0) > 0) {
methods.Add(method.Name + " " + GetSignature(method), method);
}
}
}
public static InterfaceProxy GetInterface(Type type)
{
if (!interfaceProxies.Contains(type)) {
interfaceProxies[type] = new InterfaceProxy(type);
}
return (InterfaceProxy) interfaceProxies[type];
}
public bool HasMethod(string key)
{
return this.Methods.Contains(key);
}
public bool HasSignal(string key)
{
return this.Signals.Contains(key);
}
public EventInfo GetSignal(string key)
{
return (EventInfo) this.Signals[key];
}
public MethodInfo GetMethod(string key)
{
return (MethodInfo) this.Methods[key];
}
public static string GetSignature(MethodInfo method)
{
ParameterInfo[] pars = method.GetParameters();
string key = "";
foreach (ParameterInfo par in pars) {
if (!par.IsOut) {
Type dbusType = Arguments.MatchType(par.ParameterType);
key += Arguments.GetCode(dbusType);
}
}
return key;
}
public Hashtable Methods
{
get {
return this.methods;
}
}
public Hashtable Signals
{
get {
return this.signals;
}
}
public string InterfaceName
{
get {
return this.interfaceName;
}
}
}
}

View file

@ -1,81 +0,0 @@
namespace DBus
{
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Collections;
using System.Reflection;
internal class Introspector
{
private Type type;
private static Hashtable introspectors = new Hashtable();
private Hashtable interfaceProxies = null;
public static Introspector GetIntrospector(Type type)
{
if (!introspectors.Contains(type)) {
introspectors[type] = new Introspector(type);
}
return (Introspector) introspectors[type];
}
private Introspector(Type type)
{
interfaceProxies = new Hashtable();
AddType(type);
this.type = type;
}
private void AddType(Type type)
{
if (type == typeof(object)) {
// Base case
return;
}
object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), false);
if (attributes.Length >= 1) {
// This is a D-BUS interface so add it to the hashtable
InterfaceProxy interfaceProxy = InterfaceProxy.GetInterface(type);
interfaceProxies.Add(interfaceProxy.InterfaceName, interfaceProxy);
}
AddType(type.BaseType);
}
public InterfaceProxy GetInterface(string interfaceName) {
if (interfaceProxies.Contains(interfaceName)) {
return (InterfaceProxy) interfaceProxies[interfaceName];
} else {
return null;
}
}
public Hashtable InterfaceProxies
{
get {
return this.interfaceProxies;
}
}
public ConstructorInfo Constructor
{
get {
ConstructorInfo ret = this.type.GetConstructor(new Type[0]);
if (ret != null) {
return ret;
} else {
return typeof(object).GetConstructor(new Type[0]);
}
}
}
public override string ToString()
{
return this.type.ToString();
}
}
}

View file

@ -1,76 +0,0 @@
SUBDIRS=. doc example
TARGET=$(ASSEMBLY)
NOINST_EXES=test-dbus-sharp.exe
ASSEMBLY_NAME=dbus-sharp
GACUTIL=gacutil
DBUS_SHARP_FILES= \
$(srcdir)/Arguments.cs \
$(srcdir)/Bus.cs \
$(srcdir)/BusDriver.cs \
$(srcdir)/Connection.cs \
$(srcdir)/DBusException.cs \
$(srcdir)/Error.cs \
$(srcdir)/ErrorMessage.cs \
$(srcdir)/Handler.cs \
$(srcdir)/InterfaceAttribute.cs \
$(srcdir)/InterfaceProxy.cs \
$(srcdir)/Introspector.cs \
$(srcdir)/Message.cs \
$(srcdir)/MethodAttribute.cs \
$(srcdir)/MethodCall.cs \
$(srcdir)/MethodReturn.cs \
$(srcdir)/ProxyBuilder.cs \
$(srcdir)/Server.cs \
$(srcdir)/Service.cs \
$(srcdir)/Signal.cs \
$(srcdir)/SignalAttribute.cs \
$(srcdir)/DBusType/IDBusType.cs \
$(srcdir)/DBusType/Array.cs \
$(srcdir)/DBusType/Boolean.cs \
$(srcdir)/DBusType/Byte.cs \
$(srcdir)/DBusType/Double.cs \
$(srcdir)/DBusType/Int16.cs \
$(srcdir)/DBusType/Int32.cs \
$(srcdir)/DBusType/Int64.cs \
$(srcdir)/DBusType/ObjectPath.cs \
$(srcdir)/DBusType/String.cs \
$(srcdir)/DBusType/UInt16.cs \
$(srcdir)/DBusType/UInt32.cs \
$(srcdir)/DBusType/UInt64.cs
TEST_DBUS_SHARP_FILES=Test.cs
ASSEMBLY=$(ASSEMBLY_NAME).dll
DISTCLEANFILES=AssemblyInfo.cs $(ASSEMBLY).config $(ASSEMBLY) $(ASSEMBLY).mdb
all-am: $(TARGET)
dbus-sharp.dll: $(DBUS_SHARP_FILES)
$(CSC) --debug --unsafe --target library -o dbus-sharp.dll $(DBUS_SHARP_FILES) AssemblyInfo.cs
test-dbus-sharp.exe: $(TEST_DBUS_SHARP_FILES)
$(CSC) --debug --unsafe --target exe -L . -r dbus-sharp.dll -pkg:gtk-sharp -o test-dbus-sharp.exe $(TEST_DBUS_SHARP_FILES)
clean:
rm -f $(TARGET) $(TARGET).mdb $(NOINST_EXES) $(NOINST_EXES:%=%.mdb)
install-data-local:
@if test -n '$(TARGET)'; then \
echo "$(GACUTIL) /i $(ASSEMBLY) /f /package dbus-sharp /gacdir $(DESTDIR)$(libdir)"; \
$(GACUTIL) /i $(ASSEMBLY) /f /package dbus-sharp /gacdir $(libdir) /root $(DESTDIR)$(libdir) || exit 1; \
fi
uninstall-local:
@if test -n '$(TARGET)'; then \
echo "$(GACUTIL) /u $(ASSEMBLY_NAME) /package dbus-sharp /gacdir $(DESTDIR)$(libdir)"; \
$(GACUTIL) /u $(ASSEMBLY_NAME) /package dbus-sharp /gacdir $(libdir) /root $(DESTDIR)$(libdir) || exit 1; \
fi
EXTRA_DIST= \
$(DBUS_SHARP_FILES) \
AssemblyInfo.cs.in \
$(ASSEMBLY).config.in \
dbus-sharp.snk

View file

@ -1,437 +0,0 @@
namespace DBus
{
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Collections;
public class Message : IDisposable
{
private static Stack stack = new Stack ();
static public Message Current {
get
{
return stack.Count > 0 ? (Message) stack.Peek () : null;
}
}
static internal void Push (Message message)
{
stack.Push (message);
}
static internal void Pop ()
{
stack.Pop ();
}
/// <summary>
/// A pointer to the underlying Message structure
/// </summary>
private IntPtr rawMessage;
/// <summary>
/// The current slot number
/// </summary>
private static int slot = -1;
// Keep in sync with C
public enum MessageType
{
Invalid = 0,
MethodCall = 1,
MethodReturn = 2,
Error = 3,
Signal = 4
}
private Arguments arguments = null;
protected Service service = null;
protected string pathName = null;
protected string interfaceName = null;
protected string name = null;
private string key= null;
protected Message()
{
// An empty constructor for the sake of sub-classes which know how to construct theirselves.
}
protected Message(IntPtr rawMessage, Service service)
{
RawMessage = rawMessage;
this.service = service;
}
protected Message(MessageType messageType)
{
// the assignment bumps the refcount
RawMessage = dbus_message_new((int) messageType);
if (RawMessage == IntPtr.Zero) {
throw new OutOfMemoryException();
}
dbus_message_unref(RawMessage);
}
protected Message(MessageType messageType, Service service) : this(messageType)
{
this.service = service;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose (bool disposing)
{
if (disposing) {
if (this.arguments != null)
this.arguments.Dispose ();
}
RawMessage = IntPtr.Zero; // free the native object
}
~Message()
{
Dispose (false);
}
public static Message Wrap(IntPtr rawMessage, Service service)
{
if (slot > -1) {
// If we already have a Message object associated with this rawMessage then return it
IntPtr rawThis = dbus_message_get_data(rawMessage, slot);
if (rawThis != IntPtr.Zero && ((GCHandle)rawThis).Target == typeof(DBus.Message))
return (DBus.Message) ((GCHandle)rawThis).Target;
}
// If it doesn't exist then create a new Message around it
Message message = null;
MessageType messageType = (MessageType) dbus_message_get_type(rawMessage);
switch (messageType) {
case MessageType.Signal:
message = new Signal(rawMessage, service);
break;
case MessageType.MethodCall:
message = new MethodCall(rawMessage, service);
break;
case MessageType.MethodReturn:
message = new MethodReturn(rawMessage, service);
break;
case MessageType.Error:
message = new ErrorMessage(rawMessage, service);
break;
default:
throw new ApplicationException("Unknown message type to wrap: " + messageType);
}
return message;
}
internal IntPtr RawMessage
{
get
{
return rawMessage;
}
set
{
if (value == rawMessage)
return;
if (rawMessage != IntPtr.Zero)
{
// Get the reference to this
IntPtr rawThis = dbus_message_get_data(rawMessage, Slot);
Debug.Assert (rawThis != IntPtr.Zero);
// Blank over the reference
dbus_message_set_data(rawMessage, Slot, IntPtr.Zero, IntPtr.Zero);
// Free the reference
((GCHandle) rawThis).Free();
// Unref the connection
dbus_message_unref(rawMessage);
}
this.rawMessage = value;
if (rawMessage != IntPtr.Zero)
{
GCHandle rawThis;
dbus_message_ref(rawMessage);
// We store a weak reference to the C# object on the C object
rawThis = GCHandle.Alloc(this, GCHandleType.WeakTrackResurrection);
dbus_message_set_data(rawMessage, Slot, (IntPtr) rawThis, IntPtr.Zero);
}
}
}
public void Send(ref int serial)
{
if (!dbus_connection_send (Service.Connection.RawConnection, RawMessage, ref serial))
throw new OutOfMemoryException ();
Service.Connection.Flush();
}
public void Send()
{
int ignored = 0;
Send(ref ignored);
}
public void SendWithReply()
{
IntPtr rawPendingCall = IntPtr.Zero;
if (!dbus_connection_send_with_reply (Service.Connection.RawConnection, RawMessage, rawPendingCall, Service.Connection.Timeout))
throw new OutOfMemoryException();
}
public MethodReturn SendWithReplyAndBlock()
{
Error error = new Error();
error.Init();
IntPtr rawMessage = dbus_connection_send_with_reply_and_block(Service.Connection.RawConnection,
RawMessage,
Service.Connection.Timeout,
ref error);
if (rawMessage != IntPtr.Zero) {
MethodReturn methodReturn = new MethodReturn(rawMessage, Service);
// Ownership of a ref is passed onto us from
// dbus_connection_send_with_reply_and_block(). It gets reffed as
// a result of being passed into the MethodReturn ctor, so unref
// the extra one here.
dbus_message_unref (rawMessage);
return methodReturn;
} else {
throw new DBusException(error);
}
}
public MessageType Type
{
get
{
return (MessageType) dbus_message_get_type(RawMessage);
}
}
public Service Service
{
set
{
if (this.service != null && (value.Name != this.service.Name)) {
if (!dbus_message_set_destination(RawMessage, value.Name)) {
throw new OutOfMemoryException();
}
}
this.service = value;
}
get
{
return this.service;
}
}
protected virtual string PathName
{
set
{
if (value != this.pathName)
{
if (!dbus_message_set_path(RawMessage, value)) {
throw new OutOfMemoryException();
}
this.pathName = value;
}
}
get
{
if (this.pathName == null) {
this.pathName = Marshal.PtrToStringAnsi(dbus_message_get_path(RawMessage));
}
return this.pathName;
}
}
protected virtual string InterfaceName
{
set
{
if (value != this.interfaceName)
{
dbus_message_set_interface (RawMessage, value);
this.interfaceName = value;
}
}
get
{
if (this.interfaceName == null) {
this.interfaceName = Marshal.PtrToStringAnsi(dbus_message_get_interface(RawMessage));
}
return this.interfaceName;
}
}
protected virtual string Name
{
set {
if (value != this.name) {
dbus_message_set_member(RawMessage, value);
this.name = value;
}
}
get {
if (this.name == null) {
this.name = Marshal.PtrToStringAnsi(dbus_message_get_member(RawMessage));
}
return this.name;
}
}
public string Key
{
get {
if (this.key == null) {
this.key = Name + " " + Arguments;
}
return this.key;
}
}
public Arguments Arguments
{
get
{
if (this.arguments == null) {
this.arguments = new Arguments(this);
}
return this.arguments;
}
}
public string Sender
{
get
{
return Marshal.PtrToStringAnsi(dbus_message_get_sender(RawMessage));
}
}
public string Destination
{
get
{
return Marshal.PtrToStringAnsi(dbus_message_get_destination(RawMessage));
}
}
protected int Slot
{
get
{
if (slot == -1)
{
// We need to initialize the slot
if (!dbus_message_allocate_data_slot (ref slot))
throw new OutOfMemoryException ();
Debug.Assert (slot >= 0);
}
return slot;
}
}
[DllImport ("dbus-1", EntryPoint="dbus_message_new")]
protected extern static IntPtr dbus_message_new (int messageType);
[DllImport ("dbus-1", EntryPoint="dbus_message_unref")]
protected extern static void dbus_message_unref (IntPtr ptr);
[DllImport ("dbus-1", EntryPoint="dbus_message_ref")]
protected extern static void dbus_message_ref (IntPtr ptr);
[DllImport ("dbus-1", EntryPoint="dbus_message_allocate_data_slot")]
protected extern static bool dbus_message_allocate_data_slot (ref int slot);
[DllImport ("dbus-1", EntryPoint="dbus_message_free_data_slot")]
protected extern static void dbus_message_free_data_slot (ref int slot);
[DllImport ("dbus-1", EntryPoint="dbus_message_set_data")]
protected extern static bool dbus_message_set_data (IntPtr ptr,
int slot,
IntPtr data,
IntPtr free_data_func);
[DllImport ("dbus-1", EntryPoint="dbus_message_get_data")]
protected extern static IntPtr dbus_message_get_data (IntPtr ptr,
int slot);
[DllImport ("dbus-1", EntryPoint="dbus_connection_send")]
private extern static bool dbus_connection_send (IntPtr ptr,
IntPtr message,
ref int client_serial);
[DllImport ("dbus-1", EntryPoint="dbus_connection_send_with_reply")]
private extern static bool dbus_connection_send_with_reply (IntPtr rawConnection, IntPtr rawMessage, IntPtr rawPendingCall, int timeout);
[DllImport ("dbus-1", EntryPoint="dbus_connection_send_with_reply_and_block")]
private extern static IntPtr dbus_connection_send_with_reply_and_block (IntPtr rawConnection, IntPtr message, int timeout, ref Error error);
[DllImport("dbus-1")]
private extern static int dbus_message_get_type(IntPtr rawMessage);
[DllImport("dbus-1")]
private extern static bool dbus_message_set_path(IntPtr rawMessage, string pathName);
[DllImport("dbus-1")]
private extern static IntPtr dbus_message_get_path(IntPtr rawMessage);
[DllImport("dbus-1")]
private extern static bool dbus_message_set_interface (IntPtr rawMessage, string interfaceName);
[DllImport("dbus-1")]
private extern static IntPtr dbus_message_get_interface(IntPtr rawMessage);
[DllImport("dbus-1")]
private extern static bool dbus_message_set_member(IntPtr rawMessage, string name);
[DllImport("dbus-1")]
private extern static IntPtr dbus_message_get_member(IntPtr rawMessage);
[DllImport("dbus-1")]
private extern static bool dbus_message_set_destination(IntPtr rawMessage, string serviceName);
[DllImport("dbus-1")]
private extern static IntPtr dbus_message_get_destination(IntPtr rawMessage);
[DllImport("dbus-1")]
private extern static IntPtr dbus_message_get_sender(IntPtr rawMessage);
}
}

Some files were not shown because too many files have changed in this diff Show more