[4de1c7]: / app / resources / LeapSDK / v3_python27 / src / PendingImages.cs

Download this file

76 lines (68 with data), 2.3 kB

 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
/******************************************************************************\
* Copyright (C) 2012-2016 Leap Motion, Inc. All rights reserved. *
* Leap Motion proprietary and confidential. Not for distribution. *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
\******************************************************************************/
using System;
using System.Collections.Generic;
using Leap;
namespace LeapInternal
{
public class PendingImages
{
List<ImageFuture> _pending = new List<ImageFuture>(20);
UInt32 _pendingTimeLimit = 90000; // microseconds
private object _locker = new object();
public UInt32 pendingTimeLimit { get{ return _pendingTimeLimit; }
set{ _pendingTimeLimit = value; } }
public void Add(ImageFuture pendingImage)
{
lock(_locker){
_pending.Add(pendingImage);
}
}
public ImageFuture FindAndRemove(LEAP_IMAGE_FRAME_REQUEST_TOKEN token)
{
lock(_locker){
for (int i = 0; i < _pending.Count; i++) {
ImageFuture ir = _pending[i];
if (ir.Token.requestID == token.requestID) {
_pending.RemoveAt(i);
return ir;
}
}
}
return null;
}
public int purgeOld(IntPtr connection)
{
Int64 now = LeapC.GetNow();
int purgeCount = 0;
lock(_locker){
for (int i = _pending.Count - 1; i >= 0; i--) {
ImageFuture ir = _pending[i];
if ((now - ir.Timestamp) > pendingTimeLimit){
_pending.RemoveAt(i);
LeapC.CancelImageFrameRequest(connection, ir.Token);
purgeCount++;
}
}
}
return purgeCount;
}
public int purgeAll(IntPtr connection)
{
int purgeCount = 0;
lock(_locker){
purgeCount = _pending.Count;
for (int i = 0; i < _pending.Count; i++) {
LeapC.CancelImageFrameRequest(connection, _pending[i].Token);
}
_pending.Clear();
}
return purgeCount;
}
}
}