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)
|
||||
{
|
||||
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()
|
||||
@ -24,8 +34,28 @@ DeviceProxyWrapper::~DeviceProxyWrapper()
|
||||
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 ------------------------------------------------------------
|
||||
int cmd_wrapper(lua_State* L)
|
||||
int __cmd_wrapper(lua_State* L)
|
||||
{
|
||||
DeviceProxyWrapper* udata = (DeviceProxyWrapper*)lua_touserdata(L, lua_upvalueindex(1));
|
||||
std::string dev_name = udata->dev->dev_name();
|
||||
@ -36,13 +66,8 @@ int cmd_wrapper(lua_State* L)
|
||||
|
||||
try
|
||||
{
|
||||
if(udata->cmd_info.find(cmd_name) == udata->cmd_info.end())
|
||||
{
|
||||
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;
|
||||
int in_type = udata->cmd_in_type(cmd_name);
|
||||
int out_type = udata->cmd_out_type(cmd_name);
|
||||
|
||||
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
|
||||
lua_pushlightuserdata(L, udata);
|
||||
lua_pushstring(L, name);
|
||||
lua_pushcclosure(L, cmd_wrapper, 2);
|
||||
lua_pushcclosure(L, __cmd_wrapper, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// index is an attribute
|
||||
LUT_LOG(TRACE, "Reading attribute %s", full_name.c_str());
|
||||
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());
|
||||
}
|
||||
delete cmdlist;
|
||||
@ -232,16 +255,7 @@ int lut_DeviceProxy_newindex(lua_State* L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(udata->type_map.find(attr_name) == udata->type_map.end())
|
||||
{
|
||||
// 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);
|
||||
Tango::DeviceAttribute v = lut_toTangoType<Tango::DeviceAttribute>(L, 3, udata->attr_type(attr_name), udata->attr_format(attr_name));
|
||||
v.set_name(attr_name);
|
||||
udata->dev->write_attribute(v);
|
||||
}
|
||||
|
||||
@ -34,15 +34,23 @@
|
||||
class DeviceProxyWrapper
|
||||
{
|
||||
public:
|
||||
Tango::DeviceProxy* dev;
|
||||
|
||||
DeviceProxyWrapper(const char* name);
|
||||
~DeviceProxyWrapper();
|
||||
Tango::DeviceProxy* dev;
|
||||
AttrTypeMap type_map;
|
||||
CmdInfoMap cmd_info;
|
||||
|
||||
int attr_type(const char* name);
|
||||
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
|
||||
int cmd_wrapper(lua_State* L);
|
||||
int __cmd_wrapper(lua_State* L);
|
||||
|
||||
// Tango API
|
||||
int lut_DeviceProxy_status(lua_State* L);
|
||||
|
||||
@ -13,11 +13,11 @@
|
||||
|
||||
#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::DeviceData 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, int type, Tango::AttrDataFormat format);
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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::DeviceData 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, int type, Tango::AttrDataFormat format);
|
||||
|
||||
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();
|
||||
switch(type)
|
||||
|
||||
@ -25,20 +25,14 @@
|
||||
#include <core/lua/stack.h>
|
||||
#include <core/tango/DevState/lut_DevState.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
long type;
|
||||
Tango::AttrDataFormat format;
|
||||
} AttrTypeDescription;
|
||||
|
||||
typedef std::map<const char*, AttrTypeDescription> AttrTypeMap;
|
||||
typedef std::map<const char*, Tango::CommandInfo> CmdInfoMap;
|
||||
typedef std::map<std::string, Tango::AttributeInfoEx> AttrInfoMap;
|
||||
typedef std::map<std::string, Tango::CommandInfo> CmdInfoMap;
|
||||
|
||||
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>
|
||||
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>
|
||||
void extract_number(lua_State* L, T data, Tango::AttrDataFormat format);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user