dbus-misc.c

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-misc.c  A few assorted public functions that don't fit elsewhere
00003  *
00004  * Copyright (C) 2006 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-misc.h"
00026 #include "dbus-internals.h"
00027 #include "dbus-string.h"
00028 
00072 char*
00073 dbus_get_local_machine_id (void)
00074 {
00075   DBusString uuid;
00076   char *s;
00077 
00078   s = NULL;
00079 
00080   if (!_dbus_string_init (&uuid))
00081     return NULL;
00082 
00083   if (!_dbus_get_local_machine_uuid_encoded (&uuid) ||
00084       !_dbus_string_steal_data (&uuid, &s))
00085     {
00086       _dbus_string_free (&uuid);
00087       return NULL;
00088     }
00089   else
00090     {
00091       _dbus_string_free (&uuid);
00092       return s;
00093     }
00094 
00095 }
00096 
00160 void
00161 dbus_get_version (int *major_version_p,
00162                   int *minor_version_p,
00163                   int *micro_version_p)
00164 {
00165   if (major_version_p)
00166     *major_version_p = DBUS_MAJOR_VERSION;
00167   if (minor_version_p)
00168     *minor_version_p = DBUS_MINOR_VERSION;
00169   if (micro_version_p)
00170     *micro_version_p = DBUS_MICRO_VERSION;
00171 }
00172 
00173  /* End of public API */
00175 
00176 #ifdef DBUS_BUILD_TESTS
00177 
00178 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00179 
00180 #include "dbus-test.h"
00181 #include <stdlib.h>
00182 
00183 
00184 dbus_bool_t
00185 _dbus_misc_test (void)
00186 {
00187   int major, minor, micro;
00188   DBusString str;
00189 
00190   /* make sure we don't crash on NULL */
00191   dbus_get_version (NULL, NULL, NULL);
00192 
00193   /* Now verify that all the compile-time version stuff
00194    * is right and matches the runtime. These tests
00195    * are mostly intended to catch various kinds of
00196    * typo (mixing up major and minor, that sort of thing).
00197    */
00198   dbus_get_version (&major, &minor, &micro);
00199 
00200   _dbus_assert (major == DBUS_MAJOR_VERSION);
00201   _dbus_assert (minor == DBUS_MINOR_VERSION);
00202   _dbus_assert (micro == DBUS_MICRO_VERSION);
00203 
00204 #define MAKE_VERSION(x, y, z) (((x) << 16) | ((y) << 8) | (z))
00205 
00206   /* check that MAKE_VERSION works and produces the intended ordering */
00207   _dbus_assert (MAKE_VERSION (1, 0, 0) > MAKE_VERSION (0, 0, 0));
00208   _dbus_assert (MAKE_VERSION (1, 1, 0) > MAKE_VERSION (1, 0, 0));
00209   _dbus_assert (MAKE_VERSION (1, 1, 1) > MAKE_VERSION (1, 1, 0));
00210 
00211   _dbus_assert (MAKE_VERSION (2, 0, 0) > MAKE_VERSION (1, 1, 1));
00212   _dbus_assert (MAKE_VERSION (2, 1, 0) > MAKE_VERSION (1, 1, 1));
00213   _dbus_assert (MAKE_VERSION (2, 1, 1) > MAKE_VERSION (1, 1, 1));
00214 
00215   /* check DBUS_VERSION */
00216   _dbus_assert (MAKE_VERSION (major, minor, micro) == DBUS_VERSION);
00217 
00218   /* check that ordering works with DBUS_VERSION */
00219   _dbus_assert (MAKE_VERSION (major - 1, minor, micro) < DBUS_VERSION);
00220   _dbus_assert (MAKE_VERSION (major, minor - 1, micro) < DBUS_VERSION);
00221   _dbus_assert (MAKE_VERSION (major, minor, micro - 1) < DBUS_VERSION);
00222   
00223   _dbus_assert (MAKE_VERSION (major + 1, minor, micro) > DBUS_VERSION);
00224   _dbus_assert (MAKE_VERSION (major, minor + 1, micro) > DBUS_VERSION);
00225   _dbus_assert (MAKE_VERSION (major, minor, micro + 1) > DBUS_VERSION);
00226 
00227   /* Check DBUS_VERSION_STRING */
00228 
00229   if (!_dbus_string_init (&str))
00230     _dbus_assert_not_reached ("no memory");
00231 
00232   if (!(_dbus_string_append_int (&str, major) &&
00233         _dbus_string_append_byte (&str, '.') &&
00234         _dbus_string_append_int (&str, minor) &&
00235         _dbus_string_append_byte (&str, '.') &&
00236         _dbus_string_append_int (&str, micro)))
00237     _dbus_assert_not_reached ("no memory");
00238 
00239   _dbus_assert (_dbus_string_equal_c_str (&str, DBUS_VERSION_STRING));
00240 
00241   _dbus_string_free (&str);
00242    
00243   return TRUE;
00244 }
00245 
00246 #endif /* !DOXYGEN_SHOULD_SKIP_THIS */
00247 
00248 #endif

Generated on Tue Feb 24 16:40:39 2009 for D-Bus by  doxygen 1.5.1