summaryrefslogtreecommitdiffhomepage
path: root/Tobii-EyeX/include/eyex-cpp/Snapshot.inl
blob: 553d00e26718964b90b41a1c4e9372ac6e9fdb84 (plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*********************************************************************************************************************
* Copyright 2013-2014 Tobii Technology AB. All rights reserved.
* Snapshot.inl
*********************************************************************************************************************/

#if !defined(__TOBII_TX_CLIENT_CPPBINDINGS_Snapshot__INL__)
#define __TOBII_TX_CLIENT_CPPBINDINGS_Snapshot__INL__

/*********************************************************************************************************************/

TX_NAMESPACE_BEGIN

/*********************************************************************************************************************/

	inline Snapshot::Snapshot(const std::shared_ptr<const Context>& spContext, TX_HANDLE hSnapshot)
	: InteractionObject(spContext, hSnapshot)
{}

/*********************************************************************************************************************/

inline std::shared_ptr<Snapshot> Snapshot::CreateSnapshotForQuery(const std::shared_ptr<Query>& spQuery)
{
	Tx::Utils::ScopedHandle hSnapshot;
	TX_VALIDATE(txCreateSnapshotForQuery(spQuery->GetHandle(), &hSnapshot));

	auto spContext = spQuery->GetContext();
	auto spSnapshot = spContext->CreateObject<Snapshot>(hSnapshot);
	return spSnapshot;
}

/*********************************************************************************************************************/

inline std::shared_ptr<Snapshot> Snapshot::CreateSnapshotWithQueryBounds(const std::shared_ptr<Query>& spQuery)
{
	Tx::Utils::ScopedHandle hSnapshot;
    TX_VALIDATE(txCreateSnapshotWithQueryBounds(spQuery->GetHandle(), &hSnapshot));

	auto spContext = spQuery->GetContext();
	auto spSnapshot = spContext->CreateObject<Snapshot>(hSnapshot);
	return spSnapshot;
}

/*********************************************************************************************************************/

inline std::shared_ptr<Bounds> Snapshot::GetBounds() const
{
	Tx::Utils::ScopedHandle hBounds;
	if (!TX_VALIDATE(txGetSnapshotBounds(_hObject, &hBounds), TX_RESULT_NOTFOUND))
		return nullptr;

	auto spBounds = _spContext->CreateObject<Bounds>(hBounds);
	return spBounds;
}

/*********************************************************************************************************************/

inline std::shared_ptr<Bounds> Snapshot::CreateBounds(TX_BOUNDSTYPE boundsType)
{
	Tx::Utils::ScopedHandle hBounds;
	TX_VALIDATE(txCreateSnapshotBounds(_hObject, &hBounds, boundsType));    
	auto spBounds = _spContext->CreateObject<Bounds>(hBounds);
	return spBounds;
}

/*********************************************************************************************************************/

inline void Snapshot::DeleteBounds()
{
	TX_VALIDATE(txDeleteSnapshotBounds(_hObject));
}

/*********************************************************************************************************************/

inline std::vector<std::shared_ptr<Interactor>> Snapshot::GetInteractors() const
{
	std::vector<Tx::Utils::ScopedHandle> interactorHandles;
	TX_VALIDATE(Tx::Utils::GetBufferData(interactorHandles, txGetInteractors, _hObject));

	std::vector<std::shared_ptr<Interactor>> interactors;
	for(auto& hInteractor : interactorHandles)
	{
		auto spInteractor = _spContext->CreateObject<Interactor>(hInteractor);
		interactors.push_back(spInteractor);
	}

	return interactors;
}

/*********************************************************************************************************************/

inline std::shared_ptr<Interactor> Snapshot::CreateInteractor(
	const std::string& interactorId,
	const std::string& parentId,
	const std::string& windowId)
{
	Tx::Utils::ScopedHandle hInteractor;
	TX_VALIDATE(txCreateInteractor(_hObject, &hInteractor, interactorId.c_str(), parentId.c_str(), windowId.c_str()));
	auto spInteractor = _spContext->CreateObject<Interactor>(hInteractor);
	return spInteractor;
}

/*********************************************************************************************************************/

inline void Snapshot::RemoveInteractor(const std::string& interactorId)
{
	TX_VALIDATE(txRemoveInteractor(_hObject, interactorId.c_str()));
}

/*********************************************************************************************************************/

inline std::vector<std::string> Snapshot::GetWindowIds()
{
	int windowIdCount = 0;
	TX_VALIDATE(txGetSnapshotWindowIdCount(_hObject, &windowIdCount));

	std::vector<std::string> windowIds;
	for (int i = 0; i < windowIdCount; i++)
	{
		std::string windowId;
		TX_VALIDATE(Tx::Utils::GetString(&windowId, [i, this](TX_CHAR* pBuf, TX_SIZE* pSize) 
		{
			return txGetSnapshotWindowId(_hObject, i, pBuf, pSize);
		}));

		windowIds.push_back(windowId);
	}

	return windowIds;
}

/*********************************************************************************************************************/

inline void Snapshot::AddWindowId(const std::string& windowId)
{
	TX_VALIDATE(txAddSnapshotWindowId(_hObject, windowId.c_str()));
}

/*********************************************************************************************************************/

inline void Snapshot::CommitAsync(AsyncDataHandler fnHandler) const
{    
	auto spThis = shared_from_this();
	auto fnProxy = [&, spThis, fnHandler](TX_CONSTHANDLE hAsyncData) 
	{			
		GetContext()->InvokeAsyncDataHandler(hAsyncData, fnHandler);
	};

	TX_VALIDATE(Tx::CommitSnapshotAsync(_hObject, fnProxy));
}

/*********************************************************************************************************************/

TX_NAMESPACE_END

/*********************************************************************************************************************/

#endif // !defined(__TOBII_TX_CLIENT_CPPBINDINGS_Snapshot__INL__)

/*********************************************************************************************************************/