Horizon Official Technical Documentation
TestWork Class Reference
+ Inheritance diagram for TestWork:
+ Collaboration diagram for TestWork:

Public Member Functions

 TestWork (std::shared_ptr< Horizon::System::RuntimeRoutineContext > parent_context)
 
bool execute ()
 
void set_result (ResultType res)
 
ResultType get_result ()
 
void set_request (work_request _req)
 
work_request get_request ()
 
bool has_result ()
 
- Public Member Functions inherited from Horizon::System::RuntimeRoutineContext::Work
 Work (std::shared_ptr< RuntimeRoutineContext > runtime_context)
 
 ~Work ()
 
virtual bool execute ()
 
std::shared_ptr< RuntimeRoutineContextget_runtime_context ()
 
void set_runtime_context (std::shared_ptr< RuntimeRoutineContext > runtime_context)
 
MessageAgentget_message_agent ()
 
- Public Member Functions inherited from Horizon::System::RuntimeContext::WorkContext
 WorkContext ()
 
virtual bool execute ()
 
std::string get_uuid_string ()
 

Public Attributes

work_request _request
 
ResultType _result
 
- Public Attributes inherited from Horizon::System::RuntimeContext::WorkContext
boost::uuids::uuid _uuid
 

Private Types

typedef Horizon::System::Result< int > ResultType
 

Additional Inherited Members

- Protected Attributes inherited from Horizon::System::RuntimeRoutineContext::Work
std::weak_ptr< RuntimeRoutineContext_runtime_context
 
MessageAgent _message_agent
 

Member Typedef Documentation

◆ ResultType

Constructor & Destructor Documentation

◆ TestWork()

TestWork::TestWork ( std::shared_ptr< Horizon::System::RuntimeRoutineContext parent_context)
inline
ResultType _result
Definition: SystemRoutinesTest.cpp:88

Member Function Documentation

◆ execute()

bool TestWork::execute ( )
inlinevirtual

Reimplemented from Horizon::System::RuntimeRoutineContext::Work.

55 {
56 std::promise<ResultType> p;
57 // Assuming this is the thread that will work on getting the result for either of the Kernel Components...
58 // We can use a promise / future combination of techniques to derive the final result.
59 std::thread t = std::thread([&]()
60 {
61 std::cout << "Calculating..." << std::endl;
62 p.set_value(ResultType(get_request().i * 20));
63 });
64
65 std::future<ResultType> f = p.get_future();
66 get_runtime_context()->get_runtime_synchronization_mutex().lock();
67 set_result(ResultType(f.get()));
68 get_runtime_context()->get_runtime_synchronization_mutex().unlock();
69 t.join();
70
71 return true;
72 }
std::shared_ptr< RuntimeRoutineContext > get_runtime_context()
Definition: System.hpp:412
Horizon::System::Result< int > ResultType
Definition: SystemRoutinesTest.cpp:51
work_request get_request()
Definition: SystemRoutinesTest.cpp:78
void set_result(ResultType res)
Definition: SystemRoutinesTest.cpp:74

References get_request(), Horizon::System::RuntimeRoutineContext::Work::get_runtime_context(), and set_result().

+ Here is the call graph for this function:

◆ get_request()

work_request TestWork::get_request ( )
inline
78{ return _request; }
work_request _request
Definition: SystemRoutinesTest.cpp:87

References _request.

Referenced by execute().

+ Here is the caller graph for this function:

◆ get_result()

ResultType TestWork::get_result ( )
inline
75{ return _result; }

References _result.

◆ has_result()

bool TestWork::has_result ( )
inline
80 {
81 get_runtime_context()->get_runtime_synchronization_mutex().lock();
82 bool result = _result.get_one() > 0;
83 get_runtime_context()->get_runtime_synchronization_mutex().unlock();
84 return result;
85 }
virtual T get_one()
Definition: System.hpp:362

References _result, Horizon::System::ContextWithResult< T >::get_one(), and Horizon::System::RuntimeRoutineContext::Work::get_runtime_context().

+ Here is the call graph for this function:

◆ set_request()

void TestWork::set_request ( work_request  _req)
inline
77{ _request = _req; }

References _request.

◆ set_result()

void TestWork::set_result ( ResultType  res)
inline
74{ _result = res; }

References _result.

Referenced by execute().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _request

work_request TestWork::_request

Referenced by get_request(), and set_request().

◆ _result

ResultType TestWork::_result

Referenced by get_result(), has_result(), and set_result().


The documentation for this class was generated from the following file: