From 9c22be3516d5067b98b06271e2f3545713ff6099 Mon Sep 17 00:00:00 2001 From: Aleksi Lindeman <0xdec05eba@gmail.com> Date: Sat, 17 Mar 2018 14:18:14 +0100 Subject: Add callback functions for operations --- include/odhtdb/Database.hpp | 75 +++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index 5114d28..926437a 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace odhtdb { @@ -52,57 +53,64 @@ namespace odhtdb ADD_USER }; - struct DatabaseCreateRequest + struct DatabaseCreateNodeRequest { - DISABLE_COPY(DatabaseCreateRequest) + DISABLE_COPY(DatabaseCreateNodeRequest) + const Hash *nodeHash; u64 timestamp; // In microseconds - Group *creatorGroup; + const User *creatorUser; std::string name; - DatabaseCreateRequest(u64 _timestamp, Group *_creatorGroup, std::string &&_name) : + DatabaseCreateNodeRequest(const Hash *_nodeHash, u64 _timestamp, const User *_creatorUser, std::string &&_name) : + nodeHash(_nodeHash), timestamp(_timestamp), - creatorGroup(_creatorGroup), + creatorUser(_creatorUser), name(std::move(_name)) { } - - DatabaseCreateRequest(DatabaseCreateRequest &&other) - { - timestamp = other.timestamp; - creatorGroup = other.creatorGroup; - name = std::move(other.name); - - other.timestamp = 0; - other.creatorGroup = nullptr; - } }; - struct DatabaseAddRequest + struct DatabaseAddNodeRequest { - DISABLE_COPY(DatabaseAddRequest) + DISABLE_COPY(DatabaseAddNodeRequest) + const Hash *nodeHash; + const Hash *requestHash; u64 timestamp; // In microseconds const User *creatorUser; - Decryption decryptedData; + const DataView decryptedData; - DatabaseAddRequest(u64 _timestamp, const User *_creatorUser, Decryption &&_decryptedData) : + DatabaseAddNodeRequest(const Hash *_nodeHash, const Hash *_requestHash, u64 _timestamp, const User *_creatorUser, const DataView &_decryptedData) : + nodeHash(_nodeHash), + requestHash(_requestHash), timestamp(_timestamp), creatorUser(_creatorUser), - decryptedData(std::move(_decryptedData)) + decryptedData(_decryptedData) { } - - DatabaseAddRequest(DatabaseAddRequest &&other) + }; + + struct DatabaseAddUserRequest + { + DISABLE_COPY(DatabaseAddUserRequest) + + const Hash *nodeHash; + const Hash *requestHash; + u64 timestamp; // In microseconds + const User *creatorUser; + const User *userToAdd; + const Group *groupToAddUserTo; + + DatabaseAddUserRequest(const Hash *_nodeHash, const Hash *_requestHash, u64 _timestamp, const User *_creatorUser, const User *_userToAdd, const Group *_groupToAddUserTo) : + timestamp(_timestamp), + creatorUser(_creatorUser), + userToAdd(_userToAdd), + groupToAddUserTo(_groupToAddUserTo) { - timestamp = other.timestamp; - creatorUser = other.creatorUser; - decryptedData = std::move(other.decryptedData); - - other.timestamp = 0; - other.creatorUser = nullptr; + } }; @@ -135,13 +143,19 @@ namespace odhtdb // Throws PermissionDeniedException if user @userToPerformActionWith is not allowed to add user @userToAdd to group @groupToAddUserTo void addUserToGroup(const DatabaseNode &nodeInfo, LocalUser *userToPerformActionWith, const std::string &userToAddName, const Signature::PublicKey &userToAddPublicKey, Group *groupToAddUserTo); void commit(); + + void setOnCreateNodeCallback(std::function callbackFunc); + void setOnAddNodeCallback(std::function callbackFunc); + void setOnAddUserCallback(std::function callbackFunc); + + DatabaseStorage& getStorage(); private: // Throws CommitCreateException on failure void commitStagedCreateObject(const std::unique_ptr &stagedObject); // Throws CommitAddException on failure void commitStagedAddObject(const std::unique_ptr &stagedObject); ntp::NtpTimestamp getSyncedTimestampUtc() const; - DatabaseCreateRequest deserializeCreateRequest(const std::shared_ptr &value, const Hash &hash, const std::shared_ptr encryptionKey); + void deserializeCreateRequest(const std::shared_ptr &value, const Hash &hash, const std::shared_ptr encryptionKey); void deserializeAddRequest(const std::shared_ptr &value, const Hash &requestDataHash, const std::shared_ptr encryptionKey); bool listenCreateData(std::shared_ptr value, const Hash &hash, const std::shared_ptr encryptionKey); bool listenAddData(std::shared_ptr value, const Hash &requestDataHash, const std::shared_ptr encryptionKey); @@ -150,5 +164,8 @@ namespace odhtdb std::vector> stagedCreateObjects; std::vector> stagedAddObjects; DatabaseStorage databaseStorage; + std::function onCreateNodeCallbackFunc; + std::function onAddNodeCallbackFunc; + std::function onAddUserCallbackFunc; }; } -- cgit v1.2.3