diff options
| author | ckrinitsin <101062646+ckrinitsin@users.noreply.github.com> | 2025-03-21 22:15:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-21 22:15:01 +0100 |
| commit | 5fca08baa98058508c743101dcf10cd1b178ec7a (patch) | |
| tree | 9346b38f25ab5880af3f40e49ba1e64c4f7e0ca2 /src/common/shared_memory.h | |
| parent | 2a22b4123dce661b0500dc07012d61215bdce161 (diff) | |
| parent | 7212db13b9013aa15673ae65da65eeaf97ee0d12 (diff) | |
| download | BT-Programming-Assignment-5fca08baa98058508c743101dcf10cd1b178ec7a.tar.gz BT-Programming-Assignment-5fca08baa98058508c743101dcf10cd1b178ec7a.zip | |
Merge pull request #4 from ckrinitsin/client-input
Client input
Diffstat (limited to 'src/common/shared_memory.h')
| -rw-r--r-- | src/common/shared_memory.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/shared_memory.h b/src/common/shared_memory.h index 70554e4..fe101ea 100644 --- a/src/common/shared_memory.h +++ b/src/common/shared_memory.h @@ -9,8 +9,14 @@ #define MAX_KEY_SIZE 64 #define MAX_VALUE_SIZE 128 +/** + * @brief Possible operations on the hashtable. + */ enum Operations { INSERT, DELETE, GET, PRINT }; +/** + * @brief One request constists out of the operation, the arguments and the response. + */ struct Request { Operations type; char key[MAX_KEY_SIZE]; @@ -18,6 +24,13 @@ struct Request { char response[MAX_VALUE_SIZE]; }; +/** + * @brief The shared memory between client and server. + * + * @details The shared memory consists out of: + * - A circular-buffer, to de- and enqueue multiple request at once. + * - A mutex with a conditional variable, to ensure concurrency of the buffer. + */ struct SharedMemory { Request request[QUEUE_SIZE]; pthread_mutex_t mutex; @@ -28,6 +41,9 @@ struct SharedMemory { bool full; }; +/** + * @brief Converts a generic type to a stringstream, so that it can be saved in the shared memory. + */ template <typename T> std::string serialize(const T& data) { @@ -36,6 +52,9 @@ std::string serialize(const T& data) return oss.str(); } +/** + * @brief Converts a stringstream to a generic type, so that value in the shared memory can be read. + */ template <typename T> T deserialize(const std::string& str) { |