-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from SeadexGmbH/yasmine-0.2.0
yasmine 0.2.0
- Loading branch information
Showing
343 changed files
with
13,177 additions
and
11,243 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,111 @@ | ||
////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// // | ||
// This file is part of the Seadex yasmine ecosystem (http://yasmine.seadex.de). // | ||
// Copyright (C) 2016 Seadex GmbH // | ||
// // | ||
// Licensing information is available in the folder "license" which is part of this distribution. // | ||
// The same information is available on the www @ http://yasmine.seadex.de/License.html. // | ||
// // | ||
////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
#include "detector.h" | ||
|
||
#include <thread> | ||
#include <random> | ||
|
||
#include "base.h" | ||
#include "detector_callback.h" | ||
|
||
|
||
namespace | ||
{ | ||
|
||
|
||
constexpr unsigned int DETECTOR_OFF_LOWER_EXTREMITY( 1500 ); | ||
constexpr unsigned int DETECTOR_OFF_UPPER_EXTREMITY( 12000 ); | ||
constexpr unsigned int DETECTOR_ON_UPPER_EXTREMITY( 3000 ); | ||
constexpr unsigned int DETECTOR_ON_LOWER_RXTREMITY( 1500 ); | ||
|
||
|
||
} | ||
|
||
|
||
namespace sxy | ||
{ | ||
|
||
|
||
detector::detector( detector_callback& _detector_callback ) | ||
: detector_callback_( _detector_callback ), | ||
is_on_( false ), | ||
generate_random_detector_events_(), | ||
run_( false ), | ||
mutex_(), | ||
condition_variable_() | ||
{ | ||
// Nothing to do... | ||
} | ||
|
||
|
||
detector::~detector() = default; | ||
|
||
|
||
void detector::start() | ||
{ | ||
run_ = true; | ||
generate_random_detector_events_ = | ||
std::make_unique< std::thread >( [ this ] () { this->generate_detector_events(); } ); | ||
} | ||
|
||
|
||
void detector::stop() | ||
{ | ||
{ | ||
std::unique_lock< std::mutex > lock( mutex_ ); | ||
run_ = false; | ||
} | ||
condition_variable_.notify_all(); | ||
Y_ASSERT( generate_random_detector_events_->joinable(), "Event generator thread is not joinable!" ); | ||
generate_random_detector_events_->join(); | ||
generate_random_detector_events_.reset(); | ||
} | ||
|
||
|
||
bool detector::is_on() | ||
{ | ||
std::unique_lock< std::mutex > lock( mutex_ ); | ||
return( is_on_ ); | ||
} | ||
|
||
|
||
void detector::generate_detector_events() | ||
{ | ||
std::unique_lock< std::mutex > lock( mutex_ ); | ||
while( run_ ) | ||
{ | ||
std::random_device r; | ||
std::default_random_engine e( r() ); | ||
is_on_ = false; | ||
{ | ||
std::uniform_int_distribution< int > unifordist_( DETECTOR_OFF_LOWER_EXTREMITY, | ||
DETECTOR_OFF_UPPER_EXTREMITY ); | ||
auto time_to_wait = std::chrono::milliseconds( unifordist_( e ) ); | ||
condition_variable_.wait_for( lock, time_to_wait ); | ||
detector_callback_.detector_off(); | ||
} | ||
if( run_ ) | ||
{ | ||
is_on_ = true; | ||
{ | ||
std::uniform_int_distribution< int > unifordist_( DETECTOR_ON_UPPER_EXTREMITY, | ||
DETECTOR_ON_UPPER_EXTREMITY ); | ||
auto time_to_wait = std::chrono::milliseconds( unifordist_( e ) ); | ||
condition_variable_.wait_for( lock, time_to_wait ); | ||
detector_callback_.detector_on(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
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,57 @@ | ||
////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// // | ||
// This file is part of the Seadex yasmine ecosystem (http://yasmine.seadex.de). // | ||
// Copyright (C) 2016 Seadex GmbH // | ||
// // | ||
// Licensing information is available in the folder "license" which is part of this distribution. // | ||
// The same information is available on the www @ http://yasmine.seadex.de/License.html. // | ||
// // | ||
////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
#ifndef DETECTOR_5EBE86D2_647F_4029_94D8_B5521F641349 | ||
#define DETECTOR_5EBE86D2_647F_4029_94D8_B5521F641349 | ||
|
||
|
||
#include <memory> | ||
#include <mutex> | ||
#include <thread> | ||
#include <condition_variable> | ||
|
||
|
||
namespace sxy | ||
{ | ||
|
||
|
||
class detector_callback; | ||
|
||
|
||
class detector final | ||
{ | ||
public: | ||
explicit detector( detector_callback& _detector_callback ); | ||
~detector(); | ||
detector( const detector& ) = delete; | ||
detector& operator=( const detector& ) = delete; | ||
void start(); | ||
void stop(); | ||
bool is_on(); | ||
|
||
|
||
private: | ||
void generate_detector_events(); | ||
|
||
|
||
detector_callback& detector_callback_; | ||
bool is_on_; | ||
std::unique_ptr< std::thread > generate_random_detector_events_; | ||
bool run_; | ||
std::mutex mutex_; | ||
std::condition_variable condition_variable_; | ||
}; | ||
|
||
|
||
} | ||
|
||
|
||
#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
Oops, something went wrong.