diff options
author | Ingo Bauersachs <ingo@jitsi.org> | 2011-12-12 16:56:17 +0000 |
---|---|---|
committer | Ingo Bauersachs <ingo@jitsi.org> | 2011-12-12 16:56:17 +0000 |
commit | 2d1896a464d27aeb1a0ef9e582706d17e79b2d1f (patch) | |
tree | 93074de5506e6cd54312917fcbb52f6993e48ac7 /src/net/java/sip/communicator/impl/sysactivity | |
parent | 5bef452c85705db07c7c77558271d4f12283b140 (diff) | |
download | jitsi-2d1896a464d27aeb1a0ef9e582706d17e79b2d1f.zip jitsi-2d1896a464d27aeb1a0ef9e582706d17e79b2d1f.tar.gz jitsi-2d1896a464d27aeb1a0ef9e582706d17e79b2d1f.tar.bz2 |
Adapt D-Bus NetworkManager signal listener to NM_STATE 0.9
Diffstat (limited to 'src/net/java/sip/communicator/impl/sysactivity')
-rw-r--r-- | src/net/java/sip/communicator/impl/sysactivity/DBusNetworkManager.java | 136 | ||||
-rw-r--r-- | src/net/java/sip/communicator/impl/sysactivity/NetworkManagerListenerImpl.java | 28 |
2 files changed, 155 insertions, 9 deletions
diff --git a/src/net/java/sip/communicator/impl/sysactivity/DBusNetworkManager.java b/src/net/java/sip/communicator/impl/sysactivity/DBusNetworkManager.java new file mode 100644 index 0000000..c7c99e9 --- /dev/null +++ b/src/net/java/sip/communicator/impl/sysactivity/DBusNetworkManager.java @@ -0,0 +1,136 @@ +/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.impl.sysactivity;
+
+import org.freedesktop.dbus.*;
+import org.freedesktop.dbus.exceptions.*;
+
+/**
+ * NetworkManager D-Bus Interface
+ *
+ * @author Damian Minkov
+ * @author Ingo Bauersachs
+ */
+@DBusInterfaceName("org.freedesktop.NetworkManager")
+public interface DBusNetworkManager
+ extends DBusInterface
+{
+ /*
+ * Types of NetworkManager states for versions < 0.9
+ */
+ public static final int NM_STATE_UNKNOWN = 0;
+ public static final int NM_STATE_ASLEEP = 1;
+ public static final int NM_STATE_CONNECTING = 2;
+ public static final int NM_STATE_CONNECTED = 3;
+ public static final int NM_STATE_DISCONNECTED = 4;
+
+ /*
+ * Types of NetworkManager states for versions >= 0.9
+ */
+ public static final int NM9_STATE_UNKNOWN = 0;
+ public static final int NM9_STATE_ASLEEP = 10;
+ public static final int NM9_STATE_DISCONNECTED = 20;
+ public static final int NM9_STATE_DISCONNECTING = 30;
+ public static final int NM9_STATE_CONNECTING = 40;
+ public static final int NM9_STATE_CONNECTED_LOCAL = 50;
+ public static final int NM9_STATE_CONNECTED_SITE = 60;
+ public static final int NM9_STATE_CONNECTED_GLOBAL = 70;
+
+ /**
+ * State change signal.
+ */
+ public class StateChange extends DBusSignal
+ {
+ /**
+ * The name of the signal.
+ */
+ public final String name;
+
+ /**
+ * The current status it holds.
+ */
+ public final UInt32 status;
+
+ /**
+ * Creates status change.
+ * @param path the path
+ * @param status the status
+ * @throws DBusException
+ */
+ public StateChange(String path, UInt32 status)
+ throws DBusException
+ {
+ super(path, status);
+ name = path;
+ this.status = status;
+ }
+
+ /**
+ * The current status.
+ * @return
+ */
+ public int getStatus()
+ {
+ return status.intValue();
+ }
+
+ /**
+ * Returns status description
+ * @return
+ */
+ public String getStatusName()
+ {
+ switch(status.intValue())
+ {
+ case NM_STATE_ASLEEP : return "Asleep";
+ case NM_STATE_CONNECTING : return "Connecting";
+ case NM_STATE_CONNECTED : return "Connected";
+ case NM_STATE_DISCONNECTED : return "Disconnected";
+ default : return "Unknown";
+ }
+ }
+ }
+
+ /**
+ * State changed signal.
+ */
+ public static class StateChanged extends StateChange
+ {
+ /**
+ * Creates status changed.
+ * @param path the path
+ * @param status the status
+ * @throws DBusException
+ */
+ public StateChanged(String path, UInt32 status)
+ throws DBusException
+ {
+ super(path, status);
+ }
+
+ /**
+ * Returns status description
+ * @return
+ */
+ @Override
+ public String getStatusName()
+ {
+ switch(status.intValue())
+ {
+ case NM9_STATE_UNKNOWN: return "Unknown";
+ case NM9_STATE_ASLEEP: return "Asleep";
+ case NM9_STATE_DISCONNECTED: return "Disconnected";
+ case NM9_STATE_DISCONNECTING: return "Disconnecting";
+ case NM9_STATE_CONNECTING: return "Connecting";
+ case NM9_STATE_CONNECTED_LOCAL: return "LocalConnectivity";
+ case NM9_STATE_CONNECTED_SITE: return "SiteConnectivity";
+ case NM9_STATE_CONNECTED_GLOBAL: return "GlobalConnectivity";
+ default : return "Unknown";
+ }
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/sysactivity/NetworkManagerListenerImpl.java b/src/net/java/sip/communicator/impl/sysactivity/NetworkManagerListenerImpl.java index 96bed15..6208a84 100644 --- a/src/net/java/sip/communicator/impl/sysactivity/NetworkManagerListenerImpl.java +++ b/src/net/java/sip/communicator/impl/sysactivity/NetworkManagerListenerImpl.java @@ -18,6 +18,7 @@ import org.freedesktop.dbus.exceptions.*; *
* @author Damian Minkov
*/
+@SuppressWarnings("rawtypes")
public class NetworkManagerListenerImpl
implements DBusSigHandler
{
@@ -77,7 +78,8 @@ public class NetworkManagerListenerImpl try
{
dbusConn.addSigHandler(DBus.NameOwnerChanged.class, this);
- dbusConn.addSigHandler(NetworkManager.StateChange.class, this);
+ dbusConn.addSigHandler(DBusNetworkManager.StateChange.class, this);
+ dbusConn.addSigHandler(DBusNetworkManager.StateChanged.class, this);
}
catch(DBusException e)
{
@@ -98,7 +100,10 @@ public class NetworkManagerListenerImpl try
{
dbusConn.removeSigHandler(DBus.NameOwnerChanged.class, this);
- dbusConn.removeSigHandler(NetworkManager.StateChange.class, this);
+ dbusConn.removeSigHandler(
+ DBusNetworkManager.StateChange.class, this);
+ dbusConn.removeSigHandler(
+ DBusNetworkManager.StateChanged.class, this);
}
catch(DBusException e)
{
@@ -117,7 +122,7 @@ public class NetworkManagerListenerImpl DBus.NameOwnerChanged nameOwnerChanged =
(DBus.NameOwnerChanged)dBusSignal;
- if(nameOwnerChanged.name.equals(NetworkManager.class.getName()))
+ if(nameOwnerChanged.name.equals("org.freedesktop.NetworkManager"))
{
boolean b1 = nameOwnerChanged.old_owner != null
&& nameOwnerChanged.old_owner.length() > 0;
@@ -134,21 +139,26 @@ public class NetworkManagerListenerImpl }
}
}
- else if(dBusSignal instanceof NetworkManager.StateChange)
+ else if(dBusSignal instanceof DBusNetworkManager.StateChange)
{
- NetworkManager.StateChange stateChange =
- (NetworkManager.StateChange)dBusSignal;
+ DBusNetworkManager.StateChange stateChange =
+ (DBusNetworkManager.StateChange)dBusSignal;
SystemActivityEvent evt = null;
switch(stateChange.getStatus())
{
- case NetworkManager.NM_STATE_CONNECTED:
- case NetworkManager.NM_STATE_DISCONNECTED:
+ case DBusNetworkManager.NM_STATE_CONNECTED:
+ case DBusNetworkManager.NM_STATE_DISCONNECTED:
+ case DBusNetworkManager.NM9_STATE_DISCONNECTED:
+ case DBusNetworkManager.NM9_STATE_CONNECTED_LOCAL:
+ case DBusNetworkManager.NM9_STATE_CONNECTED_SITE:
+ case DBusNetworkManager.NM9_STATE_CONNECTED_GLOBAL:
evt = new SystemActivityEvent(
SysActivityActivator.getSystemActivityService(),
SystemActivityEvent.EVENT_NETWORK_CHANGE);
break;
- case NetworkManager.NM_STATE_ASLEEP:
+ case DBusNetworkManager.NM_STATE_ASLEEP:
+ case DBusNetworkManager.NM9_STATE_ASLEEP:
evt = new SystemActivityEvent(
SysActivityActivator.getSystemActivityService(),
SystemActivityEvent.EVENT_SLEEP);
|