@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("(").append(getClass().getSimpleName()); sb.append(", Name: ").append(getName()); sb.append(", Type: ").append(getTypeDetails().getDatatype().getDisplayString()).append(")"); if (!getEventDetails().isSendEvents()) { sb.append(" (No Events)"); } if (getTypeDetails().getDefaultValue() != null) { sb.append(" Default Value: ").append("'").append(getTypeDetails().getDefaultValue()).append("'"); } if (getTypeDetails().getAllowedValues() != null) { sb.append(" Allowed Values: "); for (String s : getTypeDetails().getAllowedValues()) { sb.append(s).append("|"); } } return sb.toString(); } }
public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList<>(); if (getName() == null || getName().length() == 0) { errors.add(new ValidationError( getClass(), "name", "StateVariable without name of: " + getService() )); } else if (!ModelUtil.isValidUDAName(getName())) { log.warning("UPnP specification violation of: " + getService().getDevice()); log.warning("Invalid state variable name: " + this); } errors.addAll(getTypeDetails().validate()); return errors; }
public StateVariable<S> deepCopy() { return new StateVariable( getName(), getTypeDetails(), getEventDetails() ); }
public Service(ServiceType serviceType, ServiceId serviceId, Action<S>[] actions, StateVariable<S>[] stateVariables) throws ValidationException { this.serviceType = serviceType; this.serviceId = serviceId; if (actions != null) { for (Action action : actions) { this.actions.put(action.getName(), action); action.setService(this); } } if (stateVariables != null) { for (StateVariable stateVariable : stateVariables) { this.stateVariables.put(stateVariable.getName(), stateVariable); stateVariable.setService(this); } } }
protected StateVariable getStateVariable(String name) { for (StateVariable stateVariable : getStateVariables().keySet()) { if (stateVariable.getName().equals(name)) { return stateVariable; } } return null; }
String stateVariableName = stateVariableValue.getStateVariable().getName(); if (stateVariable.getEventDetails().getEventMaximumRateMilliseconds() == 0 && stateVariable.getEventDetails().getEventMinimumDelta() == 0) { log.finer("Variable is not moderated: " + stateVariable); continue; if (stateVariable.getEventDetails().getEventMaximumRateMilliseconds() > 0) { long timestampLastSent = lastSentTimestamp.get(stateVariableName); long timestampNextSend = timestampLastSent + (stateVariable.getEventDetails().getEventMaximumRateMilliseconds()); if (currentTime <= timestampNextSend) { log.finer("Excluding state variable with maximum rate: " + stateVariable); if (stateVariable.isModeratedNumericType() && lastSentNumericValue.get(stateVariableName) != null) { long minDelta = stateVariable.getEventDetails().getEventMinimumDelta();
public LocalGENASubscription(LocalService service, Integer requestedDurationSeconds, List<URL> callbackURLs) throws Exception { super(service); setSubscriptionDuration(requestedDurationSeconds); log.fine("Reading initial state of local service at subscription time"); long currentTime = new Date().getTime(); this.currentValues.clear(); Collection<StateVariableValue> values = getService().getManager().getCurrentState(); log.finer("Got evented state variable values: " + values.size()); for (StateVariableValue value : values) { this.currentValues.put(value.getStateVariable().getName(), value); if (log.isLoggable(Level.FINEST)) { log.finer("Read state variable value '" + value.getStateVariable().getName() + "': " + value.toString()); } // Preserve "last sent" state for future moderation lastSentTimestamp.put(value.getStateVariable().getName(), currentTime); if (value.getStateVariable().isModeratedNumericType()) { lastSentNumericValue.put(value.getStateVariable().getName(), Long.valueOf(value.toString())); } } this.subscriptionId = SubscriptionIdHeader.PREFIX + UUID.randomUUID(); this.currentSequence = new UnsignedIntegerFourBytes(0); this.callbackURLs = callbackURLs; }
public StateVariableValue(StateVariable<S> stateVariable, Object value) throws InvalidValueException { super(stateVariable.getTypeDetails().getDatatype(), value); this.stateVariable = stateVariable; }
public boolean isModeratedNumericType() { return Datatype.Builtin.isNumeric( getTypeDetails().getDatatype().getBuiltin() ) && getEventDetails().getEventMinimumDelta() > 0; }
@Override public void onQueryStateVariable(StateVariable stateVar) { Action action = stateVar.getService().getQueryStateVariableAction(); actionInvocationRequestEvent.fire(new InvokeAction( action, new ActionArgumentValue( action.getInputArgument(QueryStateVariableAction.INPUT_ARG_VAR_NAME), stateVar.getName() // The literal variable name is the argument ) )); }
protected Collection<StateVariableValue> getCurrentState(String[] variableNames) throws Exception { lock(); try { Collection<StateVariableValue> values = new ArrayList<>(); for (String variableName : variableNames) { variableName = variableName.trim(); StateVariable stateVariable = getService().getStateVariable(variableName); if (stateVariable == null || !stateVariable.getEventDetails().isSendEvents()) { log.fine("Ignoring unknown or non-evented state variable: " + variableName); continue; } StateVariableAccessor accessor = getService().getAccessor(stateVariable); if (accessor == null) { log.warning("Ignoring evented state variable without accessor: " + variableName); continue; } values.add(accessor.read(stateVariable, getImplementation())); } return values; } finally { unlock(); } }
public StateVariable<S> getStateVariable(String name) { // Some magic necessary for the deprecated 'query state variable' action stuff if (QueryStateVariableAction.VIRTUAL_STATEVARIABLE_INPUT.equals(name)) { return new StateVariable( QueryStateVariableAction.VIRTUAL_STATEVARIABLE_INPUT, new StateVariableTypeDetails(Datatype.Builtin.STRING.getDatatype()) ); } if (QueryStateVariableAction.VIRTUAL_STATEVARIABLE_OUTPUT.equals(name)) { return new StateVariable( QueryStateVariableAction.VIRTUAL_STATEVARIABLE_OUTPUT, new StateVariableTypeDetails(Datatype.Builtin.STRING.getDatatype()) ); } return stateVariables == null ? null : stateVariables.get(name); }
stateVariable.getService().getManager().execute(cmd); return new StateVariableValue(stateVariable, cmd.result);
errors.addAll(stateVariable.validate());
public Object getValueAt(int row, int column) { if (column == 0) { return values.get(row).getStateVariable().getName(); } return getValueAt(row); }
String stateVariableName = stateVariableValue.getStateVariable().getName(); if (stateVariable.getEventDetails().getEventMaximumRateMilliseconds() == 0 && stateVariable.getEventDetails().getEventMinimumDelta() == 0) { log.finer("Variable is not moderated: " + stateVariable); continue; if (stateVariable.getEventDetails().getEventMaximumRateMilliseconds() > 0) { long timestampLastSent = lastSentTimestamp.get(stateVariableName); long timestampNextSend = timestampLastSent + (stateVariable.getEventDetails().getEventMaximumRateMilliseconds()); if (currentTime <= timestampNextSend) { log.finer("Excluding state variable with maximum rate: " + stateVariable); if (stateVariable.isModeratedNumericType() && lastSentNumericValue.get(stateVariableName) != null) { long minDelta = stateVariable.getEventDetails().getEventMinimumDelta();
String name = newValue.getStateVariable().getName(); if (!excludedVariables.contains(name)) { log.fine("Adding state variable value to current values of event: " + newValue.getStateVariable() + " = " + newValue); currentValues.put(newValue.getStateVariable().getName(), newValue); if (newValue.getStateVariable().isModeratedNumericType()) { lastSentNumericValue.put(name, Long.valueOf(newValue.toString()));
public Datatype<S> getDatatype(ActionArgument argument) { return getRelatedStateVariable(argument).getTypeDetails().getDatatype(); }
public boolean isModeratedNumericType() { return Datatype.Builtin.isNumeric( getTypeDetails().getDatatype().getBuiltin() ) && getEventDetails().getEventMinimumDelta() > 0; }
public Service(ServiceType serviceType, ServiceId serviceId, Action<S>[] actions, StateVariable<S>[] stateVariables) throws ValidationException { this.serviceType = serviceType; this.serviceId = serviceId; if (actions != null) { for (Action action : actions) { this.actions.put(action.getName(), action); action.setService(this); } } if (stateVariables != null) { for (StateVariable stateVariable : stateVariables) { this.stateVariables.put(stateVariable.getName(), stateVariable); stateVariable.setService(this); } } }