summaryrefslogtreecommitdiffstats
path: root/Src/devices/deviceManager.h
blob: df076cb9a6f973db738190a19c9cd86af9669f17 (plain) (blame)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef _NULLSOFT_WINAMP_DEVICES_DEVICE_MANAGER_HEADER
#define _NULLSOFT_WINAMP_DEVICES_DEVICE_MANAGER_HEADER

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

#include "./api_devicemanager.h"
#include "./deviceObjectStore.h"
#include "./discoveryMonitor.h"
#include <vector>

class DeviceManager : public api_devicemanager
{

protected:
	DeviceManager();
	~DeviceManager();

public:
	static HRESULT CreateInstance(DeviceManager **instance);

public:
	/* Dispatchable */
	size_t AddRef();
	size_t Release();
	int QueryInterface(GUID interface_guid, void **object);

	/* api_devicemanager */
	size_t TypeRegister(ifc_devicetype **types, size_t count);
	size_t TypeRegisterIndirect(const char **names, size_t count, DeviceTypeCreator callback, void *user);
	HRESULT TypeUnregister(const char *name);
	HRESULT TypeFind(const char *name, ifc_devicetype **type);
	HRESULT TypeEnumerate(ifc_deviceobjectenum **enumerator);

	size_t ConnectionRegister(ifc_deviceconnection **connections, size_t count);
	size_t ConnectionRegisterIndirect(const char **names, size_t count, DeviceConnectionCreator callback, void *user);
	HRESULT ConnectionUnregister(const char *name);
	HRESULT ConnectionFind(const char *name, ifc_deviceconnection **connection);
	HRESULT ConnectionEnumerate(ifc_deviceobjectenum **enumerator);

	size_t CommandRegister(ifc_devicecommand **commands, size_t count);
	size_t CommandRegisterIndirect(const char **names, size_t count, DeviceCommandCreator callback, void *user);
	HRESULT CommandUnregister(const char *name);
	HRESULT CommandFind(const char *name, ifc_devicecommand **command);
	HRESULT CommandEnumerate(ifc_deviceobjectenum **enumerator);

	size_t DeviceRegister(ifc_device **devices, size_t count);
	HRESULT DeviceUnregister(const char *name);
	HRESULT DeviceFind(const char *name, ifc_device **device);
	HRESULT DeviceEnumerate(ifc_deviceobjectenum **enumerator);

	HRESULT IsDiscoveryActive();
	HRESULT BeginDiscovery();
	HRESULT CancelDiscovery();
	HRESULT RegisterProvider(ifc_deviceprovider *provider);
	HRESULT UnregisterProvider(ifc_deviceprovider *provider);
	HRESULT SetProviderActive(ifc_deviceprovider *provider, BOOL activeState);

	HRESULT Advise(ifc_devicemanagerevent *handler);
	HRESULT Unadvise(ifc_devicemanagerevent *handler);

	HRESULT CreateDeviceEventManager(ifc_deviceeventmanager **eventManager);
	HRESULT CreateSupportedCommandStore(ifc_devicesupportedcommandstore **store);
	HRESULT CreateSupportedCommandEnum(ifc_devicesupportedcommand **commands, size_t count, ifc_devicesupportedcommandenum **enumerator);
	HRESULT CreateIconStore(ifc_deviceiconstore **store);
	HRESULT CreateType(const char *name, ifc_devicetype **type);
	HRESULT CreateCommand(const char *name, ifc_devicecommand **command);
	HRESULT CreateConnection(const char *name, ifc_deviceconnection **connection);

protected:
	void EventTypeAdded(ifc_devicetype *type);
	void EventTypeRemoved(ifc_devicetype *type);
	void EventConnectionAdded(ifc_deviceconnection *connection);
	void EventConnectionRemoved(ifc_deviceconnection *connection);
	void EventCommandAdded(ifc_devicecommand *command);
	void EventCommandRemoved(ifc_devicecommand *command);
	void EventDeviceAdded(ifc_device *device);
	void EventDeviceRemoved(ifc_device *device);
	void EventDiscoveryStarted();
	void EventDiscoveryFinished();

protected:
	static void ObjectAddedCallback(DeviceObjectStore *store, ifc_deviceobject *object, void *userData);
	static void ObjectRemovedCallback(DeviceObjectStore *store, ifc_deviceobject *object, void *userData);

protected:
	typedef std::vector<ifc_devicemanagerevent*> EventList;
	typedef std::vector<ifc_deviceprovider*> ProviderList;

protected:
	size_t ref;
	
	DeviceObjectStore typeStore;
	DeviceObjectStore connectionStore;
	DeviceObjectStore commandStore;
	DeviceObjectStore deviceStore;

	CRITICAL_SECTION eventLock;
	EventList eventList;

	CRITICAL_SECTION providerLock;
	ProviderList providerList;

	DiscoveryMonitor discoveryMonitor;

protected:
	RECVS_DISPATCH;
};

#endif // _NULLSOFT_WINAMP_DEVICES_DEVICE_MANAGER_HEADER