public DeviceTwin(DeviceIO client, DeviceClientConfig config, IotHubEventCallback deviceTwinCallback, Object deviceTwinCallbackContext, TwinPropertyCallBack genericPropertyCallback, Object genericPropertyCallbackContext) { deviceTwinInternal(client, config, deviceTwinCallback, deviceTwinCallbackContext, genericPropertyCallbackContext); /* **Codes_SRS_DEVICETWIN_21_004: [**The constructor shall save the generic property callback.**]** */ this.deviceTwinGenericTwinPropertyChangeCallback = genericPropertyCallback; this.deviceTwinGenericPropertyChangeCallback = null; }
public synchronized void updateReportedProperties(Set<Property> reportedProperties) throws IOException { this.updateReportedProperties(reportedProperties, null); }
private void OnDesiredPropertyChanged(TwinCollection desiredPropertyMap) { synchronized (DEVICE_TWIN_LOCK) { if (desiredPropertyMap != null) { for (Iterator desiredPropertyIt = desiredPropertyMap.entrySet().iterator(); desiredPropertyIt.hasNext();) { Map.Entry<String, String> desiredProperty = (Map.Entry<String, String>) desiredPropertyIt.next(); Property property = this.getProperty(desiredPropertyMap, desiredProperty.getKey(), false); /* **Codes_SRS_DEVICETWIN_25_022: [**OnDesiredPropertyChange callback shall look for the user registered call back on the property that changed provided in desiredPropertyMap and call the user providing the desired property change key and value pair**]** */ if (!reportPropertyCallback(property)) { /* **Codes_SRS_DEVICETWIN_25_023: [**OnDesiredPropertyChange callback shall look for the user registered call back on the property that changed and if no callback is registered or is null then OnDesiredPropertyChange shall call the user on generic callback providing with the desired property change key and value pair**]** */ reportDeviceTwinGenericPropertyCallback(property); } desiredPropertyIt.remove(); } } } }
twin = new DeviceTwin(this.deviceIO, this.config, twinStatusCallback, twinStatusCallbackContext, genericPropertyCallBack, genericPropertyCallBackContext); twin.getDeviceTwin();
public void subscribeDesiredPropertiesNotification(Map<Property, Pair<PropertyCallBack<String, Object>, Object>> onDesiredPropertyChange) { if (onDesiredPropertyChangeMap == null) { /* **Codes_SRS_DEVICETWIN_25_017: [**The method shall create a treemap to store callbacks for desired property notifications specified in onDesiredPropertyChange.**]** */ onDesiredPropertyChangeMap = new ConcurrentSkipListMap<>(); } if (onDesiredPropertyChange != null) { for (Map.Entry<Property, Pair<PropertyCallBack<String, Object>, Object>> desired : onDesiredPropertyChange.entrySet()) { onDesiredPropertyChangeMap.put(desired.getKey().getKey(), desired.getValue()); } } checkSubscription(); }
/** * Get the current desired properties for this client * @throws IOException if the iot hub cannot be reached * @throws IOException if the twin has not been initialized yet * @throws IOException if the client has not been opened yet */ void getTwinInternal() throws IOException { if (this.twin == null) { //Codes_SRS_INTERNALCLIENT_21_040: [If the client has not started twin before calling this method, the function shall throw an IOException.] throw new IOException("Start twin before using it"); } if (!this.deviceIO.isOpen()) { //Codes_SRS_INTERNALCLIENT_21_041: [If the client has not been open, the function shall throw an IOException.] throw new IOException("Open the client connection before using it."); } //Codes_SRS_INTERNALCLIENT_21_042: [The function shall get all desired properties by calling getDeviceTwin.] this.twin.getDeviceTwin(); }
/** * Subscribes to desired properties * * @param onDesiredPropertyChange the Map for desired properties and their corresponding callback and context. Can be {@code null}. * * @throws IOException if called when client is not opened or called before starting twin. */ public void subscribeToTwinDesiredProperties(Map<Property, Pair<TwinPropertyCallBack, Object>> onDesiredPropertyChange) throws IOException { if (this.twin == null) { //Codes_SRS_INTERNALCLIENT_34_087: [If the client has not started twin before calling this method, the function shall throw an IOException.] throw new IOException("Start twin before using it"); } if (!this.deviceIO.isOpen()) { //Codes_SRS_INTERNALCLIENT_34_086: [If the client has not been open, the function shall throw an IOException.] throw new IOException("Open the client connection before using it."); } //Codes_SRS_INTERNALCLIENT_34_085: [This method shall subscribe to desired properties by calling subscribeDesiredPropertiesNotification on the twin object.] this.twin.subscribeDesiredPropertiesTwinPropertyNotification(onDesiredPropertyChange); }
/** * Subscribes to desired properties * * @param onDesiredPropertyChange the Map for desired properties and their corresponding callback and context. Can be {@code null}. * * @throws IOException if called when client is not opened or called before starting twin. */ public void subscribeToDesiredProperties(Map<Property, Pair<PropertyCallBack<String, Object>, Object>> onDesiredPropertyChange) throws IOException { if (this.twin == null) { //Codes_SRS_INTERNALCLIENT_25_029: [If the client has not started twin before calling this method, the function shall throw an IOException.] throw new IOException("Start twin before using it"); } if (!this.deviceIO.isOpen()) { //Codes_SRS_INTERNALCLIENT_25_030: [If the client has not been open, the function shall throw an IOException.] throw new IOException("Open the client connection before using it."); } //Codes_SRS_INTERNALCLIENT_25_031: [This method shall subscribe to desired properties by calling subscribeDesiredPropertiesNotification on the twin object.] this.twin.subscribeDesiredPropertiesNotification(onDesiredPropertyChange); }
private void OnReportedPropertyChanged(TwinCollection reportedPropertyMap) { synchronized (DEVICE_TWIN_LOCK) { if (reportedPropertyMap != null) { for (Iterator reportedPropertyIt = reportedPropertyMap.entrySet().iterator(); reportedPropertyIt.hasNext();) { Map.Entry<String, String> reportedProperty = (Map.Entry<String, String>) reportedPropertyIt.next(); Property property = this.getProperty(reportedPropertyMap, reportedProperty.getKey(), true); /* **Codes_SRS_DEVICETWIN_25_023: [**OnReportedPropertyChanged callback shall look for the user registered call back on the property that changed and if no callback is registered or is null then OnDesiredPropertyChange shall call the user on generic callback providing with the desired property change key and value pair**]** */ if(deviceTwinGenericTwinPropertyChangeCallback != null) { deviceTwinGenericTwinPropertyChangeCallback.TwinPropertyCallBack(property, deviceTwinGenericPropertyChangeCallbackContext); } reportedPropertyIt.remove(); } } } }
twin = new DeviceTwin( this.deviceIO, this.config, genericPropertyCallBackContext); twin.getDeviceTwin();
public void subscribeDesiredPropertiesTwinPropertyNotification(Map<Property, Pair<TwinPropertyCallBack, Object>> onDesiredPropertyChange) { if (onDesiredTwinPropertyChangeMap == null) { /* **Codes_SRS_DEVICETWIN_25_017: [**The method shall create a treemap to store callbacks for desired property notifications specified in onDesiredPropertyChange.**]** */ onDesiredTwinPropertyChangeMap = new ConcurrentSkipListMap<>(); } if (onDesiredPropertyChange != null) { for (Map.Entry<Property, Pair<TwinPropertyCallBack, Object>> desired : onDesiredPropertyChange.entrySet()) { onDesiredTwinPropertyChangeMap.put(desired.getKey().getKey(), desired.getValue()); } } checkSubscription(); }
/** * Sends reported properties * * @param reportedProperties the Set for desired properties and their corresponding callback and context. Cannot be {@code null}. * * @throws IOException if called when client is not opened or called before starting twin. * @throws IllegalArgumentException if reportedProperties is null or empty. */ public void sendReportedProperties(Set<Property> reportedProperties) throws IOException, IllegalArgumentException { if (this.twin == null) { throw new IOException("Start twin before using it"); } if (!this.deviceIO.isOpen()) { throw new IOException("Open the client connection before using it."); } if (reportedProperties == null || reportedProperties.isEmpty()) { throw new IllegalArgumentException("Reported properties set cannot be null or empty."); } this.twin.updateReportedProperties(reportedProperties); }
public DeviceTwin(DeviceIO client, DeviceClientConfig config, IotHubEventCallback deviceTwinCallback, Object deviceTwinCallbackContext, PropertyCallBack genericPropertyCallback, Object genericPropertyCallbackContext) { deviceTwinInternal(client, config, deviceTwinCallback, deviceTwinCallbackContext, genericPropertyCallbackContext); /* **Codes_SRS_DEVICETWIN_21_004: [**The constructor shall save the generic property callback.**]** */ this.deviceTwinGenericPropertyChangeCallback = genericPropertyCallback; this.deviceTwinGenericTwinPropertyChangeCallback = null; }
/** * Sends reported properties * * @param reportedProperties the Set for desired properties and their corresponding callback and context. Cannot be {@code null}. * @param version the Reported property version. Cannot be negative. * * @throws IOException if called when client is not opened or called before starting twin. * @throws IllegalArgumentException if reportedProperties is null or empty. */ public void sendReportedProperties(Set<Property> reportedProperties, int version) throws IOException, IllegalArgumentException { if (this.twin == null) { throw new IOException("Start twin before using it"); } if (!this.deviceIO.isOpen()) { throw new IOException("Open the client connection before using it."); } if (reportedProperties == null || reportedProperties.isEmpty()) { throw new IllegalArgumentException("Reported properties set cannot be null or empty."); } if(version < 0) { throw new IllegalArgumentException("Version cannot be null."); } this.twin.updateReportedProperties(reportedProperties, version); }