worker_interface.cpp 2.43 KB
Newer Older
1
#include <ITA\simulation_scheduler\worker_interface.h>
Pascal Palenda's avatar
Pascal Palenda committed
2
3

#include <ITA/simulation_scheduler/audibility_filter/audibility_filter_interface.h>
4
#include <ITA/simulation_scheduler/scheduler_interface.h>
5
#include <ITA/simulation_scheduler/room_acoustics/raven/worker_thread.h>
Pascal Palenda's avatar
Pascal Palenda committed
6

7
8
#include "configuration_keys.h"

Pascal Palenda's avatar
Pascal Palenda committed
9
10
11
12
namespace ITA
{
	namespace simulation_scheduler
	{
Pascal Palenda's avatar
Pascal Palenda committed
13
		// todo This can fail if the name changes .. Fix this/make it bullet proof
14
		std::map<std::string, CWorkerFactory::CreateCallback> CWorkerFactory::m_mWorkers =
15
		{ {room_acoustics::raven::CWorkerThread::getType(), room_acoustics::raven::CWorkerThread::createWorker} };
Pascal Palenda's avatar
Pascal Palenda committed
16

17
18
19
20
		IWorkerInterface::WorkerConfig::WorkerConfig ( ) : sWorkerType ( m_sWorkerType )
		{
			m_sWorkerType = "Unknown";
		}
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

		IWorkerInterface::WorkerConfig::WorkerConfig ( std::string sType ) : sWorkerType ( m_sWorkerType )
		{
			m_sWorkerType = sType;
		}

		IWorkerInterface::WorkerConfig::WorkerConfig ( const WorkerConfig& other ) :
			IConfig ( other ),
			sWorkerType ( m_sWorkerType ),
			m_sWorkerType ( other.m_sWorkerType )
		{ }

		IWorkerInterface::WorkerConfig& IWorkerInterface::WorkerConfig::operator=( const WorkerConfig& other )
		{
			if ( this == &other )
				return *this;
			IConfig::operator =( other );
			m_sWorkerType = other.m_sWorkerType;
			return *this;
		}

		VistaPropertyList IWorkerInterface::WorkerConfig::store ( ) const
		{
			VistaPropertyList oProperties;
			oProperties.SetValue (workerTypeKey, m_sWorkerType );
			return oProperties;
		}

		void IWorkerInterface::WorkerConfig::load ( const VistaPropertyList& oProperties )
		{
			oProperties.GetValue <std::string> ( workerTypeKey, m_sWorkerType );
		}

54
55
56
		IWorkerInterface::IWorkerInterface ( ISchedulerInterface* pParent ) :
			m_pParentScheduler ( pParent )
		{ }
57

58
59
60
61
		void CWorkerFactory::registerWorker ( const std::string& type, CreateCallback createFunction )
		{
			m_mWorkers [type] = createFunction;
		}
Pascal Palenda's avatar
Pascal Palenda committed
62

63
64
65
66
		void CWorkerFactory::unregisterWorker ( const std::string& type )
		{
			m_mWorkers.erase ( type );
		}
Pascal Palenda's avatar
Pascal Palenda committed
67

68
		std::unique_ptr<IWorkerInterface> CWorkerFactory::createWorker ( const std::shared_ptr<IWorkerInterface::WorkerConfig>& pConfig, ISchedulerInterface* pParent )
69
		{
70
			auto it = m_mWorkers.find ( pConfig->sWorkerType );
71
			if ( it != m_mWorkers.end ( ) )
Pascal Palenda's avatar
Pascal Palenda committed
72
			{
73
74
				// call the creation callback to construct this derived type
				return it->second ( pConfig, pParent );
Pascal Palenda's avatar
Pascal Palenda committed
75
			}
76
77
			return nullptr;
		}
Pascal Palenda's avatar
Pascal Palenda committed
78
79
	} // namespace simulation_scheduler
} // namespace ITA