Documentation/Maemo 5 Developer Guide/Using Connectivity Components/Maemo Connectivity

= Maemo Connectivity =

Introduction
The maemo connectivity subsystem is implemented by using known Linux conventions. It resides in the user mode area of Linux, and relies on the Linux kernel through standard C libraries. Wireless LAN or WiMAX is the main channel to the Internet, but dial-up connections through cellular networks are also supported. The only medium to the phone is Bluetooth. The Bluetooth software of maemo is based on BlueZ, which is known as the de-facto implementation of Bluetooth for Linux. D-Bus is used for internal application level message exchange.

Even though the connectivity device drivers are closely related to this subsystem, they are considered to be outside of the scope of this manual.

Components of the maemo connectivity architecture
Maemo connectivity UI - User Interface parts of the connectivity. This includes Connection manager, Control Panel applets and several different dialogs.

Maemo connectivity daemon (ICd) - LibConIC API works together with ICd, handling all Internet Access Points (IAPs). IC daemon handles both WLAN and Bluetooth connections.

OBEX wrapper - Interface to OBEX services. The primary target user of this library is the OBEX gnome-vfs module.

OpenOBEX - Open source implementation of the Object Exchange (OBEX) protocol. For more information on OpenOBEX, see http://triq.net/obex/

BlueZ Bluetooth stack - The de-facto implementation of Bluetooth for Linux. For more information on BlueZ, see http://www.bluez.org

BlueZ D-Bus API - BlueZ accepts commands via D-Bus.

WLAN connectivity daemon - The daemon controlling WLAN connections.

WLAN device driver - Device driver for Wireless LAN (IEEE 802.11g). Kernel driver is composed of two parts: a binary part (closed source) and an open source wrapper, binding the binary to the current Linux kernel.

WiMAX onnectivity daemon - The daemon controlling WiMAX connections.

WiMAX device driver - Device driver for mobile WiMAX (IEEE 802.16e).

Internet Access Points (IAP)
The central concept for maemo Internet connections is the Internet Access Point (IAP), which represents a logical Internet (IP) connection that the user defines. An IAP has a unique name, usually in form of UUID). Among other things, it defines the radio bearer (e.g. WLAN, CSD, GPRS), and usually also the data transfer speed, username, password, proxy server, and the corresponding access point in the Internet or the telephone number of the service provider's modem.

Connectivity Subsystem
This section describes the system decomposition of the Connectivity subsystem. Maemo applications can open Internet connections by using the LibConIC API. The Internet Access subsystem take care of the connection to the phone, if necessary, by using the services of the Phone Access subsystem. If an application needs to gain access to the phone's files, the File selector consults the Phone Access subsystem.

In offline mode, none of the radios must be active. The Device System Management Entity (DSME) of maemo provides information about the transitions to and from the offline mode.

Phone and Internet connections are quite different by nature and behavior. These are introduced in more detail in the following sections.

Phone Access
Phone Access is the subsystem handling connections to a cellular phone. It offers a search utility for finding potential phones and inquiring the services they can offer. This is based on the standard Bluetooth service discovery mechanism. Phone Access also keeps a record of phones that have connected to the device in GConf, and provides a list of them for the user to choose from. Phone Access relies on the Linux Bluetooth implementation called BlueZ. BlueZ offers the Berkeley socket interface to the HCI and to the L2CAP protocol for the user space applications.

In principle, any cellular phone supporting Bluetooth Service Discovery Protocol (SDP), Dial-up Networking profile (DUN) and File Transfer Profile (FTP) can connect to maemo. However, different mobile phones implement varying levels of file transfer services and OBEX. Some products limit access to the Inbox (Object Push), whereas more sophisticated ones make the Gallery and the memory card available. The recent products support the OBEX Capability request for retrieving more specific information about the file system on the phone.

Maemo connects to a phone on an on-demand basis, such as when an application requires a connection. For example, when the Internet browser is about to open a URL, it requests Phone Access to establish a connection to the phone. This causes Phone Access to bind an RFCOMM device to the requested service (in this case DUN) on the phone. In a similar fashion, the File Selector can set up a file transfer connection to the phone using another RFCOMM device. After binding to a service, the application in question can open the local RFCOMM device. Normal file selector access is performed with GnomeVFS layer to get transparent access to phone in the same way as internal flash and MMC are accessed.

The Bluetooth SIM Access (SAP) profile is also needed in maemo to perform WLAN authentication using the EAP-SIM authentication method. In this case, the EAP component asks the BT sap component to get session keys from a GSM/UMTS phone.

Maemo Bluetooth also supports HID (keyboard) and OPP (object push file transfer) profiles.

Internet Access
The Internet Access subsystem manages connections to the Internet over different bearers and is also responsible for the configuration and management of Internet Access Points. Internet Access provides applications with TCP/IP connections. They can be established in the following ways:


 * WLAN connection to a wireless access point.
 * WiMAX connection to a WiMAX base station.
 * Bluetooth connection through phone using Point-to-Point Protocol (PPP) and a cellular modem (in the phone).

For Bluetooth connections, AT commands are applied to establish a PPP link to the cellular modem and the connection to the Internet.

Internet Connectivity Daemon
This section describes how the Internet Connectivity daemon works internally. The following subsections explain the behavior and the decomposition of this component in detail, also covering the interfaces that this component realizes.

Decomposition
If the ICd receives a request to activate or deactivate an IAP, the ICd activates the IAP or, if no IAP has been defined as the default, shows a uI requesting the user to choose one. Depending on the type of the IAP, the ICd uses the appropriate network type plug-in to activate or deactivate specific network interface.

The ICd tracks the applications requesting IAPs by recording their D-Bus base service names. This allows the ICd to detect situations where processes using an IAP have aborted or crashed. The ICd also implements an idle timeout mechanism to shut down the active IAP, if no packets have been sent in a configured amount of time.

Maemo version 3.0 introduced the automatic connection creation feature in the Internet Connectivity Daemon. In other words, the device tries to connect automatically to the saved IAPs, and keep connected as long as possible, unless the idle timeout is set. With this feature, applications like e-mail and RSS reader are always up to date. The device is also always ready for online use, for example, incoming VoIP calls or IM chat. In earlier versions, the Internet connection was automatically closed if no application was using it or when the connection was idle for the period of time defined by the idle timeout configuration parameter.

When the device is not connected, it scans for saved IAPs and tries to connect automatically, taking into account the value defined by the search interval configuration parameter. The search interval can be 5, 10, 30 or 60 minutes; all other values are automatically mapped to "Never". This setup switches off the automatic connection feature. In this case, the device behaves just like the former versions: Connections are created only when applications require it.

Because each application keeps its data updated and provides the always-online feature, the ICd is only responsible for creating connections.

While writing an application making use of the ICd system, keep the following in mind:


 * The application must always use the existing available connection.
 * As in former versions, if the device is not connected but a connection is required by user interaction, the application must require connection creation using LibConIC API.
 * Ensure that the user is aware of updates and can see the time when the data was last updated.
 * Ensure that the application registers via LibConIC and listens to signals emitted by the ICd (Connection Created, Lost and Changed), and react as follows:
 * Connection Created : Use the connection and update all data.
 * Connection Lost : Go to an idle state silently and wait until a new connection is created.
 * Connection Changed : Use the new connection.
 * Ensure that automatic data updates run in background and silently:
 * Avoid alarming the user with unnecessary banners or dialogs.
 * Ensure that usernames and passwords are saved so that automatic updates can be performed without prompts.
 * During and after updates, ensure that no failures display error notifications.
 * The connectivity infrastructure must take care of error situations in a centralized way.

You can switch off the automatic connection creation feature by using offline mode. While in this mode, the configuration parameter for allowing WLAN in offline mode is checked. Depending on the state of this configuration parameter, WLAN IAPs are either enabled or disabled in the offline mode. Also other radios like Bluetooth are normally disabled in the offline mode.

Bluetooth Dial-up Networking
The ICd uses PPP to establish IP connectivity over Bluetooth DUN interfaces. If there already is a different IAP active using Bluetooth DUN, the old IAP is first deactivated. The IAP is activated according the following action sequence:


 * The character device used by the Bluetooth DUN device is acquired from btcond. If the device is not available due to gateway not being present, exhaustion of simultaneous Bluetooth connections, or similar, the ICd shows an error message to the user and aborts with a D-BUS error message.
 * The ICd starts PPP using the exec family of system calls. It directs PPP to use the acquired Bluetooth DUN device with the dial-up configuration parameters specified for the configured DUN IAP type. If PPP cannot get the connection established, the ICd shows an error message to the user and aborts with a D-BUS error message. When the PPP connection is established, PPP-specific scripts are run. The scripts configuration entries related to dynamic IP connectivity and send a state-change D-BUS message to all interested applications to indicate that the IAP has been established.

If the previously active IAP was not using Bluetooth DUN, it is closed down after establishing the PPP connection.

A Bluetooth DUN is closed down by sending the PPP daemon a SIGINT or SIGTERM signal. This terminates the PPP daemon and removes all routing entries associated with the PPP dial-up interface. The PPP shutdown scripts removes the dynamic IP connection related configuration entries and sends a state change D-BUS message announcing the deactivation of the IAP.

WLAN
For connecting to a WLAN, the ICd needs to associate with the network as well as enable EAP authentication and the DHCP client as needed. Independently of whether an active IAP using WLAN exists, the requested WLAN network is first scanned to ensure that it is available. If the requested network is found and the current IAP is using WLAN, the current IAP is deactivated. WLAN is activated according to the following procedure:


 * If the network requires EAP authentication, the EAP authentication procedure is started. While performing the EAP authentication, the EAP software may show GUI dialogs relating to the EAP authentication procedure. When EAP authentication is complete, the EAP software sets security keys for the WLAN network, resulting in state change messages from wlancond. The ICd receives these messages but ignores them and waits for the reply from EAP authentication instead. If the EAP authentication fails, the ICd aborts with a D-Bus error message.
 * After the EAP process starts, the ICd instructs wlancond to associate with the WLAN network. Any static security settings relating to pre-shared security keys are also supplied at this point. If it cannot establish a connection to the WLAN network, the ICd aborts with an error.
 * Because the DHCP client is a stand-alone program, start it by using exec if the WLAN IAP requires dynamic IP address acquisition. When the DHCP client has obtained an IP address, it configures IP-related parameters, and sends a D-Bus signal to the ICd. If it cannot obtain the IP address lease, the ICd times out, stops the DHCP client and aborts with a D-Bus error message.

LibConIC Library
Internet Connectivity API (in shorter form: Libconic) is an API for applications to manage internet connections on Maemo devices. It was introduced in the first IT OS 2007 release, deprecating the old OSSO IC API (osso-ic-lib). OSSO IC API was conclusively removed in the IT OS 2008 release. For more information on libconic interfaces, see Internet Connectivity API

Libconic is high level and stable object-oriented API suitable for the following purposes:


 * requesting Internet connection
 * listening for Internet connection status events
 * receiving statistics of Internet connection
 * getting proxy settings for the current connection
 * getting a list of user-saved connections (IAPs)

Application Requirements Before applications can use the Libconic API, they must meet the following requirements:


 * 1) use non-blocking sockets
 * 2) have the system D-BUS running
 * 3) g_type_init has to be called
 * 4) employ no threading support in the Libconic API

If the application is a standard Hildon application, almost all of these requirements are already fulfilled. LibOSSO context initialization connects the application to both session and system D-BUS buses, g_type_init is called as a part of gtk_init, and probably no extra threads are used.

Non-Blocking Sockets Blocking sockets cannot be used because that would also block incoming Connectivity events. Non-blocking sockets should be used in order to receive the events properly. For example, GLib IO Channels with the G_IO_FLAG_NONBLOCK flag provide non-blocking way to use sockets.

With threads, blocking sockets can be used, although Libconic API itself is not thread safe.

System D-BUS Libconic API uses internally system D-BUS for delivering messages to the Connectivity components. Applications must be running normal D-BUS dispatch, watch and timeout monitoring before using the Libconic API. If the GLib mainloop is used, this can be accomplished with dbus_connection_setup_with_g_main.

N.B. Setting up LibOSSO context connects the application to required D-BUS.

GType Libconic API is GObject-basedm, so in order to get the API working, you must initialize GLib's GType properly. To do that, use g_type_init.

No Multiple Threads Libconic API is not thread-safe. If the applications have threads, use Libconic API only from the same context where GMainloop is running.

Requesting for Connection
Libconic is an asynchronous connection API, which heavily relies on GObject signals. Basically this means that GMainloop must be iterated in order to successfully execute connection requests. After the application is set up, use a ConIcConnection object to request a connection:

   gboolean success  = FALSE  ;  /* Create connection object */  ConIcConnection  * connection  =  con_ic_connection_new   ;  /* Connect signal to receive connection events */   g_signal_connect  (   G_OBJECT   ( connection ),  "connection-event"  ,                        <font color="#000000">G_CALLBACK   <font color="#990000">( my_connection_handler <font color="#990000">), NULL <font color="#990000">);  <font color="#9A1900">/* Request connection and check for the result */  success <font color="#990000"> =  <font color="#000000">con_ic_connection_connect   <font color="#990000">( connection <font color="#990000">, CON_IC_CONNECT_FLAG_NONE <font color="#990000">);  <font color="#0000FF">if  <font color="#990000">(! success <font color="#990000">)   <font color="#000000">g_warning   <font color="#990000">(  <font color="#FF0000">"Request for connection failed"  <font color="#990000">); </tt>

At this point, the application does not yet have an Internet connection. A successful return from con_ic_connection_connect means only that the request was successfully dispatched to the Internet Connectivity daemon. When the daemon has a connection ready, the application receives an event (as an GObject signal) indicating that the device is connected. If the connection attempt fails, the application receives a disconnected event with an error describing the reason for the failure.

The connection handler (my_connection_handler function registered in the previous snippet) could look like this:

<tt>  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">my_connection_handler   <font color="#990000">( ConIcConnection <font color="#990000"> * connection <font color="#990000">,                                    ConIcConnectionEvent <font color="#990000"> * event <font color="#990000">,                                    gpointer user_data <font color="#990000">) <font color="#FF0000">{ ConIcConnectionStatus status <font color="#990000"> =  <font color="#000000">con_ic_connection_event_get_status   <font color="#990000">( event <font color="#990000">); ConIcConnectionError error <font color="#990000"> ;  <font color="#0000FF">const  gchar <font color="#990000"> * iap_id <font color="#990000"> =  <font color="#000000">con_ic_event_get_iap_id   <font color="#990000">(   <font color="#000000">CON_IC_EVENT   <font color="#990000">( event <font color="#990000">));  <font color="#0000FF">const  gchar <font color="#990000"> * bearer <font color="#990000"> =  <font color="#000000">con_ic_event_get_bearer_type   <font color="#990000">(   <font color="#000000">CON_IC_EVENT   <font color="#990000">( event <font color="#990000">));  <font color="#0000FF">switch  <font color="#990000">( status <font color="#990000">)  <font color="#FF0000">{  <font color="#0000FF">case  CON_IC_STATUS_CONNECTED <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Hey, we are connected to IAP %s with bearer %s!"  <font color="#990000">, iap_id <font color="#990000">, bearer <font color="#990000">);  <font color="#0000FF">break  <font color="#990000"> ;  <font color="#0000FF">case  CON_IC_STATUS_DISCONNECTING <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"We are disconnecting..."  <font color="#990000">);  <font color="#0000FF">break  <font color="#990000"> ;  <font color="#0000FF">case  CON_IC_STATUS_DISCONNECTED <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"And we are disconnected. Let's see what went wrong..."  <font color="#990000">); error <font color="#990000"> =  <font color="#000000">con_ic_connection_event_get_error   <font color="#990000">( event <font color="#990000">);  <font color="#0000FF">switch  <font color="#990000">( error <font color="#990000">)  <font color="#FF0000">{  <font color="#0000FF">case  CON_IC_CONNECTION_ERROR_NONE <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Libconic thinks there was nothing wrong."  <font color="#990000">);  <font color="#0000FF">break  <font color="#990000"> ;  <font color="#0000FF">case  CON_IC_CONNECTION_ERROR_INVALID_IAP <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Invalid (non-existing?) IAP was requested."  <font color="#990000">);  <font color="#0000FF">break  <font color="#990000"> ;  <font color="#0000FF">case  CON_IC_CONNECTION_ERROR_CONNECTION_FAILED <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Connection just failed."  <font color="#990000">);  <font color="#0000FF">break  <font color="#990000"> ;  <font color="#0000FF">case  CON_IC_CONNECTION_ERROR_USER_CANCELED <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"User canceled the connection attempt"  <font color="#990000">);  <font color="#0000FF">break  <font color="#990000"> ; <font color="#FF0000">}  <font color="#0000FF">break  <font color="#990000"> ;  <font color="#0000FF">default  <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Unknown connection status received"  <font color="#990000">); <font color="#FF0000">} <font color="#FF0000">} </tt>

Listening for Connection Events
Sometimes the application does not actively start connections but needs to detect if the device is online. The Libconic "automatic events" feature, enabled with "automatic-events" GObject property, can achieve this:

<tt>    <font color="#9A1900">/* Create connection object */  ConIcConnection <font color="#990000"> * connection <font color="#990000"> =  <font color="#000000">con_ic_connection_new   <font color="#990000">;  <font color="#9A1900">/* Connect signal to receive connection events */   <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( connection <font color="#990000">),  <font color="#FF0000">"connection-event"  <font color="#990000">,                        <font color="#000000">G_CALLBACK   <font color="#990000">( my_connection_handler <font color="#990000">), NULL <font color="#990000">);  <font color="#9A1900">/* Set automatic events */   <font color="#000000">g_object_set  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( connection <font color="#990000">),  <font color="#FF0000">"automatic-events"  <font color="#990000">, TRUE <font color="#990000">, NULL <font color="#990000">); </tt>

When automatic events are turned on, the application receives connected and disconnected events for all Internet connection changes. In addition to this, the application receives an event for the initial connection status. If the device is disconnected, ConIcConnectionEvent with status CON_IC_STATUS_DISCONNECTED is emitted. This event has NULL IAP ID and bearer, because there is no IAP getting disconnected, but the event indicates that the device is offline.

N.B. The main loop must be reiterated in order to receive the event. If you need the connection status information synchronously, you can iterate the main loop yourself:

<tt>  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">connection_info   <font color="#990000">( ConIcConnection <font color="#990000"> * connection <font color="#990000">,                              ConIcConnectionEvent <font color="#990000"> * event <font color="#990000">,                              gpointer user_data <font color="#990000">) <font color="#FF0000">{ ConIcConnectionStatus status <font color="#990000"> =  <font color="#000000">con_ic_connection_event_get_status   <font color="#990000">( event <font color="#990000">); ConIcConnectionStatus <font color="#990000"> * status_ptr <font color="#990000"> = <font color="#990000">( ConIcConnectionStatus <font color="#990000"> *) user_data <font color="#990000"> ; <font color="#990000"> * status_ptr <font color="#990000"> = status <font color="#990000"> ; <font color="#FF0000">} '' <font color="#9A1900">/* ... */       <font color="#9A1900">/* Create connection object and set on automatic events (see previous snippet) ... */ ''      <font color="#0000FF">static  ConIcConnectionStatus status <font color="#990000"> =  <font color="#993399">0xFFFF  <font color="#990000"> ; ConIcConnection <font color="#990000"> * connection <font color="#990000"> =  <font color="#000000">con_ic_connection_new   <font color="#990000">;  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( connection <font color="#990000">),  <font color="#FF0000">"connection-event"  <font color="#990000">,                        <font color="#000000">G_CALLBACK   <font color="#990000">( connection_info <font color="#990000">),  <font color="#990000">&amp; status <font color="#990000">);  <font color="#000000">g_object_set  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( Connection <font color="#990000">),  <font color="#FF0000">"automatic-events"  <font color="#990000">, TRUE <font color="#990000">, NULL <font color="#990000">);  <font color="#9A1900">/* Iterate main loop for the first connection event */   <font color="#0000FF">while  <font color="#990000">( status <font color="#990000"> ==  <font color="#993399">0xFFFF  <font color="#990000">)   <font color="#000000">g_main_context_iteration   <font color="#990000">( NULL <font color="#990000">, TRUE <font color="#990000">);  <font color="#0000FF">if  <font color="#990000">( status <font color="#990000"> == CON_IC_STATUS_CONNECTED <font color="#990000">)  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"We are connected!"  <font color="#990000">);  <font color="#0000FF">else   <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"We are not connected!"  <font color="#990000">); </tt>

Receiving Statistics of Connection
To receive statistics of the current Internet connection, use the con_ic_connection_statistics function and the corresponding event handler. You can retrieve statistics for a specified IAP or just for the current default connection. Note that currently the Internet Connectivity daemon provides only one Internet connection at a time, so the best option is to leave IAP ID NULL.

<tt>  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">connection_statistics   <font color="#990000">( ConIcConnection <font color="#990000"> * connection <font color="#990000">,                                    ConIcStatisticsEvent <font color="#990000"> * event <font color="#990000">,                                    gpointer user_data <font color="#990000">) <font color="#FF0000">{  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Here are all kind of nice statistics about the connection:"  <font color="#990000">);  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Time active: %u, signal strength: %u, received packets: %llu, "              <font color="#FF0000">"sent packets: %llu, received bytes: %llu, sent bytes: %llu"  <font color="#990000">,               <font color="#000000">con_ic_statistics_event_get_time_active   <font color="#990000">( event <font color="#990000">),               <font color="#000000">con_ic_statistics_event_get_signal_strength   <font color="#990000">( event <font color="#990000">),               <font color="#000000">con_ic_statistics_event_get_rx_packets   <font color="#990000">( event <font color="#990000">),               <font color="#000000">con_ic_statistics_event_get_tx_packets   <font color="#990000">( event <font color="#990000">),               <font color="#000000">con_ic_statistics_event_get_rx_bytes   <font color="#990000">( event <font color="#990000">),  <font color="#000000">con_ic_statistics_event_get_tx_bytes  <font color="#990000">( event <font color="#990000">));  <font color="#FF0000">}   <font color="#9A1900">/* ... */        <font color="#9A1900">/* ConIcConnection object named "connection" has already been created */        <font color="#000000">g_signal_connect   <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( connection <font color="#990000">),  <font color="#FF0000">"statistics"  <font color="#990000">,  <font color="#000000">G_CALLBACK  <font color="#990000">( connection_statistics <font color="#990000">), NULL <font color="#990000">);       <font color="#0000FF">if   <font color="#990000">(!  <font color="#000000">con_ic_connection_statistics  <font color="#990000">( connection <font color="#990000">, NULL <font color="#990000">))           <font color="#000000">g_warning   <font color="#990000">(  <font color="#FF0000">"Requesting connection statistics failed!" <font color="#990000">); </tt>

Getting Proxy Settings
Libconic allows you to set up Internet connection proxy settings for various protocols. The first step is to discover the current proxy mode by using the con_ic_connection_get_proxy_mode function. Next, use the following functions to get the actual proxy settings:

con_ic_connection_get_proxy_autoconfig_url to get a proxy auto configuration URL.
 * If proxy mode is CON_IC_PROXY_MODE_NONE, do not use any proxies.
 * If proxy mode is CON_IC_PROXY_MODE_MANUAL, use the following functions to query proxy settings:
 * con_ic_connection_get_proxy_host to get the proxy host
 * con_ic_connection_get_proxy_port to get the proxy port
 * con_ic_connection_get_proxy_ignore_hosts to get a list of hosts for which the proxy should not be used.
 * If proxy mode is CON_IC_PROXY_MODE_AUTO, use
 * Use of auto configuration URL is explained in Wikipedia

In this example, the "connection-event" handler is modified to print HTTP proxy settings when establishing connection:

<tt>  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">my_connection_handler   <font color="#990000">( ConIcConnection <font color="#990000"> * connection <font color="#990000">,                                    ConIcConnectionEvent <font color="#990000"> * event <font color="#990000">,                                    gpointer user_data <font color="#990000">) <font color="#FF0000">{ ConIcConnectionStatus status <font color="#990000"> =  <font color="#000000">con_ic_connection_event_get_status   <font color="#990000">( event <font color="#990000">); GSList <font color="#990000"> * ignore_hosts <font color="#990000"> ;  <font color="#0000FF">if  <font color="#990000">( status <font color="#990000"> == CON_IC_STATUS_CONNECTED <font color="#990000">)  <font color="#FF0000">{  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"We are connected! \  <font color="#FF0000">Let's see what kind of settings we have for HTTP proxy..."  <font color="#990000">);  <font color="#9A1900">/* Do things based on specified proxy mode */   <font color="#0000FF">switch  <font color="#990000">(   <font color="#000000">con_ic_connection_get_proxy_mode   <font color="#990000">( connection <font color="#990000">))  <font color="#FF0000">{  <font color="#0000FF">case  CON_IC_PROXY_MODE_NONE <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"No proxies defined, it is direct connection"  <font color="#990000">);  <font color="#0000FF">break  <font color="#990000"> ;  <font color="#0000FF">case  CON_IC_PROXY_MODE_MANUAL <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"HTTP proxy %s:%d in use"  <font color="#990000">,                           <font color="#000000">con_ic_connection_get_proxy_host   <font color="#990000">( connection <font color="#990000">, CON_IC_PROXY_PROTOCOL_HTTP <font color="#990000">),                           <font color="#000000">con_ic_connection_get_proxy_port   <font color="#990000">( connection <font color="#990000">, CON_IC_PROXY_PROTOCOL_HTTP <font color="#990000">));  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"List of hosts, for which proxy should not be used:"  <font color="#990000">); ignore_hosts <font color="#990000"> =  <font color="#000000">con_ic_connection_proxy_ignore_hosts   <font color="#990000">( connection <font color="#990000">);  <font color="#0000FF">for  <font color="#990000">( GSList <font color="#990000"> * iter <font color="#990000"> = ignore_hosts <font color="#990000"> ; iter <font color="#990000"> != NULL <font color="#990000"> ; iter <font color="#990000"> =   <font color="#000000">g_slist_next   <font color="#990000">( iter <font color="#990000">)) <font color="#FF0000">{  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"%s"  <font color="#990000">,  <font color="#990000">( gchar <font color="#990000"> *) iter <font color="#990000">-&gt; data <font color="#990000">);  <font color="#000000">g_free  <font color="#990000">( iter <font color="#990000">-&gt; data <font color="#990000">); <font color="#FF0000">}  <font color="#000000">g_slist_free  <font color="#990000">( ignore_hosts <font color="#990000">);  <font color="#0000FF">break  <font color="#990000"> ;  <font color="#0000FF">case  CON_IC_PROXY_MODE_AUTO <font color="#990000"> :  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Proxy auto-config URL %s should be used"  <font color="#990000">,                           <font color="#000000">con_ic_connection_get_proxy_autoconfig_url   <font color="#990000">( connection <font color="#990000">));  <font color="#0000FF">break  <font color="#990000"> ; <font color="#FF0000">} <font color="#FF0000">} <font color="#FF0000">} </tt>

Proxy functions also exist for each individual protocol (like con_ic_connection_get_proxy_ftp_host), but these functions are deprecated. Avoid them in newly-written code.

Getting List of User-Saved Connections
To query all user-saved connections (IAPs), use the con_ic_connection_get_all_iaps function. The function returns simply a singly linked list of ConIcIap objects:

<tt>    <font color="#9A1900">/* ConIcConnection object named "connection" has already been created */  GSList <font color="#990000"> * saved_iaps <font color="#990000"> =  <font color="#000000">con_ic_connection_get_all_iaps   <font color="#990000">( connection <font color="#990000">);  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"The following connections have been saved by the user:"  <font color="#990000">);  <font color="#0000FF">for  <font color="#990000">( GSList <font color="#990000"> * iter <font color="#990000"> = saved_iaps <font color="#990000"> ; iter <font color="#990000"> != NULL <font color="#990000"> ; iter <font color="#990000"> =   <font color="#000000">g_slist_next   <font color="#990000">( iter <font color="#990000">))  <font color="#FF0000">{  <font color="#9A1900">/* Get IAP object and print some information about it */  ConIcIap <font color="#990000"> * iap <font color="#990000"> = <font color="#990000">( ConIcIap <font color="#990000"> *) iter <font color="#990000">-&gt; data <font color="#990000"> ;  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Connection %s called '%s' using bearer %s"  <font color="#990000">,                   <font color="#000000">con_ic_iap_get_id   <font color="#990000">( iap <font color="#990000">),   <font color="#000000">con_ic_iap_get_name   <font color="#990000">( iap <font color="#990000">),                   <font color="#000000">con_ic_iap_get_bearer_type   <font color="#990000">( iap <font color="#990000">));  <font color="#9A1900">/* We unref the IAP object as we are not going to use it anymore */   <font color="#000000">g_object_unref  <font color="#990000">( iap <font color="#990000">); <font color="#FF0000">}  <font color="#000000">g_slist_free  <font color="#990000">( saved_iaps <font color="#990000">); </tt>

Porting Application from OSSO IC API to Libconic
<tt>     DBusConnection <font color="#990000"> * system_dbus <font color="#990000"> ; GMainloop <font color="#990000"> * main_loop <font color="#990000"> ;  <font color="#000000">g_type_init  <font color="#990000">; main_loop <font color="#990000"> =  <font color="#000000">g_main_loop_new   <font color="#990000">( NULL <font color="#990000">, FALSE <font color="#990000">); system_dbus <font color="#990000"> =  <font color="#000000">dbus_bus_get   <font color="#990000">( DBUS_BUS_SYSTEM <font color="#990000">, NULL <font color="#990000">);  <font color="#000000">dbus_connection_setup_with_g_main  <font color="#990000">( system_dbus <font color="#990000">, NULL <font color="#990000">); </tt> <tt>  <font color="#000080">     #include   <font color="#FF0000">&lt;osso-ic.h&gt; <font color="#990000"> ===&gt;  <font color="#000080">     #include   <font color="#FF0000">&lt;conic.h&gt; </tt> <tt>      <font color="#0000FF">static   <font color="#009900">void   <font color="#000000">my_connection_cb   <font color="#990000">(   <font color="#0000FF">struct   <font color="#009900">iap_event_t  <font color="#990000"> * event <font color="#990000">,  <font color="#009900">void  <font color="#990000"> * arg <font color="#990000">) <font color="#FF0000">{ '' <font color="#9A1900">/* ... */ ''       <font color="#FF0000">} '' <font color="#9A1900">/* ... */ ''            <font color="#000000">osso_iap_cb   <font color="#990000">( my_connection_cb <font color="#990000">); <font color="#990000"> ===&gt;  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">my_connection_cb   <font color="#990000">( ConIcConnection <font color="#990000"> * connection <font color="#990000">,                                     ConIcConnectionEvent <font color="#990000"> * event <font color="#990000">,                                     gpointer user_data <font color="#990000">) <font color="#FF0000">{ '' <font color="#9A1900">/* ... */ ''       <font color="#FF0000">} '' <font color="#9A1900">/* ... */ ''           ConIcConnection <font color="#990000"> * connection <font color="#990000"> =   <font color="#000000">con_ic_connection_new   <font color="#990000">;  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( connection <font color="#990000">),  <font color="#FF0000">"connection-event"  <font color="#990000">,                              <font color="#000000">G_CALLBACK   <font color="#990000">( my_connection_cb <font color="#990000">), app_data <font color="#990000">); </tt> osso_iap_connect and osso_iap_disconnect : <tt>      <font color="#000000">osso_iap_connect   <font color="#990000">( OSSO_IAP_ANY <font color="#990000">, OSSO_IAP_REQUESTED_CONNECT <font color="#990000">, app_data <font color="#990000">);  <font color="#000000">osso_iap_disconnect  <font color="#990000">( iap_name <font color="#990000">, app_data <font color="#990000">); <font color="#990000"> ===&gt;  <font color="#000000">con_ic_connection_connect  <font color="#990000">( connection <font color="#990000">, CON_IC_CONNECT_FLAG_NONE <font color="#990000">);  <font color="#000000">con_ic_connection_disconnect  <font color="#990000">( connection <font color="#990000">); </tt> osso_iap_get_statistics. osso_iap_get_configured_iaps. <tt>     PKG_CHECK_MODULES <font color="#990000">( OSSOIC <font color="#990000">, osso-ic <font color="#990000">) AC_SUBST <font color="#990000">( OSSOIC_CFLAGS <font color="#990000">) AC_SUBST <font color="#990000">( OSSOIC_LIBS <font color="#990000">) <font color="#990000"> ===&gt; PKG_CHECK_MODULES <font color="#990000">( CONIC <font color="#990000">, conic <font color="#990000">) AC_SUBST <font color="#990000">( CONIC_CFLAGS <font color="#990000">) AC_SUBST <font color="#990000">( CONIC_LIBS <font color="#990000">) </tt>
 * If the application does not have GType, GLib or D-BUS configured, set them up:
 * Include the correct header file:
 * Set up ConIcConnection object and "connection-event" handler instead of osso_iap_cb_t callback:
 * Manage connections through ConIcConnection API instead of
 * Request statistics with con_ic_connection_statistics instead of
 * List all available IAPs with con_ic_connection_get_all_iaps instead of
 * Configure autoconf to use Libconic instead of OSSO IC API:
 * In debian/control file "Build-Depends" section, depend on libconic0-dev instead of osso-ic-dev.

Bluetooth Libraries
This section explains how maemo Bluetooth libraries work internally. The following subsections explain the behavior and the decomposition of the Bluetooth library components in detail.

Libgwobex
Libgwobex provides access to libopenobex functionality by providing a helper/wrapper interface. Libopenobex is explained in detail in the following section.

The interface to libgwobex is available at GW OBEX Library Documentation.

Creating Connection
The connection with libgwobex is established using the gw_obex_setup_dev function, setting up the connection. gw-obex.h

<tt>  <font color="#000080"> #define  OBEX_FTP_UUID <font color="#990000">\ <font color="#FF0000">" <font color="#CC33CC">\x  <font color="#FF0000">F9  <font color="#CC33CC">\x  <font color="#FF0000">EC  <font color="#CC33CC">\x  <font color="#FF0000">7B  <font color="#CC33CC">\x  <font color="#FF0000">C4  <font color="#CC33CC">\x  <font color="#FF0000">95  <font color="#CC33CC">\x  <font color="#FF0000">3C  <font color="#CC33CC">\x  <font color="#FF0000">11  <font color="#CC33CC">\x  <font color="#FF0000">D2  <font color="#CC33CC">\x  <font color="#FF0000">98  <font color="#CC33CC">\x  <font color="#FF0000">4E  <font color="#CC33CC">\x  <font color="#FF0000">52  <font color="#CC33CC">\x  <font color="#FF0000">54  <font color="#CC33CC">\x  <font color="#FF0000">00  <font color="#CC33CC">\x  <font color="#FF0000">DC  <font color="#CC33CC">\x  <font color="#FF0000">9E  <font color="#CC33CC">\x  <font color="#FF0000">09"  <font color="#000080"> #define  OBEX_FTP_UUID_LEN <font color="#993399">16 '' <font color="#9A1900">/* ... */ '' GwObex <font color="#990000"> *   <font color="#000000">gw_obex_setup_dev   <font color="#990000">(   <font color="#0000FF">const  gchar <font color="#990000"> * device <font color="#990000">,   <font color="#0000FF">const  gchar <font color="#990000"> * uuid <font color="#990000">, gint uuid_len <font color="#990000">,                             GMainContext <font color="#990000"> * context <font color="#990000">, gint <font color="#990000"> * error <font color="#990000">) </tt>

The following code snippet illustrates how to open a handle using gw_obex_setup_dev.

<tt>  <font color="#0000FF">if  <font color="#990000">( ctx <font color="#990000">-&gt; rfcomm_dev <font color="#990000">)  <font color="#FF0000">{  <font color="#0000FF">if  <font color="#990000">( ctx <font color="#990000">-&gt; use_ftp <font color="#990000">) ctx <font color="#990000">-&gt; obex <font color="#990000"> =  <font color="#000000">gw_obex_setup_dev   <font color="#990000">( ctx <font color="#990000">-&gt; rfcomm_dev <font color="#990000">,                          OBEX_FTP_UUID <font color="#990000">, OBEX_FTP_UUID_LEN <font color="#990000">,                          NULL <font color="#990000">,  <font color="#990000">&amp; err <font color="#990000">);  <font color="#0000FF">else  ctx <font color="#990000">-&gt; obex <font color="#990000"> =  <font color="#000000">gw_obex_setup_dev   <font color="#990000">( ctx <font color="#990000">-&gt; rfcomm_dev <font color="#990000">, NULL <font color="#990000">,                          <font color="#993399">0  <font color="#990000">, NULL <font color="#990000">,  <font color="#990000">&amp; err <font color="#990000">);  <font color="#0000FF">if  <font color="#990000">( ctx <font color="#990000">-&gt; obex <font color="#990000"> == NULL <font color="#990000">)  <font color="#000000">printf  <font color="#990000">(  <font color="#FF0000">"OBEX setup failed: %s  <font color="#CC33CC">\n  <font color="#FF0000">"  <font color="#990000">,   <font color="#000000">response_to_string   <font color="#990000">( err <font color="#990000">)); <font color="#FF0000">} </tt>

In this example, ctx-&gt;rfcomm_dev points to a string containing the device node name (e.g. /dev/rfcomm0). ctx-&gt;use_ftp dictates whether to set up standard folder browsing services. If use_ftp is untrue, then INBOX is connected.

Closing Connection
To close a gwobex connection, use the following function: gw-obex.h

<tt> <font color="#009900">void  <font color="#000000">gw_obex_close   <font color="#990000">( GwObex <font color="#990000"> * ctx <font color="#990000">); </tt>

The following code demonstrates this usage.

<tt>  <font color="#0000FF">if  <font color="#990000">( ctx <font color="#990000">-&gt; obex <font color="#990000">)  <font color="#FF0000">{  <font color="#000000">gw_obex_close  <font color="#990000">( ctx <font color="#990000">-&gt; obex <font color="#990000">); ctx <font color="#990000">-&gt; obex <font color="#990000"> = NULL <font color="#990000"> ; <font color="#FF0000">} </tt>

If ctx-&gt;obex is not NULL, it is simply passed as an argument to gw_obex_close.

Using Connection
The libgwobex library provides general file handling functionality, including reading directory structure, browsing in different folders and getting files.

To read entries from an opened directory, use the following function: gw-obex.h

<tt>gboolean  <font color="#000000">gw_obex_read_dir  <font color="#990000">( GwObex <font color="#990000"> * ctx <font color="#990000">,                              <font color="#0000FF">const  gchar <font color="#990000"> * dir <font color="#990000">,                             gchar <font color="#990000"> ** buf <font color="#990000">,                             gint <font color="#990000"> * buf_size <font color="#990000">,                             gint <font color="#990000"> * error <font color="#990000">); </tt>

gw_obex_read_dir reads an entry from the selected folder and returns the result in the buf argument given to the function.

<tt>gboolean ret <font color="#990000"> ; '' <font color="#9A1900">/* ... */ '' ret <font color="#990000"> =   <font color="#000000">gw_obex_read_dir   <font color="#990000">( ctx <font color="#990000">-&gt; obex <font color="#990000">, dir <font color="#990000">, buf <font color="#990000">, buf_size <font color="#990000">, err <font color="#990000">); </tt>

This reads an entry from the directory dir (char *) and returns it in buf (char **).

To change the current directory, use the following function: gw-obex.h

<tt>gboolean  <font color="#000000">gw_obex_chdir  <font color="#990000">( GwObex <font color="#990000"> * ctx <font color="#990000">,   <font color="#0000FF">const  gchar <font color="#990000"> * dir <font color="#990000">, gint <font color="#990000"> * error <font color="#990000">); </tt>

which changes the directory of the FTP connection. Below is a code example using this function.

<tt>  <font color="#9A1900">/* Ignore parent dir pointers */   <font color="#0000FF">if  <font color="#990000">(   <font color="#000000">g_str_equal   <font color="#990000">( name <font color="#990000">,  <font color="#FF0000">".." <font color="#990000">))  <font color="#0000FF">return  TRUE <font color="#990000"> ;  <font color="#0000FF">if  <font color="#990000">(!   <font color="#000000">gw_obex_chdir   <font color="#990000">( ctx <font color="#990000">-&gt; obex <font color="#990000">, name <font color="#990000">, err <font color="#990000">))  <font color="#FF0000">{  <font color="#000000">printf  <font color="#990000">(  <font color="#FF0000">"Could not chdir to %s  <font color="#CC33CC">\n  <font color="#FF0000">"  <font color="#990000">, name <font color="#990000">);  <font color="#0000FF">return  FALSE <font color="#990000"> ; <font color="#FF0000">} </tt>

To retrieve files over the OBEX connection, use the gw_obex_get_file function: gw-obex.h

<tt>gboolean  <font color="#000000">gw_obex_get_file  <font color="#990000">( GwObex <font color="#990000"> * ctx <font color="#990000">,                              <font color="#0000FF">const  gchar <font color="#990000"> * local <font color="#990000">,                              <font color="#0000FF">const  gchar <font color="#990000"> * remote <font color="#990000">,                              <font color="#0000FF">const  gchar <font color="#990000"> * type <font color="#990000">,                             gint <font color="#990000"> * error <font color="#990000">); </tt>

gw_obex_get_file uses the ctx context for retrieving the remote file to local file.

<tt>gboolean ret <font color="#990000"> ; ret <font color="#990000"> =  <font color="#000000">gw_obex_get_file   <font color="#990000">( ctx <font color="#990000">-&gt; obex <font color="#990000">, name <font color="#990000">, name <font color="#990000">, err <font color="#990000">); </tt>

Using the libwobex wrapper directly allows you to perform many more functions. For more information, see the [hhttp://maemo.org/api_refs/5.0/beta/osso-gwobex/ API document].

Libopenobex
The LibOpenOBEX library implements a generic OBEX Session Protocol, but not the OBEX Application Framework. OBEX is a protocol designed to allow data interchanging between different kinds of connections (e.g. Bluetooth, IrDA). For more information on the OBEX protocol, see http://www.irda.org ; select the Developer-&gt;Specifications category. OBEX resembles the HTTP protocol, expect for a few differences:


 * Transports: While HTTP is normally layered above a TCP/IP connection, OBEX is usually transported over IrLAP/IrLMP/Tiny TP (on IrDA) or over Baseband/Link Manager/L2CAP/RFCOMM (on Bluetooth).
 * Binary transmissions: OBEX communicates using binary transmissions, as HTTP is transmitted in a human-readable XML-based format.
 * Session support: HTTP is stateless, while OBEX maintains the connection.

For more information on OBEX, see the summary available at http://en.wikipedia.org/wiki/OBEX.

For libopenobex code samples, see http://openobex.triq.net/downloads ; the samples are in the example apps package.

Using BlueZ D-Bus API
The BlueZ system exports a D-Bus API that can be employed instead of OSSO Bluetooth tools. See the following documents:


 * BlueZ D-Bus API documentation
 * BlueZ Wiki

UI Components
Connectivity UI contains various dialogs and other components used to control the connectivity. The different UI parts are:


 * Connection manager
 * Connectivity dialogs
 * Status bar applets
 * Control panel applet
 * Bluetooth UIs

The connectivity dialogs are invoked by D-Bus method calls, so for example the ICd is using these D-Bus method calls for showing dialogs when they are needed. The next section specifies the D-Bus API of maemo connectivity UI.

D-Bus Connectivity UI Interface
If the user must provide information about the IAP that the system is about to connect to, you can use the following method:

Service:          com.nokia.icd_ui Interfaces:       com.nokia.icd_ui Object paths:     /com/nokia/icd_ui

The Internet Connectivity UIs implement the following D-Bus API used by the ICd and EAP.

Method:           show_conn_dlg Parameters:       none Return parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows the Connect Dialog where the user can choose an IAP.

Method:           show_disconnect_dlg Parameters:       none Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows the disconnect dialog.

Method:           show_retry_dlg Parameters:       1. string Bluetooth address of the device used with SAP 2. string Name of the connection attempt error which selects the retry dialog type. Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows the retry dialog.

Method:           show_change_dlg Parameters:       1. string Name of the currently active IAP 2. string Name of the IAP to be activated Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows the Change IAP Dialog

Method:           show_passwd_dlg Parameters:       1. string Username supplied by ICd 2. string Password supplied by ICd 3. string Name of the IAP Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows the username/password dialog.

Method:           show_gtc_dlg Parameters:       1. string GTC challenge string Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows EAP GTC challenge dialog.

Method:           show_mschap_change_dlg Parameters:       1. string Supplied username 2. string Old password that is to be changed 3. string Name of the IAP Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows EAP MSCHAPv2 change password dialog.

Method:           show_private_key_passwd_dlg Parameters:       1. uint32 The private key ID Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows EAP private key password dialog

Method:           show_server_cert_dlg Parameters:       1. string Certificate name 2. string Certificate serial 3. boolean TRUE if certificate is expired, FALSE otherwise 4. boolean TRUE if root CA is unknown or self-signed certificate, FALSE otherwise Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows server certificate error and expiration dialogs. If both boolean arguments are false, the error dialog is                   shown. If either or both boolean arguments are TRUE, the expiration dialog is shown instead.

Method:           strong_bt_req Parameters:       1. string Bluetooth address of the device to pair with 2. boolean TRUE if strong authentication enabled, FALSE if strong authentication is disabled Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Requests strong (16 digit) BT PIN dialog for a BT device

Method:           show_sim_pin_dlg Parameters:       1. string Bluetooth address of the device used with SAP 2. boolean TRUE if PIN was incorrect and retry dialog should be displayed before asking PIN. FALSE if this is the first PIN request. Return Parameters: none Errors:           com.nokia.icd_ui.error.flight_mode: Flight mode enabled, dialog not shown Description:      Shows SIM PIN dialog

The code example for the application to show the connect dialog using show_conn_dlg is following. Note the use of the macro.

<tt>  <font color="#000080"> #include  <font color="#FF0000">&lt;osso-ic-ui-dbus.h&gt; '' <font color="#9A1900">/* ... */   <font color="#9A1900">/* in our code somewhere, where we need the Connect Dialog*/ '' DBusMessage <font color="#990000"> * uimsg <font color="#990000"> ;  <font color="#9A1900">/* construct the message for Connect Dialog request*/  uimsg <font color="#990000"> =  <font color="#000000">dbus_message_new_method_call  <font color="#990000">( ICD_UI_DBUS_SERVICE <font color="#990000">,                               ICD_UI_DBUS_PATH <font color="#990000">,                             ICD_UI_DBUS_INTERFACE <font color="#990000">,                            <font color="#9A1900">/*macro for show_conn_dlg */                                  ICD_UI_SHOW_CONNDLG_REQ <font color="#990000">);  <font color="#9A1900">/* send the message */  reply <font color="#990000"> =  <font color="#000000">dbus_connection_send_with_reply_and_block  <font color="#990000">( connection <font color="#990000">,                                      uimsg <font color="#990000">,                                     reply_timeout <font color="#990000">,                                     <font color="#990000">&amp; error <font color="#990000">);  <font color="#0000FF">if  <font color="#990000">( reply <font color="#990000"> == NULL <font color="#990000">)  <font color="#FF0000">{  <font color="#000000">DLOG_ERR  <font color="#990000">(  <font color="#FF0000">"Failed to show connect dialog: %s"  <font color="#990000">, uierror <font color="#990000">. message <font color="#990000">);  <font color="#000000">dbus_error_free  <font color="#990000">(&amp; uierror <font color="#990000">); <font color="#FF0000">}  <font color="#000000">dbus_message_unref  <font color="#990000">( uimsg <font color="#990000">);  <font color="#000000">dbus_message_unref  <font color="#990000">( reply <font color="#990000">); '' <font color="#9A1900">/* ... */ '' </tt>

The signals emitted from com.nokia.icd_ui interface are listed below.

Signal:       disconnect Parameters:   1. boolean TRUE if "disconnect" pressed, FALSE if "cancel" Description:  Signal emitted from UI when disconnect dialog has been closed.

Signal:       retry Parameters:   1. string The IAP that is to be retried 2. boolean TRUE if "retry" pressed, FALSE if "cancel" Description:  Signal emitted from UI when the retry dialog has been closed.

Signal:       change Parameters:   1. string Old IAP to change from 2. string New IAP to change to                3. boolean  Change to the new IAP If TRUE, keep old if FALSE Description:  Signal emitted from UI when change connection dialog has been closed.

Signal:       passwd Parameters:   1. string Username supplied or modified by the user 2. string Password supplied or modified by the user 3. string IAP name 4. boolean TRUE if "ok" pressed, FALSE if "cancel" Description:  Signal emitted from UI when the username/password dialog has been closed

Signal:       gtc_response Parameters:   1. string Response to the given challenge or empty string if cancelled 2. boolean TRUE if "ok" pressed, FALSE if "cancel" Description:  Signal emitted from UI when the EAP GTC challenge dialog has been closed.

Signal:       mschap_change Parameters:   1. string Supplied username 2. string The new password or empty string if cancelled 3. string IAP name 4. boolean TRUE if "ok" pressed, FALSE if "cancel" Description:  Signal emitted from UI when the MSCHAPv2 password has been changed

Signal:       private_key_passwd Parameters:   1. uint32 The id of the private key 2. string Password for the private key or empty string if none 3. boolean TRUE if "ok" pressed, FALSE if "cancel" Description:  Signal emitted from UI when the private key password dialog has been closed

Signal:       server_cert Parameters:   1. boolean TRUE if strong PIN entered, FALSE if strong PIN dialog was canceled Description:  Signal emitted from UI when the server certificate error dialog has been closed

Signal:       strong_bt Parameters:   1. boolean TRUE if strong PIN entered, FALSE if strong PIN dialog was cancelled Description:  Signal emitted from UI when the strong (16 digit) BT PIN has been entered

Signal:       sim_pin Parameters:   1. string SIM PIN code or empty string if  cancelled 2. boolean TRUE if "ok" pressed, FALSE if "cancel" Description:  Signal emitted from UI when the SIM PIN has been entered.

Bluetooth DBUS UI dialogs
conbtdialogs-dbus.h

<tt>  <font color="#9A1900">/**   <font color="#9A1900"> Example of use (command line):   <font color="#9A1900">   <font color="#9A1900"> dbus-send -system -print-reply \   <font color="#9A1900">   -dest='com.nokia.icd_ui' /com/nokia/bt_ui \   <font color="#9A1900">   com.nokia.bt_ui.show_send_file_dlg \   <font color="#9A1900">   array:string:     <font color="#0000FF">file:///home/user/MyDocs/.documents/testing.txt  <font color="#9A1900">     <font color="#9A1900"> dbus-send -system -print-reply \   <font color="#9A1900">   -dest=com.nokia.bt_ui  /com/nokia/bt_ui   <font color="#9A1900">   com.nokia.bt_ui.show_search_dlg \   <font color="#9A1900">   string: string: array:string: boolean:true   <font color="#9A1900"> */   <font color="#000080"> #ifndef  CONBTDIALOGS_DBUS_H  <font color="#000080"> #define  CONBTDIALOGS_DBUS_H  <font color="#000080"> #ifdef  __cplusplus  <font color="#0000FF">extern  <font color="#FF0000">"C"  <font color="#FF0000">{  <font color="#000080"> #endif   <font color="#9A1900">/** Conbtdialogs service, resides in system dbus */   <font color="#000080"> #define  CONBTDIALOGS_DBUS_SERVICE               <font color="#FF0000">"com.nokia.bt_ui"  <font color="#9A1900">/** Conbtdialogs interface */   <font color="#000080"> #define  CONBTDIALOGS_DBUS_INTERFACE               <font color="#FF0000">"com.nokia.bt_ui"  <font color="#9A1900">/** Conbtdialogs path */   <font color="#000080"> #define  CONBTDIALOGS_DBUS_PATH                       <font color="#FF0000">"/com/nokia/bt_ui"  <font color="#9A1900">/**   <font color="#9A1900"> Show send file dialog   <font color="#9A1900">   <font color="#9A1900"> Arguments:   <font color="#9A1900">   <font color="#9A1900"> uris: DBUS_TYPE_ARRAY                Array of strings representing the URIs of the  '' <font color="#9A1900">                               files to send.   <font color="#9A1900">  ''  <font color="#9A1900"> Returns:   <font color="#9A1900">  '' <font color="#9A1900"> DBUS_TYPE_BOOLEAN             TRUE, if dialog was shown successfully.   <font color="#9A1900"> */ ''  <font color="#000080"> #define  CONBTDIALOGS_SEND_FILE_REQ               <font color="#FF0000">"show_send_file_dlg"  <font color="#9A1900">/**   <font color="#9A1900"> File sending result signal   <font color="#9A1900">   <font color="#9A1900"> Arguments:   <font color="#9A1900">   <font color="#9A1900"> success: DBUS_TYPE_BOOLEAN        TRUE, if all files were sent successfully or   <font color="#9A1900">                               FALSE, if error occurred or sending was  '' <font color="#9A1900">                               canceled.   <font color="#9A1900"> */ ''  <font color="#000080"> #define  CONBTDIALOGS_SEND_FILE_SIG               <font color="#FF0000">"send_file"  <font color="#9A1900">/**   <font color="#9A1900"> Show BT device search dialog   <font color="#9A1900">   <font color="#9A1900"> Arguments:   <font color="#9A1900">   <font color="#9A1900"> major_class: DBUS_TYPE_STRING To set filtering based on major_class or  '' <font color="#9A1900">                               "". Possible major class values are: ''  <font color="#9A1900">                                 <font color="#9A1900">                               "miscellaneous", "computer", "phone",   <font color="#9A1900">                               "access point", "audio/video",   <font color="#9A1900">                               "peripheral", "imaging", "wearable",  '' <font color="#9A1900">                               "toy" and "uncategorized".   <font color="#9A1900">  '' '' <font color="#9A1900"> minor_class: DBUS_TYPE_STRING To set filtering based on minor_class or "".   <font color="#9A1900">                                Possible minor class values are: ''  <font color="#9A1900">                         <font color="#9A1900">                               - Minor classes for "computer":   <font color="#9A1900">                                 "uncategorized", "desktop", "server",   <font color="#9A1900">                                 "laptop", "handheld", "palm", "wearable"   <font color="#9A1900">                               - Minor classes for "phone": "uncategorized",   <font color="#9A1900">                                 "cellular", "cordless", "smart phone",   <font color="#9A1900">                                 "modem", "isdn"   <font color="#9A1900">  '' <font color="#9A1900"> service_classes: DBUS_TYPE_ARRAY To set filtering based on service classes.   <font color="#9A1900">                                   Supported classes include "positioning", ''  <font color="#9A1900">                                  "networking", "rendering", "capturing",   <font color="#9A1900">                                  "object transfer", "audio", "telephony",  '' <font color="#9A1900">                                  "information". Can be empty list, when no '' '' <font color="#9A1900">                                  service class filtering is performed.   <font color="#9A1900">  ''  <font color="#9A1900"> bonding: DBUS_TYPE_STRING     Bonding mode for found and selected device:   <font color="#9A1900">                                 <font color="#9A1900">                               "require" for requiring a bonding from a   <font color="#9A1900">                               selected device (i.e. bond device if it has not   '' <font color="#9A1900">                                been bonded before).   <font color="#9A1900">                                ''  <font color="#9A1900">                               "force" to always bond (i.e. device will be   '' <font color="#9A1900">                                bonded even if bonded before).   <font color="#9A1900">                                ''  <font color="#9A1900">                               Any other string will allow to search and  '' <font color="#9A1900">                               select device without bonding it.   <font color="#9A1900">                                ''  <font color="#9A1900"> Returns:   <font color="#9A1900">  '' <font color="#9A1900"> DBUS_TYPE_BOOLEAN             TRUE, if dialog was shown successfully.   <font color="#9A1900"> */ ''  <font color="#000080"> #define  CONBTDIALOGS_SEARCH_REQ                <font color="#FF0000">"show_search_dlg"  <font color="#9A1900">/**   <font color="#9A1900"> Bluetooth search result signal   <font color="#9A1900">   <font color="#9A1900"> Arguments:   <font color="#9A1900">   <font color="#9A1900"> address: DBUS_TYPE_STRING     Bluetooth address of the selected device, or ""  '' <font color="#9A1900">                               if search dialog was cancelled.   <font color="#9A1900">  '' '' <font color="#9A1900"> name: DBUS_TYPE_STRING        Name of the device.   <font color="#9A1900">  ''  <font color="#9A1900"> icon: DBUS_TYPE_STRING        Logical name for the icon describing the  '' <font color="#9A1900">                               device.   <font color="#9A1900">  '' '' <font color="#9A1900"> major_class: DBUS_TYPE_STRING Major class of the device.   <font color="#9A1900">  '' '' <font color="#9A1900"> minor_class: DBUS_TYPE_STRING Minor class of the device.   <font color="#9A1900">  '' '' <font color="#9A1900"> trusted: DBUS_TYPE_BOOLEAN    Defines whether the device is marked as a trusted device.   <font color="#9A1900">  ''  <font color="#9A1900"> services: DBUS_TYPE_ARRAY     List of strings describing the service classes  '' <font color="#9A1900">                               and SDP-based services provided by the device.   <font color="#9A1900"> */ ''  <font color="#000080"> #define  CONBTDIALOGS_SEARCH_SIG                <font color="#FF0000">"search_result" </tt>

<tt>  <font color="#9A1900">/**   <font color="#9A1900"> Bluetooth UI Library for maemo  '' <font color="#9A1900"> Copyright (C) 2006 Nokia. All rights reserved.   <font color="#9A1900">  ''  <font color="#9A1900"> This sample demonstrates the use of conbtdialogs API and especially  '' <font color="#9A1900"> send_file function. Compile the program with conbtdialogs and dbus: ''  <font color="#9A1900">   <font color="#9A1900"> gcc -Wall `pkg-config -libs -cflags dbus-glib-1 conbtdialogs` \   <font color="#9A1900">-o send_file conbtdialogs_send_file.c   <font color="#9A1900">   <font color="#9A1900"> Run with list of URLS:   <font color="#9A1900">   <font color="#9A1900"> ./send_file     <font color="#0000FF">file:///home/user/MyDocs/.sounds/Everyday.mp3  <font color="#9A1900"> */   <font color="#000080"> #define  DBUS_API_SUBJECT_TO_CHANGE  <font color="#000080"> #include  <font color="#FF0000">&lt;glib.h&gt;  <font color="#000080"> #include  <font color="#FF0000">&lt;conbtdialogs-dbus.h&gt;  <font color="#000080"> #include  <font color="#FF0000">&lt;dbus/dbus.h&gt;  <font color="#000080"> #include  <font color="#FF0000">&lt;dbus/dbus-glib.h&gt; DBusGConnection <font color="#990000"> * connection <font color="#990000"> = NULL <font color="#990000"> ; GMainLoop <font color="#990000"> * mainloop <font color="#990000"> = NULL <font color="#990000"> ;  <font color="#0000FF">static  gboolean  <font color="#000000">initialize  <font color="#990000">(  <font color="#009900">void  <font color="#990000">) <font color="#FF0000">{ GError <font color="#990000"> * error <font color="#990000"> = NULL <font color="#990000"> ;  <font color="#000000">g_type_init  <font color="#990000">;  <font color="#9A1900">/* Create main loop */  mainloop <font color="#990000"> =  <font color="#000000">g_main_loop_new   <font color="#990000">( NULL <font color="#990000">, TRUE <font color="#990000">);  <font color="#0000FF">if  <font color="#990000">( mainloop <font color="#990000"> == NULL <font color="#990000">)   <font color="#0000FF">return  FALSE <font color="#990000"> ;  <font color="#9A1900">/* Create DBUS connection */  connection <font color="#990000"> =  <font color="#000000">dbus_g_bus_get   <font color="#990000">( DBUS_BUS_SYSTEM <font color="#990000">,  <font color="#990000">&amp; error <font color="#990000">);  <font color="#0000FF">if  <font color="#990000">( connection <font color="#990000"> == NULL <font color="#990000">) <font color="#FF0000">{  <font color="#000000">g_print  <font color="#990000">(  <font color="#FF0000">"Error: %s  <font color="#CC33CC">\n  <font color="#FF0000">"  <font color="#990000">, error <font color="#990000">-&gt; message <font color="#990000">);  <font color="#000000">g_clear_error  <font color="#990000">(&amp; error <font color="#990000">);  <font color="#0000FF">return  FALSE <font color="#990000"> ; <font color="#FF0000">}  <font color="#0000FF">return  TRUE <font color="#990000"> ; <font color="#FF0000">}  <font color="#0000FF">static  gboolean  <font color="#000000">uninitialize  <font color="#990000">(  <font color="#009900">void  <font color="#990000">) <font color="#FF0000">{  <font color="#9A1900">/* Quit main loop and unref it */   <font color="#0000FF">if  <font color="#990000">( mainloop <font color="#990000"> != NULL <font color="#990000">) <font color="#FF0000">{  <font color="#000000">g_main_loop_quit  <font color="#990000">( mainloop <font color="#990000">);  <font color="#000000">g_main_loop_unref  <font color="#990000">( mainloop <font color="#990000">); <font color="#FF0000">}  <font color="#0000FF">return  TRUE <font color="#990000"> ; <font color="#FF0000">}  <font color="#0000FF">static  DBusHandlerResult  <font color="#000000">file_sent_signal  <font color="#990000">( DBusConnection <font color="#990000"> * connection <font color="#990000">,                                              DBusMessage <font color="#990000"> * message <font color="#990000">,                                              <font color="#009900">void  <font color="#990000"> * data <font color="#990000">) <font color="#FF0000">{ gboolean success <font color="#990000"> = FALSE <font color="#990000"> ;  <font color="#9A1900">/* check signal */   <font color="#0000FF">if  <font color="#990000">(!   <font color="#000000">dbus_message_is_signal   <font color="#990000">( message <font color="#990000">, CONBTDIALOGS_DBUS_INTERFACE <font color="#990000">, CONBTDIALOGS_SEND_FILE_SIG <font color="#990000">))  <font color="#0000FF">return  DBUS_HANDLER_RESULT_NOT_YET_HANDLED <font color="#990000"> ;  <font color="#9A1900">/* get args */   <font color="#0000FF">if  <font color="#990000">(  <font color="#990000"> !   <font color="#000000">dbus_message_get_args   <font color="#990000">( message <font color="#990000">, NULL <font color="#990000">, DBUS_TYPE_BOOLEAN <font color="#990000">, <font color="#990000">&amp; success <font color="#990000">, DBUS_TYPE_INVALID <font color="#990000">) <font color="#990000">)  <font color="#0000FF">return  DBUS_HANDLER_RESULT_NOT_YET_HANDLED <font color="#990000"> ;  <font color="#9A1900">/* print if file sending was success or failure */   <font color="#000000">g_print  <font color="#990000">(  <font color="#FF0000">"File sending was a "  <font color="#990000">);  <font color="#0000FF">if  <font color="#990000">( success <font color="#990000">)   <font color="#000000">g_print   <font color="#990000">(  <font color="#FF0000">"success  <font color="#CC33CC">\n  <font color="#FF0000">"  <font color="#990000">);   <font color="#0000FF">else    <font color="#000000">g_print   <font color="#990000">(  <font color="#FF0000">"failure  <font color="#CC33CC">\n  <font color="#FF0000">"  <font color="#990000">);  <font color="#000000">dbus_connection_close  <font color="#990000">( connection <font color="#990000">);  <font color="#000000">uninitialize  <font color="#990000">;  <font color="#0000FF">return  DBUS_HANDLER_RESULT_HANDLED <font color="#990000"> ; <font color="#FF0000">} gint  <font color="#000000">main  <font color="#990000">( gint argc <font color="#990000">, gchar <font color="#990000"> ** argv <font color="#990000">) <font color="#FF0000">{ GError <font color="#990000"> * error <font color="#990000"> = NULL <font color="#990000"> ; gchar <font color="#990000"> ** files <font color="#990000"> = NULL <font color="#990000"> ; gint idx <font color="#990000"> = <font color="#993399">0  <font color="#990000"> ; DBusGProxy <font color="#990000"> * proxy <font color="#990000"> ; DBusConnection <font color="#990000"> * sys_conn <font color="#990000"> ; gchar <font color="#990000"> * filter_string <font color="#990000"> = NULL <font color="#990000"> ;  <font color="#0000FF">if  <font color="#990000">( argc <font color="#990000">&lt;  <font color="#993399">2  <font color="#990000">)   <font color="#0000FF">return   <font color="#993399">1  <font color="#990000"> ;  <font color="#0000FF">if  <font color="#990000">(   <font color="#000000">initialize   <font color="#990000">  <font color="#990000"> == FALSE <font color="#990000">)  <font color="#FF0000">{  <font color="#000000">uninitialize  <font color="#990000">;  <font color="#0000FF">return  <font color="#993399">1  <font color="#990000"> ; <font color="#FF0000">}  <font color="#9A1900">/* Copy urls to GLib compatible char array */  files <font color="#990000"> =  <font color="#000000">g_new0   <font color="#990000">( gchar <font color="#990000"> *, argc <font color="#990000">);  <font color="#0000FF">for  <font color="#990000">( idx <font color="#990000"> =  <font color="#993399">1  <font color="#990000"> ; idx <font color="#990000">&lt; argc <font color="#990000"> ; idx <font color="#990000">++) files <font color="#990000">[ idx <font color="#990000">- <font color="#993399">1  <font color="#990000">]  <font color="#990000"> =   <font color="#000000">g_strdup   <font color="#990000">( argv <font color="#990000">[ idx <font color="#990000">]); files <font color="#990000">[ argc <font color="#990000">- <font color="#993399">1  <font color="#990000">]  <font color="#990000"> = NULL <font color="#990000"> ;  <font color="#9A1900">/* Open connection for btdialogs service */  proxy <font color="#990000"> =  <font color="#000000">dbus_g_proxy_new_for_name   <font color="#990000">( connection <font color="#990000">,                                        CONBTDIALOGS_DBUS_SERVICE <font color="#990000">,                                        CONBTDIALOGS_DBUS_PATH <font color="#990000">,                                        CONBTDIALOGS_DBUS_INTERFACE <font color="#990000">);  <font color="#9A1900">/* Send send file request to btdialogs service */   <font color="#0000FF">if  <font color="#990000">(!   <font color="#000000">dbus_g_proxy_call   <font color="#990000">( proxy <font color="#990000">, CONBTDIALOGS_SEND_FILE_REQ <font color="#990000">, <font color="#990000">&amp; error <font color="#990000">, G_TYPE_STRV <font color="#990000">, files <font color="#990000">, G_TYPE_INVALID <font color="#990000">, G_TYPE_INVALID <font color="#990000">)) <font color="#FF0000">{  <font color="#000000">g_print  <font color="#990000">(  <font color="#FF0000">"Error: %s  <font color="#CC33CC">\n  <font color="#FF0000">"  <font color="#990000">, error <font color="#990000">-&gt; message <font color="#990000">);  <font color="#000000">g_clear_error  <font color="#990000">(&amp; error <font color="#990000">);  <font color="#000000">g_strfreev  <font color="#990000">( files <font color="#990000">);  <font color="#000000">g_object_unref  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( proxy <font color="#990000">));  <font color="#000000">uninitialize  <font color="#990000">;  <font color="#0000FF">return  <font color="#993399">1  <font color="#990000"> ; <font color="#FF0000">}  <font color="#000000">g_strfreev  <font color="#990000">( files <font color="#990000">); files <font color="#990000"> = NULL <font color="#990000"> ;  <font color="#000000">g_object_unref  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( proxy <font color="#990000">));  <font color="#9A1900">/* Now wait for file sent signal, use low level bindings as glib   <font color="#9A1900">      bindings require signal marshaller registered */  sys_conn <font color="#990000"> =  <font color="#000000">dbus_bus_get   <font color="#990000">( DBUS_BUS_SYSTEM <font color="#990000">, NULL <font color="#990000">);  <font color="#000000">g_assert  <font color="#990000">(   <font color="#000000">dbus_connection_add_filter   <font color="#990000">( sys_conn <font color="#990000">, file_sent_signal <font color="#990000">, NULL <font color="#990000">, NULL <font color="#990000">)); filter_string <font color="#990000"> =  <font color="#000000">g_strdup_printf  <font color="#990000">(  <font color="#FF0000">"type='signal',interface='%s'"  <font color="#990000">, CONBTDIALOGS_DBUS_INTERFACE <font color="#990000">);  <font color="#000000">dbus_bus_add_match  <font color="#990000">( sys_conn <font color="#990000">, filter_string <font color="#990000">, NULL <font color="#990000">);  <font color="#000000">dbus_connection_unref  <font color="#990000">( sys_conn <font color="#990000">);  <font color="#9A1900">/* Run mainloop */   <font color="#000000">g_main_loop_run  <font color="#990000">( mainloop <font color="#990000">);  <font color="#0000FF">return  <font color="#993399">0  <font color="#990000"> ; <font color="#FF0000">} </tt>

Location
The location framework has one library called liblocation. Liblocation consists of helper functions, for example, functions for parsing GPSD's output and controlling GPSD.

Using Liblocation
The headers for liblocation are stored in the location subdirectory. Include them as follows:

<tt>  <font color="#000080"> #include  <font color="#FF0000">&lt;location/location-gps-device.h&gt; </tt>

Listening to GPSD
GPSD is used in maemo to talk to GPS devices and report position data. Liblocation contains an object that listens to GPSD and converts the output into GObject signals. Creating the object goes as follows

<tt>LocationGPSDevice <font color="#990000"> * device <font color="#990000"> ; device <font color="#990000"> =  <font color="#000000">g_object_new   <font color="#990000">( LOCATION_TYPE_GPS_DEVICE <font color="#990000">, NULL <font color="#990000">); </tt>

Now connect to the changed signal to hear about gps fix changes.

<tt>  <font color="#000000">g_signal_connect  <font color="#990000">( device <font color="#990000">,  <font color="#FF0000">"changed"  <font color="#990000">,   <font color="#000000">G_CALLBACK   <font color="#990000">( location_changed <font color="#990000">), NULL <font color="#990000">); </tt>

And the location changed callback looks like this

<tt>  <font color="#0000FF">static  <font color="#009900">void  <font color="#000000">location_changed  <font color="#990000">( LocationGPSDevice <font color="#990000"> * device <font color="#990000">, gpointer userdata <font color="#990000">) <font color="#FF0000">{  <font color="#000000">g_print  <font color="#990000">(  <font color="#FF0000">"Latitude: %.2f  <font color="#CC33CC">\n  <font color="#FF0000">Longitude: %.2f  <font color="#CC33CC">\n  <font color="#FF0000">Altitude: %.2f  <font color="#CC33CC">\n  <font color="#FF0000">"  <font color="#990000">,                   device <font color="#990000">-&gt; fix <font color="#990000">-&gt; latitude <font color="#990000">, device <font color="#990000">-&gt; fix <font color="#990000">-&gt; longitude <font color="#990000">, device <font color="#990000">-&gt; fix <font color="#990000">-&gt; altitude <font color="#990000">); <font color="#FF0000">} </tt>

That is all that is required for a simple GPS client that listens for GPSD. N.B. The LocationGPSDevice object has the following public fields:


 * device-&gt;online: Whether GPSD is connected to a GPS
 * device-&gt;status: The GPS status
 * device-&gt;fix: The GPS fix information
 * device-&gt;satellites_in_view: The number of satellites that the GPS can see
 * device-&gt;satellites_in_use: The number of satellites used in fix calculation
 * device-&gt;satellites: An array of satellite details

The most important of these is device-&gt;fix which contains the fix location data from GPSD. Most of the fields of the LocationGPSDeviceFix structure are fairly self-explanatory. The fields field is an exception; it is a bitmask of which other fields in the structure have valid content. To check that the latitude and longitude fields are valid, use the following:

<tt>  <font color="#0000FF">if  <font color="#990000">( fix <font color="#990000">-&gt; fields <font color="#990000">&amp; LOCATION_GPS_DEVICE_LATLONG_SET <font color="#990000">) </tt>

The bitmask flags are defined in location-gps-device.h

Controlling GPSD
To start or stop GPSD or find out when GPSD has been started or stopped, use the LocationGPSDControl object. Because this object can only be created once in a program, use the location_gpsd_control_get_default function to obtain it (see location-gpsd-control.h).

<tt>LocationGPSDControl <font color="#990000"> * control <font color="#990000"> ; control <font color="#990000"> =  <font color="#000000">location_gpsd_control_get_default   <font color="#990000">; </tt>

This signal has three signals: error, gpsd_running and gpsd_stopped. Error is emitted when there is an error starting GPSD. gpsd-running is emitted whenever GPSD starts up. gpsd-stopped is emitted when GPSD stops. Only one application is able to control GPSD at a time: the application that initially starts it. The control-&gt;can_control field is TRUE if the application can control it, or FALSE if it cannot.

Other Liblocation Functions
Liblocation also comes with a function for getting the distance between two points. This is called the great-circle distance. (For more information about great-cicle distance, see Wikipedia). The function location_distance_between (see location-distance-utils.h) takes the latitude and longitude of two locations and returns the distance between them in kilometers.

<tt>  <font color="#000000">g_print  <font color="#990000">(  <font color="#FF0000">"distance between LAX and BNA is %fkm  <font color="#CC33CC">\n  <font color="#FF0000">"  <font color="#990000">,            <font color="#000000">location_distance_between   <font color="#990000">(  <font color="#993399">36.12  <font color="#990000">,  <font color="#990000">-  <font color="#993399">86.67  <font color="#990000">,  <font color="#993399">33.94  <font color="#990000">,  <font color="#990000">-  <font color="#993399">118.40  <font color="#990000">)); </tt>

Compiling Programs With LibLocation Support
Liblocation comes with a pkgconfig file, so adding support to a program is just a case of adding liblocation to the configure scripts PKG_CHECK_MODULES macro, as follows:

<tt>PKG_CHECK_MODULES <font color="#990000">( LOCATION <font color="#990000">) AC_SUBST <font color="#990000">( LOCATION_CFLAGS <font color="#990000">) AC_SUBST <font color="#990000">( LOCATION_LIBS <font color="#990000">) </tt>

Then in the Makefile.am, add the following variables to the program's CFLAGS and LDADD flags: