Network scan and scan result handling
[ICd internal functions]


Classes

struct  icd_scan_listener
struct  icd_scan_expire_network_data
struct  icd_scan_cache_list
struct  icd_scan_srv_provider
struct  icd_scan_cache
struct  icd_scan_cache_timeout

Typedefs

typedef void(* icd_scan_cb_fn )(enum icd_scan_status status, const struct icd_scan_srv_provider *srv_provider, const struct icd_scan_cache *cache_entry, gpointer user_data)

Functions

static gboolean string_equal (const gchar *a, const gchar *b)
void icd_scan_cache_entry_free (struct icd_scan_cache *cache_entry)
void icd_scan_cache_entry_add (struct icd_network_module *module, struct icd_scan_cache_list *scan_cache, struct icd_scan_cache *cache_entry)
struct icd_scan_cache_listicd_scan_cache_list_lookup (struct icd_network_module *module, const gchar *network_id)
struct icd_scan_cacheicd_scan_cache_entry_find (struct icd_scan_cache_list *scan_cache_list, const gchar *network_type, const guint network_attrs)
gboolean icd_scan_cache_entry_remove (struct icd_scan_cache_list *scan_cache_list, const gchar *network_id, const gchar *network_type, const guint network_attrs)
static gboolean icd_scan_cache_rescan (gpointer data)
static void icd_scan_status_stop (struct icd_network_module *module)
static void icd_scan_status_start (struct icd_network_module *module)
static gboolean icd_scan_listener_exist (struct icd_network_module *module)
static gboolean icd_scan_listener_send_entry (struct icd_scan_srv_provider *srv_provider, struct icd_scan_cache *cache_entry, struct icd_scan_listener *listener, enum icd_scan_status status)
static void icd_scan_listener_send_list (gpointer key, gpointer value, gpointer user_data)
static gboolean icd_scan_cache_element_check (gpointer key, gpointer value, gpointer user_data)
static gboolean icd_scan_cache_has_elements (struct icd_network_module *module)
static void icd_scan_listener_send_cache (struct icd_network_module *module, struct icd_scan_listener *listener)
static gboolean icd_scan_listener_add (struct icd_network_module *module, const gchar *type, icd_scan_cb_fn cb, gpointer user_data)
static void icd_scan_listener_remove (struct icd_network_module *module, icd_scan_cb_fn cb, gpointer user_data)
void icd_scan_listener_notify (struct icd_network_module *module, struct icd_scan_srv_provider *srv_provider, struct icd_scan_cache *cache_entry, enum icd_scan_status status)
static gboolean icd_scan_expire_network (gpointer key, gpointer value, gpointer user_data)
static gboolean icd_scan_expire_network_for_hash (gpointer key, gpointer value, gpointer user_data)
static guint icd_scan_timeout_rescan_add (struct icd_network_module *module, guint seconds)
static guint icd_scan_timeout_add (struct icd_network_module *module, GSourceFunc expire_function, guint seconds)
static void icd_scan_timeout_free (struct icd_scan_cache_timeout *timeout_data)
static gboolean icd_scan_cache_expire (gpointer data)
static void icd_scan_cb (enum icd_network_search_status status, gchar *network_name, gchar *network_type, const guint network_attrs, gchar *network_id, enum icd_nw_levels signal, gchar *station_id, gint dB, const gpointer search_cb_token)
static gboolean icd_scan_network (struct icd_network_module *module, const gchar *network_type)
static gboolean icd_scan_cache_remove_iap_for_module (struct icd_network_module *module, gpointer user_data)
void icd_scan_cache_remove_iap (gchar *iap_name)
gboolean icd_scan_results_request (const gchar *type, guint scope, icd_scan_cb_fn cb, gpointer user_data)
gboolean icd_scan_results_unregister (icd_scan_cb_fn cb, gpointer user_data)
gboolean icd_scan_cache_init (struct icd_network_module *module)
void icd_scan_cache_remove (struct icd_network_module *module)

Variables

const gchar const * icd_scan_status_names []

Detailed Description

Internally each module has a hash table of cached scan results. The hash table is accessed using the module internal network_id. Each hash table entry contains an icd_scan_cache_list structure with a singly linked list of networks. The icd_scan_cache_list structure is used because the pointer to the singly linked list must be updated whenever a network is removed.
 +---+
 | n |   +GHashTable(network_idX)-+
 | w |-->|scan_cache_table        |
 |   |   +------------------------+
 | m |                     |  |  +->icd_scan_cache_list
 | o |                     |  |       +->GSlist for network_idN
 | d |                     |  |
 | u |                     |  +->icd_scan_cache_list
 | l |                     |       +->GSList for network_id2
 | e |                     |
 +---+                     |   ...
                           |
                           +->icd_scan_cache_list
                                +->GSList for network_idN
 

Typedef Documentation

typedef void(* icd_scan_cb_fn)(enum icd_scan_status status, const struct icd_scan_srv_provider *srv_provider, const struct icd_scan_cache *cache_entry, gpointer user_data)

Scan callback function for receiving scan results

Parameters:
status status of this network
srv_provider service provider entry; guaranteed to exist only for the lifetime of this callback function
cache_entry scan results; guaranteed to exist only for the lifetime of this callback function
user_data used data given to the scan callback


Function Documentation

static gboolean icd_scan_cache_element_check ( gpointer  key,
gpointer  value,
gpointer  user_data 
) [static]

Check for elements, return immediately on first element found

Parameters:
key the network_id, not used
value the icd_scan_cache_list
user_data not used
Returns:
TRUE on first non-NULL element found

References icd_scan_cache_list::cache_list, and ILOG_DEBUG.

Referenced by icd_scan_cache_has_elements().

void icd_scan_cache_entry_add ( struct icd_network_module module,
struct icd_scan_cache_list scan_cache,
struct icd_scan_cache cache_entry 
)

Add an cache entry to the network module

Parameters:
module network module
scan_cache scan cache list or NULL
cache_entry the entry to add

References icd_scan_cache_list::cache_list, ILOG_ERR, icd_scan_cache::network_id, and icd_network_module::scan_cache_table.

Referenced by icd_scan_cb(), and icd_srv_provider_identify_cb().

struct icd_scan_cache * icd_scan_cache_entry_find ( struct icd_scan_cache_list scan_cache_list,
const gchar *  network_type,
const guint  network_attrs 
) [read]

Find a network entry in the scan cache list

Parameters:
scan_cache_list scan cache list
network_type network type
network_attrs network attrs
Returns:
the scan cache entry or NULL if not found

References icd_scan_cache_list::cache_list, icd_scan_cache::network_attrs, icd_scan_cache::network_type, and string_equal().

Referenced by icd_scan_cb(), and icd_srv_provider_identify_cb().

void icd_scan_cache_entry_free ( struct icd_scan_cache cache_entry  ) 

gboolean icd_scan_cache_entry_remove ( struct icd_scan_cache_list scan_cache_list,
const gchar *  network_id,
const gchar *  network_type,
const guint  network_attrs 
)

Remove scan cache from scan list, the removed entry does not call listener.

Parameters:
cache_list the icd_scan_cache_list struct
network_id network identifier
network_type the network type
network_attrs network attributes
Returns:
TRUE if scan entry was removed; FALSE otherwise
Remove scan cache from scan list, the removed entry does not call listeners.
Parameters:
cache_list the icd_scan_cache_list struct
network_id network identifier
network_type the network type
network_attrs network attributes
Returns:
TRUE if scan entry was removed; FALSE otherwise

References icd_scan_cache_list::cache_list, icd_scan_cache_entry_free(), ILOG_DEBUG, ILOG_ERR, icd_scan_cache::network_attrs, icd_scan_cache::network_type, and string_equal().

Referenced by icd_iap_free().

static gboolean icd_scan_cache_expire ( gpointer  data  )  [static]

static gboolean icd_scan_cache_has_elements ( struct icd_network_module module  )  [static]

Check wheter a scan cache has any elements

Parameters:
module network module
Returns:
TRUE if there are elements, FALSE otherwise

References icd_scan_cache_element_check(), and icd_network_module::scan_cache_table.

Referenced by icd_scan_listener_send_cache(), and icd_scan_results_request().

gboolean icd_scan_cache_init ( struct icd_network_module module  ) 

Set up the scan cache for a network module

Parameters:
module network module

References ILOG_ERR, and icd_network_module::scan_cache_table.

Referenced by icd_network_api_init_cb().

struct icd_scan_cache_list * icd_scan_cache_list_lookup ( struct icd_network_module module,
const gchar *  network_id 
) [read]

Get the scan cache list associated with the network id

Parameters:
module network module
network_id network id
Returns:
the scan cache list or NULL if not found

References icd_network_module::scan_cache_table.

Referenced by icd_iap_free(), icd_scan_cache_remove_iap_for_module(), icd_scan_cb(), and icd_srv_provider_identify_cb().

void icd_scan_cache_remove ( struct icd_network_module module  ) 

void icd_scan_cache_remove_iap ( gchar *  iap_name  ) 

Function that removes all the IAPs from cache that match name.

Parameters:
iap_name IAP name

References icd_context_get(), icd_ctx, icd_network_api_foreach_module(), and icd_scan_cache_remove_iap_for_module().

Referenced by icd_gconf_notify().

static gboolean icd_scan_cache_remove_iap_for_module ( struct icd_network_module module,
gpointer  user_data 
) [static]

Function that removes all the IAPs for a given module from cache that match name.

Parameters:
module the network module
IAP name
Returns:
TRUE so that foreach func will continue

References icd_scan_cache_list::cache_list, ICD_NW_ATTR_IAPNAME, icd_scan_cache_entry_free(), icd_scan_cache_list_lookup(), ICD_SCAN_EXPIRE, icd_scan_listener_notify(), ILOG_DEBUG, ILOG_ERR, icd_scan_cache::network_attrs, icd_scan_cache::network_id, icd_scan_cache::network_name, icd_scan_cache::network_type, icd_network_module::network_types, and string_equal().

Referenced by icd_scan_cache_remove_iap().

static gboolean icd_scan_cache_rescan ( gpointer  data  )  [static]

Rescan timeout function

Parameters:
data scan cache timeout data
Returns:
FALSE so that the timeout won't repeat

References icd_scan_listener_exist(), icd_scan_network(), ILOG_INFO, icd_network_module::name, and icd_network_module::scan_timeout_rescan.

Referenced by icd_scan_timeout_rescan_add().

static void icd_scan_cb ( enum icd_network_search_status  status,
gchar *  network_name,
gchar *  network_type,
const guint  network_attrs,
gchar *  network_id,
enum icd_nw_levels  signal,
gchar *  station_id,
gint  dB,
const gpointer  search_cb_token 
) [static]

static gboolean icd_scan_expire_network ( gpointer  key,
gpointer  value,
gpointer  user_data 
) [static]

Hash table callback for removing an entry. Note that this function is also called outside of hash, so care should be taken when dealing with the hash (that is why list_entry is not deleted inside this function).

Parameters:
key the network_id
value the icd_scan_cache_list struct
user_data expiration time
Returns:
TRUE when all networks for the network_id have been expired and the hash table element can be removed; FALSE otherwise

References icd_scan_cache_list::cache_list, icd_scan_expire_network_data::expire, icd_scan_cache_entry_free(), ICD_SCAN_EXPIRE, icd_scan_listener_notify(), ILOG_DEBUG, ILOG_ERR, icd_scan_cache::last_seen, and icd_scan_expire_network_data::module.

Referenced by icd_scan_cb(), and icd_scan_expire_network_for_hash().

static gboolean icd_scan_expire_network_for_hash ( gpointer  key,
gpointer  value,
gpointer  user_data 
) [static]

Hash table callback for removing an entry, this version is only called from hash remove func.

Parameters:
key the network_id
value the icd_scan_cache_list struct
user_data expiration time
Returns:
TRUE when all networks for the network_id have been expired and the hash table element can be removed; FALSE otherwise

References icd_scan_expire_network().

Referenced by icd_scan_cache_expire(), icd_scan_cache_remove(), and icd_scan_cb().

static gboolean icd_scan_listener_add ( struct icd_network_module module,
const gchar *  type,
icd_scan_cb_fn  cb,
gpointer  user_data 
) [static]

Add a scan result listener to a module

Parameters:
module the module whose scan results to report
type the network type to receive scan results for
cb listener callback
user_data user data to pass to the callback
Returns:
TRUE when the callback is added to the list, FALSE on error

References icd_scan_listener::cb, icd_scan_listener_send_cache(), icd_network_module::scan_listener_list, icd_scan_listener::type, and icd_scan_listener::user_data.

Referenced by icd_scan_results_request().

static gboolean icd_scan_listener_exist ( struct icd_network_module module  )  [static]

Check if there are any listeners that want scan results

Parameters:
module the network module
Returns:
TRUE if there are listeners, FALSE otherwise

References icd_network_module::scan_listener_list.

Referenced by icd_scan_cache_rescan(), and icd_scan_results_request().

void icd_scan_listener_notify ( struct icd_network_module module,
struct icd_scan_srv_provider srv_provider,
struct icd_scan_cache cache_entry,
enum icd_scan_status  status 
)

Notify each matching listener about the change in the cache entry

Parameters:
module the network module
srv_provider NULL or the specific service provider entry that got updated; if non-NULL only this service provider associated with the cache_entry will be sent to the listeners
cache_entry corresponding cache entry that got updated
status status of the notification

References icd_scan_listener_send_entry(), and icd_network_module::scan_listener_list.

Referenced by icd_scan_cache_remove_iap_for_module(), icd_scan_cb(), icd_scan_expire_network(), and icd_srv_provider_identify_cb().

static void icd_scan_listener_remove ( struct icd_network_module module,
icd_scan_cb_fn  cb,
gpointer  user_data 
) [static]

Remove all matching listener callback - user data tuples from a module

Parameters:
module the network module
cb the callback to remove or NULL to remove all callbacks
user_data user data to remove

References icd_scan_listener::cb, icd_network_module::scan_listener_list, icd_scan_listener::type, and icd_scan_listener::user_data.

Referenced by icd_scan_cache_remove(), and icd_scan_results_unregister().

static void icd_scan_listener_send_cache ( struct icd_network_module module,
struct icd_scan_listener listener 
) [static]

Notify a (new) listener of the current cache

Parameters:
module the network module
listener the listener to update with the current cache

References icd_scan_cache_has_elements(), ICD_SCAN_COMPLETE, icd_scan_listener_send_entry(), icd_scan_listener_send_list(), icd_scan_cache::network_type, icd_network_module::scan_cache_table, icd_network_module::scan_timeout_rescan, and icd_scan_listener::type.

Referenced by icd_scan_listener_add().

static gboolean icd_scan_listener_send_entry ( struct icd_scan_srv_provider srv_provider,
struct icd_scan_cache cache_entry,
struct icd_scan_listener listener,
enum icd_scan_status  status 
) [static]

Send the cache entry to the listener if the network type matches

Parameters:
srv_provider send only this service provider to the listener if set; send all network and service provider entries if NULL
cache_entry the cache entry
listener the listener
status the status of the supplied cache entry
Returns:
TRUE if the type matched and listener was updated; FALSE otherwise

References icd_scan_listener::cb, ICD_NW_ATTR_SRV_PROVIDER, ICD_SCAN_COMPLETE, icd_scan_status_names, ILOG_DEBUG, ILOG_ERR, icd_scan_cache::network_attrs, icd_scan_cache::network_id, icd_scan_cache::network_type, icd_scan_srv_provider::service_attrs, icd_scan_srv_provider::service_id, icd_scan_srv_provider::service_type, icd_scan_cache::srv_provider_list, icd_scan_listener::type, and icd_scan_listener::user_data.

Referenced by icd_scan_listener_notify(), icd_scan_listener_send_cache(), and icd_scan_listener_send_list().

static void icd_scan_listener_send_list ( gpointer  key,
gpointer  value,
gpointer  user_data 
) [static]

Send all cache entries to the listener

Parameters:
key the network_id
value the icd_scan_cache_list
user_data the icd_scan_listener

References icd_scan_cache_list::cache_list, icd_scan_listener_send_entry(), and ICD_SCAN_NEW.

Referenced by icd_scan_listener_send_cache().

static gboolean icd_scan_network ( struct icd_network_module module,
const gchar *  network_type 
) [static]

Request one network module to initiate scan with given scope

Parameters:
module the network module
network_type network type to scan for
Returns:
TRUE if scan was started or already ongoing, FALSE otherwise

References icd_scan_cb(), icd_scan_status_start(), ILOG_WARN, icd_network_module::name, icd_network_module::nw, icd_network_module::scan_progress, icd_network_module::scope, and icd_nw_api::start_search.

Referenced by icd_scan_cache_rescan(), and icd_scan_results_request().

gboolean icd_scan_results_request ( const gchar *  type,
guint  scope,
icd_scan_cb_fn  cb,
gpointer  user_data 
)

Function requesting scan results; can be called many times to add more than one network type per callback

Parameters:
type network type to scan or NULL for all networks
scope scope of the scan, see network_api.h
cb callback function for the results
user_data user data to pass to the callback
Returns:
TRUE if the callback is going to be called; FALSE on error

References icd_context_get(), icd_ctx, icd_gconf_agressive_scanning(), icd_network_api_has_type(), icd_scan_cache_has_elements(), icd_scan_listener_add(), icd_scan_listener_exist(), icd_scan_network(), ILOG_ERR, ILOG_WARN, icd_network_module::nw, icd_context::nw_module_list, icd_network_module::scan_timeout_rescan, icd_network_module::scope, and icd_nw_api::start_search.

Referenced by icd_dbus_api_scan_append(), and icd_policy_api_scan_start().

gboolean icd_scan_results_unregister ( icd_scan_cb_fn  cb,
gpointer  user_data 
)

Unregister all matching callback - user data tuples from receiving scan results

Parameters:
cb the same callback as given in icd_scan_results_request
user_data the same user_data as given in icd_scan_results_request
Returns:
TRUE if the callback - user_data tuple existed and was remvoed; FALSE otherwise

References icd_context_get(), icd_ctx, icd_scan_listener_remove(), ILOG_ERR, and icd_context::nw_module_list.

Referenced by icd_dbus_api_app_exit(), and icd_policy_api_scan_stop().

static void icd_scan_status_start ( struct icd_network_module module  )  [static]

Send scan start status

Parameters:
module network module

References icd_status_scan_start(), ILOG_INFO, icd_network_module::network_types, icd_network_module::nw, and icd_nw_api::start_search.

Referenced by icd_scan_network().

static void icd_scan_status_stop ( struct icd_network_module module  )  [static]

Send scan stop status

Parameters:
module network module

References icd_status_scan_stop(), ILOG_INFO, icd_network_module::network_types, icd_network_module::nw, and icd_nw_api::start_search.

Referenced by icd_scan_cb().

static guint icd_scan_timeout_add ( struct icd_network_module module,
GSourceFunc  expire_function,
guint  seconds 
) [static]

Add a pending timeout function. The timeout function must remove the timeout data structure if the same callback is not called repeatedly.

Parameters:
module the network module
expire_function function to call
seconds seconds until timeout
Returns:
id the timeout id

References icd_scan_cache_timeout::id, icd_scan_cache_timeout::module, and icd_network_module::scan_timeout_list.

Referenced by icd_scan_cb().

static void icd_scan_timeout_free ( struct icd_scan_cache_timeout timeout_data  )  [static]

Remove and g_free() the timeout data

Parameters:
timeout_data the timeout data to free

References icd_scan_cache_timeout::module, and icd_network_module::scan_timeout_list.

Referenced by icd_scan_cache_expire().

static guint icd_scan_timeout_rescan_add ( struct icd_network_module module,
guint  seconds 
) [static]

Add a rescan timeout.

Parameters:
module the network module
seconds seconds until timeout
Returns:
id the new timeout id

References icd_scan_cache_rescan(), and icd_network_module::scan_timeout_rescan.

Referenced by icd_scan_cb().

static gboolean string_equal ( const gchar *  a,
const gchar *  b 
) [static]

Helper function for comparing two strings where a NULL string is equal to another NULL string

Parameters:
a string A
b string B
Returns:
TRUE if equal, FALSE if unequal


Variable Documentation

const gchar const* icd_scan_status_names[]

Initial value:

 {
  "ICD_SCAN_NEW",
  "ICD_SCAN_UPDATE",
  "ICD_SCAN_NOTIFY",
  "ICD_SCAN_EXPIRE",
  "ICD_SCAN_COMPLETE"
}
scan status name strings

Referenced by icd_scan_listener_send_entry().


Generated on Thu Mar 11 09:04:50 2010 for ICd2 by  doxygen 1.5.6