aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/sysactivity/SysActivityActivator.java
diff options
context:
space:
mode:
authorDamian Minkov <damencho@jitsi.org>2011-08-23 18:23:28 +0000
committerDamian Minkov <damencho@jitsi.org>2011-08-23 18:23:28 +0000
commitf9992f25f8eb116a41808e6d91064004dc91f69b (patch)
tree1f316f693b0c8c77560b6bfe9cb1bcd23ef31cd0 /src/net/java/sip/communicator/impl/sysactivity/SysActivityActivator.java
parent6e080f08a2d95ca398ee6ce15dd34f5211b82c58 (diff)
downloadjitsi-f9992f25f8eb116a41808e6d91064004dc91f69b.zip
jitsi-f9992f25f8eb116a41808e6d91064004dc91f69b.tar.gz
jitsi-f9992f25f8eb116a41808e6d91064004dc91f69b.tar.bz2
Introduces service for detecting system activity like network changes and detecting idle states. Produced events used for autoaway and reconnect plugin.
Diffstat (limited to 'src/net/java/sip/communicator/impl/sysactivity/SysActivityActivator.java')
-rw-r--r--src/net/java/sip/communicator/impl/sysactivity/SysActivityActivator.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/sysactivity/SysActivityActivator.java b/src/net/java/sip/communicator/impl/sysactivity/SysActivityActivator.java
new file mode 100644
index 0000000..ea60cfc
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/sysactivity/SysActivityActivator.java
@@ -0,0 +1,108 @@
+/*
+ * 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 net.java.sip.communicator.service.sysactivity.*;
+import org.osgi.framework.*;
+
+import net.java.sip.communicator.util.*;
+
+/**
+ * Listens for system activity changes like sleep, network change, inactivity
+ * and inform all its listeners.
+ *
+ * @author Damian Minkov
+ */
+public class SysActivityActivator
+ implements BundleActivator
+{
+ /**
+ * The logger.
+ */
+ private Logger logger = Logger.getLogger(
+ SysActivityActivator.class.getName());
+
+ /**
+ * The OSGi service registration.
+ */
+ private ServiceRegistration sysActivitiesServReg = null;
+
+ /**
+ * The OSGi <tt>BundleContext</tt>.
+ */
+ private static BundleContext bundleContext = null;
+
+ /**
+ * The system activity service impl.
+ */
+ private static SystemActivityNotificationsServiceImpl sysActivitiesServiceImpl;
+
+ /**
+ * Called when this bundle is started so the Framework can perform the
+ * bundle-specific activities necessary to start this bundle.
+ *
+ * @param context The execution context of the bundle being started.
+ * @throws Exception If this method throws an exception, this bundle is
+ * marked as stopped and the Framework will remove this bundle's
+ * listeners, unregister all services registered by this bundle, and
+ * release all services used by this bundle.
+ */
+ public void start(BundleContext context)
+ throws Exception
+ {
+ if (logger.isDebugEnabled())
+ logger.debug("Started.");
+ SysActivityActivator.bundleContext = context;
+
+ sysActivitiesServiceImpl = new SystemActivityNotificationsServiceImpl();
+ sysActivitiesServiceImpl.start();
+
+ sysActivitiesServReg = context.registerService(
+ SystemActivityNotificationsService.class.getName(),
+ sysActivitiesServiceImpl,
+ null);
+ }
+
+ /**
+ * Returns a reference to the bundle context that we were started with.
+ * @return a reference to the BundleContext instance that we were started
+ * witn.
+ */
+ public static BundleContext getBundleContext()
+ {
+ return bundleContext;
+ }
+
+ /**
+ * Returns a reference to the bundle context that we were started with.
+ * @return a reference to the BundleContext instance that we were started
+ * witn.
+ */
+ public static SystemActivityNotificationsServiceImpl
+ getSystemActivityService()
+ {
+ return sysActivitiesServiceImpl;
+ }
+
+ /**
+ * Called when this bundle is stopped so the Framework can perform the
+ * bundle-specific activities necessary to stop the bundle.
+ *
+ * @param context The execution context of the bundle being stopped.
+ * @throws Exception If this method throws an exception, the bundle is
+ * still marked as stopped, and the Framework will remove the bundle's
+ * listeners, unregister all services registered by the bundle, and
+ * release all services used by the bundle.
+ */
+ public void stop(BundleContext context) throws Exception
+ {
+ sysActivitiesServReg.unregister();
+
+ if(sysActivitiesServiceImpl != null)
+ sysActivitiesServiceImpl.stop();
+ }
+}