Package de.desy.tine.dataUtils

Examples of de.desy.tine.dataUtils.TDataType


    n32[2] = new NAME32(cnt);
    n32[3] = new NAME32(String.valueOf(eqm.getGroupIndex()));
    n32[4] = new NAME32(sub);
    n32[5] = new NAME32(prefix);
    n32[6] = new NAME32(postfix);
    TDataType din = new TDataType(n32);
    TDataType dout = new TDataType();
    if (debugLevel > 0)
    {
      String dbgstr = "/"+cnt+"/"+exp+" -> ";
      DbgLog.log("joinEnsGroup",dbgstr+"joining group "+grp+" (index "+eqm.getGroupIndex()+")");
      if (prefix.length() > 0) DbgLog.log("joinEnsGroup","device prefix: "+prefix);
View Full Code Here


    if (gCyclerNumberKey == null)
    {
      gCyclerNumberKey = "/"+gFecContext+"/CYCLER/CycleNumber";
    }
    if (!assertCycleTriggerExists()) return TErrorList.non_existent;
    TDataType sdt = new TDataType(gCycleNumber);
    String[] parts = gCyclerNumberKey.split("/");
    String cn = parts[1];
    String sn = parts[2];
    String kn = parts[3];
    String srv = "/"+cn+"/"+sn;
View Full Code Here

      lnk.dOutput.resetBuffersReady();
      TLinkFactory.getInstance().fillinIncomingData(lnk);
    }
    else
    { // try to re-format (what came in to what the caller wants ...)
      TDataType dt = new TDataType(len,fmt);
      dt.update(d,1,0);
      lnk.dOutput.blksin = lnk.dOutput.bytesin = 0;
      dt.resetBuffersReady();
      Object srcData = dt.getDataObject();
      dt.getData(srcData);
      lnk.dOutput.putData(srcData);
      lnk.dOutput.hasBeenUpdated = dt.hasBeenUpdated = true;
      lnk.dOutput.dCompletionLength = len;
    }
  }
View Full Code Here

              }
              if (lnk.hasDependencies())
              { // already has dependencies ? (a jDDD specialty)
                TLink xlnk;
                LinkedList<TLink> xlst = lnk.getDependencies();
                TDataType dout;
                for (int k=0; k<xlst.size(); k++)
                {
                  if ((xlnk = (TLink)xlst.get(k)) == null) continue;
                  dout = xlnk.getOutputDataObject();
                  if (dout.dFormat != TFormat.CF_DEFAULT) continue;
                  int dlen = lnk.dOutput.dArrayLength;
                  if (xlnk.getMcaDevice() != null) dlen = 1;
                  dout.setDataObject(dlen,lnk.dOutput.dFormat);
                  dout.dArrayLength = dlen;
                  dout.dFormat = lnk.dOutput.dFormat;
                  dout.dTimestamp = (long) dTimeStamp * 1000 + (long) (dTimeStampUSEC / 1000);
                  dout.timestamp = dTimeStamp;
                  dout.timestampMSEC = dTimeStampUSEC / 1000;
View Full Code Here

      { // device name given
        i = getDeviceNumber(devName, prp.getName());
        if (i < 0) i = index;
        if (i > len) return TErrorList.illegal_device;
      }
      TDataType dt = null;
      int offset = i;
      try
      {
        if (prpValue.compareToIgnoreCase("<$FILE") == 0)
        { // an array property
          len /= ndevs;
          if (prpValuesFile == null) return TErrorList.file_error;
          int p = prpValuesFile.lastIndexOf('.');
          if (p < 1) return TErrorList.invalid_name;
          prpValuesFile = prpValuesFile.substring(0, p) + "." + i;
          DataInputStream dis = new DataInputStream(new FileInputStream(prpValuesFile));
          hasSrValues[i] = true;
          switch (fmt)
          {
            case TFormat.CF_BYTE:
            {
              byte[] d = new byte[len];
              for (int k=0; k<len; k++) d[k] = dis.readByte();
              dt = new TDataType(d);
              break;
            }
            case TFormat.CF_INT16:
            {
              short[] d = new short[len];
              for (int k=0; k<len; k++) d[k] = dis.readShort();
              dt = new TDataType(d);
              break;
            }
            case TFormat.CF_INT32:
            {
              int[] d = new int[len];
              for (int k=0; k<len; k++) d[k] = dis.readInt();
              dt = new TDataType(d);
              break;
            }
            case TFormat.CF_INT64:
            {
              long[] d = new long[len];
              for (int k=0; k<len; k++) d[k] = dis.readLong();
              dt = new TDataType(d);
              break;
            }
            case TFormat.CF_FLOAT:
            {
              float[] d = new float[len];
              for (int k=0; k<len; k++) d[k] = dis.readFloat();
              dt = new TDataType(d);
              break;
            }
            case TFormat.CF_DOUBLE:
            {
              double[] d = new double[len];
              for (int k=0; k<len; k++) d[k] = dis.readDouble();
              dt = new TDataType(d);
              break;
            }
            default:
              dis.close();
              return TErrorList.not_supported;
          }
          dis.close();
          offset = i * len;
        }
        else
        { // normal scalar attribute or MCA property
          dt = TDataType.toTDataType(prpValue, fmt, true);
        }               
        dt.getData(srData.getDataObject(),len,offset);
      }
      catch (FileNotFoundException e)
      { // don't break the csv iterations: this is allowed !
        hasSrValues[i] = false;
        return 0;
View Full Code Here

      case TFormat.CF_HISTORY:
        data = new HISTORY[dataSize];
        // create the first one so as to pass the tag along
        short f = TFormat.getFormatCode(dataTag);
        if (f == TFormat.CF_NULL) return TErrorList.illegal_format;
        TDataType d = new TDataType(1,f);
        ((HISTORY[])data)[0] = new HISTORY(d);
        break;
      default:
        data = TFormat.makeCompoundDataObjectArray(dataFormat, dataTag, dataSize);
        break;
View Full Code Here

    if (failoverType != TEquipmentModuleFactory.FAILOVER_SLAVE) return TErrorList.not_allowed;
    String mstr = getSlaveMaster();
    if (mstr == null || mstr.length() == 0) return TErrorList.not_allowed;
    String tgt = "/"+getContext()+"/"+mstr;
    int[] lval = new int[1];
    TDataType dout = new TDataType(lval);
    TLink lnk = new TLink(tgt,"SRVSTARTTIME",dout,null,TAccess.CA_READ);
    int id = lnk.attach(TMode.CM_TIMER, new FailOverCallback(), foPollingInterval);
    foMonitorStarted = true;
    TFecLog.log("failover slave link to "+tgt+" : "+(id < 0 ? lnk.getLastError() : "success"));
    return ( id < 0) ? -id : 0;
View Full Code Here

  {
    if (!hasInitialized) return;
    long thisCycleTime = System.currentTimeMillis();
    THistoryRecord hst = null;
    THistorySpecification spc = null;
    TDataType dout = null;
    TDataType din = new TDataType();
    TAccess access = new TAccess(TAccess.CA_HIST + TAccess.CA_READ);
    int cc = 0;
    boolean skip;
    if (!isScheduled && thisCycleTime-lastHistoryCycleTime < historyCycleInterval) return;
    lastHistoryCycleTime = thisCycleTime;
    int nHistoryRecords = gLclHstList.size();
    if (nHistoryRecords == 0) return;
    TEquipmentModuleFactory f = getEquipmentModuleFactory();
    f.setCurrentContractEntry(f.hstcon);
    for (int i=0; i<nHistoryRecords; i++)
    {
      hst = (THistoryRecord)gLclHstList.get(i);
      spc = hst.getHspec();
      if (spc.getDepthShort() <= 0) continue;
      if (hst.needsToFillSTS) hst.fillSTS();
      hst.setArchiveFileName(thisCycleTime); // will also remove outdated files if necessary
      skip = (thisCycleTime-hst.getLastAccessTime()) < spc.getPollngRate();
      if (hst.isScheduled()) skip = false;
      hst.setScheduled(false);
      if (skip) continue;
      hst.setLastAccessTime(thisCycleTime);
      dout = new TDataType(hst.getArraySize(),hst.getFmt());
      dout.setDataTimeStamp(TDataTime.getDataTimeStamp());
      dout.setSystemDataStamp(TEquipmentModuleFactory.getSystemStamp());
      cc = callProperty(hst.getPrp(),hst.getDev(),dout,din,access);
      if (cc != 0) continue;
      synchronized (hst)
View Full Code Here

  protected void checkAlarmsInWatchTable()
  {
    long thisCycleTime = System.currentTimeMillis();
    if (thisCycleTime-lastAlarmCycleTime < alarmCycleInterval) return;
    lastAlarmCycleTime = thisCycleTime;
    TDataType dout = null;
    TDataType din = new TDataType();
    TAccess access = new TAccess(TAccess.CA_ALARM + TAccess.CA_READ);
    TAlarmWatchEntry awe = null;
    TAlarmDefinition adef = null;
    TAlarm alm = null;
    TDevice dev = null;
    int cc = 0, cnt = 0, siz = 0, sev = 0, devNr, code = 0, asys = 0;
    String tag = null;
    float fvals[] = null;
    int ivals[] = null;
    byte[] abytes = null;
    synchronized (gAlarmWatchList)
    {
      TEquipmentModuleFactory f = getEquipmentModuleFactory();
      f.setCurrentContractEntry(f.awtcon);
      int awlength = gAlarmWatchList.size();
      for (int i=0; i<awlength; i++)
      {
        awe = (TAlarmWatchEntry)gAlarmWatchList.get(i);
        int chk = awe.checkNormal();
        if (chk != 0)
        {
          ivals = new int[awe.getSiz()];
          dout = new TDataType(ivals);
          cc = callProperty(awe.getPrp(),awe.getDev(),dout,din,access);
        }
        else
        {
          fvals = new float[awe.getSiz()];
          dout = new TDataType(fvals);
          cc = callProperty(awe.getPrp(),awe.getDev(),dout,din,access);
        }
        if (cc != 0) continue;
        boolean hasAlarm = false;
        devNr = deviceList.getDeviceNumber(awe.getDev());
View Full Code Here

          { // at least this many with the same code
              code = TAlarm.isDiskSpaceAlarm(code) ? (code & 0xff) : TAlarm.getBaseCode(code);
              TAlarmDefinition ad = getAlarmDefinition(code);
              atag = ""+n+" alarms: "+ ad != null ? ad.getAlarmTag() : "<no defined alarm tag>";
          }
          TDataType dt = new TDataType(tna);
          ams[0] = new TAlarmMessage(thisEqm.getExportName(),thisEqm.getExportName(),atag,code,
                          deviceList.getHighestAlarmSeverity(null,0),almDynSet,dt);
          //tba = new byte[buflength * TAlarmMessage.sizeInBytes];
        }
        else
        {
          int ts = 0;
          buflength = deviceList.getNumberOfAlarms();
          ams = new TAlarmMessage[buflength];
          //tba = new byte[buflength * TAlarmMessage.sizeInBytes];
          TDevice[] dlst = deviceList.getDeviceList();
          String dnam = null, atag = null;
          for (int i=dstart; i<dstop; i++)
          {
            alms = dlst[i].getAlarmList();
            if ((alms == null) || (alms.length == 0)) continue;
            for (int n=0; n<alms.length && na<buflength; n++)
            {
              if ((ts=alms[n].getTimeStamp()) < astart || ts > astop) continue;
              if (alms[n].getSeverity() < asev) continue;
              dnam = dlst[i].getName();
              code = alms[n].getCode();
              atag = null;
              if (TAlarm.isLinkErrorAlarm(code))
              {
                dnam = thisEqm.getExportName();
                int lid = TAlarm.decodeLinkErrorAlarm(code);
                TLink lnk = TLinkFactory.getInstance().getLinkFromTable(lid);
                if (lnk != null) atag = "link error: "+lnk.getDeviceServer();
              }
              // TODO: if (TAlarm.isDiskSpaceAlarm(code)) dnam = getDiskName();
              ams[na] = new TAlarmMessage(thisEqm,dnam,atag,alms[n]);
              if (TAlarm.isHiddenAlarm(alms[n].getCode()))
              { // flagged as hidden
                ams[na].setAlarmSystem(TAlarm.hideAlarmSystem(ams[na].getAlarmSystem()));
              }
              //System.arraycopy(ams[na].toByteArray(), 0, tba, (na)*TAlarmMessage.sizeInBytes, TAlarmMessage.sizeInBytes);
              // CAS is configured and has now read the alarm => can remove it !
              if (casReadRequired && isCasInClientList()) alms[n].allowRemoval();
              na++;
            }
          }
        }
        byte[] tba = new byte[buflength * TAlarmMessage.sizeInBytes];
        if (dout.getTag().compareTo("AMSr4") == 0)
        { // modern
          for (int i=0; i<buflength && i<na; i++)
          {
            System.arraycopy(ams[i].toByteArray(), 0, tba, i*TAlarmMessage.sizeInBytes, TAlarmMessage.sizeInBytes);
          }
          if (na < dout.getArrayLength()) dout.setArrayLength(na);
          return dout.putData(tba, "AMSr4");
        }
        else
        // is legacy support necessary ?
         
        }
        return TErrorList.invalid_structure_tag;
      }
    };
    TPropertyHandler alarmDefsStructHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TAlarmDefinition[] adef = (TAlarmDefinition[])alarmDefinitionList.values().toArray(new TAlarmDefinition[0]);
        int almdefsize = alarmDefinitionList.size();
        if (devAccess.isWrite())
        {
          if (din == null) return TErrorList.dimension_error;
          if (din.dFormat != TFormat.CF_STRUCT) return TErrorList.illegal_format;
          if (din.getTag().compareTo("ADSr4") != 0) return TErrorList.invalid_structure_tag;
          TAlarmDefinition[] inpt = new TAlarmDefinition[1];
          inpt[0] = new TAlarmDefinition();
          din.getData(inpt);
          boolean found = false;
          for (int i=0; i<almdefsize; i++)
          {
            if (adef[i].getAlarmCode() == inpt[0].getAlarmCode())
            { // got it
              adef[i].setFields(inpt[0]);
              found = true;
              break;
            }
          }
          if (!found) return TErrorList.un_allocated;
          if (dout == null || dout.getArrayLength() == 0) return 0;
        }
        if (dout == null) return TErrorList.dimension_error;
        if (dout.dFormat != TFormat.CF_STRUCT) return TErrorList.illegal_format;
        int adssize = TStructRegistry.getSizeInBytes("ADSr4");
        byte[] tba = new byte[almdefsize * adssize];
        if (dout.getTag().compareTo("ADSr4") == 0)
        { // modern
          for (int i=0; i<almdefsize; i++)
          {
            System.arraycopy(adef[i].toByteArray(), 0, tba, i*adssize, adssize);
          }
          if (almdefsize < dout.getArrayLength()) dout.setArrayLength(almdefsize);
          return dout.putData(tba, "ADSr4");
        }
        else
        // is legacy support necessary ?
         
        }
        return TErrorList.invalid_structure_tag;
      }
    };
    TPropertyHandler devMaskHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          int[] newMask = new int[1];
          if ((cc=din.getData(newMask)) != 0) return cc;
          tdv.setMask(newMask[0]);         
          int[] m = new int[deviceList.getNumberOfDevices()];
          for (int i=0; i<m.length; i++) m[i] = deviceList.getDevice(i).getMask();
          saveStockPropertyValues("DEVMASK",devName,new TDataType(m));
        }               
        int mask = tdv.getMask();
        return dout.putData(mask);
      }     
    };
    TPropertyHandler devRegionHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          String[] newrg = new String[1];
          switch (din.dFormat)
          {
            case TFormat.CF_INT32:
              int[] irg = new int[1];
              if ((cc=din.getData(irg)) != 0) return cc;
              newrg[0] = TRegion.getRegion(irg[0]);
              break;
            default:
              if ((cc=din.getData(newrg)) != 0) return cc;
              break;
             
          }
          tdv.setRegion(newrg[0]);         
          int[] rg = new int[deviceList.getNumberOfDevices()];
          for (int i=0; i<rg.length; i++) rg[i] = deviceList.getDevice(i).getRegionCode();
          saveStockPropertyValues("DEVREGION",devName,new TDataType(rg));
        }
        switch (dout.dFormat)
        {
          case TFormat.CF_INT32:
            return dout.putData(tdv.getRegionCode());
          default:
            return dout.putData(tdv.getRegion());
        }
      }
    };   
    stockList.addProperty(TStockProperties.SRVSUBSYSTEM, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        String subs = getSubsystem();
        return dout.putData(subs == null ? "" : subs);
      }
    });
    TPropertyHandler alarmWatchStructHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        synchronized (gAlarmWatchList)
        {
          int almwtblsize = gAlarmWatchList.size();
          int awssize = TStructRegistry.getSizeInBytes("AWSr4");
          byte[] tba = new byte[almwtblsize * awssize];
          TAlarmWatchEntry[] aws = (TAlarmWatchEntry[])gAlarmWatchList.toArray(new TAlarmWatchEntry[0])
          if (devAccess.isWrite())
          {
            if (din.getFormat() != TFormat.CF_STRUCT) return TErrorList.illegal_format;
            if (din.getTag().compareTo("AWSr4") == 0)
            {
              TAlarmWatchEntry[] awe = new TAlarmWatchEntry[1];
              awe[0] = new TAlarmWatchEntry();
              din.getData(awe);
              awe[0].setEquipmentModule(getLocalName());
              boolean isNew = true;
              for (int i=0; i<aws.length; i++)
              {
                if (aws[i].equals(awe[0]))
                {
                  aws[i].adjustFrom(awe[0]);
                  isNew = false;
                  break;
                }
              }
              if (isNew)
              { // wasn't in list
                TExportProperty p = propertyList.getFirstProperty(awe[0].getPrp());
                if (p == null) return TErrorList.illegal_property;
                if (awe[0].getSiz() <= 0 || awe[0].getSiz() > p.getOutputSize())
                {
                  awe[0].setSiz(p.getOutputSize());
                }
                awe[0].setFmt(p.getOutputFormat());
                gAlarmWatchList.add(awe[0]);
              }
            }
            else
            {
              return TErrorList.invalid_structure_tag;           
            }
          }
          if (dout == null || dout.dArrayLength == 0) return 0;
          if (dout.dFormat != TFormat.CF_STRUCT) return TErrorList.illegal_format;
          if (dout.getTag().compareTo("AWSr4") == 0)
          { // modern
            for (int i=0; i<almwtblsize; i++)
            {
              System.arraycopy(aws[i].toByteArray(), 0, tba, i*awssize, awssize);
            }
            if (almwtblsize < dout.getArrayLength()) dout.setArrayLength(almwtblsize);
            return dout.putData(tba, "AWSr4");
          }
          else
          {
            return TErrorList.invalid_structure_tag;
          }
        }
      }
    };
    stockList.addProperty(TStockProperties.NALARMS, new TPropertyHandler()
    {
      int nalmdefs = alarmDefinitionList.size();
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        int devnr = -1;
       
        if (!devName.contains("*") && !devName.startsWith("#"))
        {
          devnr = deviceList.getDeviceNumber(devName);
        }
        if (casName != null  && !hasCasAttached) isCasInClientList();
        int[] nalms = new int[6];
        if (devnr < 0)
        { // all of them
          nalms[0] = deviceList.getNumberOfAlarms();
          nalms[1] = deviceList.getMostRecentAlarmTimestamp(nalms,3);
          nalms[2] = deviceList.getHighestAlarmSeverity(nalms,4);
          nalms[5] = nalmdefs;
          if (nalms[0] > TAlarm.getAlmCollapseWindow())
          {
            nalms[1] = almDynSet.timestamp;
            nalms[4] = nalms[3] = nalms[0] = 1;
          }
        }
        else
        { // just the device given ...
          int mrts = 0, ts, hsv = 0, sv, nts = 0, nsv = 0;
          TDevice[] dlst = deviceList.getDeviceList();
          if (devnr >= dlst.length) return TErrorList.device_not_connected;
          TAlarm[] alms = dlst[devnr].getAlarmList();
          nalms[0] = alms.length;
          for (int i=0; i<alms.length; i++)
          {
            if ((ts=alms[i].getTimeStamp()) > mrts)
            {
              mrts = ts;
              nts = 0;
            }
            if (ts == mrts) nts++;
            if ((sv=alms[i].getSeverity()) > hsv)
            {
              hsv = sv;
              nsv = 0;
            }
            if (sv == hsv) nsv++;
          }
          nalms[1] = mrts;
          nalms[2] = hsv;
          nalms[3] = nts;
          nalms[4] = nsv;
          nalms[5] = nalmdefs;
        }
        if (dout.dArrayLength > 5) nalms[5] = getAlarmDefinitionList().size();
        return dout.putData(nalms);
      }
    });
    stockList.addProperty(TStockProperties.NALARMDEFS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData((short)alarmDefinitionList.size());
      }
    });
    stockList.addProperty(TStockProperties.NALMWATCH, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData((short)gAlarmWatchList.size());
      }
    });
    stockList.addProperty(TStockProperties.ALARMS, alarmsStructHandler);
    stockList.addProperty(TStockProperties.ALARMSEXT, alarmsStructHandler);
    stockList.addProperty(TStockProperties.ALARMSEXT_STRUCTIN, alarmsStructHandler);
    stockList.addProperty(TStockProperties.ALARMDEFS, alarmDefsStructHandler);
    stockList.addProperty(TStockProperties.ALMWATCHTBL, alarmWatchStructHandler);
    stockList.addProperty(TStockProperties.NHISTORIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData((short)gLclHstList.size());
      }
    });
    stockList.addProperty(TStockProperties.HISTORIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return hstCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.HISTORIES_STRUCT, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return hstCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.ADDHISTORY, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        if (devAccess.isWrite())
        {
          if (din.getFormat() != TFormat.CF_STRUCT) return TErrorList.illegal_format;
          if (din.getTag().compareTo("HRSr4") == 0)
          {
            THistoryRecordStruct[] hrs = new THistoryRecordStruct[1];
            hrs[0] = new THistoryRecordStruct();
            din.getData(hrs);
            String prp = hrs[0].getProperty();
            String dev = hrs[0].getDevice();
            THistoryRecord hr = getLocalHistoryRecord(prp,dev);
            if (hr == null)            
            { // wasn't in list
              TExportProperty p = getPropertyList().getFirstProperty(prp);
              TPropertyDescription pd = p.getDescription();
              int at = pd != null ? pd.getArrayType() : TArrayType.AT_UNKNOWN;
              int idx = TEquipmentModuleFactory.getInstance().getNextHistoryRecordIndex();
              THistorySpecification hspec = new THistorySpecification(hrs[0].getPollingRate(), hrs[0].getArchiveRate(), hrs[0].getDepthShort(), hrs[0].getDepthLong(), hrs[0].getHeartbeat(), hrs[0].getPercentTolerance(), hrs[0].getAbsoluteTolerance(), null);
              addLocalHistoryRecord(idx, dev, prp, hrs[0].getSize(), hrs[0].getFormat(),at,hspec);
              dumpHistoryManifest();
            }
            else
            { // just an edit ...
              THistorySpecification hsp = hr.getHspec();
              hsp.setAbsoluteTolerance(hrs[0].getAbsoluteTolerance());
              hsp.setPercentTolerance(hrs[0].getPercentTolerance());
              hsp.setArchiveRate(hrs[0].getArchiveRate());
              hsp.setPollngRate(hrs[0].getPollingRate());
              hsp.setDepthLong(hrs[0].getDepthLong());
              hsp.setDepthShort(hrs[0].getDepthShort());
              hsp.setHeartbeat(hrs[0].getHeartbeat());
            }
            return 0;
          }
          else
          {
            return TErrorList.invalid_structure_tag;           
          }
        }
        return TErrorList.illegal_read_write;
      }            
    });
    stockList.addProperty(TStockProperties.ADDHISTORY_STR, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        if (devAccess.isWrite())
        {
          short fmt = din.getFormat();
          if (!TFormat.isName(fmt) && fmt != TFormat.CF_CHAR) return TErrorList.illegal_format;
          NAME64[] tgt = new NAME64[1];
          int cc = din.getData(tgt);
          if (cc != 0) return cc;
          String prp = tgt[0].getName();
          TExportProperty p = getPropertyList().getFirstProperty(prp);
          if (p == null) return TErrorList.invalid_property;
          int hfmt = p.getOutputFormat();
          int hsiz = p.getOutputSize();
          int idx = gEqmFactory.getNextHistoryRecordIndex(getLocalName(),prp,devName,hfmt,hsiz);
          addLocalHistoryRecord(idx, devName, prp, hsiz, hfmt);
          dumpHistoryManifest();
          return 0;
        }
        return TErrorList.illegal_read_write;
      }            
    });
    //TODO: finish these ...
    stockList.addProperty(TStockProperties.METAPROPERTIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return metaprpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.METAPROPS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return metaprpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.METAPROPERTIES_STRUCT, metapropertiesStructHandler);
    stockList.addProperty(TStockProperties.METAPROPS_STRUCT, metapropertiesStructHandler);
    stockList.addProperty(TStockProperties.DEVLOCATION, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          char[] newLocation = new char[64];
          if ((cc=din.getData(newLocation)) != 0) return cc;
          tdv.setLocation(new String(newLocation));         
          String[] loc = new String[deviceList.getNumberOfDevices()];
          for (int i=0; i<loc.length; i++) loc[i] = deviceList.getDevice(i).getLocation();
          saveStockPropertyValues("DEVLOCATION",devName,new TDataType(loc));
        }       
        String dloc = tdv.getLocation();
        if (dloc == null) dloc = gEqmFactory.getFecLocation();
        if (dloc != null && dloc.startsWith("<"))
        { /* redirection character */
          String rdrstr = null, envstr;
          dloc = dloc.substring(1); dloc.trim();
          if (dloc.startsWith("$"))
          {
            int idx = dloc.indexOf('/');
            if (idx < 0) idx = dloc.length();
            envstr = dloc.substring(1, idx);
            rdrstr = System.getenv(envstr);
            if (rdrstr == null) MsgLog.log("TEquipmentModule:DEVLOCATION", "environment variable "+envstr+" not set",TErrorList.not_defined,null,0);
            dloc = dloc.substring(idx);
          }
          if (rdrstr == null) rdrstr = "";
          rdrstr += dloc;
          if (rdrstr.indexOf('[') < 0) rdrstr += "[Location]";
          return gEqmFactory.setRedirectionString(rdrstr);
        }      
        return dout.putData(dloc == null ? "" : dloc);
      }
    });   
    stockList.addProperty(TStockProperties.DEVMASK, devMaskHandler);
    stockList.addProperty(TStockProperties.SYS_MASK, devMaskHandler);
    stockList.addProperty(TStockProperties.ZPOSITION, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          try
          {
            int cc = 0;
            float[] newZPos = new float[1];
            if ((cc=din.getData(newZPos)) != 0) return cc;
            tdv.setZposition(newZPos[0]);
            float[] zp = new float[deviceList.getNumberOfDevices()];
            for (int i=0; i<zp.length; i++) zp[i] = deviceList.getDevice(i).getZposition();
            saveStockPropertyValues("ZPOSITION",devName,new TDataType(zp));
          }
          catch (Exception x) { x.printStackTrace(); }
        }               
        float p = tdv.getZposition();
        return dout.putData(p);
      }
    });   
    stockList.addProperty(TStockProperties.DEVONLINE, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          int[] newFlg = new int[1];
          if ((cc=din.getData(newFlg)) != 0) return cc;
          tdv.setOffline(newFlg[0] == 0 ? true : false);         
          boolean[] m = new boolean[deviceList.getNumberOfDevices()];
          for (int i=0; i<m.length; i++) m[i] = !deviceList.getDevice(i).isOffline();
          saveStockPropertyValues("DEVONLINE",devName,new TDataType(m));
        }               
        boolean p = !tdv.isOffline();
        return dout.putData(p);
      }
    });   
    stockList.addProperty(TStockProperties.PROPERTIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return prpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.PROPERTIES_USTRING, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return prpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.PROPERTIES_STRUCT, propertiesStructHandler);
    stockList.addProperty(TStockProperties.PROPS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return prpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.PROPS_USTRING, new TPropertyHandler()
        {
          public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
          {
            return prpQueryCall(devName,dout,din,devAccess);
          }
        });
    stockList.addProperty(TStockProperties.PROPS_STRUCT, propertiesStructHandler);
    stockList.addProperty(TStockProperties.NPROPERTIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData(propertyList.countUniqueProperties());
      }
    });
    // Same as NPROPERTIES
    stockList.addProperty(TStockProperties.NPROPS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData(propertyList.countUniqueProperties());
      }
    });
    stockList.addProperty(TStockProperties.NDEVICES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        //return dout.putData(deviceList.size());
        return dout.putData(deviceList.getNumberOfDevices());
      }
    });
    stockList.addProperty(TStockProperties.DEVICES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        String[] namlst;
        if (devName.compareTo("*") != 0 && devName.indexOf("*") != -1)
        { // query for a subset of device names ...
          WildcardMatch wc = new WildcardMatch(devName);
          TDevice dev;
          LinkedList<String> nl = new LinkedList<String>();
          String dn;
          int n = 0, mask = 0;
          if (din != null && din.dArrayLength == 1 && din.dFormat == TFormat.CF_INT32)
          {
            int[] msk = new int[1];
            din.getData(msk);
            mask = msk[0];
          }
          for (int i=0; i<deviceList.getNumberOfDevices(); i++)
          {
            if ((dev=deviceList.getDevice(i)) == null) continue;
            if (dev.isOffline()) continue;
            if (mask > 0 && !dev.isMaskSet(mask)) continue;
            dn = dev.getName();
            if (!wc.matches(dn)) continue;
            nl.add(dn);
            n++;
          }
          namlst = nl.toArray(new String[n]);
        }
        else
        {
          namlst = deviceList.getDeviceNameList();
        }
        int cc = dout.putData(StringToName.stringArrayToName64(namlst));
        if (cc == 0)
        {
          if (dout.getArrayLength() > namlst.length) dout.setArrayLength(namlst.length);
          if (getDeviceList().isPropertyOriented())
            cc = TErrorList.has_query_function | TErrorList.CE_SENDDATA;
        }
        return cc;
      }
    });
    stockList.addProperty(TStockProperties.DEVDESCRIPTION, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          char[] newDesc = new char[64];
          if ((cc=din.getData(newDesc)) != 0) return cc;
          tdv.setDescription(new String(newDesc));         
          String[] dsc = new String[deviceList.getNumberOfDevices()];
          for (int i=0; i<dsc.length; i++) dsc[i] = deviceList.getDevice(i).getDescription();
          saveStockPropertyValues("DEVDESCRIPTION",devName,new TDataType(dsc));
        }       
        String dsc = tdv.getDescription();
        return dout.putData(dsc == null ? "" : dsc);
      }
    });   
View Full Code Here

TOP

Related Classes of de.desy.tine.dataUtils.TDataType

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.