File: ServiceLocator.cpp

package info (click to toggle)
jazz2-native 3.5.0-1
  • links: PTS, VCS
  • area: contrib
  • in suites:
  • size: 16,836 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (66 lines) | stat: -rw-r--r-- 1,581 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "ServiceLocator.h"
#include "../Main.h"

namespace nCine
{
	ServiceLocator& theServiceLocator()
	{
		static ServiceLocator instance;
		return instance;
	}

	ServiceLocator::ServiceLocator()
		: audioDevice_(&nullAudioDevice_), threadPool_(&nullThreadPool_), gfxCapabilities_(&nullGfxCapabilities_)
	{
	}

	void ServiceLocator::RegisterAudioDevice(std::unique_ptr<IAudioDevice> service)
	{
		registeredAudioDevice_ = std::move(service);
		audioDevice_ = registeredAudioDevice_.get();
	}

	void ServiceLocator::UnregisterAudioDevice()
	{
		registeredAudioDevice_ = nullptr;
		audioDevice_ = &nullAudioDevice_;
	}

	void ServiceLocator::RegisterThreadPool(std::unique_ptr<IThreadPool> service)
	{
		registeredThreadPool_ = std::move(service);
		threadPool_ = registeredThreadPool_.get();
	}

	void ServiceLocator::UnregisterThreadPool()
	{
		registeredThreadPool_ = nullptr;
		threadPool_ = &nullThreadPool_;
	}

	void ServiceLocator::RegisterGfxCapabilities(std::unique_ptr<nCine::IGfxCapabilities> service)
	{
		registeredGfxCapabilities_ = std::move(service);
		gfxCapabilities_ = registeredGfxCapabilities_.get();
	}

	void ServiceLocator::UnregisterGfxCapabilities()
	{
		registeredGfxCapabilities_ = nullptr;
		gfxCapabilities_ = &nullGfxCapabilities_;
	}

	void ServiceLocator::UnregisterAll()
	{
		LOGI("Unregistering all services");

		registeredAudioDevice_ = nullptr;
		audioDevice_ = &nullAudioDevice_;

		registeredThreadPool_ = nullptr;
		threadPool_ = &nullThreadPool_;

		registeredGfxCapabilities_ = nullptr;
		gfxCapabilities_ = &nullGfxCapabilities_;
	}
}