12912Sartem /*************************************************************************** 22912Sartem * CVSID: $Id$ 32912Sartem * 42912Sartem * util.h - Various utilities 52912Sartem * 62912Sartem * Copyright (C) 2004 David Zeuthen, <david@fubar.dk> 72912Sartem * 82912Sartem * Licensed under the Academic Free License version 2.1 92912Sartem * 102912Sartem * This program is free software; you can redistribute it and/or modify 112912Sartem * it under the terms of the GNU General Public License as published by 122912Sartem * the Free Software Foundation; either version 2 of the License, or 132912Sartem * (at your option) any later version. 142912Sartem * 152912Sartem * This program is distributed in the hope that it will be useful, 162912Sartem * but WITHOUT ANY WARRANTY; without even the implied warranty of 172912Sartem * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 182912Sartem * GNU General Public License for more details. 192912Sartem * 202912Sartem * You should have received a copy of the GNU General Public License 212912Sartem * along with this program; if not, write to the Free Software 222912Sartem * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 232912Sartem * 242912Sartem **************************************************************************/ 252912Sartem 262912Sartem #ifndef UTIL_H 272912Sartem #define UTIL_H 282912Sartem 292912Sartem #include "device.h" 302912Sartem #include "device_store.h" 312912Sartem 322912Sartem #ifndef __FUNCTION__ 332912Sartem #define __FUNCTION__ __func__ 342912Sartem #endif 352912Sartem 362912Sartem #ifndef __GNUC__ 372912Sartem #define __attribute__(x) 382912Sartem #endif 392912Sartem 402912Sartem #define HAL_NAME_MAX 256 412912Sartem #define HAL_PATH_MAX 512 422912Sartem #define HAL_HELPER_TIMEOUT 10000 432912Sartem 442912Sartem gboolean hal_util_remove_trailing_slash (gchar *path); 452912Sartem 462912Sartem const gchar *hal_util_get_last_element (const gchar *s); 472912Sartem 482912Sartem gchar *hal_util_get_parent_path (const gchar *path); 492912Sartem 502912Sartem gchar *hal_util_get_normalized_path (const gchar *path1, const gchar *path2); 512912Sartem 522912Sartem gboolean hal_util_get_int_from_file (const gchar *directory, const gchar *file, gint *result, gint base); 532912Sartem 542912Sartem gboolean hal_util_set_int_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file, gint base); 552912Sartem 562912Sartem gboolean hal_util_get_uint64_from_file (const gchar *directory, const gchar *file, guint64 *result, gint base); 572912Sartem 582912Sartem gboolean hal_util_set_uint64_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file, gint base); 592912Sartem 602912Sartem gchar *hal_util_get_string_from_file (const gchar *directory, const gchar *file); 612912Sartem 622912Sartem gboolean hal_util_set_string_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file); 632912Sartem 642912Sartem gboolean hal_util_get_bcd2_from_file (const gchar *directory, const gchar *file, gint *result); 652912Sartem 662912Sartem gboolean hal_util_set_bcd2_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file); 672912Sartem 682912Sartem void hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...); 692912Sartem 702912Sartem gboolean hal_util_path_ascend (gchar *path); 712912Sartem 722912Sartem void hal_util_grep_discard_existing_data (void); 732912Sartem 742912Sartem gchar *hal_util_grep_file (const gchar *directory, const gchar *file, const gchar *linestart, gboolean reuse_file); 752912Sartem 762912Sartem gint hal_util_grep_int_elem_from_file (const gchar *directory, const gchar *file, 772912Sartem const gchar *linestart, guint elem, guint base, gboolean reuse_file); 782912Sartem 792912Sartem gchar *hal_util_grep_string_elem_from_file (const gchar *directory, const gchar *file, 802912Sartem const gchar *linestart, guint elem, gboolean reuse_file); 812912Sartem 822912Sartem gboolean hal_util_set_string_elem_from_file (HalDevice *d, const gchar *key, 832912Sartem const gchar *directory, const gchar *file, 842912Sartem const gchar *linestart, guint elem, gboolean reuse_file); 852912Sartem 862912Sartem gboolean hal_util_set_int_elem_from_file (HalDevice *d, const gchar *key, 872912Sartem const gchar *directory, const gchar *file, 882912Sartem const gchar *linestart, guint elem, guint base, gboolean reuse_file); 892912Sartem 902912Sartem gboolean hal_util_set_bool_elem_from_file (HalDevice *d, const gchar *key, 912912Sartem const gchar *directory, const gchar *file, 922912Sartem const gchar *linestart, guint elem, const gchar *expected, 932912Sartem gboolean reuse_file); 942912Sartem 952912Sartem gchar **hal_util_dup_strv_from_g_slist (GSList *strlist); 962912Sartem 972912Sartem typedef void (*HalCalloutsDone) (HalDevice *d, gpointer userdata1, gpointer userdata2); 982912Sartem 992912Sartem void hal_util_callout_device_add (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2); 1002912Sartem void hal_util_callout_device_remove (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2); 1012912Sartem void hal_util_callout_device_preprobe (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2); 1022912Sartem 1032912Sartem gchar *hal_util_strdup_valid_utf8 (const char *str); 1042912Sartem 1052912Sartem void hal_util_hexdump (const void *buf, unsigned int size); 1062912Sartem 1072912Sartem gboolean hal_util_is_mounted_by_hald (const char *mount_point); 1082912Sartem 1092912Sartem void 1102912Sartem hal_util_branch_claim (HalDeviceStore *store, HalDevice *root, dbus_bool_t claimed, const char *service, int uid); 1112912Sartem 112*10659SXiao-Lin.Zhang@Sun.COM gboolean 113*10659SXiao-Lin.Zhang@Sun.COM is_valid_interface_name (const char *name); 114*10659SXiao-Lin.Zhang@Sun.COM 1152912Sartem #endif /* UTIL_H */ 116