Beispiel #1
0
  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());
  }
Beispiel #2
0
 public void setActionListener(ActionListener listener) {
   ActionList actionList = getActionList();
   int nActions = actionList.size();
   for (int n = 0; n < nActions; n++) {
     Action action = actionList.getAction(n);
     action.setActionListener(listener);
   }
 }
Beispiel #3
0
 public Action getAction(String actionName) {
   ActionList actionList = getActionList();
   int nActions = actionList.size();
   for (int n = 0; n < nActions; n++) {
     Action action = actionList.getAction(n);
     String name = action.getName();
     if (name == null) continue;
     if (name.equals(actionName) == true) return action;
   }
   return null;
 }
Beispiel #4
0
 void updateActionList(TreeNode parentNode, Service service) {
   ActionList actionList = service.getActionList();
   int nActions = actionList.size();
   for (int n = 0; n < nActions; n++) {
     Action action = actionList.getAction(n);
     String actionName = action.getName();
     TreeNode actionNode = new TreeNode(actionName);
     actionNode.setUserData(action);
     parentNode.add(actionNode);
     updateArgumentList(actionNode, action);
   }
 }
Beispiel #5
0
  public void addAction(Action a) {
    Iterator i = a.getArgumentList().iterator();
    while (i.hasNext()) {
      Argument arg = (Argument) i.next();
      arg.setService(this);
    }

    Node scdpNode = getSCPDNode();
    Node actionListNode = scdpNode.getNode(ActionList.ELEM_NAME);
    if (actionListNode == null) {
      actionListNode = new Node(ActionList.ELEM_NAME);
      scdpNode.addNode(actionListNode);
    }
    actionListNode.addNode(a.getActionNode());
  }
Beispiel #6
0
 void updateArgumentList(TreeNode parentNode, Action action) {
   ArgumentList argList = action.getArgumentList();
   int nArguments = argList.size();
   for (int n = 0; n < nArguments; n++) {
     Argument arg = argList.getArgument(n);
     String argName = arg.getName() + "(" + arg.getDirection() + ")";
     TreeNode argNode = new TreeNode(argName);
     argNode.setUserData(arg);
     parentNode.add(argNode);
   }
 }
Beispiel #7
0
 public ActionList getActionList() {
   ActionList actionList = new ActionList();
   Node scdpNode = getSCPDNode();
   if (scdpNode == null) return actionList;
   Node actionListNode = scdpNode.getNode(ActionList.ELEM_NAME);
   if (actionListNode == null) return actionList;
   int nNode = actionListNode.getNNodes();
   for (int n = 0; n < nNode; n++) {
     Node node = actionListNode.getNode(n);
     if (Action.isActionNode(node) == false) continue;
     Action action = new Action(serviceNode, node);
     actionList.add(action);
   }
   return actionList;
 }
Beispiel #8
0
 public Action(Action action) {
   this.serviceNode = action.getServiceNode();
   this.actionNode = action.getActionNode();
 }
Beispiel #9
-1
  public boolean actionControlReceived(Action action) {
    String actionName = action.getName();

    boolean ret = false;

    if (actionName.equals("GetPower") == true) {
      String state = getPowerState();
      Argument powerArg = action.getArgument("Power");
      powerArg.setValue(state);
      ret = true;
    }
    if (actionName.equals("SetPower") == true) {
      Argument powerArg = action.getArgument("Power");
      String state = powerArg.getValue();
      setPowerState(state);
      state = getPowerState();
      Argument resultArg = action.getArgument("Result");
      resultArg.setValue(state);
      ret = true;
    }

    comp.repaint();

    return ret;
  }