1/*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef IO_SCHEDULER_H
6#define IO_SCHEDULER_H
7
8
9#include <KernelExport.h>
10
11#include <util/DoublyLinkedList.h>
12
13#include "IOCallback.h"
14#include "IORequest.h"
15
16
17struct IORequestOwner : DoublyLinkedListLinkImpl<IORequestOwner> {
18	team_id			team;
19	thread_id		thread;
20	int32			priority;
21	IORequestList	requests;
22	IORequestList	completed_requests;
23	IOOperationList	operations;
24	IORequestOwner*	hash_link;
25
26			bool				IsActive() const
27									{ return !requests.IsEmpty()
28										|| !completed_requests.IsEmpty()
29										|| !operations.IsEmpty(); }
30
31			void				Dump() const;
32};
33
34
35class IOScheduler : public DoublyLinkedListLinkImpl<IOScheduler> {
36public:
37								IOScheduler(DMAResource* resource);
38	virtual						~IOScheduler();
39
40	virtual	status_t			Init(const char* name);
41
42			const char*			Name() const	{ return fName; }
43			int32				ID() const		{ return fID; }
44
45	virtual	void				SetCallback(IOCallback& callback);
46	virtual	void				SetCallback(io_callback callback, void* data);
47
48	virtual	void				SetDeviceCapacity(off_t deviceCapacity);
49	virtual void				MediaChanged();
50
51	virtual	status_t			ScheduleRequest(IORequest* request) = 0;
52
53	virtual	void				AbortRequest(IORequest* request,
54									status_t status = B_CANCELED) = 0;
55	virtual	void				OperationCompleted(IOOperation* operation,
56									status_t status,
57									generic_size_t transferredBytes) = 0;
58									// called by the driver when the operation
59									// has been completed successfully or failed
60									// for some reason
61
62	virtual	void				Dump() const = 0;
63
64protected:
65			DMAResource*		fDMAResource;
66			char*				fName;
67			int32				fID;
68			io_callback			fIOCallback;
69			void*				fIOCallbackData;
70			bool				fSchedulerRegistered;
71};
72
73
74#endif	// IO_SCHEDULER_H
75