]> rtime.felk.cvut.cz Git - l4.git/blobdiff - l4/pkg/io/server/src/device.h
update
[l4.git] / l4 / pkg / io / server / src / device.h
index e3730d05ca0fd978c0ef5f0d6d46f2ab73a26d83..16deda660a3582debd22555fbcdf52ec4cc13d4c 100644 (file)
@@ -1,5 +1,7 @@
 /*
- * (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.
@@ -14,6 +16,8 @@
 #include "resource.h"
 
 #include <cstdio> 
+#include <cstring>
+#include <string>
 
 template< typename D >
 class Device_tree
@@ -88,12 +92,17 @@ public:
 
     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())
@@ -136,6 +145,15 @@ public:
 
   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); }
@@ -168,6 +186,7 @@ public:
   void request_child_resources();
   void allocate_pending_child_resources();
   void allocate_pending_resources();
+
   virtual void setup_resources() = 0;
 
   virtual char const *name() const = 0;
@@ -176,18 +195,20 @@ public:
 
   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;
@@ -197,20 +218,28 @@ public:
 
   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;
 };