TIVI-1924: Initial commit of IVI settings daemon.
[profile/ivi/settings-daemon.git] / include / settingsd / reverse_lock.hpp
1 /**
2  * @file reverse_lock.hpp
3  *
4  * @brief C++11 style smart pointer for use by settings plug-ins.
5  *
6  * @author Ossama Othman @<ossama.othman@@intel.com@>
7  *
8  * @copyright @par
9  * Copyright 2013 Intel Corporation All Rights Reserved.
10  * @par
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation;
14  * version 2.1 of the License.
15  * @par
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  * @par
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA  02110-1301  USA
25  */
26
27 #ifndef IVI_SETTINGS_REVERSE_LOCK_HPP
28 #define IVI_SETTINGS_REVERSE_LOCK_HPP
29
30
31 namespace ivi
32 {
33   namespace settings
34   {
35     /**
36      * @typename reverse_lock
37      *
38      * @brief Mutex implementation that reverse the lock/unlock
39      *        operations.
40      */
41     template<typename T>
42     class reverse_lock
43     {
44     public:
45
46       constexpr reverse_lock(T & m) : mutex_(m) {}
47
48       /// Unlock the underlying mutex.
49       void lock() { return mutex_.unlock(); }
50
51       /// Lock the underlying mutex.
52       void unlock()  { return mutex_.lock(); }
53
54     private:
55
56       /**
57        * @name Prevent copying
58        */
59       //@{
60       reverse_lock(reverse_lock const &) = delete;
61       reverse_lock & operator=(reverse_lock const &) = delete;
62       //@}
63
64     private:
65
66       /// The underlying mutex.
67       T & mutex_;
68
69     };
70
71   }
72 }
73
74
75 #endif /* IVI_SETTINGS_REVERSE_LOCK_HPP */
76
77
78 // Local Variables:
79 // mode:c++
80 // c-basic-offset:2
81 // indent-tabs-mode: nil
82 // End: