Commit d021cfae authored by Havoc Pennington's avatar Havoc Pennington

2003-09-01 Havoc Pennington <hp@pobox.com>

	* glib/dbus-gparser.c: implement

	* glib/dbus-gobject.c: start implementing skeletons support

	* configure.in: when disabling checks/assert, also define
	G_DISABLE_ASSERT and G_DISABLE_CHECKS
parent 7b4ac5de
2003-09-01 Havoc Pennington <hp@pobox.com>
* glib/dbus-gparser.c: implement
* glib/dbus-gobject.c: start implementing skeletons support
* configure.in: when disabling checks/assert, also define
G_DISABLE_ASSERT and G_DISABLE_CHECKS
2003-09-01 Havoc Pennington <hp@pobox.com>
* glib/Makefile.am: rearrange a bunch of files and get "make
......
......@@ -54,9 +54,11 @@ if test x$enable_verbose_mode = xyes; then
fi
if test x$enable_asserts = xno; then
AC_DEFINE(DBUS_DISABLE_ASSERT,1,[Disable assertion checking])
AC_DEFINE(G_DISABLE_ASSERT,1,[Disable GLib assertion macros])
fi
if test x$enable_checks = xno; then
AC_DEFINE(DBUS_DISABLE_CHECKS,1,[Disable public API sanity checking])
AC_DEFINE(G_DISABLE_CHECKS,1,[Disable GLib public API sanity checking])
fi
#### gcc warning flags
......@@ -545,7 +547,7 @@ AC_SUBST(DBUS_TEST_CFLAGS)
AC_SUBST(DBUS_TEST_LIBS)
# Glib detection
PKG_CHECK_MODULES(DBUS_GLIB, glib-2.0, have_glib=yes, have_glib=no)
PKG_CHECK_MODULES(DBUS_GLIB, gobject-2.0, have_glib=yes, have_glib=no)
PKG_CHECK_MODULES(DBUS_GLIB_THREADS, glib-2.0 gthread-2.0, have_glib_threads=yes, have_glib_threads=no)
if test x$have_glib = xno ; then
......@@ -570,6 +572,11 @@ 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
AC_SUBST(DBUS_GLIB_TOOL_CFLAGS)
AC_SUBST(DBUS_GLIB_TOOL_LIBS)
# Qt detection
have_qt=no
AC_MSG_CHECKING([for qglobal.h])
......
......@@ -1473,7 +1473,8 @@ _dbus_demarshal_string_array (const DBusString *str,
#define VERBOSE_DECOMPOSE 0
/**
* Demarshals an object path.
* Demarshals an object path. A path of just "/" is
* represented as an empty vector of strings.
*
* @param str the string containing the data
* @param byte_order the byte order
......@@ -1556,7 +1557,6 @@ _dbus_demarshal_object_path (const DBusString *str,
i = j;
}
_dbus_assert (i == len);
_dbus_assert (retval[0] != NULL);
*path = retval;
if (path_len)
......
......@@ -87,6 +87,18 @@ extern "C" {
#define DBUS_PATH_ORG_FREEDESKTOP_DBUS "/org/freedesktop/DBus"
#define DBUS_PATH_ORG_FREEDESKTOP_LOCAL "/org/freedesktop/Local"
/* Interfaces, these #define don't do much other than
* catch typos at compile time
*/
#define DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "org.freedesktop.DBus"
#define DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE "org.freedesktop.Introspectable"
/* This is a special interface whose methods can only be invoked
* by the local implementation (messages from remote apps aren't
* allowed to specify this interface).
*/
#define DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL "org.freedesktop.Local"
/* Service owner flags */
#define DBUS_SERVICE_FLAG_PROHIBIT_REPLACEMENT 0x1
#define DBUS_SERVICE_FLAG_REPLACE_EXISTING 0x2
......@@ -101,17 +113,6 @@ extern "C" {
#define DBUS_ACTIVATION_REPLY_ACTIVATED 0x0
#define DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE 0x1
/* Interfaces, these #define don't do much other than
* catch typos at compile time
*/
#define DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "org.freedesktop.DBus"
/* This is a special interface whose methods can only be invoked
* by the local implementation (messages from remote apps aren't
* allowed to specify this interface).
*/
#define DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL "org.freedesktop.Local"
#ifdef __cplusplus
}
#endif
......
INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) -DDBUS_COMPILATION=1
INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) $(DBUS_GLIB_TOOL_CFLAGS) -DDBUS_COMPILATION=1
dbusincludedir=$(includedir)/dbus-1.0/dbus
......@@ -10,6 +10,7 @@ dbusinclude_HEADERS= \
libdbus_glib_1_la_SOURCES = \
dbus-gmain.c \
dbus-gobject.c \
dbus-gproxy.c \
dbus-gtest.c \
dbus-gtest.h \
......@@ -23,12 +24,13 @@ dbus_glib_tool_SOURCES = \
dbus-gidl.c \
dbus-gidl.h \
dbus-glib-tool.c \
dbus-gloader-expat.c \
dbus-gparser.c \
dbus-gparser.h \
dbus-gtool-test.h
dbus_glib_tool_LDADD= libdbus-glib-1.la $(DBUS_GLIB_LIBS) $(top_builddir)/dbus/libdbus-1.la
dbus_glib_tool_LDADD= $(DBUS_GLIB_TOOL_LIBS) libdbus-glib-1.la $(top_builddir)/dbus/libdbus-1.la
if DBUS_BUILD_TESTS
......
......@@ -24,6 +24,13 @@
#include "dbus-gidl.h"
struct NodeInfo
{
int refcount;
char *name;
GSList *interfaces;
};
struct InterfaceInfo
{
int refcount;
......@@ -54,6 +61,20 @@ struct ArgInfo
ArgDirection direction;
};
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_method_list (GSList **methods_p)
{
......@@ -82,6 +103,59 @@ free_signal_list (GSList **signals_p)
*signals_p = NULL;
}
NodeInfo*
node_info_new (const char *name)
{
NodeInfo *info;
/* name can be NULL */
info = g_new0 (NodeInfo, 1);
info->refcount = 1;
info->name = g_strdup (name);
return info;
}
void
node_info_ref (NodeInfo *info)
{
info->refcount += 1;
}
void
node_info_unref (NodeInfo *info)
{
info->refcount -= 1;
if (info->refcount == 0)
{
free_interface_list (&info->interfaces);
g_free (info->name);
g_free (info);
}
}
const char*
node_info_get_name (NodeInfo *info)
{
return info->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);
}
InterfaceInfo*
interface_info_new (const char *name)
{
......@@ -90,7 +164,7 @@ interface_info_new (const char *name)
info = g_new0 (InterfaceInfo, 1);
info->refcount = 1;
info->name = g_strdup (name);
return info;
}
......@@ -113,6 +187,12 @@ interface_info_unref (InterfaceInfo *info)
}
}
const char*
interface_info_get_name (InterfaceInfo *info)
{
return info->name;
}
GSList*
interface_info_get_methods (InterfaceInfo *info)
{
......@@ -163,7 +243,7 @@ method_info_new (const char *name)
info = g_new0 (MethodInfo, 1);
info->refcount = 1;
info->name = g_strdup (name);
return info;
}
......@@ -213,7 +293,7 @@ signal_info_new (const char *name)
info = g_new0 (SignalInfo, 1);
info->refcount = 1;
info->name = g_strdup (name);
return info;
}
......@@ -264,10 +344,12 @@ arg_info_new (const char *name,
info = g_new0 (ArgInfo, 1);
info->refcount = 1;
/* name can be NULL */
info->name = g_strdup (name);
info->direction = direction;
info->type = type;
return info;
}
......
......@@ -29,6 +29,7 @@
G_BEGIN_DECLS
typedef struct NodeInfo NodeInfo;
typedef struct InterfaceInfo InterfaceInfo;
typedef struct MethodInfo MethodInfo;
typedef struct SignalInfo SignalInfo;
......@@ -40,9 +41,18 @@ typedef enum
ARG_OUT
} ArgDirection;
NodeInfo* node_info_new (const char *name);
void 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);
void node_info_add_interface (NodeInfo *info,
InterfaceInfo *interface);
InterfaceInfo* interface_info_new (const char *name);
void interface_info_ref (InterfaceInfo *info);
void interface_info_unref (InterfaceInfo *info);
const char* interface_info_get_name (InterfaceInfo *info);
GSList* interface_info_get_methods (InterfaceInfo *info);
GSList* interface_info_get_signals (InterfaceInfo *info);
void interface_info_add_method (InterfaceInfo *info,
......
......@@ -24,7 +24,7 @@
#define DBUS_GLIB_H
#include <dbus/dbus.h>
#include <glib.h>
#include <glib-object.h>
G_BEGIN_DECLS
......@@ -36,6 +36,30 @@ void dbus_connection_setup_with_g_main (DBusConnection *connection,
void dbus_server_setup_with_g_main (DBusServer *server,
GMainContext *context);
typedef struct DBusGObjectInfo DBusGObjectInfo;
typedef struct DBusGMethodInfo DBusGMethodInfo;
struct DBusGMethodInfo
{
GCallback function;
DBusHandleMessageFunction marshaller;
int data_offset;
};
struct DBusGObjectInfo
{
const DBusGMethodInfo *infos;
const unsigned char *data;
void *dbus_internal_padding1;
void *dbus_internal_padding2;
};
void dbus_gobject_class_install_info (GObjectClass *object_class,
const DBusGObjectInfo *info);
void dbus_connection_register_gobject (DBusConnection *connection,
const char *at_path,
GObject *object);
#undef DBUS_INSIDE_DBUS_GLIB_H
G_END_DECLS
......
/* -*- 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 1.2
*
* 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>
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
};
typedef struct
{
Parser *parser;
const char *filename;
GString *content;
GError **error;
gboolean 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);
}
Parser*
description_load_from_file (const char *filename,
GError **error)
{
char *contents;
gsize len;
Parser *parser;
contents = NULL;
if (!g_file_get_contents (filename, &contents, &len, error))
return NULL;
parser = description_load_from_string (contents, len, error);
g_free (contents);
return parser;
}
Parser*
description_load_from_string (const char *str,
int len,
GError **error)
{
XML_Parser expat;
ExpatParseContext context;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
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);
return context.parser;
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;
}
This diff is collapsed.
This diff is collapsed.
......@@ -25,10 +25,10 @@
#include <dbus/dbus.h>
#include <glib.h>
#include "dbus-gidl.h"
G_BEGIN_DECLS
typedef struct Parser Parser;
Parser* parser_new (void);
......@@ -52,7 +52,13 @@ gboolean parser_content (Parser *parser,
gboolean parser_finished (Parser *parser,
GError **error);
Parser* description_load_from_file (const char *filename,
GError **error);
Parser* description_load_from_string (const char *str,
int len,
GError **error);
NodeInfo* parser_get_nodes (Parser *parser);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment