All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.esrf.TangoApi.DeviceDataHistoryDAODefaultImpl Maven / Gradle / Ivy

There is a newer version: 10.0.0
Show newest version
//+======================================================================
// $Source$
//
// Project:   Tango
//
// Description:  java source code for the TANGO client/server API.
//
// $Author: pascal_verdier $
//
// Copyright (C) :      2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,
//						European Synchrotron Radiation Facility
//                      BP 220, Grenoble 38043
//                      FRANCE
//
// This file is part of Tango.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with Tango.  If not, see .
//
// $Revision: 25297 $
//
//-======================================================================


package fr.esrf.TangoApi;

import fr.esrf.Tango.*;
import fr.esrf.TangoDs.Except;
import fr.esrf.TangoDs.TangoConst;
import org.omg.CORBA.Any;
import org.omg.CORBA.TCKind;
import org.omg.CORBA.TypeCode;


/**
 *	Class Description:
 *	This class manage data object for Tango device history Data access.
 *	

*
Usage example:
*
    * DeviceDataHistory[] histo = dev.command_history("ReadCurrent", 10);
    * for (int i=0 ; i < histo.length ; i++)
    * {
      * Date d = new Date(histo[i].getTime());
      * double[] values = histo[i].extractDoubleArray();
    * }
    *
* * @author verdier * @version $Revision: 25297 $ */ public class DeviceDataHistoryDAODefaultImpl implements IDeviceDataHistoryDAO { private Any any; private AttributeValue_3 attrval; private TimeVal tval; public DeviceDataHistoryDAODefaultImpl() { } //=========================================== /** * Constructor from a DevCmdHistory. */ //=========================================== public void init(DeviceDataHistory deviceDataHistory, String cmdname, DevCmdHistory cmd_hist) throws DevFailed { any = cmd_hist.value; deviceDataHistory.source = TangoConst.COMMAND; deviceDataHistory.name = cmdname; tval = cmd_hist.time; deviceDataHistory.failed = cmd_hist.cmd_failed; deviceDataHistory.errors = cmd_hist.errors; } //=========================================== /** * Constructor from an AttributeValue. */ //=========================================== public void init(DeviceDataHistory deviceDataHistory, DevAttrHistory att_histo) throws DevFailed { any = att_histo.value.value; deviceDataHistory.source = TangoConst.ATTRIBUTE; attrval = new AttributeValue_3(any, att_histo.value.quality, att_histo.value.time, att_histo.value.name, new AttributeDim(att_histo.value.dim_x, att_histo.value.dim_y), new AttributeDim(0, 0), att_histo.errors); deviceDataHistory.name = att_histo.value.name; tval = att_histo.value.time; deviceDataHistory.failed = att_histo.attr_failed; deviceDataHistory.errors = att_histo.errors; } //=========================================== /** * Constructor from an AttributeValue for Device_3Impl. */ //=========================================== public void init(DeviceDataHistory deviceDataHistory, DevAttrHistory_3 att_histo) throws DevFailed { any = att_histo.value.value; deviceDataHistory.source = TangoConst.ATTRIBUTE; attrval = att_histo.value; deviceDataHistory.name = att_histo.value.name; tval = att_histo.value.time; deviceDataHistory.failed = att_histo.attr_failed; deviceDataHistory.errors = att_histo.value.err_list; } //=========================================== /** * Constructor from an AttributeValue for Device_4Impl. */ //=========================================== public void init(DeviceDataHistory deviceDataHistory, String name, int source, TimeVal time) throws DevFailed { any = null; deviceDataHistory.source = source; attrval = new AttributeValue_3(null, null, time, name, null, null, null); deviceDataHistory.name = name; tval = time; deviceDataHistory.failed = false; deviceDataHistory.errors = null; } //=========================================== /** * Constructor from an AttributeValue for Device_4Impl. */ //=========================================== public void init(DeviceDataHistory deviceDataHistory, String name, int source, long t) throws DevFailed { any = null; deviceDataHistory.source = source; int sec = (int) (t/1000); int usec = (int) ((t-1000*sec)*1000); TimeVal time = new TimeVal(sec, usec, 0); attrval = new AttributeValue_3(null, null, time, name, null, null, null); deviceDataHistory.name = name; tval = time; deviceDataHistory.failed = false; deviceDataHistory.errors = null; } //=========================================== /** * Set attribute time value. */ //=========================================== public void setTimeVal(DeviceDataHistory deviceDataHistory, TimeVal tval) { this.tval = tval; } //=========================================== /** * Return attribute time value. */ //=========================================== public TimeVal getTimeVal(DeviceDataHistory deviceDataHistory) { return tval; } //=========================================== /** * Return attribute time value in seconds since EPOCH. */ //=========================================== public long getTimeValSec(DeviceDataHistory deviceDataHistory) { return (long)tval.tv_sec; } //=========================================== /** * return time in milliseconds since EPOCH * to build a Date class. */ //=========================================== public long getTime(DeviceDataHistory deviceDataHistory) { return (long)tval.tv_sec * 1000 + tval.tv_usec/1000; } //=========================================== /** * Set AttrQuality if from attribute. */ //=========================================== public void setAttrQuality(DeviceDataHistory deviceDataHistory, AttrQuality q) throws DevFailed { attrval.quality = q; } //=========================================== /** * return AttrQuality if from attribute. */ //=========================================== public AttrQuality getAttrQuality(DeviceDataHistory deviceDataHistory) throws DevFailed { if (deviceDataHistory.source==TangoConst.COMMAND) Except.throw_non_supported_exception("TangoApi_NOT_AVAILABLE", "Method not avalaible for command", "DeviceDataHistory.getAttrQuality()"); return attrval.quality; } //=========================================== /** * Ret Seturn attribute dim_x if from attribute. */ //=========================================== public void setDimX(DeviceDataHistory deviceDataHistory, int dim) throws DevFailed { if (attrval.r_dim==null) attrval.r_dim = new AttributeDim(); attrval.r_dim.dim_x = dim; attrval.r_dim.dim_y = 1; } //=========================================== /** * Ret Seturn attribute dim_y if from attribute. */ //=========================================== public void setDimY(DeviceDataHistory deviceDataHistory, int dim) throws DevFailed { if (attrval.r_dim==null) attrval.r_dim = new AttributeDim(); attrval.r_dim.dim_y = ((dim==0)? 1:dim); } //=========================================== /** * Return attribute dim_x if from attribute. */ //=========================================== public int getDimX(DeviceDataHistory deviceDataHistory) throws DevFailed { if (deviceDataHistory.source==TangoConst.COMMAND && attrval.r_dim==null) Except.throw_non_supported_exception("TangoApi_NOT_AVAILABLE", "Method not avalaible for command", "DeviceDataHistory.getDimX()"); return attrval.r_dim.dim_x; } //=========================================== /** * Return attribute dim_y if from attribute. */ //=========================================== public int getDimY(DeviceDataHistory deviceDataHistory) throws DevFailed { if (deviceDataHistory.source==TangoConst.COMMAND && attrval.r_dim==null) Except.throw_non_supported_exception("TangoApi_NOT_AVAILABLE", "Method not avalaible for command", "DeviceDataHistory.getDimY()"); return attrval.r_dim.dim_y; } //=========================================== /** * Returns true is attribute failed */ //=========================================== public boolean hasFailed(DeviceDataHistory deviceDataHistory) { return deviceDataHistory.failed; } //=========================================== /** * Set the attribute errors list */ //=========================================== public void setErrStack(DeviceDataHistory deviceDataHistory, DevError[] err) { deviceDataHistory.failed = true; attrval.err_list = err; } //=========================================== /** * Returns the attribute errors list */ //=========================================== public DevError[] getErrStack(DeviceDataHistory deviceDataHistory) { return attrval.err_list; } //=========================================== /** * Return attribute name. */ //=========================================== public String getName(DeviceDataHistory deviceDataHistory) { return attrval.name; } //=========================================== //=========================================== private int DIM_MINI(int x) { return (x==0) ? 1 : x; } //=========================================== /** * Return number of data read. */ //=========================================== public int getNbRead(DeviceDataHistory deviceDataHistory) { return attrval.r_dim.dim_x * DIM_MINI(attrval.r_dim.dim_y); } //=========================================== /** * Return number of data written. */ //=========================================== public int getNbWritten(DeviceDataHistory deviceDataHistory) { return attrval.w_dim.dim_x * DIM_MINI(attrval.w_dim.dim_y); } //=========================================== /** * Set attribute written dim_x. */ //=========================================== public void setWrittenDimX(DeviceDataHistory deviceDataHistory, int dim) { if (attrval.w_dim==null) attrval.w_dim = new AttributeDim(); attrval.w_dim.dim_x = dim; attrval.w_dim.dim_y = 1; } //=========================================== /** * Set attribute written dim_y. */ //=========================================== public void setWrittenDimY(DeviceDataHistory deviceDataHistory, int dim) { if (attrval.w_dim==null) attrval.w_dim = new AttributeDim(); attrval.w_dim.dim_y = ((dim==0)? 1:dim); } //=========================================== /** * Return attribute written dim_x. */ //=========================================== public int getWrittenDimX(DeviceDataHistory deviceDataHistory) { return attrval.w_dim.dim_x; } //=========================================== /** * Return attribute written dim_y. */ //=========================================== public int getWrittenDimY(DeviceDataHistory deviceDataHistory) { return attrval.w_dim.dim_y; } //=========================================== //=========================================== //=========================================== //=========================================== //=========================================== /** * Throws exception if err_list not null. * * @throws DevFailed in case of read_attribute failed */ //=========================================== private void manageExceptions(String method_name) throws DevFailed { if (attrval.err_list!=null) if (attrval.err_list.length>0) throw new WrongData(attrval.err_list); if (attrval.quality==AttrQuality.ATTR_INVALID) Except.throw_wrong_data_exception("AttrQuality_ATTR_INVALID", "Attribute quality factor is INVALID", "DeviceAttributeHistory." + method_name + "()"); } //********** Extract Methods for basic types ********************* //=========================================== /** * extract method for a CORBA Any. */ //=========================================== public Any extractAny(DeviceDataHistory deviceDataHistory) throws DevFailed { return any; } //=========================================== /** * extract method for a boolean. */ //=========================================== public boolean extractBoolean(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractBoolean()"); if (bool_data!=null) // Result is not in any return bool_data[0]; else return DevBooleanHelper.extract(any); } //=========================================== /** * extract method for an unsigned char. * @return the extracted value. */ //=========================================== public short extractUChar(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractUChar()"); if (short_data!=null) // Result is not in any return short_data[0]; else if (deviceDataHistory.source==TangoConst.ATTRIBUTE) return extractUCharArray(deviceDataHistory)[0]; else return extractUChar(deviceDataHistory); } //=========================================== /** * extract method for a short. */ //=========================================== public short extractShort(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractShort()"); if (short_data!=null) // Result is not in any return short_data[0]; else if (deviceDataHistory.source==TangoConst.ATTRIBUTE) return extractShortArray(deviceDataHistory)[0]; else return DevShortHelper.extract(any); } //=========================================== /** * extract method for an unsigned short. */ //=========================================== public short extractUShort(DeviceDataHistory deviceDataHistory) throws DevFailed { return DevUShortHelper.extract(any); } //=========================================== /** * extract method for a long. */ //=========================================== public int extractLong(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractLong()"); if (int_data!=null) // Result is not in any return int_data[0]; else if (deviceDataHistory.source==TangoConst.ATTRIBUTE) return extractLongArray(deviceDataHistory)[0]; else return DevLongHelper.extract(any); } //=========================================== /** * extract method for an unsigned long. */ //=========================================== public int extractULong(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractULong()"); if (int_data!=null) // Result is not in any return int_data[0]; else if (deviceDataHistory.source==TangoConst.ATTRIBUTE) return extractULongArray(deviceDataHistory)[0]; else return DevULongHelper.extract(any); } //=========================================== /** * extract method for a long. * * @return the extracted value. * @throws DevFailed in case of read_attribute failed * or if AttrQuality is ATTR_INVALID. */ //=========================================== public long extractLong64(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractLong64"); if (long_data!=null) // Result is not in any return long_data[0]; else return extractLong64Array(deviceDataHistory)[0]; } //=========================================== /** * extract method for a long. * * @return the extracted value. * @throws DevFailed in case of read_attribute failed * or if AttrQuality is ATTR_INVALID. */ //=========================================== public long extractULong64(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractULong64"); if (long_data!=null) // Result is not in any return long_data[0]; else return extractULong64Array(deviceDataHistory)[0]; } //=========================================== /** * extract method for a float. */ //=========================================== public float extractFloat(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractFloat()"); if (float_data!=null) // Result is not in any return float_data[0]; else if (deviceDataHistory.source==TangoConst.ATTRIBUTE) return extractFloatArray(deviceDataHistory)[0]; else return DevFloatHelper.extract(any); } //=========================================== /** * extract method for a double. */ //=========================================== public double extractDouble(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractDouble()"); if (double_data!=null) // Result is not in any return double_data[0]; else if (deviceDataHistory.source==TangoConst.ATTRIBUTE) return extractDoubleArray(deviceDataHistory)[0]; else return DevDoubleHelper.extract(any); } //=========================================== /** * extract method for a String. */ //=========================================== public String extractString(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractString()"); if (string_data!=null) // Result is not in any return string_data[0]; else if (deviceDataHistory.source==TangoConst.ATTRIBUTE) return extractStringArray(deviceDataHistory)[0]; else return DevStringHelper.extract(any); } //=========================================== /** * extract method for an DevState. * @return the extracted value. * @throws DevFailed in case of read_attribute failed * or if AttrQuality is ATTR_INVALID. */ //=========================================== public DevState extractDevState(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractDevState"); if (state_data!=null) // Result is not in any return state_data[0]; else if (isArray()) return deviceDataHistory.extractDevStateArray()[0]; else return DevStateHelper.extract(attrval.value); } //=========================================== /** * extract method for an DevEncoded * @return the extracted value. * @throws DevFailed in case of read_attribute failed * or if AttrQuality is ATTR_INVALID. */ //=========================================== public DevEncoded extractDevEncoded(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractDevEncoded"); if (enc_data!=null) // Result is not in any return enc_data[0]; else if (deviceDataHistory.source==TangoConst.ATTRIBUTE) return extractDevEncodedArray(deviceDataHistory)[0]; else return DevEncodedHelper.extract(any); } //********** Extract Methods for sequence types ********************* //=========================================== /** * extract method for a byte Array. */ //=========================================== public boolean[] extractBooleanArray(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractBooleanArray()"); if (bool_data!=null) // Result is not in any return bool_data; else return DevVarBooleanArrayHelper.extract(any); } //=========================================== /** * extract method for a byte Array. */ //=========================================== public byte[] extractByteArray(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractByteArray()"); return DevVarCharArrayHelper.extract(any); } //=========================================== /** * extract method for an unsigned char Array. * * @return the extracted value. */ //=========================================== public short[] extractUCharArray(DeviceDataHistory deviceDataHistory) throws DevFailed { manageExceptions("extractUCharArray()"); if (short_data!=null) // Result is not in any return short_data; else { byte[] argout = DevVarCharArrayHelper.extract(any); short[] val = new short[argout.length]; short mask = 0xFF; for (int i=0 ; i1) // setType = TangoConst.Tango_DEVVAR_BOOLEANARRAY; return (base-data_length); } //========================================================================== /** * Insert values between base and (base-length) if not failed * and return base for next insertion. * * @param ddh DeviceDataHistory object. * @param values values to be inserted * @param base base index to start to get values * @return base index for next insertion. */ //========================================================================== public int insert(DeviceDataHistory ddh, short[] values, int base) throws DevFailed { if (ddh.failed || (ddh.source==TangoConst.ATTRIBUTE && ddh.getAttrQuality()==AttrQuality.ATTR_INVALID)) return base; // Build an array to be inserted int data_length = ddh.getDataLength(); short_data = new short[data_length]; for (int i=0 ; i1) setType = TangoConst.Tango_DEVVAR_SHORTARRAY; return (base-data_length); } //========================================================================== /** * Insert values between base and (base-length) if not failed * and return base for next insertion. * * @param ddh DeviceDataHistory object. * @param values values to be inserted * @param base base index to start to get values * @return base index for next insertion. */ //========================================================================== public int insert(DeviceDataHistory ddh, int[] values, int base) throws DevFailed { if (ddh.failed || (ddh.source==TangoConst.ATTRIBUTE && ddh.getAttrQuality()==AttrQuality.ATTR_INVALID)) return base; // Build an array to be inserted int data_length = ddh.getDataLength(); int_data = new int[data_length]; for (int i=0 ; i1) setType = TangoConst.Tango_DEVVAR_LONGARRAY; return (base-data_length); } //========================================================================== /** * Insert values between base and (base-length) if not failed * and return base for next insertion. * * @param ddh DeviceDataHistory object. * @param values values to be inserted * @param base base index to start to get values * @return base index for next insertion. */ //========================================================================== public int insert(DeviceDataHistory ddh, long[] values, int base) throws DevFailed { if (ddh.failed || (ddh.source==TangoConst.ATTRIBUTE && ddh.getAttrQuality()==AttrQuality.ATTR_INVALID)) return base; // Build an array to be inserted int data_length = ddh.getDataLength(); long_data = new long[data_length]; for (int i=0 ; i1) setType = TangoConst.Tango_DEVVAR_LONG64ARRAY; return (base-data_length); } //========================================================================== /** * Insert values between base and (base-length) if not failed * and return base for next insertion. * * @param ddh DeviceDataHistory object. * @param values values to be inserted * @param base base index to start to get values * @return base index for next insertion. */ //========================================================================== public int insert(DeviceDataHistory ddh, float[] values, int base) throws DevFailed { if (ddh.failed || (ddh.source==TangoConst.ATTRIBUTE && ddh.getAttrQuality()==AttrQuality.ATTR_INVALID)) return base; // Build an array to be inserted int data_length = ddh.getDataLength(); float_data = new float[data_length]; for (int i=0 ; i1) setType = TangoConst.Tango_DEVVAR_FLOATARRAY; return (base-data_length); } //========================================================================== /** * Insert values between base and (base-length) if not failed * and return base for next insertion. * * @param ddh DeviceDataHistory object. * @param values values to be inserted * @param base base index to start to get values * @return base index for next insertion. */ //========================================================================== public int insert(DeviceDataHistory ddh, double[] values, int base) throws DevFailed { if (ddh.failed || (ddh.source==TangoConst.ATTRIBUTE && ddh.getAttrQuality()==AttrQuality.ATTR_INVALID)) return base; // Build an array to be inserted int data_length = ddh.getDataLength(); double_data = new double[data_length]; for (int i=0 ; i1) setType = TangoConst.Tango_DEVVAR_DOUBLEARRAY; return (base-data_length); } //========================================================================== /** * Insert values between base and (base-length) if not failed * and return base for next insertion. * * @param ddh DeviceDataHistory object. * @param values values to be inserted * @param base base index to start to get values * @return base index for next insertion. */ //========================================================================== public int insert(DeviceDataHistory ddh, String[] values, int base) throws DevFailed { if (ddh.failed || (ddh.source==TangoConst.ATTRIBUTE && ddh.getAttrQuality()==AttrQuality.ATTR_INVALID)) return base; // Build an array to be inserted int data_length = ddh.getDataLength(); string_data = new String[data_length]; for (int i=0 ; i1) setType = TangoConst.Tango_DEVVAR_STRINGARRAY; return (base-data_length); } //========================================================================== /** * Insert values between base and (base-length) if not failed * and return base for next insertion. * * @param ddh DeviceDataHistory object. * @param values values to be inserted * @param base base index to start to get values * @return base index for next insertion. */ //========================================================================== public int insert(DeviceDataHistory ddh, DevState[] values, int base) throws DevFailed { if (ddh.failed || (ddh.source==TangoConst.ATTRIBUTE && ddh.getAttrQuality()==AttrQuality.ATTR_INVALID)) return base; // Build an array to be inserted int data_length = ddh.getDataLength(); state_data = new DevState[data_length]; for (int i=0 ; i1) setType = TangoConst.Tango_DEVVAR_DOUBLEARRAY; } //========================================================================== /** * Insert values * * @param values values to be inserted */ //========================================================================== public void insert(DeviceDataHistory ddh, String[] values) throws DevFailed { if (ddh.failed || (ddh.source==TangoConst.ATTRIBUTE && ddh.getAttrQuality()==AttrQuality.ATTR_INVALID)) return; ddh.setDimX(values.length); ddh.setDimY(1); ddh.setWrittenDimX(0); ddh.setWrittenDimY(0); string_data = values; setType = TangoConst.Tango_DEV_STRING; if (ddh.source==TangoConst.COMMAND && values.length>1) setType = TangoConst.Tango_DEVVAR_STRINGARRAY; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy