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