{
return getDevicePropertyInformationX("PROPS", context,server,device,property,timeout);
}
private static synchronized XPropertyQuery[] getDevicePropertyInformationX(String stockprop, String context,String server,String device,String property,int timeout)
{
TLink tl;
TDataType dout, din;
int cc = 0,i;
String tgt, dev;
XPropertyQuery[] xpq = null;
XPropertyQuery xpq1 = new XPropertyQuery();
byte[] blob = hByteBlobX;
boolean hasTarget = true;
if (server == null || server.length() == 0) return null;
if (device == null || device.length() == 0)
dev = new String("#0");
else
dev = device;
if (context == null || context.length() == 0)
tgt = new String("/DEFAULT/" + server + "/" + dev);
else
tgt = new String("/" + context + "/" + server + "/" + dev);
int np = nicePropertyQuerySize;
if (property == null || property.compareTo("*") == 0)
{
din = new TDataType();
String target = "/" + context + "/" + server;
try
{
np = getNumberOf("PROPERTIES", target, timeout);
}
catch (IOException e)
{
throw new RuntimeException("Could not acquire property information for " + server + " (" + TErrorList.getErrorString(cc) + ")");
}
int fudge_factor = np > 150 ? 1 : 2;
blob = new byte[fudge_factor * np * XPropertyQuery.sizeInBytes]; // allow room for overloads
hasTarget = false;
}
else
{
din = new TDataType(property);
}
dout = new TDataType(blob,"XPQS");
while (np > 0)
{
try
{
tl = new TLink(tgt,stockprop,dout,din,TAccess.CA_READ);
cc = tl.execute(timeout,true);
srvAddr = tl.srvAddr;
if ((cc & TErrorList.CE_SENDDATA) == TErrorList.CE_SENDDATA) cc = 0;
tl.close();
}
catch (Exception e)
{
MsgLog.log("getDevicePropertyInformationX", e.getMessage(),TErrorList.non_existent_elem,e,0);
cc = TErrorList.non_existent_elem;
}
if (cc == TErrorList.invalid_transport_size)
{
np /= 2;
blob = new byte[np * XPropertyQuery.sizeInBytes]; // allow room for overloads
dout = new TDataType(blob,"XPQS");
}
else
{
break;
}
}
if (cc == 0) // it's at lease a 3.31 server
{
try
{
TStructIo.bytesToStruct(xpq1, blob,0,XPropertyQuery.sizeInBytes);
}
catch (IOException e1) { e1.printStackTrace(); }
int nxpq = dout.dCompletionLength;
if (hasTarget)
{
if (xpq1.prpNumOverloads < 1) xpq1.prpNumOverloads = 1; // can't be less than 1 !
nxpq = xpq1.prpNumOverloads;
if (nxpq > nicePropertyQuerySize) nxpq = nicePropertyQuerySize;
}
if (nxpq == 0) return null;
if (xpq1.prpNumOverloads < 1) xpq1.prpNumOverloads = 1; // can't be less than 1 !
if (nxpq > np) nxpq = np;
xpq = new XPropertyQuery[nxpq];
xpq[0] = xpq1;
for (i=1; i<nxpq; i++)
{
xpq[i] = new XPropertyQuery();
try {
TStructIo.bytesToStruct(xpq[i],blob,i*XPropertyQuery.sizeInBytes,XPropertyQuery.sizeInBytes);
} catch (Exception e) {
e.printStackTrace();
}
}
return xpq;
}
if (cc == TErrorList.link_not_open)
{
throw new RuntimeException("Could not acquire property information for " + server + " (" + TErrorList.getErrorString(cc) + ")");
}
if (cc == TErrorList.non_existent) return null;
PropertyQueryLegacy[] pqx = null;
PropertyQueryLegacy pqx1 = new PropertyQueryLegacy();
dout = new TDataType(hByteBlobL,"PQSX");
tl = new TLink(tgt,stockprop,dout,din,TAccess.CA_READ);
cc = tl.execute(timeout,true);
tl.close();
if (cc == 0) // it's at lease a 3.20 server
{
byte b[] = pqx1.toByteArray();
System.arraycopy(hByteBlobL,0,b,0,PropertyQueryLegacy.sizeInBytes);
pqx1.toStruct();
int npqx = np;
if (hasTarget)
{
if (pqx1.prpNumOverloads < 1) pqx1.prpNumOverloads = 1; // can't be less than 1 !
npqx = pqx1.prpNumOverloads;
}
if (npqx > nicePropertyQuerySize) npqx = nicePropertyQuerySize;
pqx = new PropertyQueryLegacy[npqx];
xpq = new XPropertyQuery[npqx];
pqx[0] = pqx1;
for (i=1; i<npqx; i++)
{
pqx[i] = new PropertyQueryLegacy();
b = pqx[i].toByteArray();
System.arraycopy(hByteBlobL,i*PropertyQueryLegacy.sizeInBytes,b,0,PropertyQueryLegacy.sizeInBytes);
pqx[i].toStruct();
}
for (i=0; i<npqx; i++)
{
xpq[i] = new XPropertyQuery();
xpq[i].prpFormat = pqx[i].prpFormat;
xpq[i].prpFormatIn = pqx[i].prpFormatIn;
xpq[i].prpSize = pqx[i].prpSize;
xpq[i].prpSizeIn = pqx[i].prpSizeIn;
xpq[i].prpAccess = pqx[i].prpAccess;
xpq[i].prpDescription = pqx[i].prpDescription;
xpq[i].prpName = pqx[i].prpName;
xpq[i].prpNumOverloads = pqx[i].prpNumOverloads;
xpq[i].prpTag = pqx[i].prpTag;
xpq[i].prpTagIn = pqx[i].prpTagIn;
xpq[i].prpRedirection = pqx[i].prpRedirection;
xpq[i].prpHistoryDepthLong = pqx[i].prpHistoryDepthLong;
xpq[i].prpHistoryDepthShort = pqx[i].prpHistoryDepthShort;
xpq[i].prpUnits = pqx[i].prpUnits;
xpq[i].prpMaxValue = pqx[i].prpMaxValue;
xpq[i].prpMinValue = pqx[i].prpMinValue;
xpq[i].prpGraphType = pqx[i].prpGraphType;
}
return xpq;
}
if (cc == TErrorList.link_not_open)
{
throw new RuntimeException("Could not acquire property information for " + server + " (" + TErrorList.getErrorString(cc) + ")");
}
// legacy server
hLegacyByteBlob = null;
String[] prps = getDeviceProperties(context,server,device);
if (prps == null || prps.length == 0) return null;
PropertyQuery[] pq = new PropertyQuery[prps.length];
xpq = new XPropertyQuery[1];
byte b[];
if (hLegacyByteBlob == null) return null;
for (i=0; i<prps.length; i++)
{
pq[i] = new PropertyQuery();
b = pq[i].toByteArray();
System.arraycopy(hLegacyByteBlob,i*PropertyQuery.sizeInBytes,b,0,PropertyQuery.sizeInBytes);
pq[i].toStruct();
if (pq[i].name.compareTo(property) != 0) continue;
xpq[0] = new XPropertyQuery();
xpq[0].prpFormat = pq[i].prpFormat;
xpq[0].prpSize = pq[i].prpSize;
xpq[0].prpAccess = pq[i].prpAccess;
xpq[0].prpDescription = pq[i].prpDesc;
xpq[0].prpName = pq[i].name;
xpq[0].prpNumOverloads = 1;
if ((pq[0].prpAccess & TAccess.CA_WRITE) == TAccess.CA_WRITE)
{
xpq[0].prpFormatIn = pq[i].prpFormat;
xpq[0].prpSizeIn = pq[i].prpSize;
}
else
{
xpq[0].prpFormatIn = (byte)TFormat.CF_NULL;
xpq[0].prpSizeIn = 0;
}
USTRING[] egu = new USTRING[1];
egu[0] = new USTRING();
dout = new TDataType(egu);
din = new TDataType();
String prpegu = new String(property + ".EGU");
tl = new TLink(tgt,prpegu,dout,din,TAccess.CA_READ);
cc = tl.execute(timeout,false);
tl.close();
if (cc == 0)
{
xpq[0].prpMinValue = egu[0].f1val;
xpq[0].prpMaxValue = egu[0].f2val;
xpq[0].prpUnits = egu[0].str;