Newer
Older
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
// The Fraunhofer HHI Unity Framework
// ___________ .__ _____ ___ ___ ___ ___ .___
// \_ _____/___________ __ __ ____ | |__ _____/ ____\___________ / | \ / | \| |
// | __) \_ __ \__ \ | | \/ \| | \ / _ \ __\/ __ \_ __ \ / ~ \/ ~ \ |
// | \ | | \// __ \| | / | \ Y ( <_> ) | \ ___/| | \/ \ Y /\ Y / |
// \___ / |__| (____ /____/|___| /___| /\____/|__| \___ >__| \___|_ / \___|_ /|___|
// \/ \/ \/ \/ \/ \/ \/
// (C) Fraunhofer HHI, 2024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
namespace ETSI.ARF.OpenAPI.WorldAnalysis
{
public class CancelToken
{
protected CancellationTokenSource tokenSource;
protected CancellationToken ct;
public CancellationToken cancellationToken { get => ct; }
public void Cancel()
{
tokenSource.Cancel();
}
}
public class ResponseObject<T> : CancelToken
{
// Management stuffs
static int ID = 0;
public int transactionId = 0;
public string message = ""; // custom message, type of data...
// Time monitoring
public TimeSpan DeltaTime { get => responseTime - requestTime; }
public DateTime requestTime;
public DateTime responseTime;
// Incoming data
public T result;
public int payload; // size of data
//public string result = ""; // text result
//public object data = null; // custom result
// Callback
public Action<ResponseObject<T>> callback;
public ResponseObject(string msg, Action<ResponseObject<T>> func = null)
{
requestTime = DateTime.Now;
message = msg;
callback = func;
transactionId = ++ID;
tokenSource = new CancellationTokenSource();
ct = tokenSource.Token;
}
}
}