mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Remove default argument for callbacks, reorder function arguments
This commit is contained in:
parent
605973497f
commit
e6f1eea1b7
11 changed files with 72 additions and 75 deletions
|
@ -76,12 +76,12 @@ void OpenResultCallback::Complete(OperationResult res) {
|
|||
trigger->Release();
|
||||
}
|
||||
|
||||
OperationResult Backend::Open(RecordValPtr options, TypePtr kt, TypePtr vt, OpenResultCallback* cb) {
|
||||
OperationResult Backend::Open(OpenResultCallback* cb, RecordValPtr options, TypePtr kt, TypePtr vt) {
|
||||
key_type = std::move(kt);
|
||||
val_type = std::move(vt);
|
||||
backend_options = options;
|
||||
|
||||
auto ret = DoOpen(std::move(options), cb);
|
||||
auto ret = DoOpen(cb, std::move(options));
|
||||
if ( ! ret.value )
|
||||
ret.value = cb->Backend();
|
||||
|
||||
|
@ -90,8 +90,8 @@ OperationResult Backend::Open(RecordValPtr options, TypePtr kt, TypePtr vt, Open
|
|||
|
||||
OperationResult Backend::Close(OperationResultCallback* cb) { return DoClose(cb); }
|
||||
|
||||
OperationResult Backend::Put(ValPtr key, ValPtr value, bool overwrite, double expiration_time,
|
||||
OperationResultCallback* cb) {
|
||||
OperationResult Backend::Put(OperationResultCallback* cb, ValPtr key, ValPtr value, bool overwrite,
|
||||
double expiration_time) {
|
||||
// The intention for this method is to do some other heavy lifting in regard
|
||||
// to backends that need to pass data through the manager instead of directly
|
||||
// through the workers. For the first versions of the storage framework it
|
||||
|
@ -107,10 +107,10 @@ OperationResult Backend::Put(ValPtr key, ValPtr value, bool overwrite, double ex
|
|||
return ret;
|
||||
}
|
||||
|
||||
return DoPut(std::move(key), std::move(value), overwrite, expiration_time, cb);
|
||||
return DoPut(cb, std::move(key), std::move(value), overwrite, expiration_time);
|
||||
}
|
||||
|
||||
OperationResult Backend::Get(ValPtr key, OperationResultCallback* cb) {
|
||||
OperationResult Backend::Get(OperationResultCallback* cb, ValPtr key) {
|
||||
// See the note in Put().
|
||||
if ( ! same_type(key->GetType(), key_type) ) {
|
||||
auto ret = OperationResult{ReturnCode::KEY_TYPE_MISMATCH};
|
||||
|
@ -118,10 +118,10 @@ OperationResult Backend::Get(ValPtr key, OperationResultCallback* cb) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
return DoGet(std::move(key), cb);
|
||||
return DoGet(cb, std::move(key));
|
||||
}
|
||||
|
||||
OperationResult Backend::Erase(ValPtr key, OperationResultCallback* cb) {
|
||||
OperationResult Backend::Erase(OperationResultCallback* cb, ValPtr key) {
|
||||
// See the note in Put().
|
||||
if ( ! same_type(key->GetType(), key_type) ) {
|
||||
auto ret = OperationResult{ReturnCode::KEY_TYPE_MISMATCH};
|
||||
|
@ -129,7 +129,7 @@ OperationResult Backend::Erase(ValPtr key, OperationResultCallback* cb) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
return DoErase(std::move(key), cb);
|
||||
return DoErase(cb, std::move(key));
|
||||
}
|
||||
|
||||
void Backend::CompleteCallback(ResultCallback* cb, const OperationResult& data) const {
|
||||
|
|
|
@ -78,8 +78,8 @@ public:
|
|||
* @return A struct describing the result of the operation, containing a code, an
|
||||
* optional error string, and a ValPtr for operations that return values.
|
||||
*/
|
||||
OperationResult Put(ValPtr key, ValPtr value, bool overwrite = true, double expiration_time = 0,
|
||||
OperationResultCallback* cb = nullptr);
|
||||
OperationResult Put(OperationResultCallback* cb, ValPtr key, ValPtr value, bool overwrite = true,
|
||||
double expiration_time = 0);
|
||||
|
||||
/**
|
||||
* Retrieve a value from the backend for a provided key.
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
* @return A struct describing the result of the operation, containing a code, an
|
||||
* optional error string, and a ValPtr for operations that return values.
|
||||
*/
|
||||
OperationResult Get(ValPtr key, OperationResultCallback* cb = nullptr);
|
||||
OperationResult Get(OperationResultCallback* cb, ValPtr key);
|
||||
|
||||
/**
|
||||
* Erases the value for a key from the backend.
|
||||
|
@ -99,7 +99,7 @@ public:
|
|||
* @return A struct describing the result of the operation, containing a code, an
|
||||
* optional error string, and a ValPtr for operations that return values.
|
||||
*/
|
||||
OperationResult Erase(ValPtr key, OperationResultCallback* cb = nullptr);
|
||||
OperationResult Erase(OperationResultCallback* cb, ValPtr key);
|
||||
|
||||
/**
|
||||
* Returns whether the backend is opened.
|
||||
|
@ -146,7 +146,7 @@ protected:
|
|||
* @return A struct describing the result of the operation, containing a code, an
|
||||
* optional error string, and a ValPtr for operations that return values.
|
||||
*/
|
||||
OperationResult Open(RecordValPtr options, TypePtr kt, TypePtr vt, OpenResultCallback* cb = nullptr);
|
||||
OperationResult Open(OpenResultCallback* cb, RecordValPtr options, TypePtr kt, TypePtr vt);
|
||||
|
||||
/**
|
||||
* Finalizes the backend when it's being closed.
|
||||
|
@ -155,7 +155,7 @@ protected:
|
|||
* @return A struct describing the result of the operation, containing a code, an
|
||||
* optional error string, and a ValPtr for operations that return values.
|
||||
*/
|
||||
OperationResult Close(OperationResultCallback* cb = nullptr);
|
||||
OperationResult Close(OperationResultCallback* cb);
|
||||
|
||||
/**
|
||||
* Removes any entries in the backend that have expired. Can be overridden by
|
||||
|
@ -188,12 +188,12 @@ protected:
|
|||
std::string tag;
|
||||
|
||||
private:
|
||||
virtual OperationResult DoOpen(RecordValPtr options, OpenResultCallback* cb = nullptr) = 0;
|
||||
virtual OperationResult DoClose(OperationResultCallback* cb = nullptr) = 0;
|
||||
virtual OperationResult DoPut(ValPtr key, ValPtr value, bool overwrite = true, double expiration_time = 0,
|
||||
OperationResultCallback* cb = nullptr) = 0;
|
||||
virtual OperationResult DoGet(ValPtr key, OperationResultCallback* cb = nullptr) = 0;
|
||||
virtual OperationResult DoErase(ValPtr key, OperationResultCallback* cb = nullptr) = 0;
|
||||
virtual OperationResult DoOpen(OpenResultCallback* cb, RecordValPtr options) = 0;
|
||||
virtual OperationResult DoClose(OperationResultCallback* cb) = 0;
|
||||
virtual OperationResult DoPut(OperationResultCallback* cb, ValPtr key, ValPtr value, bool overwrite = true,
|
||||
double expiration_time = 0) = 0;
|
||||
virtual OperationResult DoGet(OperationResultCallback* cb, ValPtr key) = 0;
|
||||
virtual OperationResult DoErase(OperationResultCallback* cb, ValPtr key) = 0;
|
||||
virtual void DoPoll() {}
|
||||
virtual void DoExpire(double current_network_time) {}
|
||||
|
||||
|
|
|
@ -73,9 +73,9 @@ zeek::expected<BackendPtr, std::string> Manager::Instantiate(const Tag& type) {
|
|||
return bp;
|
||||
}
|
||||
|
||||
OperationResult Manager::OpenBackend(BackendPtr backend, RecordValPtr options, TypePtr key_type, TypePtr val_type,
|
||||
OpenResultCallback* cb) {
|
||||
auto res = backend->Open(std::move(options), std::move(key_type), std::move(val_type), cb);
|
||||
OperationResult Manager::OpenBackend(BackendPtr backend, OpenResultCallback* cb, RecordValPtr options, TypePtr key_type,
|
||||
TypePtr val_type) {
|
||||
auto res = backend->Open(cb, std::move(options), std::move(key_type), std::move(val_type));
|
||||
if ( res.code != ReturnCode::SUCCESS && res.code != ReturnCode::IN_PROGRESS ) {
|
||||
res.err_str = util::fmt("Failed to open backend %s: %s", backend->Tag(), res.err_str.c_str());
|
||||
return res;
|
||||
|
|
|
@ -60,8 +60,8 @@ public:
|
|||
* @return A struct describing the result of the operation, containing a code, an
|
||||
* optional error string, and a ValPtr for operations that return values.
|
||||
*/
|
||||
OperationResult OpenBackend(BackendPtr backend, RecordValPtr options, TypePtr key_type, TypePtr val_type,
|
||||
OpenResultCallback* cb = nullptr);
|
||||
OperationResult OpenBackend(BackendPtr backend, OpenResultCallback* cb, RecordValPtr options, TypePtr key_type,
|
||||
TypePtr val_type);
|
||||
|
||||
/**
|
||||
* Closes a storage backend.
|
||||
|
@ -71,7 +71,7 @@ public:
|
|||
* @return A struct describing the result of the operation, containing a code, an
|
||||
* optional error string, and a ValPtr for operations that return values.
|
||||
*/
|
||||
OperationResult CloseBackend(BackendPtr backend, OperationResultCallback* cb = nullptr);
|
||||
OperationResult CloseBackend(BackendPtr backend, OperationResultCallback* cb);
|
||||
|
||||
void Expire();
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ storage::BackendPtr Redis::Instantiate(std::string_view tag) { return make_intru
|
|||
/**
|
||||
* Called by the manager system to open the backend.
|
||||
*/
|
||||
OperationResult Redis::DoOpen(RecordValPtr options, OpenResultCallback* cb) {
|
||||
OperationResult Redis::DoOpen(OpenResultCallback* cb, RecordValPtr options) {
|
||||
RecordValPtr backend_options = options->GetField<RecordVal>("redis");
|
||||
|
||||
key_prefix = backend_options->GetField<StringVal>("key_prefix")->ToStdString();
|
||||
|
@ -254,8 +254,8 @@ OperationResult Redis::DoClose(OperationResultCallback* cb) {
|
|||
/**
|
||||
* The workhorse method for Put(). This must be implemented by plugins.
|
||||
*/
|
||||
OperationResult Redis::DoPut(ValPtr key, ValPtr value, bool overwrite, double expiration_time,
|
||||
OperationResultCallback* cb) {
|
||||
OperationResult Redis::DoPut(OperationResultCallback* cb, ValPtr key, ValPtr value, bool overwrite,
|
||||
double expiration_time) {
|
||||
// The async context will queue operations until it's connected fully.
|
||||
if ( ! connected && ! async_ctx )
|
||||
return {ReturnCode::NOT_CONNECTED};
|
||||
|
@ -308,7 +308,7 @@ OperationResult Redis::DoPut(ValPtr key, ValPtr value, bool overwrite, double ex
|
|||
/**
|
||||
* The workhorse method for Get(). This must be implemented for plugins.
|
||||
*/
|
||||
OperationResult Redis::DoGet(ValPtr key, OperationResultCallback* cb) {
|
||||
OperationResult Redis::DoGet(OperationResultCallback* cb, ValPtr key) {
|
||||
// The async context will queue operations until it's connected fully.
|
||||
if ( ! connected && ! async_ctx )
|
||||
return {ReturnCode::NOT_CONNECTED};
|
||||
|
@ -331,7 +331,7 @@ OperationResult Redis::DoGet(ValPtr key, OperationResultCallback* cb) {
|
|||
/**
|
||||
* The workhorse method for Erase(). This must be implemented for plugins.
|
||||
*/
|
||||
OperationResult Redis::DoErase(ValPtr key, OperationResultCallback* cb) {
|
||||
OperationResult Redis::DoErase(OperationResultCallback* cb, ValPtr key) {
|
||||
// The async context will queue operations until it's connected fully.
|
||||
if ( ! connected && ! async_ctx )
|
||||
return {ReturnCode::NOT_CONNECTED};
|
||||
|
|
|
@ -50,12 +50,12 @@ public:
|
|||
bool ExpireRunning() const { return expire_running.load(); }
|
||||
|
||||
private:
|
||||
OperationResult DoOpen(RecordValPtr options, OpenResultCallback* cb = nullptr) override;
|
||||
OperationResult DoClose(OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoPut(ValPtr key, ValPtr value, bool overwrite = true, double expiration_time = 0,
|
||||
OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoGet(ValPtr key, OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoErase(ValPtr key, OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoOpen(OpenResultCallback* cb, RecordValPtr options) override;
|
||||
OperationResult DoClose(OperationResultCallback* cb) override;
|
||||
OperationResult DoPut(OperationResultCallback* cb, ValPtr key, ValPtr value, bool overwrite = true,
|
||||
double expiration_time = 0) override;
|
||||
OperationResult DoGet(OperationResultCallback* cb, ValPtr key) override;
|
||||
OperationResult DoErase(OperationResultCallback* cb, ValPtr key) override;
|
||||
void DoExpire(double current_network_time) override;
|
||||
void DoPoll() override;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ storage::BackendPtr SQLite::Instantiate(std::string_view tag) { return make_intr
|
|||
/**
|
||||
* Called by the manager system to open the backend.
|
||||
*/
|
||||
OperationResult SQLite::DoOpen(RecordValPtr options, OpenResultCallback* cb) {
|
||||
OperationResult SQLite::DoOpen(OpenResultCallback* cb, RecordValPtr options) {
|
||||
if ( sqlite3_threadsafe() == 0 ) {
|
||||
std::string res =
|
||||
"SQLite reports that it is not threadsafe. Zeek needs a threadsafe version of "
|
||||
|
@ -51,7 +51,7 @@ OperationResult SQLite::DoOpen(RecordValPtr options, OpenResultCallback* cb) {
|
|||
std::string err = util::fmt("Error executing table creation statement: %s", errorMsg);
|
||||
Error(err.c_str());
|
||||
sqlite3_free(errorMsg);
|
||||
Close();
|
||||
Close(nullptr);
|
||||
return {ReturnCode::INITIALIZATION_FAILED, err};
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ OperationResult SQLite::DoOpen(RecordValPtr options, OpenResultCallback* cb) {
|
|||
std::string err = util::fmt("Error executing integrity check: %s", errorMsg);
|
||||
Error(err.c_str());
|
||||
sqlite3_free(errorMsg);
|
||||
Close();
|
||||
Close(nullptr);
|
||||
return {ReturnCode::INITIALIZATION_FAILED, err};
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ OperationResult SQLite::DoOpen(RecordValPtr options, OpenResultCallback* cb) {
|
|||
std::string err = util::fmt("Error executing tuning pragma statement: %s", errorMsg);
|
||||
Error(err.c_str());
|
||||
sqlite3_free(errorMsg);
|
||||
Close();
|
||||
Close(nullptr);
|
||||
return {ReturnCode::INITIALIZATION_FAILED, err};
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ OperationResult SQLite::DoOpen(RecordValPtr options, OpenResultCallback* cb) {
|
|||
sqlite3_stmt* ps;
|
||||
if ( auto prep_res = CheckError(sqlite3_prepare_v2(db, stmt.c_str(), stmt.size(), &ps, NULL));
|
||||
prep_res.code != ReturnCode::SUCCESS ) {
|
||||
Close();
|
||||
Close(nullptr);
|
||||
return prep_res;
|
||||
}
|
||||
|
||||
|
@ -146,8 +146,8 @@ OperationResult SQLite::DoClose(OperationResultCallback* cb) {
|
|||
/**
|
||||
* The workhorse method for Put(). This must be implemented by plugins.
|
||||
*/
|
||||
OperationResult SQLite::DoPut(ValPtr key, ValPtr value, bool overwrite, double expiration_time,
|
||||
OperationResultCallback* cb) {
|
||||
OperationResult SQLite::DoPut(OperationResultCallback* cb, ValPtr key, ValPtr value, bool overwrite,
|
||||
double expiration_time) {
|
||||
if ( ! db )
|
||||
return {ReturnCode::NOT_CONNECTED};
|
||||
|
||||
|
@ -193,7 +193,7 @@ OperationResult SQLite::DoPut(ValPtr key, ValPtr value, bool overwrite, double e
|
|||
/**
|
||||
* The workhorse method for Get(). This must be implemented for plugins.
|
||||
*/
|
||||
OperationResult SQLite::DoGet(ValPtr key, OperationResultCallback* cb) {
|
||||
OperationResult SQLite::DoGet(OperationResultCallback* cb, ValPtr key) {
|
||||
if ( ! db )
|
||||
return {ReturnCode::NOT_CONNECTED};
|
||||
|
||||
|
@ -213,7 +213,7 @@ OperationResult SQLite::DoGet(ValPtr key, OperationResultCallback* cb) {
|
|||
/**
|
||||
* The workhorse method for Erase(). This must be implemented for plugins.
|
||||
*/
|
||||
OperationResult SQLite::DoErase(ValPtr key, OperationResultCallback* cb) {
|
||||
OperationResult SQLite::DoErase(OperationResultCallback* cb, ValPtr key) {
|
||||
if ( ! db )
|
||||
return {ReturnCode::NOT_CONNECTED};
|
||||
|
||||
|
|
|
@ -23,12 +23,12 @@ public:
|
|||
bool IsOpen() override { return db != nullptr; }
|
||||
|
||||
private:
|
||||
OperationResult DoOpen(RecordValPtr options, OpenResultCallback* cb = nullptr) override;
|
||||
OperationResult DoClose(OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoPut(ValPtr key, ValPtr value, bool overwrite = true, double expiration_time = 0,
|
||||
OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoGet(ValPtr key, OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoErase(ValPtr key, OperationResultCallback* cb = nullptr) override;
|
||||
OperationResult DoOpen(OpenResultCallback* cb, RecordValPtr options) override;
|
||||
OperationResult DoClose(OperationResultCallback* cb) override;
|
||||
OperationResult DoPut(OperationResultCallback* cb, ValPtr key, ValPtr value, bool overwrite = true,
|
||||
double expiration_time = 0) override;
|
||||
OperationResult DoGet(OperationResultCallback* cb, ValPtr key) override;
|
||||
OperationResult DoErase(OperationResultCallback* cb, ValPtr key) override;
|
||||
void DoExpire(double current_network_time) override;
|
||||
|
||||
/**
|
||||
|
|
|
@ -109,7 +109,7 @@ function Storage::Async::__open_backend%(btype: Storage::Backend, options: any,
|
|||
auto kt = key_type->AsTypeVal()->GetType()->AsTypeType()->GetType();
|
||||
auto vt = val_type->AsTypeVal()->GetType()->AsTypeType()->GetType();
|
||||
auto options_val = IntrusivePtr<RecordVal>{NewRef{}, options->AsRecordVal()};
|
||||
auto op_result = storage_mgr->OpenBackend(b.value(), options_val, kt, vt, cb);
|
||||
auto op_result = storage_mgr->OpenBackend(b.value(), cb, options_val, kt, vt);
|
||||
|
||||
handle_async_result(b.value(), cb, op_result);
|
||||
|
||||
|
@ -156,7 +156,7 @@ function Storage::Async::__put%(backend: opaque of Storage::BackendHandle, key:
|
|||
|
||||
auto key_v = IntrusivePtr<Val>{NewRef{}, key};
|
||||
auto val_v = IntrusivePtr<Val>{NewRef{}, value};
|
||||
auto op_result = (*b)->backend->Put(key_v, val_v, overwrite, expire_time, cb);
|
||||
auto op_result = (*b)->backend->Put(cb, key_v, val_v, overwrite, expire_time);
|
||||
handle_async_result((*b)->backend, cb, op_result);
|
||||
|
||||
return nullptr;
|
||||
|
@ -177,7 +177,7 @@ function Storage::Async::__get%(backend: opaque of Storage::BackendHandle, key:
|
|||
}
|
||||
|
||||
auto key_v = IntrusivePtr<Val>{NewRef{}, key};
|
||||
auto op_result = (*b)->backend->Get(key_v, cb);
|
||||
auto op_result = (*b)->backend->Get(cb, key_v);
|
||||
handle_async_result((*b)->backend, cb, op_result);
|
||||
|
||||
return nullptr;
|
||||
|
@ -198,7 +198,7 @@ function Storage::Async::__erase%(backend: opaque of Storage::BackendHandle, key
|
|||
}
|
||||
|
||||
auto key_v = IntrusivePtr<Val>{NewRef{}, key};
|
||||
auto op_result = (*b)->backend->Erase(key_v, cb);
|
||||
auto op_result = (*b)->backend->Erase(cb, key_v);
|
||||
handle_async_result((*b)->backend, cb, op_result);
|
||||
|
||||
return nullptr;
|
||||
|
@ -224,7 +224,7 @@ function Storage::Sync::__open_backend%(btype: Storage::Backend, options: any, k
|
|||
auto kt = key_type->AsTypeVal()->GetType()->AsTypeType()->GetType();
|
||||
auto vt = val_type->AsTypeVal()->GetType()->AsTypeType()->GetType();
|
||||
auto options_val = IntrusivePtr<RecordVal>{NewRef{}, options->AsRecordVal()};
|
||||
auto op_result = storage_mgr->OpenBackend(b.value(), options_val, kt, vt, cb);
|
||||
auto op_result = storage_mgr->OpenBackend(b.value(), cb, options_val, kt, vt);
|
||||
|
||||
// If the backend only supports async, block until it's ready and then pull the result out of
|
||||
// the callback.
|
||||
|
@ -277,7 +277,7 @@ function Storage::Sync::__put%(backend: opaque of Storage::BackendHandle, key: a
|
|||
auto cb = new OperationResultCallback();
|
||||
auto key_v = IntrusivePtr<Val>{NewRef{}, key};
|
||||
auto val_v = IntrusivePtr<Val>{NewRef{}, value};
|
||||
op_result = (*b)->backend->Put(key_v, val_v, overwrite, expire_time, cb);
|
||||
op_result = (*b)->backend->Put(cb, key_v, val_v, overwrite, expire_time);
|
||||
|
||||
// If the backend only supports async, block until it's ready and then pull the result out of
|
||||
// the callback.
|
||||
|
@ -302,7 +302,7 @@ function Storage::Sync::__get%(backend: opaque of Storage::BackendHandle, key: a
|
|||
else {
|
||||
auto cb = new OperationResultCallback();
|
||||
auto key_v = IntrusivePtr<Val>{NewRef{}, key};
|
||||
op_result = (*b)->backend->Get(key_v, cb);
|
||||
op_result = (*b)->backend->Get(cb, key_v);
|
||||
|
||||
// If the backend only supports async, block until it's ready and then pull the result out of
|
||||
// the callback.
|
||||
|
@ -327,7 +327,7 @@ function Storage::Sync::__erase%(backend: opaque of Storage::BackendHandle, key:
|
|||
else {
|
||||
auto cb = new OperationResultCallback();
|
||||
auto key_v = IntrusivePtr<Val>{NewRef{}, key};
|
||||
op_result = (*b)->backend->Erase(key_v, cb);
|
||||
op_result = (*b)->backend->Erase(cb, key_v);
|
||||
|
||||
// If the backend only supports async, block until it's ready and then pull the result out of
|
||||
// the callback.
|
||||
|
|
|
@ -20,7 +20,7 @@ BackendPtr StorageDummy::Instantiate(std::string_view tag) { return make_intrusi
|
|||
* implementation must call \a Opened(); if not, it must call Error()
|
||||
* with a corresponding message.
|
||||
*/
|
||||
OperationResult StorageDummy::DoOpen(RecordValPtr options, OpenResultCallback* cb) {
|
||||
OperationResult StorageDummy::DoOpen(OpenResultCallback* cb, RecordValPtr options) {
|
||||
RecordValPtr backend_options = options->GetField<RecordVal>("dummy");
|
||||
bool open_fail = backend_options->GetField<BoolVal>("open_fail")->Get();
|
||||
if ( open_fail )
|
||||
|
@ -42,8 +42,8 @@ OperationResult StorageDummy::DoClose(OperationResultCallback* cb) {
|
|||
/**
|
||||
* The workhorse method for Put(). This must be implemented by plugins.
|
||||
*/
|
||||
OperationResult StorageDummy::DoPut(ValPtr key, ValPtr value, bool overwrite, double expiration_time,
|
||||
OperationResultCallback* cb) {
|
||||
OperationResult StorageDummy::DoPut(OperationResultCallback* cb, ValPtr key, ValPtr value, bool overwrite,
|
||||
double expiration_time) {
|
||||
auto json_key = key->ToJSON()->ToStdString();
|
||||
auto json_value = value->ToJSON()->ToStdString();
|
||||
data[json_key] = json_value;
|
||||
|
@ -53,7 +53,7 @@ OperationResult StorageDummy::DoPut(ValPtr key, ValPtr value, bool overwrite, do
|
|||
/**
|
||||
* The workhorse method for Get(). This must be implemented for plugins.
|
||||
*/
|
||||
OperationResult StorageDummy::DoGet(ValPtr key, OperationResultCallback* cb) {
|
||||
OperationResult StorageDummy::DoGet(OperationResultCallback* cb, ValPtr key) {
|
||||
auto json_key = key->ToJSON();
|
||||
auto it = data.find(json_key->ToStdString());
|
||||
if ( it == data.end() )
|
||||
|
@ -71,7 +71,7 @@ OperationResult StorageDummy::DoGet(ValPtr key, OperationResultCallback* cb) {
|
|||
/**
|
||||
* The workhorse method for Erase(). This must be implemented for plugins.
|
||||
*/
|
||||
OperationResult StorageDummy::DoErase(ValPtr key, OperationResultCallback* cb) {
|
||||
OperationResult StorageDummy::DoErase(OperationResultCallback* cb, ValPtr key) {
|
||||
auto json_key = key->ToJSON();
|
||||
auto it = data.find(json_key->ToStdString());
|
||||
if ( it == data.end() )
|
||||
|
|
|
@ -21,8 +21,7 @@ public:
|
|||
/**
|
||||
* Called by the manager system to open the backend.
|
||||
*/
|
||||
zeek::storage::OperationResult DoOpen(zeek::RecordValPtr options,
|
||||
zeek::storage::OpenResultCallback* cb = nullptr) override;
|
||||
zeek::storage::OperationResult DoOpen(zeek::storage::OpenResultCallback* cb, zeek::RecordValPtr options) override;
|
||||
|
||||
/**
|
||||
* Finalizes the backend when it's being closed.
|
||||
|
@ -37,21 +36,19 @@ public:
|
|||
/**
|
||||
* The workhorse method for Put().
|
||||
*/
|
||||
zeek::storage::OperationResult DoPut(zeek::ValPtr key, zeek::ValPtr value, bool overwrite = true,
|
||||
double expiration_time = 0,
|
||||
zeek::storage::OperationResultCallback* cb = nullptr) override;
|
||||
zeek::storage::OperationResult DoPut(zeek::storage::OperationResultCallback* cb, zeek::ValPtr key,
|
||||
zeek::ValPtr value, bool overwrite = true,
|
||||
double expiration_time = 0) override;
|
||||
|
||||
/**
|
||||
* The workhorse method for Get().
|
||||
*/
|
||||
zeek::storage::OperationResult DoGet(zeek::ValPtr key,
|
||||
zeek::storage::OperationResultCallback* cb = nullptr) override;
|
||||
zeek::storage::OperationResult DoGet(zeek::storage::OperationResultCallback* cb, zeek::ValPtr key) override;
|
||||
|
||||
/**
|
||||
* The workhorse method for Erase().
|
||||
*/
|
||||
zeek::storage::OperationResult DoErase(zeek::ValPtr key,
|
||||
zeek::storage::OperationResultCallback* cb = nullptr) override;
|
||||
zeek::storage::OperationResult DoErase(zeek::storage::OperationResultCallback* cb, zeek::ValPtr key) override;
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> data;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue