dbus-glib.c

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
00002 /* dbus-glib.c General GLib binding stuff
00003  *
00004  * Copyright (C) 2004 Red Hat, Inc.
00005  *
00006  * Licensed under the Academic Free License version 2.1
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 #include <config.h>
00025 #include "dbus-glib.h"
00026 #include "dbus-glib-lowlevel.h"
00027 #include "dbus-gtest.h"
00028 #include "dbus-gutils.h"
00029 #include "dbus-gobject.h"
00030 #include <string.h>
00031 
00032 #include <libintl.h>
00033 #define _(x) dgettext (GETTEXT_PACKAGE, x)
00034 #define N_(x) x
00035 
00036 
00052 void
00053 dbus_g_connection_flush (DBusGConnection *connection)
00054 {
00055   dbus_connection_flush (DBUS_CONNECTION_FROM_G_CONNECTION (connection));
00056 }
00057 
00066 DBusGConnection*
00067 dbus_g_connection_ref (DBusGConnection *gconnection)
00068 {
00069   DBusConnection *c;
00070 
00071   c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
00072   dbus_connection_ref (c);
00073   return gconnection;
00074 }
00075 
00076 
00083 void
00084 dbus_g_connection_unref (DBusGConnection *gconnection)
00085 {
00086   DBusConnection *c;
00087 
00088   c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
00089   dbus_connection_unref (c);
00090 }
00091 
00092 
00110 DBusGMessage*
00111 dbus_g_message_ref (DBusGMessage *gmessage)
00112 {
00113   DBusMessage *c;
00114 
00115   c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
00116   dbus_message_ref (c);
00117   return gmessage;
00118 }
00119 
00126 void
00127 dbus_g_message_unref (DBusGMessage *gmessage)
00128 {
00129   DBusMessage *c;
00130 
00131   c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
00132   dbus_message_unref (c);
00133 }
00134 
00152 GQuark
00153 dbus_g_error_quark (void)
00154 {
00155   static GQuark quark = 0;
00156   if (quark == 0)
00157     quark = g_quark_from_static_string ("dbus-glib-error-quark");
00158   return quark;
00159 }
00160 
00177 gboolean
00178 dbus_g_error_has_name (GError *error, const char *name)
00179 {
00180   g_return_val_if_fail (error != NULL, FALSE);
00181 
00182   if (error->domain != DBUS_GERROR
00183       || error->code != DBUS_GERROR_REMOTE_EXCEPTION)
00184     return FALSE;
00185 
00186   return !strcmp (dbus_g_error_get_name (error), name);
00187 }
00188 
00202 const char *
00203 dbus_g_error_get_name (GError *error)
00204 {
00205   g_return_val_if_fail (error != NULL, NULL);
00206   g_return_val_if_fail (error->domain == DBUS_GERROR, NULL);
00207   g_return_val_if_fail (error->code == DBUS_GERROR_REMOTE_EXCEPTION, NULL);
00208 
00209   return error->message + strlen (error->message) + 1;
00210 }
00211 
00218 GType
00219 dbus_connection_get_g_type (void)
00220 {
00221   static GType our_type = 0;
00222   
00223   if (our_type == 0)
00224     our_type = g_boxed_type_register_static ("DBusConnection",
00225                                              (GBoxedCopyFunc) dbus_connection_ref,
00226                                              (GBoxedFreeFunc) dbus_connection_unref);
00227 
00228   return our_type;
00229 }
00230 
00237 GType
00238 dbus_message_get_g_type (void)
00239 {
00240   static GType our_type = 0;
00241   
00242   if (our_type == 0)
00243     our_type = g_boxed_type_register_static ("DBusMessage",
00244                                              (GBoxedCopyFunc) dbus_message_ref,
00245                                              (GBoxedFreeFunc) dbus_message_unref);
00246 
00247   return our_type;
00248 }
00249 
00256 GType
00257 dbus_g_connection_get_g_type (void)
00258 {
00259   static GType our_type = 0;
00260   
00261   if (our_type == 0)
00262     our_type = g_boxed_type_register_static ("DBusGConnection",
00263                                              (GBoxedCopyFunc) dbus_g_connection_ref,
00264                                              (GBoxedFreeFunc) dbus_g_connection_unref);
00265 
00266   return our_type;
00267 }
00268 
00275 GType
00276 dbus_g_message_get_g_type (void)
00277 {
00278   static GType our_type = 0;
00279   
00280   if (our_type == 0)
00281     our_type = g_boxed_type_register_static ("DBusGMessage",
00282                                              (GBoxedCopyFunc) dbus_g_message_ref,
00283                                              (GBoxedFreeFunc) dbus_g_message_unref);
00284 
00285   return our_type;
00286 }
00287 
00305 DBusConnection*
00306 dbus_g_connection_get_connection (DBusGConnection *gconnection)
00307 {
00308   g_return_val_if_fail (gconnection, NULL);
00309   return DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
00310 }
00311 
00312 extern dbus_int32_t _dbus_gmain_connection_slot;
00313 
00325 DBusGConnection*
00326 dbus_connection_get_g_connection (DBusConnection *connection)
00327 {
00328   g_return_val_if_fail (connection, NULL);
00329   g_return_val_if_fail (dbus_connection_get_data (connection, _dbus_gmain_connection_slot), NULL);
00330   
00331   return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
00332 }
00333 
00334 
00344 DBusMessage*
00345 dbus_g_message_get_message (DBusGMessage *gmessage)
00346 {
00347   return DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
00348 }
00349 
00350 #ifdef DBUS_BUILD_TESTS
00351 
00357 gboolean
00358 _dbus_glib_test (const char *test_data_dir)
00359 {
00360   DBusError err;
00361   GError *gerror = NULL;
00362 
00363   dbus_error_init (&err);
00364   dbus_set_error_const (&err, DBUS_ERROR_NO_MEMORY, "Out of memory!");
00365 
00366   dbus_set_g_error (&gerror, &err);
00367   g_assert (gerror != NULL);
00368   g_assert (gerror->domain == DBUS_GERROR);
00369   g_assert (gerror->code == DBUS_GERROR_NO_MEMORY);
00370   g_assert (!strcmp (gerror->message, "Out of memory!"));
00371   
00372   dbus_error_init (&err);
00373   g_clear_error (&gerror);
00374 
00375   return TRUE;
00376 }
00377 
00378 #endif /* DBUS_BUILD_TESTS */

Generated on Sat Dec 6 19:56:17 2008 for D-BUSGLibBindings by  doxygen 1.5.1