[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r459 - /projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/configuration/ConfigurationService.java

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Mon Sep 24 17:20:01 CEST 2012


Author: manlio.bacco
Date: Mon Sep 24 17:20:01 2012
New Revision: 459

Log:
updating conf via ConfAdmin corrected
cosmetic fixes

Modified:
    projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/configuration/ConfigurationService.java

Modified: projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/configuration/ConfigurationService.java
==============================================================================
--- projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/configuration/ConfigurationService.java (original)
+++ projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/configuration/ConfigurationService.java Mon Sep 24 17:20:01 2012
@@ -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.zigbee.basedriver.configuration;
 
@@ -50,12 +50,12 @@
 public class ConfigurationService implements ManagedService {
 
 	public static final String PID = Constants.MANAGED_SERVICE_PID;	
-	
+
 	private final static Logger logger = LoggerFactory.getLogger(ConfigurationService.class);
-		
+
 	private final HashMap<String, Object> configuration = new HashMap<String, Object>();
 	private SimpleDriver driver;
-	
+
 	public ConfigurationService(){
 		synchronized (configuration) {
 			configuration.put(ConfigurationProperties.PAN_ID_KEY, OSGiProperties.getInt(Activator.getBundleContext(), ConfigurationProperties.PAN_ID_KEY, ConfigurationProperties.PAN_ID) );
@@ -64,72 +64,76 @@
 			configuration.put(ConfigurationProperties.COM_NAME_KEY, OSGiProperties.getString(Activator.getBundleContext(), ConfigurationProperties.COM_NAME_KEY, ConfigurationProperties.COM_NAME) );
 			configuration.put(ConfigurationProperties.NETWORK_MODE_KEY, NetworkMode.valueOf(OSGiProperties.getString(Activator.getBundleContext(), ConfigurationProperties.NETWORK_MODE_KEY, ConfigurationProperties.NETWORK_MODE)) );
 			configuration.put(ConfigurationProperties.NETWORK_FLUSH_KEY, OSGiProperties.getBoolean(Activator.getBundleContext(), ConfigurationProperties.NETWORK_FLUSH_KEY, ConfigurationProperties.NETWORK_FLUSH) );
-			
+
 			configuration.put(ConfigurationProperties.APPLICATION_MSG_RETRY_COUNT_KEY, OSGiProperties.getInt(Activator.getBundleContext(), ConfigurationProperties.APPLICATION_MSG_RETRY_COUNT_KEY, ConfigurationProperties.APPLICATION_MSG_RETRY_COUNT) );
 			configuration.put(ConfigurationProperties.APPLICATION_MSG_RETRY_DELAY_KEY, OSGiProperties.getInt(Activator.getBundleContext(), ConfigurationProperties.APPLICATION_MSG_RETRY_DELAY_KEY, ConfigurationProperties.APPLICATION_MSG_RETRY_DELAY) );
 			configuration.put(ConfigurationProperties.APPLICATION_MSG_TIMEOUT_KEY, OSGiProperties.getLong(Activator.getBundleContext(), ConfigurationProperties.APPLICATION_MSG_TIMEOUT_KEY, ConfigurationProperties.APPLICATION_MSG_TIMEOUT) );
-			
-            configuration.put(ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY, OSGiProperties.getLong(Activator.getBundleContext(), ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY, ConfigurationProperties.NETWORK_BROWSING_PERIOD) );
-            configuration.put(ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY, OSGiProperties.getLong(Activator.getBundleContext(), ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY, ConfigurationProperties.DEVICE_INSPECTION_PERIOD) );
-            
-            configuration.put(ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY, OSGiProperties.getInt(Activator.getBundleContext(), ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY, ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY) );
-            configuration.put(ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY, OSGiProperties.getInt(Activator.getBundleContext(), ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY, ConfigurationProperties.FIRST_ENDPOINT_ADDRESS) );
-		}
-		
+
+			configuration.put(ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY, OSGiProperties.getLong(Activator.getBundleContext(), ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY, ConfigurationProperties.NETWORK_BROWSING_PERIOD) );
+			configuration.put(ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY, OSGiProperties.getLong(Activator.getBundleContext(), ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY, ConfigurationProperties.DEVICE_INSPECTION_PERIOD) );
+
+			configuration.put(ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY, OSGiProperties.getInt(Activator.getBundleContext(), ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY, ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY) );
+			configuration.put(ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY, OSGiProperties.getInt(Activator.getBundleContext(), ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY, ConfigurationProperties.FIRST_ENDPOINT_ADDRESS) );
+
+			//configuration.put(ConfigurationProperties.PERMIT_JOIN_KEY, OSGiProperties.getBoolean(Activator.getBundleContext(), ConfigurationProperties.PERMIT_JOIN_KEY, ConfigurationProperties.PERMIT_JOIN) );
+		}
+
 		logger.debug("Initialized {} with {}", this, configuration);
 	}
-	
+
 	@SuppressWarnings("unchecked")
 	public void updated(Dictionary newConfig) throws ConfigurationException {
-		
+
 		logger.info("Updating configuration with {}", newConfig);
-		
+
 		if( newConfig == null ){
 			logger.debug("New configuration is null, avoiding to update it");
 			return;
 		}
-		
+
 		DictionaryHelper helper = new DictionaryHelper(newConfig);
-		boolean isChanged = false;
+		//boolean isChanged = false;
 		synchronized (this) {
-			isChanged = setInteger( ConfigurationProperties.PAN_ID_KEY, helper.getInt(ConfigurationProperties.PAN_ID_KEY, getPanId() ) );			
-			isChanged = setInteger( ConfigurationProperties.CHANNEL_ID_KEY, helper.getInt(ConfigurationProperties.CHANNEL_ID_KEY, getChannelId() ) );
-			isChanged = setInteger( ConfigurationProperties.COM_BOUDRATE_KEY, helper.getInt(ConfigurationProperties.COM_BOUDRATE_KEY, getSerialBoudRate() ) );
-			isChanged = setStringCaseSensitve( ConfigurationProperties.COM_NAME_KEY, helper.getString(ConfigurationProperties.COM_NAME_KEY, getSerialPortName() ) );
-			isChanged = setNetworkMode( ConfigurationProperties.NETWORK_MODE_KEY, NetworkMode.valueOf(helper.getString(ConfigurationProperties.NETWORK_MODE_KEY, getNetworkMode().toString()) ) );
-			isChanged = setBoolean( ConfigurationProperties.NETWORK_FLUSH_KEY ,helper.getBoolean(ConfigurationProperties.NETWORK_FLUSH_KEY, getForceNetworkCleaning() ) );			
-			
-			isChanged = setInteger( ConfigurationProperties.APPLICATION_MSG_RETRY_COUNT_KEY, helper.getInt(ConfigurationProperties.APPLICATION_MSG_RETRY_COUNT_KEY, getMessageRetryCount() ) );
-			isChanged = setInteger( ConfigurationProperties.APPLICATION_MSG_RETRY_DELAY_KEY, helper.getInt(ConfigurationProperties.APPLICATION_MSG_RETRY_DELAY_KEY, getMessageRetryDelay() ) );
-			isChanged = setLong( ConfigurationProperties.APPLICATION_MSG_TIMEOUT_KEY, helper.getLong(ConfigurationProperties.APPLICATION_MSG_TIMEOUT_KEY, getZigBeeTimeout() ) );
-			
-            setLong( ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY, helper.getLong(ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY, getNetworkBrowsingPeriod() ) );
-            setLong( ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY, helper.getLong(ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY, getDeviceInspectionPeriod() ) );
-            
-            setInteger( ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY, helper.getInt( ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY, getAutomaticFreeEndPointRetry() ) );
-            setInteger( ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY, helper.getInt( ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY, getFirstFreeEndPoint() ) );
-		}
-		
+			/*isChanged = */setInteger( ConfigurationProperties.PAN_ID_KEY, helper.getInt(ConfigurationProperties.PAN_ID_KEY, getPanId() ) );			
+			/*isChanged = */ setInteger( ConfigurationProperties.CHANNEL_ID_KEY, helper.getInt(ConfigurationProperties.CHANNEL_ID_KEY, getChannelId() ) );
+			/*isChanged = */ setInteger( ConfigurationProperties.COM_BOUDRATE_KEY, helper.getInt(ConfigurationProperties.COM_BOUDRATE_KEY, getSerialBoudRate() ) );
+			/*isChanged = */ setStringCaseSensitve( ConfigurationProperties.COM_NAME_KEY, helper.getString(ConfigurationProperties.COM_NAME_KEY, getSerialPortName() ) );
+			/*isChanged = */ setNetworkMode( ConfigurationProperties.NETWORK_MODE_KEY, NetworkMode.valueOf(helper.getString(ConfigurationProperties.NETWORK_MODE_KEY, getNetworkMode().toString()) ) );
+			/*isChanged = */ setBoolean( ConfigurationProperties.NETWORK_FLUSH_KEY ,helper.getBoolean(ConfigurationProperties.NETWORK_FLUSH_KEY, getForceNetworkCleaning() ) );			
+
+			/*isChanged = */ setInteger( ConfigurationProperties.APPLICATION_MSG_RETRY_COUNT_KEY, helper.getInt(ConfigurationProperties.APPLICATION_MSG_RETRY_COUNT_KEY, getMessageRetryCount() ) );
+			/*isChanged = */ setInteger( ConfigurationProperties.APPLICATION_MSG_RETRY_DELAY_KEY, helper.getInt(ConfigurationProperties.APPLICATION_MSG_RETRY_DELAY_KEY, getMessageRetryDelay() ) );
+			/*isChanged = */ setLong( ConfigurationProperties.APPLICATION_MSG_TIMEOUT_KEY, helper.getLong(ConfigurationProperties.APPLICATION_MSG_TIMEOUT_KEY, getZigBeeTimeout() ) );
+
+			/*isChanged = */  setLong( ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY, helper.getLong(ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY, getNetworkBrowsingPeriod() ) );
+			/*isChanged = */  setLong( ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY, helper.getLong(ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY, getDeviceInspectionPeriod() ) );
+
+			/*isChanged = */  setInteger( ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY, helper.getInt( ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY, getAutomaticFreeEndPointRetry() ) );
+			/*isChanged = */  setInteger( ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY, helper.getInt( ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY, getFirstFreeEndPoint() ) );
+
+			//isChanged =  setBoolean( ConfigurationProperties.PERMIT_JOIN_KEY ,helper.getBoolean(ConfigurationProperties.PERMIT_JOIN_KEY, getPermitJoin() ) );			
+		}
+
 		logger.debug("Current configuration after applying new configuration is {}", configuration);
-		
-		if(isChanged) {
-			logger.info("Configuration related to the dongle changed, updating it");
-			updateDriverConfiguration();
-		}
+
+		//if(isChanged) {
+		logger.info("Configuration related to the dongle changed, updating it.ss");
+		updateDriverConfiguration();
+		//}
 	}
 
 	private int getInt(String key){
 		return ((Integer) configuration.get(key)).intValue();
 	}
-	
+
 	private long getLong(String key){
 		return ((Long) configuration.get(key)).longValue();
 	}
-	
+
 	private boolean getBoolean(String key){
 		return ((Boolean) configuration.get(key)).booleanValue();
 	}
-	
+
 	private String getString(String key){
 		return (String) configuration.get(key);
 	}	
@@ -137,13 +141,13 @@
 	private NetworkMode getNetworkMode(String key){
 		return (NetworkMode) configuration.get(key);
 	}		
-	
+
 	private boolean setStringCaseInsensitve(String key, String value){
 		if( getString(key).equalsIgnoreCase(value) ) return false;
 		configuration.put(key, value);
 		return true;
 	}
-	
+
 	private boolean setStringCaseSensitve(String key, String value){
 		if( getString(key).compareTo(value) == 0) return false;
 		configuration.put(key, value);
@@ -167,13 +171,13 @@
 		configuration.put(key, value);
 		return true;
 	}
-	
+
 	private boolean setNetworkMode(String key, NetworkMode value){
 		if( getNetworkMode(key) == value ) return false;
 		configuration.put(key, value);
 		return true;
 	}	
-	
+
 	public synchronized short getPanId(){
 		return (short) getInt(ConfigurationProperties.PAN_ID_KEY);
 	}
@@ -189,7 +193,7 @@
 	public synchronized int getSerialBoudRate() {
 		return getInt(ConfigurationProperties.COM_BOUDRATE_KEY);
 	}		
-	
+
 	public synchronized NetworkMode getNetworkMode() {
 		return getNetworkMode(ConfigurationProperties.NETWORK_MODE_KEY);
 	}
@@ -197,7 +201,7 @@
 	public synchronized boolean getForceNetworkCleaning() {
 		return getBoolean(ConfigurationProperties.NETWORK_FLUSH_KEY);
 	}
-	
+
 	public synchronized int getMessageRetryCount() {
 		return getInt(ConfigurationProperties.APPLICATION_MSG_RETRY_COUNT_KEY);
 	}
@@ -209,6 +213,10 @@
 	public synchronized long getZigBeeTimeout() {
 		return getLong(ConfigurationProperties.APPLICATION_MSG_TIMEOUT_KEY);
 	}
+
+	/*public synchronized boolean getPermitJoin() {
+		return getBoolean(ConfigurationProperties.PERMIT_JOIN_KEY);
+	}*/
 
 	/**
 	 * This method configures the {@link SimpleDriver} and open it. Moreover it will start
@@ -226,7 +234,7 @@
 	}
 
 	private void updateDriverConfiguration() {
-		if ( driver.getDriverStatus() != DriverStatus.CLOSED ){
+		if ( driver != null && driver.getDriverStatus() != DriverStatus.CLOSED ){
 			logger.info("{} not configured nor started because its status is not equal to CLOSED", driver);
 			return;
 		}
@@ -234,33 +242,33 @@
 		driver.setSerialPort(getSerialPortName(), getSerialBoudRate());
 		driver.setZigBeeNetwork(getChannelId(), (short) getPanId());
 		driver.setZigBeeNodeMode(getNetworkMode());
+		//driver.setPermitJoin(getPermitJoin());
 		driver.open(Activator.getCurrentConfiguration().getForceNetworkCleaning());
 	}
 
-    public synchronized long getDeviceInspectionPeriod() {
-        return getLong(ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY);
-    }
-    
-    public synchronized long getNetworkBrowsingPeriod() {
-        return getLong(ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY);
-    }
-
-    /**
-     * 
-     * @return
-     * @since 0.6.0 - Revision 81
-     */
+	public synchronized long getDeviceInspectionPeriod() {
+		return getLong(ConfigurationProperties.DEVICE_INSPECTION_PERIOD_KEY);
+	}
+
+	public synchronized long getNetworkBrowsingPeriod() {
+		return getLong(ConfigurationProperties.NETWORK_BROWSING_PERIOD_KEY);
+	}
+
+	/**
+	 * 
+	 * @return
+	 * @since 0.6.0 - Revision 81
+	 */
 	public synchronized int getAutomaticFreeEndPointRetry() {
-        return getInt(ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY);
-	}
-
-    /**
-     * 
-     * @return
-     * @since 0.6.0 - Revision 86
-     */
+		return getInt(ConfigurationProperties.AUTOMATIC_ENDPOINT_ADDRESS_RETRY_KEY);
+	}
+
+	/**
+	 * 
+	 * @return
+	 * @since 0.6.0 - Revision 86
+	 */
 	public synchronized int getFirstFreeEndPoint() {
-        return getInt(ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY);
-	}
-    
-}
+		return getInt(ConfigurationProperties.FIRST_ENDPOINT_ADDRESS_KEY);
+	}
+}




More information about the Commit mailing list