forked from daneos/lutango
add attribute and command info cache to DeviceProxy
This commit is contained in:
parent
59fb9aa2b3
commit
1338eae773
@ -17,6 +17,16 @@
|
|||||||
DeviceProxyWrapper::DeviceProxyWrapper(const char* name)
|
DeviceProxyWrapper::DeviceProxyWrapper(const char* name)
|
||||||
{
|
{
|
||||||
dev = new Tango::DeviceProxy(name);
|
dev = new Tango::DeviceProxy(name);
|
||||||
|
Tango::AttributeInfoListEx* attrlist = dev->attribute_list_query_ex();
|
||||||
|
Tango::CommandInfoList* cmdlist = dev->command_list_query();
|
||||||
|
|
||||||
|
for(int i = 0; i < attrlist->size(); i++)
|
||||||
|
attr_cache[(*attrlist)[i].name] = (*attrlist)[i];
|
||||||
|
for(int i = 0; i < cmdlist->size(); i++)
|
||||||
|
cmd_cache[(*cmdlist)[i].cmd_name] = (*cmdlist)[i];
|
||||||
|
|
||||||
|
delete attrlist;
|
||||||
|
delete cmdlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceProxyWrapper::~DeviceProxyWrapper()
|
DeviceProxyWrapper::~DeviceProxyWrapper()
|
||||||
@ -24,8 +34,28 @@ DeviceProxyWrapper::~DeviceProxyWrapper()
|
|||||||
delete dev;
|
delete dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DeviceProxyWrapper::attr_type(const char* name)
|
||||||
|
{
|
||||||
|
return attr_cache[name].data_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tango::AttrDataFormat DeviceProxyWrapper::attr_format(const char* name)
|
||||||
|
{
|
||||||
|
return attr_cache[name].data_format;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DeviceProxyWrapper::cmd_in_type(const char* name)
|
||||||
|
{
|
||||||
|
return cmd_cache[name].in_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DeviceProxyWrapper::cmd_out_type(const char* name)
|
||||||
|
{
|
||||||
|
return cmd_cache[name].out_type;
|
||||||
|
}
|
||||||
|
|
||||||
// COMMAND WRAPPER ------------------------------------------------------------
|
// COMMAND WRAPPER ------------------------------------------------------------
|
||||||
int cmd_wrapper(lua_State* L)
|
int __cmd_wrapper(lua_State* L)
|
||||||
{
|
{
|
||||||
DeviceProxyWrapper* udata = (DeviceProxyWrapper*)lua_touserdata(L, lua_upvalueindex(1));
|
DeviceProxyWrapper* udata = (DeviceProxyWrapper*)lua_touserdata(L, lua_upvalueindex(1));
|
||||||
std::string dev_name = udata->dev->dev_name();
|
std::string dev_name = udata->dev->dev_name();
|
||||||
@ -36,13 +66,8 @@ int cmd_wrapper(lua_State* L)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(udata->cmd_info.find(cmd_name) == udata->cmd_info.end())
|
int in_type = udata->cmd_in_type(cmd_name);
|
||||||
{
|
int out_type = udata->cmd_out_type(cmd_name);
|
||||||
LUT_LOG(TRACE, "Command info for %s doesn't exist, fetching first", full_name.c_str());
|
|
||||||
udata->cmd_info[cmd_name] = udata->dev->get_command_config(cmd_name);
|
|
||||||
}
|
|
||||||
long in_type = udata->cmd_info[cmd_name].in_type;
|
|
||||||
long out_type = udata->cmd_info[cmd_name].out_type;
|
|
||||||
|
|
||||||
LUT_LOG(TRACE, "Command: %s in:%d out:%d", full_name.c_str(), in_type, out_type);
|
LUT_LOG(TRACE, "Command: %s in:%d out:%d", full_name.c_str(), in_type, out_type);
|
||||||
|
|
||||||
@ -190,15 +215,13 @@ int lut_DeviceProxy_index(lua_State* L)
|
|||||||
// command "read" returns a function closure
|
// command "read" returns a function closure
|
||||||
lua_pushlightuserdata(L, udata);
|
lua_pushlightuserdata(L, udata);
|
||||||
lua_pushstring(L, name);
|
lua_pushstring(L, name);
|
||||||
lua_pushcclosure(L, cmd_wrapper, 2);
|
lua_pushcclosure(L, __cmd_wrapper, 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// index is an attribute
|
// index is an attribute
|
||||||
LUT_LOG(TRACE, "Reading attribute %s", full_name.c_str());
|
LUT_LOG(TRACE, "Reading attribute %s", full_name.c_str());
|
||||||
Tango::DeviceAttribute attr = udata->dev->read_attribute(name);
|
Tango::DeviceAttribute attr = udata->dev->read_attribute(name);
|
||||||
udata->type_map[name].type = attr.get_type();
|
|
||||||
udata->type_map[name].format = attr.get_data_format();
|
|
||||||
lut_fromTangoType(L, attr, attr.get_type(), attr.get_data_format());
|
lut_fromTangoType(L, attr, attr.get_type(), attr.get_data_format());
|
||||||
}
|
}
|
||||||
delete cmdlist;
|
delete cmdlist;
|
||||||
@ -232,16 +255,7 @@ int lut_DeviceProxy_newindex(lua_State* L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(udata->type_map.find(attr_name) == udata->type_map.end())
|
Tango::DeviceAttribute v = lut_toTangoType<Tango::DeviceAttribute>(L, 3, udata->attr_type(attr_name), udata->attr_format(attr_name));
|
||||||
{
|
|
||||||
// no cached type mapping
|
|
||||||
LUT_LOG(TRACE, "Type mapping for attribute %s doesn't exist, reading first", full_name.c_str());
|
|
||||||
Tango::DeviceAttribute attr = udata->dev->read_attribute(attr_name);
|
|
||||||
udata->type_map[attr_name].type = attr.get_type();
|
|
||||||
udata->type_map[attr_name].format = attr.get_data_format();
|
|
||||||
}
|
|
||||||
|
|
||||||
Tango::DeviceAttribute v = lut_toTangoType<Tango::DeviceAttribute>(L, 3, udata->type_map[attr_name].type, udata->type_map[attr_name].format);
|
|
||||||
v.set_name(attr_name);
|
v.set_name(attr_name);
|
||||||
udata->dev->write_attribute(v);
|
udata->dev->write_attribute(v);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,15 +34,23 @@
|
|||||||
class DeviceProxyWrapper
|
class DeviceProxyWrapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Tango::DeviceProxy* dev;
|
||||||
|
|
||||||
DeviceProxyWrapper(const char* name);
|
DeviceProxyWrapper(const char* name);
|
||||||
~DeviceProxyWrapper();
|
~DeviceProxyWrapper();
|
||||||
Tango::DeviceProxy* dev;
|
|
||||||
AttrTypeMap type_map;
|
int attr_type(const char* name);
|
||||||
CmdInfoMap cmd_info;
|
Tango::AttrDataFormat attr_format(const char* name);
|
||||||
|
int cmd_in_type(const char* name);
|
||||||
|
int cmd_out_type(const char* name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AttrInfoMap attr_cache;
|
||||||
|
CmdInfoMap cmd_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Command wrapper
|
// Command wrapper
|
||||||
int cmd_wrapper(lua_State* L);
|
int __cmd_wrapper(lua_State* L);
|
||||||
|
|
||||||
// Tango API
|
// Tango API
|
||||||
int lut_DeviceProxy_status(lua_State* L);
|
int lut_DeviceProxy_status(lua_State* L);
|
||||||
|
|||||||
@ -13,11 +13,11 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
template void lut_fromTangoType(lua_State* L, Tango::DeviceAttribute data, long type, Tango::AttrDataFormat format);
|
template void lut_fromTangoType(lua_State* L, Tango::DeviceAttribute data, int type, Tango::AttrDataFormat format);
|
||||||
template void lut_fromTangoType(lua_State* L, Tango::DeviceData data, long type, Tango::AttrDataFormat format);
|
template void lut_fromTangoType(lua_State* L, Tango::DeviceData data, int type, Tango::AttrDataFormat format);
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void lut_fromTangoType(lua_State* L, T data, long type, Tango::AttrDataFormat format)
|
void lut_fromTangoType(lua_State* L, T data, int type, Tango::AttrDataFormat format)
|
||||||
{
|
{
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
@ -178,11 +178,11 @@ void lut_fromTangoType(lua_State* L, T data, long type, Tango::AttrDataFormat fo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template Tango::DeviceAttribute lut_toTangoType(lua_State* L, int idx, long type, Tango::AttrDataFormat format);
|
template Tango::DeviceAttribute lut_toTangoType(lua_State* L, int idx, int type, Tango::AttrDataFormat format);
|
||||||
template Tango::DeviceData lut_toTangoType(lua_State* L, int idx, long type, Tango::AttrDataFormat format);
|
template Tango::DeviceData lut_toTangoType(lua_State* L, int idx, int type, Tango::AttrDataFormat format);
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
T lut_toTangoType(lua_State* L, int idx, long type, Tango::AttrDataFormat format)
|
T lut_toTangoType(lua_State* L, int idx, int type, Tango::AttrDataFormat format)
|
||||||
{
|
{
|
||||||
T data = T();
|
T data = T();
|
||||||
switch(type)
|
switch(type)
|
||||||
|
|||||||
@ -25,20 +25,14 @@
|
|||||||
#include <core/lua/stack.h>
|
#include <core/lua/stack.h>
|
||||||
#include <core/tango/DevState/lut_DevState.h>
|
#include <core/tango/DevState/lut_DevState.h>
|
||||||
|
|
||||||
typedef struct
|
typedef std::map<std::string, Tango::AttributeInfoEx> AttrInfoMap;
|
||||||
{
|
typedef std::map<std::string, Tango::CommandInfo> CmdInfoMap;
|
||||||
long type;
|
|
||||||
Tango::AttrDataFormat format;
|
|
||||||
} AttrTypeDescription;
|
|
||||||
|
|
||||||
typedef std::map<const char*, AttrTypeDescription> AttrTypeMap;
|
|
||||||
typedef std::map<const char*, Tango::CommandInfo> CmdInfoMap;
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void lut_fromTangoType(lua_State* L, T data, long type, Tango::AttrDataFormat format=Tango::SCALAR);
|
void lut_fromTangoType(lua_State* L, T data, int type, Tango::AttrDataFormat format=Tango::SCALAR);
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
T lut_toTangoType(lua_State* L, int idx, long type, Tango::AttrDataFormat format=Tango::SCALAR);
|
T lut_toTangoType(lua_State* L, int idx, int type, Tango::AttrDataFormat format=Tango::SCALAR);
|
||||||
|
|
||||||
template<class dT, class T>
|
template<class dT, class T>
|
||||||
void extract_number(lua_State* L, T data, Tango::AttrDataFormat format);
|
void extract_number(lua_State* L, T data, Tango::AttrDataFormat format);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user