-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a global LogPooler to allow pooling of Logs across modes.
- Loading branch information
Showing
11 changed files
with
145 additions
and
39 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
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,77 @@ | ||
#include "logpooler.hpp" | ||
|
||
#include "key_absorber.hpp" | ||
#include "key_log.hpp" | ||
#include "mapgate.hpp" | ||
|
||
#include <queue> | ||
|
||
|
||
#if defined(DEBUG) | ||
|
||
#include "key_logger_base.hpp" | ||
|
||
#include <iostream> | ||
|
||
#endif | ||
|
||
|
||
namespace vind | ||
{ | ||
namespace core | ||
{ | ||
struct LogPooler::Impl { | ||
std::queue<KeyLog> pool_{} ; | ||
} ; | ||
|
||
LogPooler::LogPooler() | ||
: pimpl(std::make_unique<Impl>()) | ||
{} | ||
|
||
LogPooler::~LogPooler() noexcept = default ; | ||
|
||
LogPooler& LogPooler::get_instance() { | ||
static LogPooler instance ; | ||
return instance ; | ||
} | ||
|
||
void LogPooler::push_log(const KeyLog& log) { | ||
pimpl->pool_.push(log) ; | ||
} | ||
|
||
void LogPooler::push_log(KeyLog&& log) { | ||
pimpl->pool_.push(std::move(log)) ; | ||
} | ||
|
||
KeyLog LogPooler::pop_log() { | ||
KeyLog log ; | ||
if(pimpl->pool_.empty()) { | ||
log = get_pressed_list() ; | ||
|
||
auto logs = MapGate::get_instance().map_logger(log) ; | ||
if(!logs.empty()) { | ||
auto itr = std::make_move_iterator(logs.begin()) ; | ||
log = std::move(*itr) ; | ||
itr ++ ; | ||
|
||
// | ||
// To simulate the input, make a state transition with an empty log. | ||
// This is to make the logger recognize that it is a key release, | ||
// not a long pressing of the key. | ||
// | ||
while(itr != std::make_move_iterator(logs.end())) { | ||
pimpl->pool_.emplace() ; | ||
pimpl->pool_.push(std::move(*itr)) ; | ||
itr ++ ; | ||
} | ||
} | ||
} | ||
else { | ||
log = std::move(pimpl->pool_.front()) ; | ||
pimpl->pool_.pop() ; | ||
} | ||
|
||
return log ; | ||
} | ||
} | ||
} |
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,38 @@ | ||
#ifndef _LOGPOOLER_HPP | ||
#define _LOGPOOLER_HPP | ||
|
||
#include <memory> | ||
|
||
|
||
namespace vind | ||
{ | ||
namespace core | ||
{ | ||
class KeyLog ; | ||
|
||
class LogPooler { | ||
private: | ||
struct Impl ; | ||
std::unique_ptr<Impl> pimpl ; | ||
|
||
explicit LogPooler() ; | ||
virtual ~LogPooler() noexcept ; | ||
|
||
public: | ||
static LogPooler& get_instance() ; | ||
|
||
void push_log(const KeyLog& log) ; | ||
void push_log(KeyLog&& log) ; | ||
|
||
KeyLog pop_log() ; | ||
|
||
LogPooler(LogPooler&&) = delete ; | ||
LogPooler& operator=(LogPooler&&) = delete ; | ||
LogPooler(const LogPooler&) = delete ; | ||
LogPooler& operator=(const LogPooler&) = delete ; | ||
} ; | ||
|
||
} | ||
} | ||
|
||
#endif |
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