示例#1
0
  public boolean performOperations(RifidiTag tag, TagReportData trd) {
    logger.debug("checking to see if access operations should be performed...");
    this.numOfOperationsPerformed++;
    // iterate through list of opspecs and perform each operation
    Iterator<_OpSpec> iter = opSpecs.iterator();

    // accumulation of results so that we don't add results to trd if there
    // was an error in a opSpec
    ArrayList<C1G2OpSpecResult> results = new ArrayList<C1G2OpSpecResult>();

    boolean stop = false;
    while (iter.hasNext() && !stop) {
      _OpSpec op = iter.next();
      _OpSpecResult result = op.performOperation(tag);
      results.add(result.getLLRPTKResult());
      if (result.getResult() != 0) {
        stop = true;
      }
    }

    // add each result to trd
    for (C1G2OpSpecResult r : results) {
      trd.addOpSpecResultParam(r);
      AccessSpecID id = new AccessSpecID();
      id.setAccessSpecID(this.specID);
      trd.setAccessSpecIDParam(id);
    }

    // if accessReport trigger is not defined, look up the global value
    if (accessReportTrigger == -1) {
      accessReportTrigger = llrpsr.getProperties().accessReportTrigger;
    }
    // send report now if we need to
    if (this.accessReportTrigger == 1) {
      LLRPReportControllerFactory.getInstance()
          .getReportController(llrpsr.getReaderName())
          .sendReport(trd);
      // remove from list so we don't resend it later
      llrpsr.getTagReportDataEntries().remove(trd);
    }

    // if stop trigger has fired, delete this spec from the list
    if (this.stopTriggerType == 1 && this.operationCount != 0) {
      if (this.numOfOperationsPerformed >= this.operationCount) {
        logger.debug("AccessSpec stop trigger has fired, delete access spec");
        llrpsr.accessSpecs.removeAccessSpec(this.specID);
      }
    }

    return true;
  }
  /**
   * Runs a ROSpec, then generates a report after the ROSpec has finished.
   *
   * @see java.lang.Runnable#run()
   */
  public void run() {
    logger.debug("Starting the autonomous executer");

    keepExecuting = true;

    /*
     * This sleep causes a context switch so that another process can run
     * first. The problem is that if a client sends a START_ROSPEC message,
     * sometimes the START_ROSPEC_RESPONSE is recieved after the reader
     * event notification signaling the beginning of a rospec. This short
     * sleep code, while it doesn't gauentee a fix for the problem, helps
     * reduce it
     */
    try {
      Thread.sleep(100);
    } catch (InterruptedException e1) {
      e1.printStackTrace();
    }

    /* send ROSpec Start Event if enabled */
    EventNotificationTable table = llrpsr.getProperties().eventNotificaionTable;
    if (table.getEventNotificaiton(EventNotificationTable.RO_SPEC_EVENT_TYPE)) {
      ReaderEventNotificationData rend = new ReaderEventNotificationData();
      ROSpecEvent event = new ROSpecEvent();
      event.setEventType((byte) 0);
      event.setROSpecID(roSpec.getId());
      rend.setROSpecEventParam(event);

      LLRPReportController controller =
          LLRPReportControllerFactory.getInstance().getReportController(llrpsr.getReaderName());
      controller.sendEvent(rend);
    }

    if (roSpec.getStopTrigger() instanceof TimerTrigger) {
      TimerTrigger trig = (TimerTrigger) roSpec.getStopTrigger();
      trig.startTimer();
    }

    this.execute();
    ROReportFormat format = roSpec.getRoReportFormat();
    if (format == null) {
      format = llrpsr.getProperties().roReportFormat_Global;
    }
    int trig = format.reportTrigger;
    if (trig == 2 && llrpsr.getTagReportDataEntries().getNumDataEntries() > 0) {
      LLRPReportControllerFactory.getInstance()
          .getReportController(this.roSpec.getReaderName())
          .sendAllReports(llrpsr, 0);
    }
    /* Send ROSpec End Event if enabled */
    if (table.getEventNotificaiton(EventNotificationTable.RO_SPEC_EVENT_TYPE)) {
      ReaderEventNotificationData rend = new ReaderEventNotificationData();
      ROSpecEvent event = new ROSpecEvent();
      event.setEventType((byte) 1);
      event.setROSpecID(roSpec.getId());
      rend.setROSpecEventParam(event);

      LLRPReportController controller =
          LLRPReportControllerFactory.getInstance().getReportController(llrpsr.getReaderName());
      controller.sendEvent(rend);
    }

    logger.debug("finished executing ROSpec");

    // TODO: if immediate trigger, should we restart the rospec?
    if (roSpec.getStartTrigger() instanceof ImmediateTrigger) {
      // ((ImmediateTrigger)roSpec.getStartTrigger()).restartRoSpec();
    }
  }