5454#include " misc.h"
5555#include " dbus_portal.hpp"
5656
57+ #include < random>
58+
5759
5860#define MOD_NAME " [dbus] "
5961
6062namespace {
63+
64+ std::string generate_token (){
65+ std::random_device random_device;
66+ auto random_engine = std::default_random_engine (random_device ());
67+ auto dist = std::uniform_int_distribution<uint64_t >();
68+ const auto rand_val = dist (random_engine);
69+
70+ return " uv_" + std::to_string (rand_val);
71+ }
72+
6173struct request_path_t {
6274 std::string token;
6375 std::string path;
6476
6577 static request_path_t create (const std::string &name) {
66- ++token_counter;
67-
68- auto token = std::string (" uv" ) + std::to_string (token_counter);
78+ const auto token = generate_token ();
6979 request_path_t result = {
7080 .token = token,
7181 .path = std::string (" /org/freedesktop/portal/desktop/request/" ) + name + " /" + token
@@ -74,33 +84,21 @@ struct request_path_t {
7484 LOG (LOG_LEVEL_DEBUG) << " new request: '" << result.path << " '\n " ;
7585 return result;
7686 }
77-
78- private:
79- static unsigned int token_counter;
8087};
8188
82- unsigned int request_path_t ::token_counter = 0 ;
83-
8489struct session_path_t {
8590 std::string token;
8691 std::string path;
8792
8893 static session_path_t create (const std::string &name) {
89- ++token_counter;
90-
91- auto token = std::string (" uv" ) + std::to_string (token_counter);
94+ auto token = generate_token ();
9295 return {
9396 .token = token,
9497 .path = std::string (" /org/freedesktop/portal/desktop/session/" ) + name + " /" + token
9598 };
9699 }
97-
98- private:
99- static unsigned int token_counter;
100100};
101101
102- unsigned int session_path_t ::token_counter = 0 ;
103-
104102struct GVariant_deleter { void operator ()(GVariant *a) { g_variant_unref (a); } };
105103using GVariant_uniq = std::unique_ptr<GVariant, GVariant_deleter>;
106104
0 commit comments