xref: /illumos-gate/usr/src/cmd/hal/hald/util.h (revision 55fea89d)
118c2aff7Sartem /***************************************************************************
218c2aff7Sartem  * CVSID: $Id$
318c2aff7Sartem  *
418c2aff7Sartem  * util.h - Various utilities
518c2aff7Sartem  *
618c2aff7Sartem  * Copyright (C) 2004 David Zeuthen, <david@fubar.dk>
718c2aff7Sartem  *
818c2aff7Sartem  * Licensed under the Academic Free License version 2.1
918c2aff7Sartem  *
1018c2aff7Sartem  * This program is free software; you can redistribute it and/or modify
1118c2aff7Sartem  * it under the terms of the GNU General Public License as published by
1218c2aff7Sartem  * the Free Software Foundation; either version 2 of the License, or
1318c2aff7Sartem  * (at your option) any later version.
1418c2aff7Sartem  *
1518c2aff7Sartem  * This program is distributed in the hope that it will be useful,
1618c2aff7Sartem  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1718c2aff7Sartem  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1818c2aff7Sartem  * GNU General Public License for more details.
1918c2aff7Sartem  *
2018c2aff7Sartem  * You should have received a copy of the GNU General Public License
2118c2aff7Sartem  * along with this program; if not, write to the Free Software
2218c2aff7Sartem  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
2318c2aff7Sartem  *
2418c2aff7Sartem  **************************************************************************/
2518c2aff7Sartem 
2618c2aff7Sartem #ifndef UTIL_H
2718c2aff7Sartem #define UTIL_H
2818c2aff7Sartem 
2918c2aff7Sartem #include "device.h"
3018c2aff7Sartem #include "device_store.h"
3118c2aff7Sartem 
3218c2aff7Sartem #ifndef __FUNCTION__
3318c2aff7Sartem #define __FUNCTION__ __func__
3418c2aff7Sartem #endif
3518c2aff7Sartem 
3618c2aff7Sartem #ifndef __GNUC__
3718c2aff7Sartem #define __attribute__(x)
3818c2aff7Sartem #endif
3918c2aff7Sartem 
4018c2aff7Sartem #define HAL_NAME_MAX 256
4118c2aff7Sartem #define HAL_PATH_MAX 512
4218c2aff7Sartem #define HAL_HELPER_TIMEOUT 10000
4318c2aff7Sartem 
4418c2aff7Sartem gboolean hal_util_remove_trailing_slash (gchar *path);
4518c2aff7Sartem 
4618c2aff7Sartem const gchar *hal_util_get_last_element (const gchar *s);
4718c2aff7Sartem 
4818c2aff7Sartem gchar *hal_util_get_parent_path (const gchar *path);
4918c2aff7Sartem 
5018c2aff7Sartem gchar *hal_util_get_normalized_path (const gchar *path1, const gchar *path2);
5118c2aff7Sartem 
5218c2aff7Sartem gboolean hal_util_get_int_from_file (const gchar *directory, const gchar *file, gint *result, gint base);
5318c2aff7Sartem 
5418c2aff7Sartem gboolean hal_util_set_int_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file, gint base);
5518c2aff7Sartem 
5618c2aff7Sartem gboolean hal_util_get_uint64_from_file (const gchar *directory, const gchar *file, guint64 *result, gint base);
5718c2aff7Sartem 
5818c2aff7Sartem gboolean hal_util_set_uint64_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file, gint base);
5918c2aff7Sartem 
6018c2aff7Sartem gchar *hal_util_get_string_from_file (const gchar *directory, const gchar *file);
6118c2aff7Sartem 
6218c2aff7Sartem gboolean hal_util_set_string_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file);
6318c2aff7Sartem 
6418c2aff7Sartem gboolean hal_util_get_bcd2_from_file (const gchar *directory, const gchar *file, gint *result);
6518c2aff7Sartem 
6618c2aff7Sartem gboolean hal_util_set_bcd2_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file);
6718c2aff7Sartem 
6818c2aff7Sartem void hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...);
6918c2aff7Sartem 
7018c2aff7Sartem gboolean hal_util_path_ascend (gchar *path);
7118c2aff7Sartem 
7218c2aff7Sartem void hal_util_grep_discard_existing_data (void);
7318c2aff7Sartem 
7418c2aff7Sartem gchar *hal_util_grep_file (const gchar *directory, const gchar *file, const gchar *linestart, gboolean reuse_file);
7518c2aff7Sartem 
76*55fea89dSDan Cross gint hal_util_grep_int_elem_from_file (const gchar *directory, const gchar *file,
7718c2aff7Sartem 				       const gchar *linestart, guint elem, guint base, gboolean reuse_file);
7818c2aff7Sartem 
79*55fea89dSDan Cross gchar *hal_util_grep_string_elem_from_file (const gchar *directory, const gchar *file,
8018c2aff7Sartem 					    const gchar *linestart, guint elem, gboolean reuse_file);
8118c2aff7Sartem 
82*55fea89dSDan Cross gboolean hal_util_set_string_elem_from_file (HalDevice *d, const gchar *key,
83*55fea89dSDan Cross 					     const gchar *directory, const gchar *file,
8418c2aff7Sartem 					     const gchar *linestart, guint elem, gboolean reuse_file);
8518c2aff7Sartem 
86*55fea89dSDan Cross gboolean hal_util_set_int_elem_from_file (HalDevice *d, const gchar *key,
87*55fea89dSDan Cross 					  const gchar *directory, const gchar *file,
8818c2aff7Sartem 					  const gchar *linestart, guint elem, guint base, gboolean reuse_file);
8918c2aff7Sartem 
90*55fea89dSDan Cross gboolean hal_util_set_bool_elem_from_file (HalDevice *d, const gchar *key,
91*55fea89dSDan Cross 					   const gchar *directory, const gchar *file,
92*55fea89dSDan Cross 					   const gchar *linestart, guint elem, const gchar *expected,
9318c2aff7Sartem 					   gboolean reuse_file);
9418c2aff7Sartem 
9518c2aff7Sartem gchar **hal_util_dup_strv_from_g_slist (GSList *strlist);
9618c2aff7Sartem 
9718c2aff7Sartem typedef void (*HalCalloutsDone) (HalDevice *d, gpointer userdata1, gpointer userdata2);
9818c2aff7Sartem 
9918c2aff7Sartem void hal_util_callout_device_add (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2);
10018c2aff7Sartem void hal_util_callout_device_remove (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2);
10118c2aff7Sartem void hal_util_callout_device_preprobe (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2);
10218c2aff7Sartem 
10318c2aff7Sartem gchar *hal_util_strdup_valid_utf8 (const char *str);
10418c2aff7Sartem 
10518c2aff7Sartem void hal_util_hexdump (const void *buf, unsigned int size);
10618c2aff7Sartem 
10718c2aff7Sartem gboolean hal_util_is_mounted_by_hald (const char *mount_point);
10818c2aff7Sartem 
10918c2aff7Sartem void
11018c2aff7Sartem hal_util_branch_claim (HalDeviceStore *store, HalDevice *root, dbus_bool_t claimed, const char *service, int uid);
11118c2aff7Sartem 
11297191cecSXiaolin Zhang - Sun Microsystems - Beijing China gboolean
11397191cecSXiaolin Zhang - Sun Microsystems - Beijing China is_valid_interface_name (const char *name);
11497191cecSXiaolin Zhang - Sun Microsystems - Beijing China 
11518c2aff7Sartem #endif /* UTIL_H */
116