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

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.

Warning: This page is 65 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 301: Line 301:
====Listening for Connection Events ====
====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 the <code>automatic-connection-events</code> <code>GObject</code> property, can achieve this:
+
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-connection-events" <code>GObject</code> property, can achieve this:
-
<source lang="c">
+
<tt>    <span>''<span><font color="#9A1900">/* Create connection object */</font></span>''</span>
-
    /* Create connection object */
+
    ConIcConnection <span><font color="#990000"><nowiki>*</nowiki></font></span>connection <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">con_ic_connection_new</font></span>'''</span><span><font color="#990000">();</font></span>
-
    ConIcConnection *connection = con_ic_connection_new();
+
    <span>''<span><font color="#9A1900">/* Connect signal to receive connection events */</font></span>''</span>
-
    /* Connect signal to receive connection events */
+
    <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span><span><font color="#990000">(</font></span>connection<span><font color="#990000">),</font></span> <span><font color="#FF0000">"connection-event"</font></span><span><font color="#990000">,</font></span>
-
    g_signal_connect(G_OBJECT(connection), "connection-event",
+
                      <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span><span><font color="#990000">(</font></span>my_connection_handler<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
-
                    G_CALLBACK(my_connection_handler), NULL);
+
    <span>''<span><font color="#9A1900">/* Set automatic events */</font></span>''</span>
-
    /* Set automatic events */
+
    <span>'''<span><font color="#000000">g_object_set</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span><span><font color="#990000">(</font></span>connection<span><font color="#990000">),</font></span> <span><font color="#FF0000">"automatic-connection-events"</font></span><span><font color="#990000">,</font></span> TRUE<span><font color="#990000">,</font></span> NULL<span><font color="#990000">);</font></span></tt>
-
    g_object_set(G_OBJECT(connection), "automatic-connection-events", TRUE, NULL);
+
-
</source>
+
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, <code>ConIcConnectionEvent</code> with status <code>CON_IC_STATUS_DISCONNECTED</code> is emitted. This event has <code>NULL</code> IAP ID and bearer, because there is no IAP getting disconnected, but the event indicates that the device is offline.
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, <code>ConIcConnectionEvent</code> with status <code>CON_IC_STATUS_DISCONNECTED</code> is emitted. This event has <code>NULL</code> 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 iterated in order to receive the event. If you need the connection status information synchronously, you can iterate the main loop yourself:
+
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:
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">connection_info</font></span>'''</span><span><font color="#990000">(</font></span>ConIcConnection <span><font color="#990000"><nowiki>*</nowiki></font></span>connection<span><font color="#990000">,</font></span>
-
static void connection_info(ConIcConnection *connection,
+
                            ConIcConnectionEvent <span><font color="#990000"><nowiki>*</nowiki></font></span>event<span><font color="#990000">,</font></span>
-
                            ConIcConnectionEvent *event,
+
                            gpointer user_data<span><font color="#990000">)</font></span>
-
                            gpointer user_data)
+
<span><font color="#FF0000">{</font></span>
-
{
+
    ConIcConnectionStatus status <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">con_ic_connection_event_get_status</font></span>'''</span><span><font color="#990000">(</font></span>event<span><font color="#990000">);</font></span>
-
    ConIcConnectionStatus status = con_ic_connection_event_get_status(event);
+
    ConIcConnectionStatus <span><font color="#990000"><nowiki>*</nowiki></font></span>status_ptr <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#990000">(</font></span>ConIcConnectionStatus<span><font color="#990000"><nowiki>*)</nowiki></font></span>user_data<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
    ConIcConnectionStatus *status_ptr = (ConIcConnectionStatus*)user_data;
+
    <span><font color="#990000"><nowiki>*</nowiki></font></span>status_ptr <span><font color="#990000"><nowiki>=</nowiki></font></span> status<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
    *status_ptr = status;
+
<span><font color="#FF0000">}</font></span>
-
}
+
<span>''<span><font color="#9A1900">/* ... */</font></span>''</span>
-
/* ... */
+
    <span>''<span><font color="#9A1900">/* Create connection object and set on automatic events (see previous snippet) ... */</font></span>''</span>
-
    /* Create connection object and set on automatic events (see previous snippet) ... */
+
    <span>'''<span><font color="#0000FF">static</font></span>'''</span> ConIcConnectionStatus status <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#993399">0xFFFF</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
-
    static ConIcConnectionStatus status = 0xFFFF;
+
    ConIcConnection <span><font color="#990000"><nowiki>*</nowiki></font></span>connection <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">con_ic_connection_new</font></span>'''</span><span><font color="#990000">();</font></span>
-
    ConIcConnection *connection = con_ic_connection_new();
+
    <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span><span><font color="#990000">(</font></span>connection<span><font color="#990000">),</font></span> <span><font color="#FF0000">"connection-event"</font></span><span><font color="#990000">,</font></span>
-
    g_signal_connect(G_OBJECT(connection), "connection-event",
+
                      <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span><span><font color="#990000">(</font></span>connection_info<span><font color="#990000">),</font></span> <span><font color="#990000">&amp;</font></span>status<span><font color="#990000">);</font></span>
-
                    G_CALLBACK(connection_info), &status);
+
    <span>'''<span><font color="#000000">g_object_set</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span><span><font color="#990000">(</font></span>Connection<span><font color="#990000">),</font></span> <span><font color="#FF0000">"automatic-connection-events"</font></span><span><font color="#990000">,</font></span> TRUE<span><font color="#990000">,</font></span> NULL<span><font color="#990000">);</font></span>
-
    g_object_set(G_OBJECT(Connection), "automatic-connection-events", TRUE, NULL);
+
    <span>''<span><font color="#9A1900">/* Iterate main loop for the first connection event */</font></span>''</span>
-
    /* Iterate main loop for the first connection event */
+
    <span>'''<span><font color="#0000FF">while</font></span>'''</span> <span><font color="#990000">(</font></span>status <span><font color="#990000"><nowiki>==</nowiki></font></span> <span><font color="#993399">0xFFFF</font></span><span><font color="#990000">)</font></span> <span>'''<span><font color="#000000">g_main_context_iteration</font></span>'''</span><span><font color="#990000">(</font></span>NULL<span><font color="#990000">,</font></span> TRUE<span><font color="#990000">);</font></span>
-
    while (status == 0xFFFF) g_main_context_iteration(NULL, TRUE);
+
    <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>status <span><font color="#990000"><nowiki>==</nowiki></font></span> CON_IC_STATUS_CONNECTED<span><font color="#990000">)</font></span>
-
    if (status == CON_IC_STATUS_CONNECTED)
+
        <span>'''<span><font color="#000000">g_debug</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#FF0000">"We are connected!"</font></span><span><font color="#990000">);</font></span>
-
        g_debug("We are connected!");
+
    <span>'''<span><font color="#0000FF">else</font></span>'''</span>
-
    else
+
        <span>'''<span><font color="#000000">g_debug</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#FF0000">"We are not connected!"</font></span><span><font color="#990000">);</font></span></tt>
-
        g_debug("We are not connected!");
+
-
</source>
+
==== Receiving Statistics of Connection ====
==== Receiving Statistics of Connection ====

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)