-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplesim: Add session id to GET_INFO messages
- Loading branch information
1 parent
07c1272
commit a03a694
Showing
7 changed files
with
77 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "session_id.hpp" | ||
|
||
#include <boost/uuid/random_generator.hpp> | ||
|
||
|
||
#ifndef SESSION_ID | ||
#define SESSION_ID boost::uuids::random_generator()() | ||
#endif | ||
|
||
using rofi::hal::SessionId; | ||
|
||
const SessionId & SessionId::get() | ||
{ | ||
static SessionId instance = SessionId( SESSION_ID ); | ||
return instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <type_traits> | ||
|
||
|
||
namespace rofi::hal | ||
{ | ||
|
||
class SessionId { | ||
public: | ||
static const SessionId & get(); | ||
|
||
const std::string & bytes() const | ||
{ | ||
return _bytes; | ||
} | ||
|
||
private: | ||
template < typename T, std::enable_if_t< std::is_integral_v< T >, int > = 0 > | ||
constexpr SessionId( T id ) | ||
{ | ||
_bytes.reserve( sizeof( T ) ); | ||
|
||
for ( size_t i = 0; i < sizeof( T ); i++ ) { | ||
_bytes.push_back( *( reinterpret_cast< char * >( &id ) + i ) ); | ||
} | ||
} | ||
|
||
template < typename T, | ||
std::enable_if_t< sizeof( typename T::value_type ) == sizeof( char ), int > = 0 > | ||
constexpr SessionId( T id ) | ||
{ | ||
_bytes.reserve( id.size() ); | ||
|
||
for ( auto & c : id ) { | ||
static_assert( sizeof( decltype( c ) ) == sizeof( char ) ); | ||
_bytes.push_back( reinterpret_cast< char & >( c ) ); | ||
} | ||
} | ||
|
||
SessionId( const SessionId & other ) = delete; | ||
SessionId & operator=( const SessionId & other ) = delete; | ||
|
||
private: | ||
std::string _bytes; | ||
}; | ||
|
||
} // namespace rofi::hal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters