cleaning resources code, improving resource_type
[quarnos.git] / resources / resource.h
blobe6d6c8295364554fe59976fabdd0507269b3afc7
1 /* Quarn OS
3 * Resources base class
5 * Copyright (C) 2008 Pawel Dziepak
7 * Base class for all resources that are attended by Manes Resource System.
8 */
11 #ifndef _RESOURCE_H_
12 #define _RESOURCE_H_
14 #include "access_control.h"
15 #include "device_descr.h"
17 #include "resource_manager.h"
18 #include "resource_order.h"
19 #include "resource_result.h"
20 #include "resource_type.h"
22 #include "libs/base_delegate.h"
23 #include "libs/list.h"
24 #include "libs/list_ptr.h"
25 #include "libs/string.h"
27 #include "manes/object.h"
29 #define RESOURCE(x) resource_manager::get_instance()->get_type(#x)
31 namespace resources {
32 class resource : public manes::object {
33 private:
34 access_control *locker;
36 list<base_delegate> methods;
37 list_ptr<const char*> names;
39 void access_command();
41 protected:
42 resource *dep;
44 device_descr descr;
46 void set_access_control(access_control*);
48 /**
49 * Gain read access to the device
50 * This method should be executed by read* method of resource
51 * before any other action will be done. This method uses the
52 * resource locker to get read access and waits as long as it
53 * is needed to read from the resource.
55 void access_read();
57 /**
58 * Gain write access to the device
59 * This method should be executed by write* method of resource
60 * before any other action will be done. This method uses the
61 * resource locker to get write access and waits as long as it
62 * is needed to read from the resource.
64 void access_write();
66 /**
67 * Release the device
68 * When all needed operations are done, resource implementation
69 * has to release the device (and thus unlock the locker). It
70 * does *not* matter which type of access was gained before.
72 void release();
74 /**
75 * Exports a method
76 * This method allows the resource to make resources orders
77 * responsible by attaching to them methods that will perform
78 * all necessary operations including returning resource_result
79 * object.
80 * @param name name of the order
81 * @param pointer delegate to the function or method
82 * @see methods
83 * @see names
85 void add_ord_response(const char *name, base_delegate *pointer);
87 public:
88 resource(resource_type *);
90 virtual bool init_device(isa_address);
92 /**
93 * Send command to the resource
94 * Send order to the device. This method checks if the type of
95 * the order is the same as the type of the device. Then it
96 * looks through all exported response methods in search of
97 * proper method. Finally it returns a resource_result object.
98 * @param order a pointer to the order that has to be sent
99 * @return a resource_result object that describes the status of
100 * the operation
102 resource_result *send_order(resource_order *order);
104 friend class resource_manager;
108 #endif