2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
5 * Licensed under the Academic Free License version 2.1
8 #pragma ident "%Z%%M% %I% %E% SMI"
20 #include "network-discovery.h"
23 * The interfaces in this file comprise a means of keeping track of devices
24 * that we have already seen and those that have gone missing. This allows
25 * us to quickly determine if we need to probe the device and quickly search
26 * for devices that are no longer available.
34 static GHashTable
*seen
= NULL
;
37 device_remove_if_stale(gpointer key
, gpointer value
, gpointer user_data
)
39 gboolean result
= FALSE
;
40 removal_args_t
*args
= user_data
;
44 HAL_DEBUG(("test stale: %s (%d > %d)", name
, args
->timestamp
, *val
));
45 if (args
->timestamp
> *val
) {
50 dbus_error_init(&error
);
51 udi
= libhal_manager_find_device_string_match(args
->ctx
,
52 "network_device.address", name
,
58 for (i
= 0; i
< num
; i
++) {
59 libhal_remove_device(args
->ctx
, udi
[i
], &error
);
60 HAL_DEBUG(("remove: %s (%s)", name
, udi
[i
]));
62 libhal_free_string_array(udi
);
65 if (dbus_error_is_set(&error
))
66 dbus_error_free(&error
);
73 scan_for_stale_devices(LibHalContext
*ctx
, time_t timestamp
)
76 removal_args_t args
[1];
79 args
->timestamp
= timestamp
;
81 g_hash_table_foreach_remove(seen
, device_remove_if_stale
, args
);
86 device_seen(char *name
)
93 seen
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
96 result
= g_hash_table_lookup_extended(seen
, name
,
97 (gpointer
)&key
, (gpointer
)&val
);
99 if ((result
== FALSE
) && ((val
= calloc(1, sizeof (*val
))) != NULL
)) {
100 g_hash_table_insert(seen
, strdup(name
), val
);
103 HAL_DEBUG(("seen: %s (%d)", name
, *val
));