5 * Copyright (C) 2008 Pawel Dziepak
7 * Base class for all resources that are attended by Manes Resource System.
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)
32 class resource
: public manes::object
{
34 access_control
*locker
;
36 list
<base_delegate
> methods
;
37 list_ptr
<const char*> names
;
39 void access_command();
46 void set_access_control(access_control
*);
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.
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.
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.
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
80 * @param name name of the order
81 * @param pointer delegate to the function or method
85 void add_ord_response(const char *name
, base_delegate
*pointer
);
88 resource(resource_type
*);
90 virtual bool init_device(isa_address
);
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
102 resource_result
*send_order(resource_order
*order
);
104 friend class resource_manager
;