The Following User Says Thank You to rbailly For This Useful Post: | ||
![]() |
2010-02-26
, 16:14
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#2
|
![]() |
2010-03-01
, 14:49
|
Posts: 3 |
Thanked: 6 times |
Joined on Feb 2010
@ Paris
|
#3
|
GError* error = NULL; DBusGConnection* dbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); DBusGProxy* phoneNetProxy = dbus_g_proxy_new_for_name(dbus, "com.nokia.phone.net", "/com/nokia/phone/net", "Phone.Net"); guchar status; guint lac; guint cellId; guint operatorCode; guint countryCode; guchar networkType; guchar supportedServices; gint netError; dbus_g_proxy_call(phoneNetProxy, "get_registration_status", &error, G_TYPE_INVALID, G_TYPE_UCHAR, &status, G_TYPE_UINT, &lac, G_TYPE_UINT, &cellId, G_TYPE_UINT, &operatorCode, G_TYPE_UINT, &countryCode, G_TYPE_UCHAR, &networkType, G_TYPE_UCHAR, &supportedServices, G_TYPE_INT, &netError, G_TYPE_INVALID); g_object_unref(phoneNetProxy); if (supportedServices & 0x08) return "3.5G"; // HSDPA if (supportedServices & 0x04) return "3G"; // EGPRS if (supportedServices & 0x01) return "2.5G"; // GPRS if (supportedServices & 0x02) return "2G"; // CS (Circuit Switched) return NULL;
The Following User Says Thank You to rbailly For This Useful Post: | ||
![]() |
2010-03-01
, 16:24
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#4
|
Thanks, that was indeed really helpful. Here's the code I came up with, in case someone else is interested:
Code:GError* error = NULL; DBusGConnection* dbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); DBusGProxy* phoneNetProxy = dbus_g_proxy_new_for_name(dbus, "com.nokia.phone.net", "/com/nokia/phone/net", "Phone.Net"); guchar status; guint lac; guint cellId; guint operatorCode; guint countryCode; guchar networkType; guchar supportedServices; gint netError; dbus_g_proxy_call(phoneNetProxy, "get_registration_status", &error, G_TYPE_INVALID, G_TYPE_UCHAR, &status, G_TYPE_UINT, &lac, G_TYPE_UINT, &cellId, G_TYPE_UINT, &operatorCode, G_TYPE_UINT, &countryCode, G_TYPE_UCHAR, &networkType, G_TYPE_UCHAR, &supportedServices, G_TYPE_INT, &netError, G_TYPE_INVALID); g_object_unref(phoneNetProxy); if (supportedServices & 0x08) return "3.5G"; // HSDPA if (supportedServices & 0x04) return "3G"; // EGPRS if (supportedServices & 0x01) return "2.5G"; // GPRS if (supportedServices & 0x02) return "2G"; // CS (Circuit Switched) return NULL;
The Following User Says Thank You to noobmonkey For This Useful Post: | ||
![]() |
2010-03-01
, 18:51
|
Posts: 60 |
Thanked: 23 times |
Joined on Jan 2010
|
#5
|
![]() |
2010-03-02
, 09:30
|
Posts: 3 |
Thanked: 6 times |
Joined on Feb 2010
@ Paris
|
#6
|
Thanks for posting that!
Can you please post code for how to detect if the current connection is wifi or cellular ?
#include <conic/conicconnection.h> #include <conic/conicconnectionevent.h> #include <conic/conicevent.h> #include <glib/gmain.h> #include <string.h> enum ConnectionType { CONN_TYPE_UNKNOWN, CONN_TYPE_WIFI, CONN_TYPE_CELLULAR, }; struct ConnectionEventData { GMainLoop* loop; ConnectionType type; }; void ConnectionEventCallback(ConIcConnection* /*connection*/, ConIcConnectionEvent* event, gpointer user_data) { ConnectionEventData* data = static_cast<ConnectionEventData*>(user_data); bool connected = (con_ic_connection_event_get_status(event) == CON_IC_STATUS_CONNECTED); if (connected) { const gchar* bearer = con_ic_event_get_bearer_type(CON_IC_EVENT(event)); if (strcmp(bearer,CON_IC_BEARER_WLAN_ADHOC)==0 || strcmp(bearer,CON_IC_BEARER_WLAN_INFRA)==0) data->type = CONN_TYPE_WIFI; else if (strcmp(bearer,"GPRS") == 0) data->type = CONN_TYPE_CELLULAR; } g_main_loop_quit(data->loop); } ConnectionType GetConnectionType() { ConnectionEventData data; data.loop = g_main_loop_new(NULL, FALSE); data.type = CONN_TYPE_UNKNOWN; // Create connection ConIcConnection* connection = con_ic_connection_new(); g_object_ref_sink(connection); g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(ConnectionEventCallback), &data); // Ask whether we're already connected con_ic_connection_connect(connection, CON_IC_CONNECT_FLAG_AUTOMATICALLY_TRIGGERED); // Run our own event loop to wait for notification g_main_loop_run(data.loop); g_main_loop_unref(data.loop); g_object_unref(connection); return data.type; }
The Following 4 Users Say Thank You to rbailly For This Useful Post: | ||
I need to detect the network type I'm connected through on a N900, in order to adapt the size of what I'm downloading to the connection speed.
I can already find out whether I'm connected through WiFi or cellular data, but in the latter case I would need to know what's the "generation" of that cellular connection (2.5G, 3G or 3.5G ?) in order to estimate the throughput I can expect.
There's got to be a way to get that information since the status area displays it, but so far I haven't been able to find it.
Any hint is welcome,
Thanks in advance