Add 'commit' method to kv transaction
[archive/platform/core/system/libConfig.git] / src / config / kvstore.hpp
index 1b24b36..0717665 100644 (file)
@@ -45,7 +45,20 @@ public:
     /**
      * A guard struct for thread synchronization and transaction management.
      */
-    typedef std::shared_ptr<void> Transaction;
+    class Transaction {
+    public:
+        Transaction(KVStore& store);
+        ~Transaction();
+
+        Transaction(const Transaction&) = delete;
+        Transaction& operator=(const Transaction&) = delete;
+
+        void commit();
+    private:
+        std::unique_lock<std::recursive_mutex> mLock;
+        KVStore& mKVStore;
+        bool mIsOuter;
+    };
 
     /**
      * @param path configuration database file path
@@ -113,14 +126,12 @@ public:
      */
     std::vector<std::string> getKeys();
 
-    KVStore::Transaction getTransaction();
-
 private:
     typedef std::lock_guard<std::recursive_mutex> Lock;
 
-    struct TransactionImpl;
-    std::weak_ptr<TransactionImpl> mTransactionImplPtr;
     std::recursive_mutex mMutex;
+    size_t mTransactionDepth;
+    bool mIsTransactionCommited;
 
     void setInternal(const std::string& key, const std::string& value);
     void setInternal(const std::string& key, const std::initializer_list<std::string>& values);