[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r995 - in /projects/zb4osgi/sandbox/giancarlo.riolo: zigbee.common/src/main/java/it/cnr/isti/osgi/util/ zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/ zigbee.tester/configurations/factories/ zigbee.tester/configurations/services/
scm-notify at zb4osgi.aaloa.org
scm-notify at zb4osgi.aaloa.org
Thu Apr 10 19:03:00 CEST 2014
Author: giancarlo.riolo
Date: Thu Apr 10 19:03:00 2014
New Revision: 995
Log:
noGUI
Added:
projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.tester/configurations/services/it.cnr.isti.zigbee.noGUI.reporting.configuration.properties
- copied, changed from r992, projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.tester/configurations/services/it.cnr.isti.zigbee.noGUI.reporting.configuration.properties
Modified:
projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.common/src/main/java/it/cnr/isti/osgi/util/DictionaryHelper.java
projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.common/src/main/java/it/cnr/isti/osgi/util/OSGiProperties.java
projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/DeviceMonitor.java
projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/DeviceProvider.java
projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/ReportingConfiguratorDaemon.java
projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/TesterConfiguration.java
projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.tester/configurations/factories/org.apache.felix.fileinstall.properties
Modified: projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.common/src/main/java/it/cnr/isti/osgi/util/DictionaryHelper.java
==============================================================================
--- projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.common/src/main/java/it/cnr/isti/osgi/util/DictionaryHelper.java (original)
+++ projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.common/src/main/java/it/cnr/isti/osgi/util/DictionaryHelper.java Thu Apr 10 19:03:00 2014
@@ -18,7 +18,7 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-*/
+ */
package it.cnr.isti.osgi.util;
@@ -26,73 +26,75 @@
/**
*
* @author <a href="mailto:stefano.lenzi at isti.cnr.it">Stefano "Kismet" Lenzi</a>
- * @version $LastChangedRevision$ ($LastChangedDate$)
- *
+ * @version $LastChangedRevision$ ($LastChangedDate: 2013-08-06 18:00:05
+ * +0200(mar, 06 ago 2013) $)
+ *
*/
public class DictionaryHelper {
private Dictionary<Object, Object> dictionary;
-
- public DictionaryHelper(Dictionary<Object, Object> dictionary){
- if(dictionary == null){
+
+ public DictionaryHelper(Dictionary<Object, Object> dictionary) {
+ if (dictionary == null) {
throw new NullPointerException("Can't wrap a null object");
}
-
+
this.dictionary = dictionary;
}
- public String getString(String property){
+ public String getString(String property) {
return (String) dictionary.get(property);
}
- public String getString(String property, String defaultValue){
+ public String getString(String property, String defaultValue) {
String value = (String) dictionary.get(property);
return value == null ? defaultValue : value;
}
-
- public int getInt(String property){
+
+ public int getInt(String property) {
String value = (String) dictionary.get(property);
return Integer.parseInt(value);
}
- public int getInt(String property, int defaultValue){
+ public int getInt(String property, int defaultValue) {
String value = (String) dictionary.get(property);
return value == null ? defaultValue : Integer.parseInt(value);
}
-
- public boolean getBoolean(String property){
+
+ public boolean getBoolean(String property) {
String value = (String) dictionary.get(property);
- if( value == null){
- throw new NullPointerException("Property "+property+" doesn't exist");
- }else if( value.equalsIgnoreCase("true") ){
+ if (value == null) {
+ throw new NullPointerException("Property " + property
+ + " doesn't exist");
+ } else if (value.equalsIgnoreCase("true")) {
return true;
- }else if( value.equalsIgnoreCase("on") ){
+ } else if (value.equalsIgnoreCase("on")) {
return true;
- }else if( value.equalsIgnoreCase("yes") ){
+ } else if (value.equalsIgnoreCase("yes")) {
return true;
- }else{
+ } else {
return false;
}
- }
- public boolean getBoolean(String property, boolean defaultValue){
+ }
+ public boolean getBoolean(String property, boolean defaultValue) {
String value = (String) dictionary.get(property);
- if( value == null){
+ if (value == null) {
return defaultValue;
- }else if( value.equalsIgnoreCase("true") ){
+ } else if (value.equalsIgnoreCase("true")) {
return true;
- }else if( value.equalsIgnoreCase("on") ){
+ } else if (value.equalsIgnoreCase("on")) {
return true;
- }else if( value.equalsIgnoreCase("yes") ){
+ } else if (value.equalsIgnoreCase("yes")) {
return true;
- }else{
+ } else {
return false;
}
}
- public long getLong(String property){
+ public long getLong(String property) {
String value = (String) dictionary.get(property);
return Long.parseLong(value);
}
-
- public long getLong(String property, long defaultValue){
+
+ public long getLong(String property, long defaultValue) {
String value = (String) dictionary.get(property);
return value == null ? defaultValue : Long.parseLong(value);
}
@@ -101,7 +103,13 @@
String value = (String) dictionary.get(property);
return value == null ? defaultValue : Double.parseDouble(value);
}
-
-
-
+
+ /**
+ *
+ */
+ public int size() {
+ return dictionary.size();
+
+ }
+
}
Modified: projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.common/src/main/java/it/cnr/isti/osgi/util/OSGiProperties.java
==============================================================================
--- projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.common/src/main/java/it/cnr/isti/osgi/util/OSGiProperties.java (original)
+++ projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.common/src/main/java/it/cnr/isti/osgi/util/OSGiProperties.java Thu Apr 10 19:03:00 2014
@@ -126,4 +126,6 @@
String value = bundle == null ? null : bundle.getProperty(property);
return value == null ? defaultValue : Double.parseDouble(value);
}
+
+
}
Modified: projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/DeviceMonitor.java
==============================================================================
--- projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/DeviceMonitor.java (original)
+++ projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/DeviceMonitor.java Thu Apr 10 19:03:00 2014
@@ -22,7 +22,8 @@
package it.cnr.isti.zb4osgi.zigbee.noGUI.tester;
-import java.util.ArrayList;
+import it.cnr.isti.zigbee.ha.driver.core.HADevice;
+
import java.util.List;
import org.osgi.framework.BundleContext;
@@ -33,12 +34,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* @author <a href="mailto:giancarlo.riolo at isti.cnr.it">Giancarlo Riolo</a>
* @author <a href="mailto:luigi.fortunati at isti.cnr.it">Luigi Fortunati</a>
*/
-
class DeviceMonitor {
@@ -51,14 +50,16 @@
private DeviceListener deviceListener = null;
+ private List<ServiceReference> availableServiceRefs;
+
public DeviceMonitor(BundleContext context) {
this.context = context;
this.refinedDeviceProvider = new DeviceProvider(context);
}
- public void startListeningForDevices() {
- //TODO HADevice ---> RefinedDevice
+ public void createDeviceListener() {
+ // TODO HADevice ---> RefinedDevice
String refinedDeviceFilter = "(objectClass=it.cnr.isti.zigbee.ha.driver.core.HADevice)";
try {
deviceListener = new DeviceListener();
@@ -70,20 +71,17 @@
}
public void start() {
- startListeningForDevices();
- registerMissedDevices();
+ createDeviceListener();
+ registerDevices();
+
}
public void stop() {
unregisterServiceListener();
-
}
- private void registerMissedDevices() {
- List<ServiceReference> availableServiceRefs = refinedDeviceProvider
- .getHADeviceServiceRefs();
- List<ServiceReference> servicesRefsToRegister = new ArrayList<ServiceReference>(
- availableServiceRefs);
+ private void registerDevices() {
+ setAvailableServiceRefs(refinedDeviceProvider.getDeviceServiceRefs());
}
@@ -92,18 +90,48 @@
log.debug(DeviceMonitor.class.getSimpleName() + " unregistered");
}
+ public List<ServiceReference> getAvailableServiceRefs() {
+ return availableServiceRefs;
+ }
+
+ public void setAvailableServiceRefs(
+ List<ServiceReference> availableServiceRefs) {
+ this.availableServiceRefs = availableServiceRefs;
+ }
+
private class DeviceListener implements ServiceListener {
public void serviceChanged(ServiceEvent event) {
log.trace(String.format("Caught %s(%s): %s",
ServiceEvent.class.getName(), event.getType(), event));
ServiceReference serviceRef = event.getServiceReference();
- if (event.getType() == ServiceEvent.REGISTERED) {
+ switch (event.getType()) {
+ case ServiceEvent.MODIFIED :
+ log.debug("Refined Device MODIFIED");
+ break;
+ case ServiceEvent.REGISTERED :
+ log.debug("Refined Device REGISTERED");
+ addDevice(serviceRef);
+ break;
+ case ServiceEvent.UNREGISTERING :
+ log.debug("Refined Device UNREGISTERING");
+ removeDevice(serviceRef);
+ break;
+ default :
+ break;
+ }
- } else if (event.getType() == ServiceEvent.UNREGISTERING) {
+ }
- }
- }
+ }
+
+ private void addDevice(ServiceReference serviceReference) {
+ availableServiceRefs.add(context.getServiceReference(HADevice.class.getName()));
+ }
+
+ public void removeDevice(ServiceReference serviceReference) {
+ availableServiceRefs.remove(context
+ .getServiceReference(HADevice.class.getName()));
}
}
Modified: projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/DeviceProvider.java
==============================================================================
--- projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/DeviceProvider.java (original)
+++ projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/DeviceProvider.java Thu Apr 10 19:03:00 2014
@@ -55,7 +55,7 @@
*
* @return
*/
- public List<ServiceReference> getHADeviceServiceRefs() {
+ public List<ServiceReference> getDeviceServiceRefs() {
ServiceReference[] serviceRefs = new ServiceReference[0];
try {
serviceRefs = context.getServiceReferences(
@@ -64,8 +64,9 @@
log.error("Error occurred while getting "
+ HADevice.class.getSimpleName() + " service references.");
}
- if (serviceRefs == null)
+ if (serviceRefs == null) {
return new ArrayList<ServiceReference>();
+ }
return Arrays.asList(serviceRefs);
}
@@ -90,7 +91,7 @@
* @return
*/
public List<HADevice> getHADevices() {
- return getHADevices(getHADeviceServiceRefs());
+ return getHADevices(getDeviceServiceRefs());
}
}
Modified: projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/ReportingConfiguratorDaemon.java
==============================================================================
--- projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/ReportingConfiguratorDaemon.java (original)
+++ projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/ReportingConfiguratorDaemon.java Thu Apr 10 19:03:00 2014
@@ -59,17 +59,18 @@
monitor.start();
log.info(ReportingConfiguratorDaemon.class.getName() + ": STARTED");
doRegisterConfigurationService(context);
+
}
private void doRegisterConfigurationService(BundleContext context) {
Properties properties = new Properties();
-
properties.setProperty(Constants.SERVICE_PID, NOGUI_CONFIG_PID);
-
configuration = new TesterConfiguration(context);
+ log.info(ManagedService.class.getName() + " STARTING");
configRegistration = context.registerService(
ManagedService.class.getName(), getCurrentConfiguration(),
properties);
+ log.info(ManagedService.class.getName() + ": STARTED");
}
@@ -80,6 +81,11 @@
}
public void stop() {
+
+ log.info(ManagedService.class.getName() + " STOPPING");
+ configRegistration.unregister();
+ log.debug(ManagedService.class.getSimpleName() + " unregistered");
+ log.info(ManagedService.class.getName() + ": STOPPED");
log.info(ReportingConfiguratorDaemon.class.getName() + " STOPPING");
monitor.stop();
log.info(ReportingConfiguratorDaemon.class.getName() + " STOPPED");
Modified: projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/TesterConfiguration.java
==============================================================================
--- projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/TesterConfiguration.java (original)
+++ projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/TesterConfiguration.java Thu Apr 10 19:03:00 2014
@@ -23,8 +23,8 @@
package it.cnr.isti.zb4osgi.zigbee.noGUI.tester;
import it.cnr.isti.osgi.util.DictionaryHelper;
-import it.cnr.isti.osgi.util.OSGiProperties;
+import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
@@ -51,11 +51,7 @@
public TesterConfiguration(BundleContext bundleContext) {
context = bundleContext;
synchronized (configuration) {
- configuration
- .put("ciao", OSGiProperties.getInt(context, "ciao", 0));
-
logger.debug("Initialized {} with {}", this, configuration);
-
}
}
@@ -70,10 +66,10 @@
}
DictionaryHelper helper = new DictionaryHelper(newConfig);
- boolean isChanged = false;
synchronized (this) {
- isChanged = setInteger("ciao", helper.getInt("ciao")) || isChanged;
-
+ for (int i = 0; i < helper.size(); i++) {
+ setString("Reporting_" + i, helper.getString("Reporting_" + i));
+ }
logger.debug(
"Current configuration after applying new configuration is {}",
configuration);
@@ -81,42 +77,21 @@
}
- private int getInt(String key) {
- return ((Integer) configuration.get(key)).intValue();
- }
-
- private long getLong(String key) {
- return ((Long) configuration.get(key)).longValue();
- }
-
- private double getDouble(String key) {
- return ((Double) configuration.get(key)).doubleValue();
- }
-
- private boolean getBoolean(String key) {
- return ((Boolean) configuration.get(key)).booleanValue();
+ private ArrayList<String[]> doParseConfiguration() {
+ ArrayList<String[]> list = new ArrayList<String[]>();
+ for (String key : configuration.keySet()) {
+ String[] reporting = ((String) configuration.get(key)).split(",");
+ list.add(reporting);
+ }
+ return list;
}
private String getString(String key) {
return (String) configuration.get(key);
}
- private boolean setInteger(String key, int value) {
- if (getInt(key) == value)
- return false;
- configuration.put(key, value);
- return true;
- }
-
- private boolean setBoolean(String key, boolean value) {
- if (getBoolean(key) == value)
- return false;
- configuration.put(key, value);
- return true;
- }
-
- private boolean setDouble(String key, double value) {
- if (getDouble(key) == value)
+ private boolean setString(String key, String value) {
+ if (getString(key) == value)
return false;
configuration.put(key, value);
return true;
Modified: projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.tester/configurations/factories/org.apache.felix.fileinstall.properties
==============================================================================
--- projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.tester/configurations/factories/org.apache.felix.fileinstall.properties (original)
+++ projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.tester/configurations/factories/org.apache.felix.fileinstall.properties Thu Apr 10 19:03:00 2014
@@ -1,10 +1,11 @@
-#service.pid=org.apache.felix.fileinstall
-#instances=1
-#keys=felix.fileinstall.poll,felix.fileinstall.log.level,felix.fileinstall.dir,felix.fileinstall.enableConfigSave
-#felix.fileinstall.poll.1=1000
-#felix.fileinstall.log.level.1=4
-#felix.fileinstall.dir.1=../target
-#felix.fileinstall.enableConfigSave.1=false
+service.pid=org.apache.felix.fileinstall
+instances=1
+keys=felix.fileinstall.poll,felix.fileinstall.log.level,felix.fileinstall.dir,felix.fileinstall.enableConfigSave
+
+felix.fileinstall.poll=1000
+felix.fileinstall.log.level=4
+felix.fileinstall.dir=../configurations/services
+felix.fileinstall.enableConfigSave=false
#felix.fileinstall.poll.2=1000
#felix.fileinstall.log.level.2=4
More information about the Commit
mailing list