/*
* SIP Communicator, 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.neomedia;
import net.java.sip.communicator.service.audionotifier.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.fileaccess.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.neomedia.*;
import net.java.sip.communicator.service.netaddr.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.impl.neomedia.notify.*;
import org.osgi.framework.*;
/**
* Implements BundleActivator for the neomedia bundle.
*
* @author Martin Andre
* @author Emil Ivov
* @author Lubomir Marinov
*/
public class NeomediaActivator
implements BundleActivator
{
/**
* The Logger used by the NeomediaActivator class and its
* instances for logging output.
*/
private final Logger logger = Logger.getLogger(NeomediaActivator.class);
/**
* The context in which the one and only NeomediaActivator instance
* has started executing.
*/
private static BundleContext bundleContext;
/**
* The ConfigurationService registered in {@link #bundleContext}
* and used by the NeomediaActivator instance to read and write
* configuration properties.
*/
private static ConfigurationService configurationService;
/**
* The FileAccessService registered in {@link #bundleContext} and
* used by the NeomediaActivator instance to safely access files.
*/
private static FileAccessService fileAccessService;
/**
* The one and only MediaServiceImpl instance registered in
* {@link #bundleContext} by the NeomediaActivator instance.
*/
private static MediaServiceImpl mediaServiceImpl;
/**
* The NetworkAddressManagerService registered in
* {@link #bundleContext} and used by the NeomediaActivator
* instance for network address resolution.
*/
private static NetworkAddressManagerService networkAddressManagerService;
/**
* The ResourceManagementService registered in
* {@link #bundleContext} and representing the resources such as
* internationalized and localized text and images used by the neomedia
* bundle.
*/
private static ResourceManagementService resources;
/**
* The OSGi ServiceRegistration of {@link #mediaServiceImpl} in
* {@link #bundleContext}.
*/
private ServiceRegistration mediaServiceRegistration;
/**
* Starts the execution of the neomedia bundle in the specified context.
*
* @param bundleContext the context in which the neomedia bundle is to start
* executing
* @throws Exception if an error occurs while starting the execution of the
* neomedia bundle in the specified context
*/
public void start(BundleContext bundleContext)
throws Exception
{
if (logger.isDebugEnabled())
logger.debug("Started.");
NeomediaActivator.bundleContext = bundleContext;
// MediaService
mediaServiceImpl = new MediaServiceImpl();
mediaServiceImpl.start();
mediaServiceRegistration
= bundleContext
.registerService(
MediaService.class.getName(),
mediaServiceImpl,
null);
if (logger.isDebugEnabled())
logger.debug("Media Service ... [REGISTERED]");
// MediaConfigurationForm
bundleContext
.registerService(
ConfigurationForm.class.getName(),
new LazyConfigurationForm(
"net.java.sip.communicator.impl.neomedia"
+ ".MediaConfigurationPanel",
getClass().getClassLoader(),
"plugin.mediaconfig.PLUGIN_ICON",
"impl.neomedia.configform.TITLE",
41),
null);
// ZRTPConfiguration panel
bundleContext
.registerService(
ConfigurationForm.class.getName(),
new LazyConfigurationForm(
"net.java.sip.communicator.impl.neomedia.ZrtpConfigurePanel",
getClass().getClassLoader(),
"impl.media.security.zrtp.CONF_ICON",
"impl.media.security.zrtp.TITLE",
1100),
null);
GatherEntropy entropy
= new GatherEntropy(mediaServiceImpl.getDeviceConfiguration());
entropy.setEntropy();
//we use the nist-sdp stack to make parse sdp and we need to set the
//following property to make sure that it would accept java generated
//IPv6 addresses that contain address scope zones.
System.setProperty("gov.nist.core.STRIP_ADDR_SCOPES", "true");
// AudioNotify Service
AudioNotifierServiceImpl audioNotifier = new AudioNotifierServiceImpl(
mediaServiceImpl.getDeviceConfiguration());
audioNotifier.setMute(
!getConfigurationService()
.getBoolean(
"net.java.sip.communicator.impl.sound.isSoundEnabled",
true));
getBundleContext()
.registerService(
AudioNotifierService.class.getName(),
audioNotifier,
null);
if (logger.isInfoEnabled())
logger.info("Audio Notifier Service ...[REGISTERED]");
}
/**
* Stops the execution of the neomedia bundle in the specified context.
*
* @param bundleContext the context in which the neomedia bundle is to stop
* executing
* @throws Exception if an error occurs while stopping the execution of the
* neomedia bundle in the specified context
*/
public void stop(BundleContext bundleContext)
throws Exception
{
mediaServiceImpl.stop();
mediaServiceRegistration.unregister();
}
/**
* Returns a reference to the bundle context that we were started with.
*
* @return a reference to the BundleContext instance that we were started
* with.
*/
public static BundleContext getBundleContext()
{
return bundleContext;
}
/**
* Returns a reference to a ConfigurationService implementation currently
* registered in the bundle context or null if no such implementation was
* found.
*
* @return a currently valid implementation of the ConfigurationService.
*/
public static ConfigurationService getConfigurationService()
{
if (configurationService == null)
{
ServiceReference confReference
= bundleContext
.getServiceReference(ConfigurationService.class.getName());
configurationService
= (ConfigurationService)
bundleContext.getService(confReference);
}
return configurationService;
}
/**
* Returns a reference to a FileAccessService implementation
* currently registered in the bundle context or null if no such
* implementation was found.
*
* @return a currently valid implementation of the
* FileAccessService .
*/
public static FileAccessService getFileAccessService()
{
if (fileAccessService == null && bundleContext != null)
{
ServiceReference faReference
= bundleContext
.getServiceReference(FileAccessService.class.getName());
fileAccessService
= (FileAccessService) bundleContext.getService(faReference);
}
return fileAccessService;
}
/**
* Gets the MediaService implementation instance registered by the
* neomedia bundle.
*
* @return the MediaService implementation instance registered by
* the neomedia bundle
*/
public static MediaServiceImpl getMediaServiceImpl()
{
return mediaServiceImpl;
}
/**
* Returns a reference to a NetworkAddressManagerService implementation
* currently registered in the bundle context or null if no such
* implementation was found.
*
* @return a currently valid implementation of the
* NetworkAddressManagerService .
*/
public static NetworkAddressManagerService getNetworkAddressManagerService()
{
if (networkAddressManagerService == null)
{
ServiceReference namReference
= bundleContext
.getServiceReference(
NetworkAddressManagerService.class.getName());
networkAddressManagerService
= (NetworkAddressManagerService)
bundleContext.getService(namReference);
}
return networkAddressManagerService;
}
/**
* Gets the ResourceManagementService instance which represents the
* resources such as internationalized and localized text and images used by
* the neomedia bundle.
*
* @return the ResourceManagementService instance which represents
* the resources such as internationalized and localized text and images
* used by the neomedia bundle
*/
public static ResourceManagementService getResources()
{
if (resources == null)
resources
= ResourceManagementServiceUtils.getService(bundleContext);
return resources;
}
}