#include "vdevice.h"
#include "vbus_factory.h"
#include "hw_device.h"
+#include "gpio"
static int is_lua_propval(lua_State *L, int idx)
{
int add_filter(cxx::String const &, cxx::String const &);
int add_filter(cxx::String const &, unsigned long long);
int add_filter(cxx::String const &, unsigned long long, unsigned long long);
+
+ void dump(int) const;
};
class Dev_factory
Device *next() const;
int depth() const;
void plugin();
+
+ void dump(int) const;
};
class Device_factory
return 0;
}
+
+ Hw::Device *__getitem(std::string const &name) const
+ {
+ for (Hw::Device::iterator c = self->begin(0);
+ c != self->end(); ++c)
+ if (name == (*c)->name())
+ return *c;
+
+ return 0;
+ }
+
+ void __setitem(std::string const &name, Hw::Device *dev)
+ {
+ dev->set_name(name);
+ self->add_child(dev);
+ if (self->parent() || self == system_bus())
+ dev->plugin();
+ }
};
Hw::Device *system_bus();
void dump_devs(Device *d);
int add_vbus(Vi::Device *dev);
+
+class Gpio_resource : public Resource
+{
+public:
+ explicit Gpio_resource(Hw::Device *dev, unsigned start, unsigned end)
+ throw(char const *);
+};
+
%luacode {
Io.Res = {}
function Io.Dt.add_child(parent, name, dev, idx)
parent:add_child(dev)
- if dev.plugin and (parent:parent() or parent == Io.system_bus()) then
+ if dev.plugin and (parent:parent() or swig_equals(parent, Io.system_bus())) then
dev:plugin()
end
if type(name) == "string" then
end
end
+function Io.Dt.add_children(parent, bus_func)
+ if type(bus_func) == "function" then
+ local d = {}
+ setmetatable(d, { __index = getfenv(1) })
+ setfenv(bus_func, d)
+ bus_func()
+ if type(d._res) == "table" then
+ for i, r in ipairs(d._res) do
+ Io.Dt.add_resource(parent, r)
+ end
+ d._res = nil
+ elseif type(d._res) == "userdata" then
+ Io.Dt.add_resource(parent, d._res)
+ d._res = nil
+ end
+ Io.Dt.add_device_data(parent, d)
+ end
+ return parent;
+end
+
function Io.Dt.iterator(dev, max_depth)
local max_d = (max_depth or 0) + dev:depth()
local current = dev
print("ERROR: cannot handle device member: " .. tostring(name) .. ": " .. tostring(val))
end
+function Io.Dt.add_resource(dev, res)
+ if not Io.swig_instance_of(res, "Resource *") then
+ error("expected a resource object got: " .. tostring(res))
+ end
+ dev:add_resource(res)
+end
+
function Io.Dt.add_device_data(dev, data)
local maxi = 0
for i, v in ipairs(data) do
end
local set_dev_data = Io.Dt.add_device_data
+local add_children = Io.Dt.add_children
Io.Hw = {}
setmetatable(Io.Hw, { __index = function (self, t)
return function (data)
local b = Io.Hw_dev_factory_create(t)
- if data then
+ if type(data) == "function" then
+ add_children(b, data)
+ elseif type(data) == "table" then
set_dev_data(b, data)
end
return b
setmetatable(Io.Vi, { __index = function (self, t)
return function (data)
local b = Io.Vi_dev_factory_create(t)
- if data then
+ if type(data) == "function" then
+ add_children(b, data)
+ elseif type(data) == "table" then
set_dev_data(b, data)
end
return b