diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-03-20 12:21:18 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-03-20 12:21:18 -0700 |
commit | 7ee1a1151f71bfdc3e35e8e055cb1699106131bc (patch) | |
tree | c02f557132fa178b37d836a05798f6cf81c21dca /netconf/SqliteNetworkConfigMaster.hpp | |
parent | a8a92c5b89b51f6786d6e5cb41a588197b6afabb (diff) | |
download | infinitytier-7ee1a1151f71bfdc3e35e8e055cb1699106131bc.tar.gz infinitytier-7ee1a1151f71bfdc3e35e8e055cb1699106131bc.zip |
Add SqliteNetworkConfigMaster::DBC for external access to raw sqlite3 db.
Diffstat (limited to 'netconf/SqliteNetworkConfigMaster.hpp')
-rw-r--r-- | netconf/SqliteNetworkConfigMaster.hpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/netconf/SqliteNetworkConfigMaster.hpp b/netconf/SqliteNetworkConfigMaster.hpp index 77398434..b2028ab5 100644 --- a/netconf/SqliteNetworkConfigMaster.hpp +++ b/netconf/SqliteNetworkConfigMaster.hpp @@ -39,12 +39,16 @@ #include "../node/Constants.hpp" #include "../node/NetworkConfigMaster.hpp" #include "../node/Mutex.hpp" +#include "../node/NonCopyable.hpp" namespace ZeroTier { class SqliteNetworkConfigMaster : public NetworkConfigMaster { public: + class DBC; + friend class SqliteNetworkConfigMaster::DBC; + SqliteNetworkConfigMaster(const Identity &signingId,const char *dbPath); virtual ~SqliteNetworkConfigMaster(); @@ -80,6 +84,24 @@ private: sqlite3_stmt *_sCacheNetconf; Mutex _lock; + +public: + /** + * Provides a safe interface for direct access to this master's database + * + * This acts as both a contextual lock of the master's Mutex and a pointer + * to the Sqlite3 database instance. Dereferencing this with * yields the + * sqlite3* pointer. Create on parent with DBC(SqliteNetworkConfigMaster &). + */ + class DBC : NonCopyable + { + public: + DBC(SqliteNetworkConfigMaster &nc) : _p(&nc) { nc._lock.lock(); } + ~DBC() { _p->_lock.unlock(); } + inline sqlite3 *operator*() { return _p->_db; } + private: + SqliteNetworkConfigMaster *const _p; + }; }; } // namespace ZeroTier |