xref: /titanic_41/usr/src/cmd/hal/hald/util.h (revision 571909175b4f9a1ef15ec4afead6d6d463dbe760)
1 /***************************************************************************
2  * CVSID: $Id$
3  *
4  * util.h - Various utilities
5  *
6  * Copyright (C) 2004 David Zeuthen, <david@fubar.dk>
7  *
8  * Licensed under the Academic Free License version 2.1
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  **************************************************************************/
25 
26 #ifndef UTIL_H
27 #define UTIL_H
28 
29 #include "device.h"
30 #include "device_store.h"
31 
32 #ifndef __FUNCTION__
33 #define __FUNCTION__ __func__
34 #endif
35 
36 #ifndef __GNUC__
37 #define __attribute__(x)
38 #endif
39 
40 #define HAL_NAME_MAX 256
41 #define HAL_PATH_MAX 512
42 #define HAL_HELPER_TIMEOUT 10000
43 
44 gboolean hal_util_remove_trailing_slash (gchar *path);
45 
46 const gchar *hal_util_get_last_element (const gchar *s);
47 
48 gchar *hal_util_get_parent_path (const gchar *path);
49 
50 gchar *hal_util_get_normalized_path (const gchar *path1, const gchar *path2);
51 
52 gboolean hal_util_get_int_from_file (const gchar *directory, const gchar *file, gint *result, gint base);
53 
54 gboolean hal_util_set_int_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file, gint base);
55 
56 gboolean hal_util_get_uint64_from_file (const gchar *directory, const gchar *file, guint64 *result, gint base);
57 
58 gboolean hal_util_set_uint64_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file, gint base);
59 
60 gchar *hal_util_get_string_from_file (const gchar *directory, const gchar *file);
61 
62 gboolean hal_util_set_string_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file);
63 
64 gboolean hal_util_get_bcd2_from_file (const gchar *directory, const gchar *file, gint *result);
65 
66 gboolean hal_util_set_bcd2_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file);
67 
68 void hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...);
69 
70 gboolean hal_util_path_ascend (gchar *path);
71 
72 void hal_util_grep_discard_existing_data (void);
73 
74 gchar *hal_util_grep_file (const gchar *directory, const gchar *file, const gchar *linestart, gboolean reuse_file);
75 
76 gint hal_util_grep_int_elem_from_file (const gchar *directory, const gchar *file,
77 				       const gchar *linestart, guint elem, guint base, gboolean reuse_file);
78 
79 gchar *hal_util_grep_string_elem_from_file (const gchar *directory, const gchar *file,
80 					    const gchar *linestart, guint elem, gboolean reuse_file);
81 
82 gboolean hal_util_set_string_elem_from_file (HalDevice *d, const gchar *key,
83 					     const gchar *directory, const gchar *file,
84 					     const gchar *linestart, guint elem, gboolean reuse_file);
85 
86 gboolean hal_util_set_int_elem_from_file (HalDevice *d, const gchar *key,
87 					  const gchar *directory, const gchar *file,
88 					  const gchar *linestart, guint elem, guint base, gboolean reuse_file);
89 
90 gboolean hal_util_set_bool_elem_from_file (HalDevice *d, const gchar *key,
91 					   const gchar *directory, const gchar *file,
92 					   const gchar *linestart, guint elem, const gchar *expected,
93 					   gboolean reuse_file);
94 
95 gchar **hal_util_dup_strv_from_g_slist (GSList *strlist);
96 
97 typedef void (*HalCalloutsDone) (HalDevice *d, gpointer userdata1, gpointer userdata2);
98 
99 void hal_util_callout_device_add (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2);
100 void hal_util_callout_device_remove (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2);
101 void hal_util_callout_device_preprobe (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2);
102 
103 gchar *hal_util_strdup_valid_utf8 (const char *str);
104 
105 void hal_util_hexdump (const void *buf, unsigned int size);
106 
107 gboolean hal_util_is_mounted_by_hald (const char *mount_point);
108 
109 void
110 hal_util_branch_claim (HalDeviceStore *store, HalDevice *root, dbus_bool_t claimed, const char *service, int uid);
111 
112 gboolean
113 is_valid_interface_name (const char *name);
114 
115 #endif /* UTIL_H */
116