Package org.cybergarage.upnp

Examples of org.cybergarage.upnp.Action


      ser.setEventSubURL(id+"/service/"+i+"/event");

      UPnPAction[] actions = services[i].getActions();
      for (int j = 0; j < actions.length; j++) {
                boolean valid=true;
        Action act = new Action(ser.getServiceNode());
        act.setName(actions[j].getName());
        ArgumentList al = new ArgumentList();
       
        String[] names=actions[j].getInputArgumentNames();       
        if(names!=null){
          for (int k = 0; k < names.length; k++) {
                        UPnPStateVariable variable = actions[j].getStateVariable(names[k]);
                        if(variable==null){
                            /*
                             * //TODO Create a stict and relaxed behavior of the base driver which
                             * export as much it can or export only 100% complaint UPnPDevice service
                             */
                            Activator.logger.WARNING(
                                "UPnP Device that cotains serviceId="+id+" contains the action "
                                +actions[j].getName()+" with the Input argument "+names[k]
                                +" not related to any UPnPStateVariable. Thus this action won't be exported");
                            valid=false;
                            break;
                        }
                        Argument a = new Argument();
            a.setDirection(Argument.IN);
            a.setName(names[k]);
            a.setRelatedStateVariableName(variable.getName());           
            al.add(a);           
          }
        }
        names=actions[j].getOutputArgumentNames();
        if(names!=null && valid){
          for (int k = 0; k < names.length; k++) {
                        UPnPStateVariable variable = actions[j].getStateVariable(names[k]);
                        if(variable==null){
                            /*
                             * //TODO Create a stict and relaxed behavior of the base driver which
                             * export as much it can or export only 100% complaint UPnPDevice service
                             */
                            Activator.logger.WARNING(
                                "UPnP Device that cotains serviceId="+id+" contains the action "
                                +actions[j].getName()+" with the Output argument "+names[k]
                                +" not related to any UPnPStateVariable. Thus this action won't be exported");                           
                        }
            Argument a = new Argument();
            a.setDirection(Argument.OUT);
            a.setName(names[k]);
            a.setRelatedStateVariableName(variable.getName());           
            al.add(a);           
          }
        }
                if(valid) {
            act.setArgumentList(al);
            ser.addAction(act);
                }
      }     
     
      UPnPStateVariable[] vars = services[i].getStateVariables();
View Full Code Here


    public void startDevice(){
      stopDevice();
      try {
        antsDev = new Device(DESCRIPTION_FILE_NAME);

        Action getTimeAction = antsDev.getAction("GetLANAddress");
        getTimeAction.setActionListener(this);

        ServiceList serviceList = antsDev.getServiceList();
        Service service = serviceList.getService(0);
        service.setQueryListener(this);
View Full Code Here

    /**
     * @return the external address the NAT thinks we have.  Blocking.
     * null if we can't find it.
     */
    public InetAddress getNATAddress() throws UnknownHostException {
            Action getIP;

        synchronized(this) {
                if (!isNATPresent())
                        return null;
                getIP = _service.getAction("GetExternalIPAddress");
        }

        if(getIP == null) {
            _logger.info("Couldn't find GetExternalIPAddress action!");
            return null;
        }


        if (!getIP.postControlAction()) {
                _logger.info("couldn't get our external address");
                return null;
        }

        Argument ret = getIP.getOutputArgumentList().getArgument("NewExternalIPAddress");
        return InetAddress.getByName(ret.getValue());
    }
View Full Code Here

   */
  private boolean addMapping(Mapping m) {

      _logger.info("adding "+m);

    Action add;
    synchronized(this) {
      add = _service.getAction("AddPortMapping");
    }

    if(add == null) {
        _logger.info("Couldn't find AddPortMapping action!");
        return false;
    }


    add.setArgumentValue("NewRemoteHost",m._externalAddress);
    add.setArgumentValue("NewExternalPort",m._externalPort);
    add.setArgumentValue("NewInternalClient",m._internalAddress);
    add.setArgumentValue("NewInternalPort",m._internalPort);
    add.setArgumentValue("NewProtocol",m._protocol);
    add.setArgumentValue("NewPortMappingDescription",m._description);
    add.setArgumentValue("NewEnabled","1");
    add.setArgumentValue("NewLeaseDuration",0);

    boolean success = add.postControlAction();
        _logger.info("Post succeeded: " + success);
    return success;
  }
View Full Code Here

   */
  private boolean removeMapping(Mapping m) {

      _logger.info("removing "+m);

    Action remove;
    synchronized(this) {
      remove = _service.getAction("DeletePortMapping");
    }

    if(remove == null) {
        _logger.info("Couldn't find DeletePortMapping action!");
        return false;
      }

    remove.setArgumentValue("NewRemoteHost",m._externalAddress);
    remove.setArgumentValue("NewExternalPort",m._externalPort);
    remove.setArgumentValue("NewProtocol",m._protocol);

    boolean success = remove.postControlAction();
        _logger.info("Remove succeeded: " + success);
    return success;
  }
View Full Code Here

    public void run() {

        _logger.info("Looking for stale mappings...");

      Set mappings = new HashSet();
      Action getGeneric;
      synchronized(UPnPManager.this) {
        getGeneric = _service.getAction("GetGenericPortMappingEntry");
      }

      if(getGeneric == null) {
          _logger.info("Couldn't find GetGenericPortMappingEntry action!");
          return;
      }

      // get all the mappings
      try {
        for (int i=0;;i++) {
            getGeneric.setArgumentValue("NewPortMappingIndex",i);
                _logger.info("Stale Iteration: " + i + ", generic.input: " + list(getGeneric.getInputArgumentList()) + ", generic.output: " + list(getGeneric.getOutputArgumentList()));

          if (!getGeneric.postControlAction())
            break;

          mappings.add(new Mapping(
              getGeneric.getArgumentValue("NewRemoteHost"),
              getGeneric.getArgumentValue("NewExternalPort"),
              getGeneric.getArgumentValue("NewInternalClient"),
              getGeneric.getArgumentValue("NewInternalPort"),
              getGeneric.getArgumentValue("NewProtocol"),
              getGeneric.getArgumentValue("NewPortMappingDescription")));
            // TODO: erase output arguments.

        }
      }catch(NumberFormatException bad) {
          _logger.error("NFE reading mappings!", bad);
View Full Code Here

  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);
    }
View Full Code Here

        IconTable iconTable = new IconTable(icon);
        setRightComponent(new TableComp(iconTable));
        return;
      }
      if (data instanceof Action) {
        Action action = (Action)data;
        ActionPane actionPane = new ActionPane(ctrlPoint, action);
        setRightComponent(actionPane);
        return;
      }
      if (data instanceof Argument) {
View Full Code Here

  ////////////////////////////////////////////////
 
  private String getExternalIPAddress()
  {
    Device dev = getSelectedDevice();
    Action addPortAct = dev.getAction("GetExternalIPAddress");
    if (addPortAct == null) {
      showWarnning("GetExternalIPAddress is not found");
      return "";
    }
    if (addPortAct.postControlAction() == true)
      return addPortAct.getArgumentValue("NewExternalIPAddress");
    return "";
  }
View Full Code Here

  }
 
  private void addPortMapping(UpnpIGDToolAddPortDlg addPortDlg)
  {
    Device dev = getSelectedDevice();
    Action addPortAct = dev.getAction("AddPortMapping");
    if (addPortAct == null) {
      showWarnning("AddPortMapping is not found");
      return;
    }
    addPortAct.setArgumentValue("NewRemoteHost", "");
    addPortAct.setArgumentValue("NewProtocol", addPortDlg.getProtocol());
    addPortAct.setArgumentValue("NewPortMappingDescription", addPortDlg.getName());
    addPortAct.setArgumentValue("NewExternalPort", addPortDlg.getExternalPort());
    addPortAct.setArgumentValue("NewInternalClient", addPortDlg.getInternalIP());
    addPortAct.setArgumentValue("NewInternalPort", addPortDlg.getInternalPort());
    addPortAct.setArgumentValue("NewEnabled", 1);
    addPortAct.setArgumentValue("NewLeaseDuration", 0);
   
    String actionMsg =
      addPortDlg.getName() + " " +
      "(" + addPortDlg.getProtocol() + ") : " +
      addPortDlg.getExternalPort() + " -> " +
      addPortDlg.getInternalIP() + ":" +
      addPortDlg.getInternalPort();
   
    if (addPortAct.postControlAction() == true) {
      UPnPStatus upnpStat = addPortAct.getStatus();
      String msg = "New port mapping is created\n" + actionMsg;
      showMessage(msg);
    }
    else {
      UPnPStatus upnpStat = addPortAct.getStatus();
      String msg = "New port mapping is failed\n" +
          upnpStat.getDescription() + " (" + upnpStat.getCode() + ")\n" +
          actionMsg;
      showWarnning(msg);
    }
View Full Code Here

TOP

Related Classes of org.cybergarage.upnp.Action

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.