Main Page | Modules | Data Structures | Directories | File List | Data Fields | Related Pages

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/dbus-glib.h>
00026 #include <dbus/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 
00046 void
00047 dbus_g_connection_flush (DBusGConnection *connection)
00048 {
00049   dbus_connection_flush (DBUS_CONNECTION_FROM_G_CONNECTION (connection));
00050 }
00051 
00058 DBusGConnection*
00059 dbus_g_connection_ref (DBusGConnection *gconnection)
00060 {
00061   DBusConnection *c;
00062 
00063   c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
00064   dbus_connection_ref (c);
00065   return gconnection;
00066 }
00067 
00068 
00074 void
00075 dbus_g_connection_unref (DBusGConnection *gconnection)
00076 {
00077   DBusConnection *c;
00078 
00079   c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
00080   dbus_connection_unref (c);
00081 }
00082 
00083 
00090 DBusGMessage*
00091 dbus_g_message_ref (DBusGMessage *gmessage)
00092 {
00093   DBusMessage *c;
00094 
00095   c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
00096   dbus_message_ref (c);
00097   return gmessage;
00098 }
00099 
00105 void
00106 dbus_g_message_unref (DBusGMessage *gmessage)
00107 {
00108   DBusMessage *c;
00109 
00110   c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
00111   dbus_message_unref (c);
00112 }
00113 
00120 GQuark
00121 dbus_g_error_quark (void)
00122 {
00123   static GQuark quark = 0;
00124   if (quark == 0)
00125     quark = g_quark_from_static_string ("g-exec-error-quark");
00126   return quark;
00127 }
00128 
00143 gboolean
00144 dbus_g_error_has_name (GError *error, const char *name)
00145 {
00146   g_return_val_if_fail (error != NULL, FALSE);
00147 
00148   if (error->domain != DBUS_GERROR
00149       || error->code != DBUS_GERROR_REMOTE_EXCEPTION)
00150     return FALSE;
00151 
00152   return !strcmp (dbus_g_error_get_name (error), name);
00153 }
00154 
00167 const char *
00168 dbus_g_error_get_name (GError *error)
00169 {
00170   g_return_val_if_fail (error != NULL, NULL);
00171   g_return_val_if_fail (error->domain == DBUS_GERROR, NULL);
00172   g_return_val_if_fail (error->code == DBUS_GERROR_REMOTE_EXCEPTION, NULL);
00173 
00174   return error->message + strlen (error->message) + 1;
00175 }
00176 
00182 GType
00183 dbus_connection_get_g_type (void)
00184 {
00185   static GType our_type = 0;
00186   
00187   if (our_type == 0)
00188     our_type = g_boxed_type_register_static ("DBusConnection",
00189                                              (GBoxedCopyFunc) dbus_connection_ref,
00190                                              (GBoxedFreeFunc) dbus_connection_unref);
00191 
00192   return our_type;
00193 }
00194 
00200 GType
00201 dbus_message_get_g_type (void)
00202 {
00203   static GType our_type = 0;
00204   
00205   if (our_type == 0)
00206     our_type = g_boxed_type_register_static ("DBusMessage",
00207                                              (GBoxedCopyFunc) dbus_message_ref,
00208                                              (GBoxedFreeFunc) dbus_message_unref);
00209 
00210   return our_type;
00211 }
00212 
00218 GType
00219 dbus_g_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 ("DBusGConnection",
00225                                              (GBoxedCopyFunc) dbus_g_connection_ref,
00226                                              (GBoxedFreeFunc) dbus_g_connection_unref);
00227 
00228   return our_type;
00229 }
00230 
00236 GType
00237 dbus_g_message_get_g_type (void)
00238 {
00239   static GType our_type = 0;
00240   
00241   if (our_type == 0)
00242     our_type = g_boxed_type_register_static ("DBusGMessage",
00243                                              (GBoxedCopyFunc) dbus_g_message_ref,
00244                                              (GBoxedFreeFunc) dbus_g_message_unref);
00245 
00246   return our_type;
00247 }
00248 
00255 DBusConnection*
00256 dbus_g_connection_get_connection (DBusGConnection *gconnection)
00257 {
00258   return DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
00259 }
00260 
00267 DBusMessage*
00268 dbus_g_message_get_message (DBusGMessage *gmessage)
00269 {
00270   return DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
00271 }
00272  /* end of public API */
00274 
00275 
00276 #ifdef DBUS_BUILD_TESTS
00277 
00283 gboolean
00284 _dbus_glib_test (const char *test_data_dir)
00285 {
00286   DBusError err;
00287   GError *gerror = NULL;
00288 
00289   dbus_error_init (&err);
00290   dbus_set_error_const (&err, DBUS_ERROR_NO_MEMORY, "Out of memory!");
00291 
00292   dbus_set_g_error (&gerror, &err);
00293   g_assert (gerror != NULL);
00294   g_assert (gerror->domain == DBUS_GERROR);
00295   g_assert (gerror->code == DBUS_GERROR_NO_MEMORY);
00296   g_assert (!strcmp (gerror->message, "Out of memory!"));
00297   
00298   dbus_error_init (&err);
00299   g_clear_error (&gerror);
00300 
00301   return TRUE;
00302 }
00303 
00304 #endif /* DBUS_BUILD_TESTS */

Generated on Tue Aug 30 16:35:50 2005 for D-BUS by  doxygen 1.4.3