1*99768086Shyche /* 2*99768086Shyche * Copyright 2017, Chế Vũ Gia Hy, cvghy116@gmail.com. 3*99768086Shyche * Copyright 2001-2012, Axel Dörfler, axeld@pinc-software.de. 4*99768086Shyche * This file may be used under the terms of the MIT License. 5*99768086Shyche */ 6c1320b3aShyche #ifndef JOURNAL_H 7c1320b3aShyche #define JOURNAL_H 8c1320b3aShyche 9c1320b3aShyche 10c1320b3aShyche #include "Volume.h" 11c1320b3aShyche 12c1320b3aShyche class Transaction; 13c1320b3aShyche 14c1320b3aShyche 15c1320b3aShyche class Journal { 16c1320b3aShyche public: 17c1320b3aShyche Journal(Volume* volume); 18c1320b3aShyche ~Journal(); 19c1320b3aShyche 20c1320b3aShyche Volume* GetVolume() const { return fVolume; } 21c1320b3aShyche Transaction* CurrentTransaction() const { return fOwner; } 22c1320b3aShyche uint64 SystemTransactionID() const 23c1320b3aShyche { return fCurrentGeneration; } 24c1320b3aShyche int32 TransactionID() const { return fTransactionID; } 25c1320b3aShyche status_t Lock(Transaction* owner); 26c1320b3aShyche status_t UnLock(Transaction* owner, bool success); 27c1320b3aShyche 28c1320b3aShyche private: 29c1320b3aShyche static void _TransactionWritten(int32 transactionID, int32 event, 30c1320b3aShyche void* _journal); 31c1320b3aShyche status_t _TransactionDone(bool success); 32c1320b3aShyche 33c1320b3aShyche private: 34c1320b3aShyche Volume* fVolume; 35c1320b3aShyche recursive_lock fLock; 36c1320b3aShyche Transaction* fOwner; 37c1320b3aShyche int32 fTransactionID; 38c1320b3aShyche uint64 fCurrentGeneration; 39c1320b3aShyche }; 40c1320b3aShyche 41c1320b3aShyche 42c1320b3aShyche class Transaction { 43c1320b3aShyche public: 44c1320b3aShyche Transaction(Volume* volume); 45c1320b3aShyche Transaction(); 46c1320b3aShyche ~Transaction(); 47c1320b3aShyche 48c1320b3aShyche int32 ID() const { return fJournal->TransactionID(); } 49c1320b3aShyche uint64 SystemID() const 50c1320b3aShyche { return fJournal->SystemTransactionID(); } 51c1320b3aShyche bool HasBlock(fsblock_t blockNumber) const; 52c1320b3aShyche Transaction* Parent() const { return fParent; } 53c1320b3aShyche void SetParent(Transaction* parent) { fParent = parent; } 54c1320b3aShyche status_t Start(Volume* volume); 55c1320b3aShyche status_t Done(); 56c1320b3aShyche private: 57c1320b3aShyche Journal* fJournal; 58c1320b3aShyche Transaction* fParent; 59c1320b3aShyche }; 60c1320b3aShyche 61c1320b3aShyche 62c1320b3aShyche #endif // JOURNAL_H 63