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
16class Journal;
17class Volume;
18
19
20class TransactionListener
21	: public DoublyLinkedListLinkImpl<TransactionListener> {
22public:
23								TransactionListener();
24	virtual						~TransactionListener();
25
26	virtual void				TransactionDone(bool success) = 0;
27	virtual void				RemovedFromTransaction() = 0;
28};
29
30typedef DoublyLinkedList<TransactionListener> TransactionListeners;
31
32
33class Transaction {
34public:
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;
63private:
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