/*
- * (c) 2010 Technische Universität Dresden
+ * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
+ * economic rights: Technische Universität Dresden (Germany)
+ *
* This file is part of TUD:OS and distributed under the terms of the
* GNU General Public License 2.
* Please see the COPYING-GPL-2 file for details.
#include "resource.h"
#include <cstdio>
+#include <cstring>
+#include <string>
template< typename D >
class Device_tree
iterator operator ++ ()
{
+ if (!_c)
+ return *this;
+
if (_d > _c->depth() && _c->children())
// go to a child if not at max depth and there are children
_c = _c->children();
else if (_c->next())
// go to the next sibling
_c = _c->next();
+ else if (_c == _p)
+ _c = 0;
else
{
for (D *x = _c->parent(); x && x != _p; x = x->parent())
static iterator end() { return iterator(); }
+ D *find_by_name(char const *name) const
+ {
+ for (iterator c = begin(0); c != end(); ++c)
+ if (strcmp((*c)->name(), name) == 0)
+ return *c;
+
+ return 0;
+ }
+
void set_depth(int d) { return _dt.set_depth(d); }
void set_parent(D *p) { _dt.set_parent(p); }
void add_sibling(D *s) { _dt.add_sibling(s); }
void request_child_resources();
void allocate_pending_child_resources();
void allocate_pending_resources();
+
virtual void setup_resources() = 0;
virtual char const *name() const = 0;
virtual void dump(int) const {};
- virtual ~Device() {}
-
typedef Device_tree<Device>::iterator iterator;
iterator begin(int depth = 0) const { return iterator(this, depth); }
static iterator end() { return iterator(); }
+ virtual int pm_suspend() = 0;
+ virtual int pm_resume() = 0;
+
+ virtual std::string get_full_path() const = 0;
};
-class Generic_device : public virtual Device
+class Generic_device : public Device
{
private:
Resource_list _resources;
Resource_list const *resources() const { return &_resources; }
void add_resource(Resource *r)
- { _resources.insert(r); }
+ { _resources.push_back(r); }
+
+ void add_resource_rq(Resource *r)
+ {
+ add_resource(r);
+ request_resource(r);
+ }
virtual bool match_cid(cxx::String const &) const { return false; }
- virtual char const *name() const { return "(noname)"; }
- virtual char const *hid() const { return 0; }
- virtual bool name(cxx::String const &) { return false; }
+ char const *name() const { return "(noname)"; }
+ char const *hid() const { return 0; }
+ bool name(cxx::String const &) { return false; }
- virtual bool request_child_resource(Resource *, Device *);
- virtual bool alloc_child_resource(Resource *, Device *);
- virtual void setup_resources();
+ bool request_child_resource(Resource *, Device *);
+ bool alloc_child_resource(Resource *, Device *);
+ void setup_resources();
- virtual ~Generic_device() {}
+ int pm_suspend() { return 0; }
+ int pm_resume() { return 0; }
+ std::string get_full_path() const;
};