summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-03-20 12:21:18 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-03-20 12:21:18 -0700
commit7ee1a1151f71bfdc3e35e8e055cb1699106131bc (patch)
treec02f557132fa178b37d836a05798f6cf81c21dca
parenta8a92c5b89b51f6786d6e5cb41a588197b6afabb (diff)
downloadinfinitytier-7ee1a1151f71bfdc3e35e8e055cb1699106131bc.tar.gz
infinitytier-7ee1a1151f71bfdc3e35e8e055cb1699106131bc.zip
Add SqliteNetworkConfigMaster::DBC for external access to raw sqlite3 db.
-rw-r--r--netconf/SqliteNetworkConfigMaster.hpp22
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