MySQL 8.4.2
Source Code Documentation
mock_server_global_scope.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLROUTER_MOCK_SERVER_GLOBAL_SCOPE_INCLUDED
27#define MYSQLROUTER_MOCK_SERVER_GLOBAL_SCOPE_INCLUDED
28
29#include <map>
30#include <mutex>
31#include <string>
32#include <vector>
33
34/**
35 * stores global data as pair of <string, jsonfied-string>
36 */
38 public:
39 using key_type = std::string;
40 using value_type = std::string;
41 using type = std::map<key_type, value_type>;
42
44 std::lock_guard<std::mutex> lk(global_mutex_);
45 return global_;
46 }
47
48 std::vector<key_type> get_keys() {
49 std::lock_guard<std::mutex> lk(global_mutex_);
50
51 std::vector<key_type> keys;
52 for (const auto &k : global_) {
53 keys.emplace_back(k.first);
54 }
55
56 return keys;
57 }
58
59 void set(const key_type &key, const value_type &value) {
60 std::lock_guard<std::mutex> lk(global_mutex_);
61
62 global_[key] = value;
63 }
64
65 size_t erase(const key_type &key) {
66 std::lock_guard<std::mutex> lk(global_mutex_);
67
68 return global_.erase(key);
69 }
70
71 void reset(type globals) {
72 std::lock_guard<std::mutex> lk(global_mutex_);
73 global_ = globals;
74 }
75
76 private:
78 std::mutex global_mutex_;
79};
80
81#endif
stores global data as pair of <string, jsonfied-string>
Definition: mock_server_global_scope.h:37
std::map< key_type, value_type > type
Definition: mock_server_global_scope.h:41
size_t erase(const key_type &key)
Definition: mock_server_global_scope.h:65
std::mutex global_mutex_
Definition: mock_server_global_scope.h:78
std::vector< key_type > get_keys()
Definition: mock_server_global_scope.h:48
std::string key_type
Definition: mock_server_global_scope.h:39
type global_
Definition: mock_server_global_scope.h:77
std::string value_type
Definition: mock_server_global_scope.h:40
void set(const key_type &key, const value_type &value)
Definition: mock_server_global_scope.h:59
type get_all()
Definition: mock_server_global_scope.h:43
void reset(type globals)
Definition: mock_server_global_scope.h:71
static uint keys
Definition: hp_test2.cc:49
required string key
Definition: replication_asynchronous_connection_failover.proto:60