1 /*************************************************************************** 2 * CVSID: $Id$ 3 * 4 * device.c : HalDevice methods 5 * 6 * Copyright (C) 2003 David Zeuthen, <david@fubar.dk> 7 * Copyright (C) 2004 Novell, Inc. 8 * 9 * Licensed under the Academic Free License version 2.1 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 * 25 **************************************************************************/ 26 27 #ifndef DEVICE_H 28 #define DEVICE_H 29 30 #include <glib-object.h> 31 #include <dbus/dbus.h> 32 33 #include "property.h" 34 35 typedef struct _HalDevice HalDevice; 36 typedef struct _HalDeviceClass HalDeviceClass; 37 38 struct _HalDevice { 39 GObject parent; 40 41 char *udi; 42 43 GSList *properties; 44 45 int num_addons; 46 int num_addons_ready; 47 }; 48 49 struct _HalDeviceClass { 50 GObjectClass parent_class; 51 52 /* signals */ 53 void (*property_changed) (HalDevice *device, 54 const char *key, 55 gboolean removed, 56 gboolean added); 57 58 void (*capability_added) (HalDevice *device, 59 const char *capability); 60 61 void (*callouts_finished) (HalDevice *device); 62 63 void (*cancelled) (HalDevice *device); 64 }; 65 66 #define HAL_TYPE_DEVICE (hal_device_get_type ()) 67 #define HAL_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ 68 HAL_TYPE_DEVICE, HalDevice)) 69 #define HAL_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \ 70 HAL_TYPE_DEVICE, HalDeviceClass)) 71 #define HAL_IS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ 72 HAL_TYPE_DEVICE)) 73 #define HAL_IS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \ 74 HAL_TYPE_DEVICE)) 75 76 typedef void (*HalDeviceAsyncCallback) (HalDevice *device, 77 gpointer user_data, 78 gboolean prop_exists); 79 80 /* Return value of FALSE means that the foreach should be short-circuited */ 81 typedef gboolean (*HalDevicePropertyForeachFn) (HalDevice *device, 82 HalProperty *property, 83 gpointer user_data); 84 85 GType hal_device_get_type (void); 86 87 HalDevice *hal_device_new (void); 88 89 void hal_device_merge (HalDevice *target, 90 HalDevice *source); 91 92 void hal_device_merge_with_rewrite (HalDevice *target, 93 HalDevice *source, 94 const char *target_namespace, 95 const char *source_namespace); 96 97 gboolean hal_device_matches (HalDevice *device1, 98 HalDevice *device2, 99 const char *namespace); 100 101 const char *hal_device_get_udi (HalDevice *device); 102 void hal_device_set_udi (HalDevice *device, 103 const char *udi); 104 105 void hal_device_add_capability (HalDevice *device, 106 const char *capability); 107 gboolean hal_device_has_capability (HalDevice *device, 108 const char *capability); 109 110 gboolean hal_device_has_property (HalDevice *device, 111 const char *key); 112 HalProperty *hal_device_property_find (HalDevice *device, 113 const char *key); 114 int hal_device_num_properties (HalDevice *device); 115 char * hal_device_property_to_string (HalDevice *device, 116 const char *key); 117 void hal_device_property_foreach (HalDevice *device, 118 HalDevicePropertyForeachFn callback, 119 gpointer user_data); 120 121 int hal_device_property_get_type (HalDevice *device, 122 const char *key); 123 const char *hal_device_property_get_as_string (HalDevice *device, 124 const char *key, 125 char *buf, 126 size_t bufsize); 127 128 129 const char *hal_device_property_get_string (HalDevice *device, 130 const char *key); 131 dbus_int32_t hal_device_property_get_int (HalDevice *device, 132 const char *key); 133 dbus_uint64_t hal_device_property_get_uint64 (HalDevice *device, 134 const char *key); 135 dbus_bool_t hal_device_property_get_bool (HalDevice *device, 136 const char *key); 137 double hal_device_property_get_double (HalDevice *device, 138 const char *key); 139 GSList *hal_device_property_get_strlist (HalDevice *device, 140 const char *key); 141 const char *hal_device_property_get_strlist_elem (HalDevice *device, 142 const char *key, 143 guint index); 144 145 146 147 gboolean hal_device_property_set_string (HalDevice *device, 148 const char *key, 149 const char *value); 150 gboolean hal_device_property_set_int (HalDevice *device, 151 const char *key, 152 dbus_int32_t value); 153 gboolean hal_device_property_set_uint64 (HalDevice *device, 154 const char *key, 155 dbus_uint64_t value); 156 gboolean hal_device_property_set_bool (HalDevice *device, 157 const char *key, 158 dbus_bool_t value); 159 gboolean hal_device_property_set_double (HalDevice *device, 160 const char *key, 161 double value); 162 gboolean hal_device_property_strlist_append (HalDevice *device, 163 const char *key, 164 const char *value); 165 gboolean hal_device_property_strlist_prepend (HalDevice *device, 166 const char *key, 167 const char *value); 168 gboolean hal_device_property_strlist_remove_elem (HalDevice *device, 169 const char *key, 170 guint index); 171 gboolean hal_device_property_strlist_clear (HalDevice *device, 172 const char *key); 173 gboolean hal_device_property_strlist_add (HalDevice *device, 174 const char *key, 175 const char *value); 176 gboolean hal_device_property_strlist_remove (HalDevice *device, 177 const char *key, 178 const char *value); 179 gboolean hal_device_property_strlist_is_empty (HalDevice *device, 180 const char *key); 181 182 gboolean hal_device_property_remove (HalDevice *device, 183 const char *key); 184 185 gboolean hal_device_copy_property (HalDevice *from_device, 186 const char *from, 187 HalDevice *to_device, 188 const char *to); 189 190 191 void hal_device_print (HalDevice *device); 192 193 void hal_device_async_wait_property (HalDevice *device, 194 const char *key, 195 HalDeviceAsyncCallback callback, 196 gpointer user_data, 197 int timeout); 198 199 void hal_device_callouts_finished (HalDevice *device); 200 201 void hal_device_cancel (HalDevice *device); 202 203 gboolean hal_device_property_set_attribute (HalDevice *device, 204 const char *key, 205 enum PropertyAttribute attr, 206 gboolean persistence); 207 208 void hal_device_inc_num_addons (HalDevice *device); 209 210 gboolean hal_device_inc_num_ready_addons (HalDevice *device); 211 212 gboolean hal_device_are_all_addons_ready (HalDevice *device); 213 214 215 #endif /* DEVICE_H */ 216