Skip to content

Commit

Permalink
Merge pull request #2 from SeadexGmbH/yasmine-0.2.0
Browse files Browse the repository at this point in the history
yasmine 0.2.0
  • Loading branch information
SeadexTM authored Sep 19, 2016
2 parents e40b001 + c4fbc4d commit 5ebf998
Show file tree
Hide file tree
Showing 343 changed files with 13,177 additions and 11,243 deletions.
3 changes: 2 additions & 1 deletion yasmine/build/debug_info.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<GenerateDebugInformation>DebugFastLink</GenerateDebugInformation>
</Link>
<ClCompile>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup />
Expand Down
14 changes: 7 additions & 7 deletions yasmine/classic_farmroad/classic_farmroad.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -232,34 +232,34 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="t_detector.h">
<ClInclude Include="detector.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="i_detector_callback.h">
<ClInclude Include="detector_callback.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="t_intersection.h">
<ClInclude Include="intersection.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="t_traffic_light.h">
<ClInclude Include="traffic_light.h">
<SubType>
</SubType>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="t_detector.cpp">
<ClCompile Include="detector.cpp">
<SubType>
</SubType>
</ClCompile>
<ClCompile Include="t_intersection.cpp">
<ClCompile Include="intersection.cpp">
<SubType>
</SubType>
</ClCompile>
<ClCompile Include="t_traffic_light.cpp">
<ClCompile Include="traffic_light.cpp">
<SubType>
</SubType>
</ClCompile>
Expand Down
16 changes: 8 additions & 8 deletions yasmine/classic_farmroad/classic_farmroad.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="t_intersection.h">
<ClInclude Include="detector_callback.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="t_traffic_light.h">
<ClInclude Include="detector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="t_detector.h">
<ClInclude Include="intersection.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="i_detector_callback.h">
<ClInclude Include="traffic_light.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="t_intersection.cpp">
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="t_traffic_light.cpp">
<ClCompile Include="detector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="t_detector.cpp">
<ClCompile Include="intersection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<ClCompile Include="traffic_light.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down
111 changes: 111 additions & 0 deletions yasmine/classic_farmroad/detector.cpp
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();
}
}
}
}


}
57 changes: 57 additions & 0 deletions yasmine/classic_farmroad/detector.h
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@
//////////////////////////////////////////////////////////////////////////////////////////////////////


#ifndef I_SHALLOW_HISTORY_2F18336E_AEBD_4040_B40D_E96E0738B83E
#define I_SHALLOW_HISTORY_2F18336E_AEBD_4040_B40D_E96E0738B83E


#include "i_history.h"
#ifndef DETECTOR_CALLBACK_0AF0AB58_4818_48B8_A10D_3894B6652355
#define DETECTOR_CALLBACK_0AF0AB58_4818_48B8_A10D_3894B6652355


namespace sxy
{


class i_shallow_history:
public virtual i_history
class detector_callback
{
public:
i_shallow_history() = default;
virtual ~i_shallow_history() override = default;
i_shallow_history( const i_shallow_history& ) = delete;
i_shallow_history& operator=( const i_shallow_history& ) = delete;
detector_callback() = default;
virtual ~detector_callback() = default;
detector_callback( const detector_callback& ) = delete;
detector_callback& operator=( const detector_callback& ) = delete;
virtual void detector_on() = 0;
virtual void detector_off() = 0;
};


Expand Down
Loading

0 comments on commit 5ebf998

Please sign in to comment.