コード例 #1
0
ファイル: LightDevice.java プロジェクト: Zerak/CyberLink4Java
  public LightDevice() throws InvalidDescriptionException {
    super(new File(DESCRIPTION_FILE_NAME));
    setSSDPBindAddress(HostInterface.getInetAddress(HostInterface.IPV4_BITMASK, null));
    setHTTPBindAddress(HostInterface.getInetAddress(HostInterface.IPV4_BITMASK, null));

    Action getPowerAction = getAction("GetPower");
    getPowerAction.setActionListener(this);

    Action setPowerAction = getAction("SetPower");
    setPowerAction.setActionListener(this);

    ServiceList serviceList = getServiceList();
    Service service = serviceList.getService(0);
    service.setQueryListener(this);

    powerVar = getStateVariable("Power");

    Argument powerArg = getPowerAction.getArgument("Power");
    StateVariable powerState = powerArg.getRelatedStateVariable();
    AllowedValueList allowList = powerState.getAllowedValueList();
    for (int n = 0; n < allowList.size(); n++)
      System.out.println("[" + n + "] = " + allowList.getAllowedValue(n));

    AllowedValueRange allowRange = powerState.getAllowedValueRange();
    System.out.println("maximum = " + allowRange.getMaximum());
    System.out.println("minimum = " + allowRange.getMinimum());
    System.out.println("step = " + allowRange.getStep());
  }
コード例 #2
0
ファイル: ActionMessage.java プロジェクト: hszander/TomP2P
 /**
  * Set the value of an input parameter before a message service call
  *
  * @param parameterName the parameter name
  * @param parameterValue the date parameter value, will be automatically translated to the correct
  *     ISO 8601 date format for the given action input param related state variable
  * @return the current ActionMessage object instance
  * @throws IllegalArgumentException if the provided parameterName is not valid for this message or
  *     if no input parameters are required for this message
  */
 public ActionMessage setInputParameter(String parameterName, Date parameterValue)
     throws IllegalArgumentException {
   if (serviceAction.getInputActionArguments() == null) {
     throw new IllegalArgumentException("No input parameters required for this message");
   }
   Argument arg = serviceAction.getInputActionArgument(parameterName);
   if (arg == null) {
     throw new IllegalArgumentException(
         "Wrong input argument name for this action:"
             + parameterName
             + " available parameters are : "
             + serviceAction.getInputActionArguments());
   }
   StateVariable linkedVar = arg.getRelatedStateVariable();
   if (linkedVar.dataType.equals(StateVariableTypes.TIME)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoTime(parameterValue));
   } else if (linkedVar.dataType.equals(StateVariableTypes.TIME_TZ)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoTimeZone(parameterValue));
   } else if (linkedVar.dataType.equals(StateVariableTypes.DATE)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoDate(parameterValue));
   } else if (linkedVar.dataType.equals(StateVariableTypes.DATETIME)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoDateTime(parameterValue));
   } else if (linkedVar.dataType.equals(StateVariableTypes.DATETIME_TZ)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoDateTimeZone(parameterValue));
   } else {
     throw new IllegalArgumentException(
         "Related input state variable " + linkedVar.name + " is not of an date type");
   }
 }