xref: /haiku/src/add-ons/kernel/file_systems/ext2/Transaction.h (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2010, Haiku Inc. All rights reserved.
3  * Copyright 2001-2010, Axel Dörfler, axeld@pinc-software.de.
4  * This file may be used under the terms of the MIT License.
5  *
6  * Authors:
7  *		Janito V. Ferreira Filho
8  */
9 #ifndef TRANSACTION_H
10 #define TRANSACTION_H
11 
12 
13 #include <util/DoublyLinkedList.h>
14 
15 
16 class Journal;
17 class Volume;
18 
19 
20 class TransactionListener
21 	: public DoublyLinkedListLinkImpl<TransactionListener> {
22 public:
23 								TransactionListener();
24 	virtual						~TransactionListener();
25 
26 	virtual void				TransactionDone(bool success) = 0;
27 	virtual void				RemovedFromTransaction() = 0;
28 };
29 
30 typedef DoublyLinkedList<TransactionListener> TransactionListeners;
31 
32 
33 class Transaction {
34 public:
35 									Transaction();
36 									Transaction(Journal* journal);
37 									~Transaction();
38 
39 			status_t				Start(Journal* journal);
40 			status_t				Done(bool success = true);
41 
42 			bool					IsStarted() const;
43 			bool					HasParent() const;
44 
45 			status_t				WriteBlocks(off_t blockNumber,
46 										const uint8* buffer,
47 										size_t numBlocks = 1);
48 
49 			void					Split();
50 
51 			Volume*					GetVolume() const;
52 			int32					ID() const;
53 
54 			void					AddListener(TransactionListener* listener);
55 			void					RemoveListener(
56 										TransactionListener* listener);
57 
58 			void					NotifyListeners(bool success);
59 			void					MoveListenersTo(Transaction* transaction);
60 
61 			void					SetParent(Transaction* transaction);
62 			Transaction*			Parent() const;
63 private:
64 									Transaction(const Transaction& other);
65 			Transaction&			operator=(const Transaction& other);
66 				// no implementation
67 
68 			Journal*				fJournal;
69 			TransactionListeners	fListeners;
70 			Transaction*			fParent;
71 };
72 
73 #endif	// TRANSACTION_H
74