Skip to content

Commit

Permalink
code formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Bräutigam <[email protected]>
  • Loading branch information
peuter committed Mar 20, 2015
1 parent 489be9e commit 549886a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public interface TTSService {
/**
* Speaks the text with a given voice
*
* @param text the text to speak
* @param voice the name of the voice to use or null, if the default voice should be used
* @param device the name of audio device to be used to play the audio or null, if the default output device should be used
* @param text
* the text to speak
* @param voice
* the name of the voice to use or null, if the default voice
* should be used
* @param device
* the name of audio device to be used to play the audio or null,
* if the default output device should be used
*/
void say(String text, String voice, String outputDevice);

}

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

import org.eclipse.smarthome.io.multimedia.tts.TTSService;


/**
* This class serves as a mapping from the "old" org.openhab namespace to the new org.eclipse.smarthome
* namespace for the action service. It wraps an instance with the old interface
* into a class with the new interface.
* This class serves as a mapping from the "old" org.openhab namespace to the
* new org.eclipse.smarthome namespace for the action service. It wraps an
* instance with the old interface into a class with the new interface.
*
* @author Tobias Bräutigam - Initial contribution and API
*/
Expand All @@ -28,7 +27,7 @@ public TTSServiceDelegate(org.openhab.io.multimedia.tts.TTSService service) {

@Override
public void say(String text, String voice, String outputDevice) {
service.say(text,voice,outputDevice);
service.say(text, voice, outputDevice);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,68 +29,73 @@
import org.slf4j.LoggerFactory;

/**
* This class listens for services that implement the old tts service interface and registers
* an according service for each under the new interface.
* This class listens for services that implement the old tts service interface
* and registers an according service for each under the new interface.
*
* @author Tobias Bräutigam - Initial contribution and API (copied from ActionServiceFactory)
* @author Tobias Bräutigam - Initial contribution and API (copied from
* ActionServiceFactory)
*/
public class TTSServiceFactory {
private static final Logger logger = LoggerFactory.getLogger(TTSServiceFactory.class);

private static final Logger logger = LoggerFactory
.getLogger(TTSServiceFactory.class);

private Map<String, ServiceRegistration<org.eclipse.smarthome.io.multimedia.tts.TTSService>> delegates = new HashMap<>();
private BundleContext context;

private Set<TTSService> ttsServices = new HashSet<>();

private Map properties;

public void activate(BundleContext context) {
this.context = context;
for(TTSService service : ttsServices) {
for (TTSService service : ttsServices) {
registerDelegateService(service);
}
}

public void deactivate() {
for(ServiceRegistration<org.eclipse.smarthome.io.multimedia.tts.TTSService> serviceReg : delegates.values()) {
for (ServiceRegistration<org.eclipse.smarthome.io.multimedia.tts.TTSService> serviceReg : delegates
.values()) {
serviceReg.unregister();
}
delegates.clear();
this.context = null;
}
public void addTTSService(TTSService service,Map prop) {

public void addTTSService(TTSService service, Map prop) {
properties = prop;
if(context!=null) {
registerDelegateService(service);
if (context != null) {
registerDelegateService(service);
} else {
ttsServices.add(service);
}
}

public void removeTTSService(TTSService service) {
properties=null;
if(context!=null) {
properties = null;
if (context != null) {
unregisterDelegateService(service);
}
}

private void registerDelegateService(TTSService ttsService) {
if(!delegates.containsKey(ttsService.getClass().getName())) {
if (!delegates.containsKey(ttsService.getClass().getName())) {
TTSServiceDelegate service = new TTSServiceDelegate(ttsService);
Dictionary<String, Object> props = new Hashtable<String,Object>();
if (properties!=null && properties.containsKey("os"))
props.put("os",properties.get("os"));
ServiceRegistration<org.eclipse.smarthome.io.multimedia.tts.TTSService> serviceReg =
context.registerService(org.eclipse.smarthome.io.multimedia.tts.TTSService.class, service, props);
Dictionary<String, Object> props = new Hashtable<String, Object>();
if (properties != null && properties.containsKey("os"))
props.put("os", properties.get("os"));
ServiceRegistration<org.eclipse.smarthome.io.multimedia.tts.TTSService> serviceReg = context
.registerService(
org.eclipse.smarthome.io.multimedia.tts.TTSService.class,
service, props);
delegates.put(ttsService.getClass().getName(), serviceReg);
}
}

private void unregisterDelegateService(TTSService service) {
if(delegates.containsKey(service.getClass().getName())) {
ServiceRegistration<org.eclipse.smarthome.io.multimedia.tts.TTSService> serviceReg =
delegates.get(service.getClass().getName());
if (delegates.containsKey(service.getClass().getName())) {
ServiceRegistration<org.eclipse.smarthome.io.multimedia.tts.TTSService> serviceReg = delegates
.get(service.getClass().getName());
delegates.remove(service.getClass().getName());
serviceReg.unregister();
}
Expand Down

0 comments on commit 549886a

Please sign in to comment.