forked from blue/lmdbal
Sessions to manage db open state
This commit is contained in:
parent
3701fb92a1
commit
f9902bc0b1
13 changed files with 342 additions and 124 deletions
73
src/session.cpp
Normal file
73
src/session.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* LMDB Abstraction Layer.
|
||||
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "session.h"
|
||||
|
||||
LMDBAL::Session::Session():
|
||||
parent(nullptr) {}
|
||||
|
||||
LMDBAL::Session::Session(Base* parent):
|
||||
parent(parent)
|
||||
{
|
||||
parent->registerSession(this);
|
||||
}
|
||||
|
||||
LMDBAL::Session::Session(Session&& other):
|
||||
parent(other.parent)
|
||||
{
|
||||
if (parent)
|
||||
parent->replaceSession(&other, this);
|
||||
}
|
||||
|
||||
LMDBAL::Session::~Session() {
|
||||
if (parent)
|
||||
parent->unregisterSession(this);
|
||||
}
|
||||
|
||||
LMDBAL::Session& LMDBAL::Session::operator = (Session&& other) {
|
||||
if (parent)
|
||||
if (other.parent)
|
||||
parent->unregisterSession(&other);
|
||||
else
|
||||
parent->unregisterSession(this);
|
||||
else
|
||||
if (other.parent)
|
||||
other.parent->replaceSession(&other, this);
|
||||
|
||||
parent = other.parent;
|
||||
other.terminate();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void LMDBAL::Session::close() {
|
||||
if (!parent)
|
||||
return;
|
||||
|
||||
parent->unregisterSession(this);
|
||||
terminate();
|
||||
}
|
||||
|
||||
bool LMDBAL::Session::opened() const {
|
||||
return parent != nullptr;
|
||||
}
|
||||
|
||||
void LMDBAL::Session::terminate() {
|
||||
parent = nullptr;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue