Package de.desy.tine.server.devices

Source Code of de.desy.tine.server.devices.TDevice

/*
* Created on Aug 24, 2005
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package de.desy.tine.server.devices;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import de.desy.tine.client.TLinkFactory;
import de.desy.tine.dataUtils.TDataType;
import de.desy.tine.definitions.TErrorList;
import de.desy.tine.definitions.TStrings;
import de.desy.tine.server.alarms.TAlarm;
import de.desy.tine.server.alarms.TAlarmDefinition;
import de.desy.tine.server.alarms.TAlarmDescriptor;
import de.desy.tine.server.alarms.TAlarmWatchEntry;
import de.desy.tine.server.connections.TClient;
import de.desy.tine.server.connections.TNetAcl;
import de.desy.tine.server.equipment.TEquipmentModule;
import de.desy.tine.server.equipment.TEquipmentModuleFactory;
import de.desy.tine.server.logger.*;
import de.desy.tine.stringUtils.StringToName;
import de.desy.tine.types.NAME16;
/**
* Instances of devices served by a device server should inherit from TDevice
*
* @author duval
*
*/
public class TDevice
{
  public int devNumber;
  public String devName;
  private String devDescription;
  private int maximumAllowedNumberOfAlarms = 500;
  public int getMaximumAllowedNumberOfAlarms() { return maximumAllowedNumberOfAlarms; }
  public void setMaximumAllowedNumberOfAlarms(int value) { maximumAllowedNumberOfAlarms = value; }
  private LinkedList<TAlarm> devAlarmList = new LinkedList<TAlarm>();
  private int devAlarmMrt = 0; // Most Recent Timestamp
  private int devAlarmMrct = 0; // Most Recent Complete Timestamp
  private short devAlarmHsv = 0;
  private int nDevAlarmsAtMrt;
  private int nDevAlarmsAtMrct;
  private int nDevAlarmsAtHsv;
  private TEquipmentModule eqm = null;
  private String redirection = null;
  private String region = null;
  private int regionCode = TRegion.DEV_REGION_UNKNOWN;
  public String getRegion() { return region; }
  public int getRegionCode() { return regionCode; }
  public void setRegion(int regionCode)
  {
    region = TRegion.getRegion(regionCode);
    this.regionCode = regionCode;
  }
  public void setRegion(String region)
  {
    if (region == null || region.length() == 0)
      region = TRegion.getRegionMatch(devName);
    this.region = region;
    regionCode = TRegion.getRegionCode(region);
  }
  private String location = null;
  /**
   * @return the location text string assigned to this device.
   */
  public String getLocation()
  {
    return location;
  }
  /**
   * Assigns a location text string to this device.
   *
   * This can be a text description of the physical location of the
   * device or a 'redirection string' of the form '<redirection' or
   * '<$env/device'.
   *
   * For example, '</SITE/Locator/131.169.151.66[Location]' will
   * redirect a call to stock property "DEVLOCATION" to the
   * redirection address given.
   *
   * '<$TINE_LCTR/131.169.151.66' will redirect to which ever
   * server the environment variable 'TINE_LCTR' points to plus
   * the 'device' 131.169.151.66 and the default property 'Location'.
   *
   * In this manner, a server can provide the physical location of
   * any remote IP devices it addresses.
   *
   * @param location is the desired location text for this device
   */
  public void setLocation(String location)
  {
    this.location = location;
  }
  /**
   * @return the configured Z or longitudinal postion of this device.
   */
  public float getZposition()
  {
    return zpos;
  }
  /**
   * Assigns a Z or longitudinal position for this device.
   *
   * The Z position may or may not be relevant to a given device. It
   * essentially refers to the location of the device readout in the accelerator
   * (e.g. along the beam path).
   *
   * @param zpos is the desired Z (longitudinal) position for this
   * device.
   */
  public void setZposition(float zpos)
  {
    this.zpos = zpos;
  }
  /**
   * @return the current device mask for this device
   */
  public int getMask()
  {
    return mask;
  }
  /**
   * Determines whether this device will be returned in
   * a query containing the given mask.
   *
   * @param mask is the mask value to query against.
   * @return
   */
  public boolean isMaskSet(int mask)
  {
    if (this.mask == 0 || mask == 0) return true;
    if ((this.mask & mask) != 0) return true;
    return false;
  }
  /**
   * Assigns a device mask to this device.
   *
   * This is a positive signed integer which can be used as a
   * tag for this device.  Typically this will be a single bit
   * identifier for the category of device that this device
   * belongs to.
   *
   * \note a value of '0' is equivalent to ALL bits.  Hence
   * a device with mask 0 will always appear in any query.
   *
   *  This mask only plays a role in wildcard calls or in calls
   *  referencing the meta-property ".DMASK.".
   *
   * @param mask is the desired device mask
   */
  public void setMask(int mask)
  {
    this.mask = mask;
  }
  /**
   * @return the current off-line status of the device
   */
  public boolean isOffline()
  {
    return offline;
  }
  /**
   * Set this device off-line (true) or on-line (false).
   *
   * This is a purely software flag which is only relevant in
   * wildcard calls or calls referencing the meta-property ".ONLINE".
   *
   * @param offline is the desired 'off line' status of the device
   */
  public void setOffline(boolean offline)
  {
    this.offline = offline;
  }
  private float zpos = 0;
  private int mask = 0;
  private boolean offline = false;
  private LinkedList<String> gRegisteredUsersList = new LinkedList<String>();
  private LinkedList<String> gRegisteredGroupsList = new LinkedList<String>();
  private LinkedList<TNetAcl> gRegisteredNetsList = new LinkedList<TNetAcl>();
  public NAME16[] getRegisteredUsers() { return StringToName.stringSetToName16(gRegisteredUsersList); }
  public int getNumberRegisteredUsers() { return gRegisteredUsersList.size(); }
  public int getNumberRegisteredNets() { return gRegisteredNetsList.size(); }
  public int addRegisteredUser(String newUser)
  {
    if (newUser == null) return TErrorList.argument_list_error;
    newUser = newUser.toUpperCase();
    synchronized (gRegisteredUsersList)
    {
      if (gRegisteredUsersList.contains(newUser)) return TErrorList.already_assigned;
      gRegisteredUsersList.add(newUser);
    }
    return 0;
  }
  public int removeRegisteredUser(String oldUser)
  {
    if (oldUser == null) return TErrorList.argument_list_error;
    oldUser = oldUser.toUpperCase();
    synchronized (gRegisteredUsersList)
    {
      if (!gRegisteredUsersList.contains(oldUser)) return TErrorList.invalid_name;   
      gRegisteredUsersList.remove(oldUser);   
    }
    return 0;
  }
  public void removeAllRegisteredUsers()
  {
    synchronized (gRegisteredUsersList)
    {
      gRegisteredUsersList.clear();
    }
  }
  public boolean isMemberUsersList(TClient tc)
  {
    TEquipmentModuleFactory eqmf = TEquipmentModuleFactory.getInstance();
    if (tc.isMemberUsersList(gRegisteredUsersList)) return true;
    if (eqmf.isMemberGroupsList(gRegisteredGroupsList, tc.userName)) return true;
    return false;
  }
  public NAME16[] getRegisteredNets()
  {
    int n = gRegisteredNetsList.size();
    if (n == 0) return null;
    NAME16[] n16 = new NAME16[n];
    int i = 0;
    for (TNetAcl a : gRegisteredNetsList)
    {
      if (i++ < n) n16[i] = new NAME16(a.getStrAddress());
    }
    return n16;
  }
  public int addRegisteredNet(String newNet)
  {
    if (newNet == null) return TErrorList.argument_list_error;
    synchronized (gRegisteredNetsList)
    {
      TNetAcl a = new TNetAcl(newNet);
      if (gRegisteredNetsList.contains(a)) return TErrorList.already_assigned;
      gRegisteredNetsList.add(a);
    }
    return 0;
  }
  public int removeRegisteredNet(String oldNet)
  {
    if (oldNet == null) return TErrorList.argument_list_error;
    synchronized (gRegisteredNetsList)
    {
      TNetAcl a = new TNetAcl(oldNet);
      if (!gRegisteredNetsList.contains(a)) return TErrorList.invalid_name;   
      gRegisteredNetsList.remove(a);
    }
    return 0;
  }
  public void removeAllRegisteredNets()
  {
    synchronized (gRegisteredNetsList)
    {
      gRegisteredNetsList.clear();
    }
  } 
  public boolean isMemberControlNets(TClient tc)
  {
    return tc.isMemberControlNets(gRegisteredNetsList);
  }
  private LinkedList<String> devPrpList = null;
  public LinkedList<String> getPropertyList() { return devPrpList; }
  private LinkedList<String> mapStringArrayToList(String[] prpArray)
  {
    if (prpArray == null) return null;
    LinkedList<String> ll = new LinkedList<String>();
    for (String p : prpArray) ll.add(p);
    return ll;
  }
  /**
   * Assigns a list of registered properties to this device.
   *
   * Under some circumstances not all registered properties will be
   * supported by all registered devices.  This registration call can
   * be used to assign a specific list of (registered) properties to
   * this devices.  If a property in the assigned list is NOT found
   * in the property registry then will have no effect.
   *
   * @param prpList is the list of properties to assign to this device.
   */
  public void setPropertyList(String[] prpList)
  {
    devPrpList = mapStringArrayToList(prpList);
  }
  public void setPropertyList(List<String> prpList)
  {
    if (prpList instanceof LinkedList<?>)
    {
      devPrpList = (LinkedList<String>)prpList;
    }
    else if (prpList instanceof ArrayList<?>)
    {
      String[] prps = ((ArrayList<String>)prpList).toArray(new String[0]);
      devPrpList = mapStringArrayToList(prps);
    }
  }
  public int getHighestAlarmSeverity() { return devAlarmHsv; }
  public int getNumberOfAlarmsAtMostRecentTimestamp() { return nDevAlarmsAtMrct; }
  public int getNumberOfAlarmsAtHighestSeverity() { return nDevAlarmsAtHsv; }
  public TAlarm[] getAlarmList()
  {
    synchronized (devAlarmList)
    {
      return (TAlarm[])devAlarmList.toArray(new TAlarm[0]);
    }
  }
  private TAlarm getAlarmFromList(int code,byte[] data,short flags,TAlarmWatchEntry awe)
  { // called only by setAlarm() ...
    TAlarm alm = null;
    int nerr = 0;
    int thisTimeStamp = (int)(System.currentTimeMillis()/1000);
    boolean keepTimestamp = false;
    synchronized (devAlarmList)
    {
      Iterator<TAlarm> li = devAlarmList.iterator();
      if (code == 0) DbgLog.log("getAlarmFromList","searching for alarm code == 0?");
      while (li.hasNext())
      {
        try
        {
          alm = (TAlarm)li.next();
        }
        catch (ConcurrentModificationException e)
        { // this shouldn't happen !
          // (if a caller uses a 'set' method on the alarm, it's almost gotta be right after this gets called)
          nerr++;
          MsgLog.log("getAlarmFromList", "concurrent modification error "+nerr,TErrorList.semaphore_error,e,0);
          if (nerr > 3) return null;
          continue;
        }
        keepTimestamp = false;
        TAlarmDefinition ads = alm.getAlmDef();
        if (alm.isTerminated())
        { // is marked for termination
          boolean oscPinned = TAlarm.getAlmOscillationWindowPinned();
          int oscw = TAlarm.getAlmOscillationWindow();
          if (ads != null)
          {
            if (!oscPinned) oscPinned = ads.isOscillationWindowPinned();
            oscw = ads.getAlarmOscillationWindow();
          }
          if (!alm.isTransient() && !oscPinned)
          { // oscillation window too small ?
            int dt = (alm.getTimeStamp()+TAlarm.getTerminationWindow()) - (int)(System.currentTimeMillis()/1000);
            if (dt > 0 && dt < TAlarm.ALM_OSCILLATION_MAXIMUM-oscw)
            { // adjust the oscillation window
              oscw += dt;
              if (ads != null) ads.setAlarmOscillationWindow(oscw);
              else TAlarm.setAlmOscillationWindow(oscw,false);
              if (TEquipmentModuleFactory.getDebugLevel() > 0)
                DbgLog.log("getAlarmFromList","increase alarm oscillation windows to "+oscw+" clear counts");
            }
          }
          continue;
        }
        else
        { // not marked for termination
          if (alm.getCode() == code && alm.getWatchEntry() == awe)
          { // it's already in the list so remove NEW bit !
            byte dsc = alm.getDescriptor();
            byte[] adata = alm.getData();
            int dlen = ads == null ? 0 : ads.getAlarmDataArraySize();
            if (dlen > 0 && data != null && adata != null)
            { // check for alarm data changed
              for (int n=0; n<dlen && n<adata.length && n<data.length; n++)
              {
                if (data[n] != adata[n])
                { // remove NEW and add DATACHANGE
                  dsc &= ~(byte)(TAlarmDescriptor.NEW);
                  if (alm.isDataChange())
                  { // already marked as data change (when was the last time ?)
                    if (thisTimeStamp - alm.getTimeStamp() < TAlarm.getAlmDataChangeWindow())
                    {
                      keepTimestamp = true;
                    }
                  }
                  if (!keepTimestamp) alm.setTimeStamp(thisTimeStamp);
                  dsc |= (byte)TAlarmDescriptor.DATACHANGE;
                  if (TEquipmentModuleFactory.getDebugLevel() > 0)
                    DbgLog.log("getAlarmFromList",alm.getTag() + " : alarm data changed");
                  break;
                }
              }
            }
            if (alm.getClearCount() > 1)
            { // check for oscillating alarm ...
              dsc &= ~(byte)(TAlarmDescriptor.NEW);
              if (alm.isOscillating()) keepTimestamp = true;
              if (!keepTimestamp) alm.setTimeStamp(thisTimeStamp);
              dsc |= (byte)TAlarmDescriptor.OSCILLATION;
              if (TEquipmentModuleFactory.getDebugLevel() > 0)
                DbgLog.log("getAlarmFromList",alm.getTag() + " : mark alarm as oscillating");
            }
            alm.resetClearCount();
            alm.setDescriptor(dsc);
            return alm;
          }
        }
      }
      // not found, so this is a new one ...
      // TODO: worry about 'max_alarms_exceeded', i.e. alarm storms and the length of this list!
      if (devAlarmList.size() > maximumAllowedNumberOfAlarms)
      {
        devAlarmList.removeFirst();
        MsgLog.log("TDevice.getAlarmFromList", "alarm buffer full",TErrorList.max_alarms_exceeded,null,1);
      }
      flags |= TAlarmDescriptor.NEW;
      if ((flags & TAlarmDescriptor.TRANSIENT) != 0) flags |= TAlarmDescriptor.TERMINATE;
      alm = new TAlarm(code,(byte)flags,data,this);
      alm.setWatchEntry(awe);
      if (eqm.casReadRequired) alm.blockRemoval();
      devAlarmList.add(alm);
    }
    if (TEquipmentModuleFactory.getDebugLevel() > 0)
      DbgLog.log("getAlarmFromList",devName + " : " + alm.getTag() + "(" + code + ") : add alarm to list");
    return alm;
  }
  public int getNumberOfAlarms()
  {
    synchronized (devAlarmList)
    {
      return devAlarmList.size();
    }  
  }
  public int getMostRecentTimestamp()
  {
    synchronized (devAlarmList)
    {
      return devAlarmMrct;
    }
  }
  private void refreshMrt(int ts)
  {
    if (ts > devAlarmMrt)
    {
      devAlarmMrt = ts;
      nDevAlarmsAtMrt = 1;
    }
    else if (ts == devAlarmMrt)
    {
      nDevAlarmsAtMrt++;
   
  }
  private void refreshHsv(short sv)
  {
    if (sv > devAlarmHsv)
    {
      devAlarmHsv = sv;
      nDevAlarmsAtHsv = 1;
    }
    else if (sv == devAlarmHsv)
    {
      nDevAlarmsAtHsv++;
    }
  }
  public void processAlarms()
  {
    int nerr = 0;
    int thisTimeStamp = (int)(System.currentTimeMillis()/1000);
    TAlarm alm = null;
    synchronized (devAlarmList)
    {
      Iterator<TAlarm> li = devAlarmList.iterator();
      nDevAlarmsAtHsv = 0; devAlarmHsv = 0;
      nDevAlarmsAtMrt = 0; devAlarmMrt = 0;
      nDevAlarmsAtMrct = 0;
      while (li.hasNext())
      {
        try
        {
          alm = (TAlarm)li.next();
        }
        catch (ConcurrentModificationException e)
        { // someone could be using e.g. the setData() method on the alarm itself
          // (not a good way to do it, but it's supported)
          nerr++;
          MsgLog.log("processAlarms", "concurrent modification error "+nerr,TErrorList.semaphore_error,e,0);
          if (nerr > 3) return;
          continue;
        }
        if (alm.isTerminated() && 
            thisTimeStamp > alm.getTimeStamp() + TAlarm.getTerminationWindow())
        {
          if (alm.getSeverity() > 0 && alm.isRemovalBlocked())
          {
            if (TEquipmentModuleFactory.getDebugLevel() > 2) DbgLog.log("processAlarms",alm.getTag() + " : missing CAS read -> removal blocked");
          }
          else
          {
            if (TEquipmentModuleFactory.getDebugLevel() > 1) DbgLog.log("processAlarms",alm.getTag() + " : remove alarm");
            li.remove();
            continue;
          }
        }
        // apply termination flag if necessary ...
        if (!alm.isTerminated() && thisTimeStamp > alm.getTimeStamp())
        {
          int oscw = TAlarm.getAlmOscillationWindow();
          TAlarmDefinition ads = alm.getAlmDef();
          if (ads != null) oscw = ads.getAlarmOscillationWindow();
          if (alm.getClearCount() > (oscw-TAlarm.ALM_OSCILLATION_CUSHION))
          {
            byte dsc = alm.getDescriptor();
            dsc &= ~(byte)TAlarmDescriptor.NEW;
            dsc |= (byte)TAlarmDescriptor.TERMINATE;
            alm.setDescriptor(dsc);
            alm.setTimeStamp(thisTimeStamp);
            //refreshMrt(thisTimeStamp);
            alm.setTerminated(true);
            DbgLog.log("processAlarms",alm.getTag() + " : mark alarm as terminated");
          }
        }
        // apply heartbeat if necessary
        if (thisTimeStamp > alm.getTimeStamp() + TAlarm.getAlmHeartbeatWindow())
        {
          byte dsc = alm.getDescriptor();
          dsc &= ~(byte)TAlarmDescriptor.NEW;
          dsc |= (byte)TAlarmDescriptor.HEARTBEAT;
          alm.setDescriptor(dsc);
          alm.setTimeStamp(thisTimeStamp);
          //refreshMrt(thisTimeStamp);
        }
        refreshMrt(alm.getTimeStamp());
        refreshHsv((short)alm.getSeverity());
      }
      // adjust most recent completed timestamp (if necessary)
      int mrct = 0;
      if (thisTimeStamp > devAlarmMrt && devAlarmMrt > mrct)
      {
        nDevAlarmsAtMrct = nDevAlarmsAtMrt;
        mrct = devAlarmMrt;         
      }
      devAlarmMrct = mrct;
    }
  }
  /**
   * Sets an alarm with the given code
   *
   * @param code The alarm code to apply to the alarm
   * @return the Alarm instance that was set.
   */
  public TAlarm setAlarm(int code)
  {
    return setAlarm(code,null,TAlarmDescriptor.NEW);   
  }
  /**
   * Sets an alarm with the given data set
   *
   * @param code The alarm code to apply to the alarm
   * @param data The alarm data associated with the alarm
   * @return the Alarm instance that was set.
   */
  public TAlarm setAlarm(int code,byte[] data)
  {
    return setAlarm(code,data,TAlarmDescriptor.NEW);
  }
  public TAlarm setAlarm(int code,byte[] data,TAlarmWatchEntry awe)
  {
    TAlarm alm = getAlarmFromList(code,data,TAlarmDescriptor.NEW,awe);
    if (alm.isTerminated()) DbgLog.log("setAlarm",alm.getTag() + " : set alarm as terminated");
    return alm;
  }
  /**
   * Sets an alarm with the given data set
   *
   * @param code The alarm code to apply to the alarm
   * @param data The alarm data associated with the alarm
   * @return the Alarm instance that was set.
   */
  public TAlarm setAlarm(int code,TDataType data)
  {
    return setAlarm(code,data.getDataBuffer(),TAlarmDescriptor.NEW);
  }
  /**
   * Sets an alarm with the given data set
   *
   * @param code The alarm code to apply to the alarm
   * @param data The alarm data associated with the alarm
   * @return
   */
  public TAlarm setAlarm(int code,float data)
  {
    float[] fdata = new float[1];
    fdata[0] = data;
    TDataType td = new TDataType(fdata);
    return setAlarm(code,td.getDataBuffer(),TAlarmDescriptor.NEW);
  }
  /**
   * Sets an alarm with the given data set
   *
   * @param code The alarm code to apply to the alarm
   * @param data The alarm data associated with the alarm
   * @return the Alarm instance that was set.
   */
  public TAlarm setAlarm(int code,int data)
  {
    int[] idata = new int[1];
    idata[0] = data;
    TDataType td = new TDataType(idata);
    return setAlarm(code,td.getDataBuffer(),TAlarmDescriptor.NEW);
  }
  /**
   * Sets an alarm with the given data set
   *
   * @param code The alarm code to apply to the alarm
   * @param data The alarm data associated with the alarm
   * @return the Alarm instance that was set.
   */
  public TAlarm setAlarm(int code,short[] data)
  {
    TDataType td = new TDataType(data);
    return setAlarm(code,td.getDataBuffer(),TAlarmDescriptor.NEW);
  }
  /**
   * Sets an alarm with the given data set and given flags
   *
   * On rare occasions you might want to apply the alarm descriptor flags
   * yourself in a call to setAlarms(). 
   *
   * @param code The alarm code to apply to the alarm
   * @param data The alarm data associated with the alarm
   * @param flags The alarm descriptor to apply to the alarm
   * @return the Alarm instance that was set.
   */
  public TAlarm setAlarm(int code,byte[] data,short flags)
  {
    if (offline)
    {
      if (TLinkFactory.debugLevel > 2) DbgLog.log("setAlarm","alarm not set: "+devName+" is off line");
      return null;
    }
    TAlarm alm = getAlarmFromList(code,data,flags,null);
    if (alm.isTerminated()) DbgLog.log("setAlarm",alm.getTag() + " : set alarm as terminated");
    return alm;
  }
  /**
   * Clears all alarms in the local alarm server's list
   *
   */
  public void clearAlarms()
  {
    synchronized (devAlarmList)
    {
      Iterator<TAlarm> li = devAlarmList.iterator();
      while (li.hasNext()) ((TAlarm)li.next()).clear();
    }
  }
  /**
   * Clears the alarm with the given code in the local alarm server's list
   *
   * The alarm's clear counter will be incremented.  A call to clearAlarm() will
   * not cause the alarm to be removed from the list until the clear counter is
   * greater than 8.
   *
   * @param code Is the alarm code specifying which alarm to clear
   */
  public void clearAlarm(int code)
  {
    TAlarm alm = null;
    synchronized (devAlarmList)
    {
      int lstalm = 0;
      Iterator<TAlarm> li = devAlarmList.iterator();
      while (li.hasNext())
      {
        alm = (TAlarm)li.next();
        if ((alm.getDescriptor() & TAlarmDescriptor.TERMINATE) != 0) continue;
        lstalm = alm.getCode();
        if (code == TErrorList.warn_disk_space || code == TErrorList.low_disk_space)
        { // mask off the high bits
          lstalm &= 0xff;
        }
        if (lstalm != code) continue;
        alm.clear();
      }
    }
  }
  public void clearAlarm(int code,TAlarmWatchEntry awe)
  {
    TAlarm alm = null;
    synchronized (devAlarmList)
    {
      Iterator<TAlarm> li = devAlarmList.iterator();
      while (li.hasNext())
      {
        alm = (TAlarm)li.next();
        if ((alm.getDescriptor() & TAlarmDescriptor.TERMINATE) != 0) continue;
        if (alm.getCode() != code && alm.getWatchEntry() != awe) continue;
        alm.clear();
      }
    }
  }
  /**
   * Removes the alarm with the given code from the local alarm server's list
   *
   * @param code Is the alarm code specifying which alarm to remove from the
   * local alarm server's list
   */
  public void removeAlarm(int code)
  {
    synchronized (devAlarmList)
    {
      boolean found = false;
      Iterator<TAlarm> li = devAlarmList.iterator();
      TAlarm alm = null;
      while (li.hasNext())
      {
        alm = (TAlarm)li.next();
        if ((alm.getDescriptor() & TAlarmDescriptor.TERMINATE) != 0) continue;
        if (alm.getCode() != code) continue;
        alm.setDescriptor((byte)TAlarmDescriptor.TERMINATE);
        alm.clear();
        found = true;
      }
      if (!found)
      {
        if (TEquipmentModuleFactory.getDebugLevel() > 2)
          DbgLog.log("removeAlarm","removeAlarm: no alarms with code "+code+" for device "+devName+" were found!");
      }
    }
  }
  /**
   * Simple constructor which assigns a device name and number
   *
   * Use this constructor if you do not make use of a '<local-names>-devices.csv'
   * but instead either read your own database to determine the device name
   * name list.  You can assign a number and name to the device in question.
   *
   * @param name The device name to apply to this device
   * @param number The device number to apply to this device
   */
  public TDevice(String name, int number)
  {
    TStrings.validateDeviceName(name);
    devName = name;
    devNumber = number;
  }
  /**
   * Simple constructor which assigns a device number
   *
   * Use this constructor if you make use of a '<local-names>-devices.csv'
   * configuration file to register devices or if you intend on using the
   * setName() method to attach a name to the device.
   * 
   * @param number The device number associated with this device
   */
  public TDevice(int number)
  {
    devName = "#" + number;
    devNumber = number;
  }
  /**
   * Complex constructor which assigns name, number, and equipment module
   *
   * You should not normally need to make use of this constructor, as the
   * identity of the equipment module is usually determined elsewhere during
   * initialization.
   *
   * @param name The device name associated with this device
   * @param number The device number associated with this device
   * @param equipmentModule The equipment module to associate with this device
   */
  public TDevice(String name, int number, TEquipmentModule equipmentModule)
  {
    TStrings.validateDeviceName(name);
    devName = name;
    devNumber = number;
    eqm = equipmentModule;
    if (!eqm.getRegisteredUsersFromFile(gRegisteredUsersList,gRegisteredGroupsList,null,name))
    {
      eqm.getRegisteredUsersFromFile(gRegisteredUsersList,gRegisteredGroupsList,null,"device-default");
    }
    if (!eqm.getRegisteredNetsFromFile(gRegisteredNetsList,null,name))     
    {
      eqm.getRegisteredNetsFromFile(gRegisteredNetsList,null,"device-default");
    }
  }
  public TEquipmentModule getEqm()
  {
    return eqm;
  }
  /**
   * Returns the registered device name
   *
   * @return The registered device name
   */
  public String getName() { return devName; }
  /**
   * Sets the device name for this device
   *
   * @param name The device name to associate with this device
   */
  public void setName(String name)
  {
    TStrings.validateDeviceName(name);
    devName = name;
  }
  public void setEqm(TEquipmentModule eqm)
  {
    this.eqm = eqm;
    if (eqm != null)
    {
      if (!this.eqm.getRegisteredUsersFromFile(gRegisteredUsersList,gRegisteredGroupsList,null,devName))
      {
        this.eqm.getRegisteredUsersFromFile(gRegisteredUsersList,gRegisteredGroupsList,null,"device-default");
      }
      if (!this.eqm.getRegisteredNetsFromFile(gRegisteredNetsList,null,devName))     
      {
        this.eqm.getRegisteredNetsFromFile(gRegisteredNetsList,null,"device-default");
      }
    }
  }
  /**
   * Returns the redirection string associated with this device
   * @return the redirection string associated with this device
   */
  public String getRedirection()
  {
    return redirection;
  }
  /**
   * Sets a redirection string to apply to this device
   *
   * If the device has a redirection string associated with it, then
   * all remote requests for properties for this device will be
   * redirected to the remote device server given in the redirection string.
   *
   * @param redirection The redirection string of the general form
   * '/<context>/<server>/<device name>[property]'.  In this case, ONLY
   * the '<server>' element is relevant.
   */
  public void setRedirection(String redirection)
  {
    this.redirection = redirection;
  }
  /**
   * Gets the assigned description for this device
   *
   * A device description can be assigned to a specific device. This
   * method call returns the assigned description.
   *
   */
  public String getDescription()
  {
    return devDescription;
  }
  /**
   * Sets a description for this device
   *
   * A device description can be assigned to a specific device via this
   * method call.
   *
   * @param description The description to be applied to this device.
   */
  public void setDescription(String description)
  {
    devDescription = description;
  }
}
TOP

Related Classes of de.desy.tine.server.devices.TDevice

TOP
Copyright © 2018 www.massapi.com. 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.