Package org.cybergarage.upnp

Examples of org.cybergarage.upnp.Service


      return;
   
   
   
    for (int i = 0; i < services.length; i++) {
      Service ser = new Service();
      devUPnP.addService(ser);
      ser.setServiceType(services[i].getType() );
      ser.setServiceID(services[i].getId());
      ser.setSCPDURL(id+"/service/"+i+"/gen-desc.xml");
      ser.setDescriptionURL(id+"/service/"+i+"/gen-desc.xml");
      ser.setControlURL(id+"/service/"+i+"/ctrl");
      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();
      for (int j = 0; j < vars.length; j++) {
        StateVariable var = new StateVariable();
        var.setDataType(vars[j].getUPnPDataType());
        var.setName(vars[j].getName());
        var.setSendEvents(vars[j].sendsEvents());
        String[] values = vars[j].getAllowedValues();
        if(values!=null){
          AllowedValueList avl = new AllowedValueList(values);
          var.setAllowedValueList(avl);
        }else if(vars[j].getMaximum()!= null){
          AllowedValueRange avr = new AllowedValueRange(
              vars[j].getMaximum(),
              vars[j].getMinimum(),
              vars[j].getStep()
            );
          var.setAllowedValueRange(avr);
        }
        if(vars[j].getDefaultValue()!=null)
          try {
            var.setDefaultValue(Converter.toString(
                vars[j].getDefaultValue(),vars[j].getUPnPDataType()
              ));
          } catch (Exception ignored) {
          }
        ser.addStateVariable(var);       
      }
           
      Activator.bc.ungetService(sr);
    }
   
View Full Code Here


                          (String[]) (device.getDescriptions(null).get(UPnPService.TYPE));
                     
            Device cyberDevice = findDeviceCtrl(this, udn);
            Vector vec = new Vector();
            for (int i = 0; i < oldServiceType.length; i++) {
              Service ser = cyberDevice.getService(oldServicesID[i]);
              if (!(ser.getServiceType().equals(parseUSN.getServiceType())))
                          {
                vec.add(oldServicesID[i]);
              }
            }
 
View Full Code Here

   * notifierQueue.enqueue(msg); }
   */

  public Service serviceFromSid(String sid) {
    Enumeration e = devices.elements();
    Service cyberService = null;
    while (e.hasMoreElements()) {
      OSGiDeviceInfo deviceinfo = (OSGiDeviceInfo) e.nextElement();
      UPnPDevice device = deviceinfo.getOSGiDevice();
      UPnPService[] services = (UPnPService[]) device.getServices();
      UPnPServiceImpl[] servicesImpl = new UPnPServiceImpl[services.length];
      for (int i = 0; i < servicesImpl.length; i++) {
        servicesImpl[i] = (UPnPServiceImpl) services[i];
      }
      for (int i = 0; i < servicesImpl.length; i++) {
        cyberService = servicesImpl[i].getCyberService();
        boolean bool = cyberService.isSubscribed();
        if (bool) {
          if (cyberService.getSID().equals(sid)) {
            return cyberService;
          }
        }
      }
    }
View Full Code Here

   * @see org.apache.felix.upnpbase.importer.MyEventListener#newEventArrived(java.lang.String,
   *      long, java.util.Dictionary)
   */
  public void newEventArrived(String uuid, long seq, PropertyList props) {
        Activator.logger.DEBUG("[Importer] newEventArrived");
    Service service = serviceFromSid(uuid);
    if (service != null) {
            int size = props.size();
            Hashtable hash = new Hashtable();
            for (int i = 0; i < size; i++) {
                Property prop = props.getProperty(i);
                String varName = prop.getName();
                String varValue = prop.getValue();
                String upnpType = service.getStateVariable(varName).getDataType();
                Object valueObj;
                try {
                    valueObj = Converter.parseString(varValue,upnpType);
                } catch (Exception e) {
                    Activator.logger.ERROR("[Importer] Bad data value in Notify event: "
                            +"var name="+varName +" value="+varValue +" type="+upnpType + "\n"+e);
                    return;
                }
                hash.put(varName, valueObj);
            }
          
      Device device = service.getDevice();
      StateChanged msg = new StateChanged(uuid, seq, hash, device, service);
      notifierQueue.enqueue(msg);
    }
  }
View Full Code Here

      hash.put(UPnPDevice.TYPE, deviceType);
      ServiceList services = device.getServiceList();
      Vector eventedSers = new Vector();

      for (int i = 0; i < services.size(); i++) {
        Service service = (Service) services.elementAt(i);
        ServiceStateTable vars = service.getServiceStateTable();
        for (int j = 0; j < vars.size(); j++) {
          StateVariable var = (StateVariable) vars.elementAt(j);
          if (var.isSendEvents()) {
            eventedSers.add(service);
            break;
          }
        }
      }

      for (int i = 0; i < listeners.length; i++) {
        UPnPEventListener listener = (UPnPEventListener) context
            .getService(listeners[i]);
        Filter filter = (Filter) listeners[i]
            .getProperty(UPnPEventListener.UPNP_FILTER);
        if (filter == null) {
          for (int j = 0; j < eventedSers.size(); j++) {
            Service ser = (Service) eventedSers.elementAt(j);
            subQueue.enqueue(new FirstMessage(ser, listener));
          }
        } else {
          for (int j = 0; j < eventedSers.size(); j++) {
            Service ser = (Service) eventedSers.elementAt(j);
            serviceID = ser.getServiceID();
            serviceType = ser.getServiceType();
            hash.put(UPnPService.ID, serviceID);
            hash.put(UPnPService.TYPE, serviceType);
            boolean bool = filter.match(hash);
            if (bool) {
              subQueue.enqueue(new FirstMessage(ser, listener));
View Full Code Here

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

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

        serverInfo = antsDev.getStateVariable("LANAddress");

        antsDev.setLeaseTime(60);
        antsDev.start();
View Full Code Here

     */
    String[] servicesIDProperty = new String[serviceList.size()];
    String[] servicesTypeProperty;
    HashSet serTypeSet = new HashSet();
    for (int i = 0; i < serviceList.size(); i++) {
      Service service = serviceList.getService(i);
      UPnPServiceImpl serviceImpl = new UPnPServiceImpl(service);
      services.put(service.getServiceID(), serviceImpl);
      servicesIDProperty[i] = serviceImpl.getId();
      serTypeSet.add(serviceImpl.getType());
    }
    servicesTypeProperty = new String[serTypeSet.size()];
    Iterator iter = serTypeSet.iterator();
View Full Code Here

    if(d.getUDN().equals(deviceId)){
      dAux=d;
    }else{
      dAux=d.getDevice(deviceId);
    }
    Service s = dAux.getService(serviceId);
    // fix 2/9/2004 francesco
    Enumeration e = events.keys();
    while (e.hasMoreElements()) {
            StateVariable sv;
            String dataType;
            String name;
            Object key = e.nextElement();
            if(key instanceof String){
                name=(String) key;
                sv=s.getStateVariable(name);
                dataType=sv.getDataType();
            }else{
                Activator.logger.ERROR(deviceId + " notified the change in the StateVariable of "
                                       + serviceId + " but the key Java type contained in the Dictiories was "
                                       + key.getClass().getName() + " instead of " + String.class.getName()
View Full Code Here

          String sid = (String) i.next();
        Vector listeners =
                    sidListSid.getListenersFromSid(sid);
        listeners.remove(listener);
        if (listeners.size() == 0) {
          Service service =
                        ctrl.serviceFromSid(sid);
          //##renew  Renewer renewer = sidRenewer.get((String) sids.elementAt(i));
          //##renew  renewer.stop();
          if (service != null) {
            boolean ok = ctrl.unsubscribe(service);
            if (!ok) {
                //TODO Log?s
              service.clearSID();
            }
          }
          sidListSid.setAlreadyFirst(sid,false);
          sidStateVars.remove(sid);
          i.remove();
View Full Code Here

    Vector newServices = msg.getNewServices();
    Vector subscribed = new Vector();
    Vector notSubscribed = new Vector();
   
    for (int i = 0; i < newServices.size(); i++) {
      Service ser = (Service) newServices.elementAt(i);
      if (ser.isSubscribed()) {
        subscribed.add(ser);
      } else {
        notSubscribed.add(ser);
      }
    }
   

    Vector oldSids = sidListSid.getSidsFromListener(listener);
        // francesco-renew
        // check subscribed services
    if(oldSids==null) return;
   
    for (int i = 0; i < notSubscribed.size(); i++) {
      Service ser = (Service) notSubscribed.elementAt(i);
      subqueue.enqueue(new FirstMessage(ser, listener));
    }
   
    for (int i = 0; i < oldSids.size(); i++) {
      String oldSid = (String) oldSids.elementAt(i);
View Full Code Here

TOP

Related Classes of org.cybergarage.upnp.Service

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.