-
Notifications
You must be signed in to change notification settings - Fork 0
/
RequestQueue.cs
94 lines (72 loc) · 2.4 KB
/
RequestQueue.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using DmEnvRpc.V1;
namespace AurelianTactics.BlackBoxRL
{
/// <summary>
/// Handles information from the communication layer
/// Currently takes request info from grpc server and packages it a bit before agentsession grabs it from queue
/// </summary>
//to do
//think if this is really designed properly
//synchronization: locking etc
//how to work better with the WTM
//generalize the RequestQueueObject better for configuring stuff and what not
//once I know more from teh communications layer, expand RQO
//not sure whether i want to push from here to WorldTimeManager or pull from WorldTimeManager
//do I want to do some sort of check so that dm_env_rpc (or whatever teh outer thing) is synced with this?
public class RequestQueue
{
LinkedList<RequestQueueObject> rqoLinkedList;
public RequestQueue()
{
this.rqoLinkedList = new LinkedList<RequestQueueObject>();
}
//then just
public RequestQueueObject GetNextRequest()
{
if (this.rqoLinkedList.Count > 0)
{
var rqo = this.rqoLinkedList.First.Value;
this.rqoLinkedList.RemoveFirst();
return rqo;
}
return null;
}
public void AddRequestQueueObject(EnvironmentRequest ero)
{
var rqo = new RequestQueueObject(ero);
this.rqoLinkedList.AddLast(rqo);
}
public bool IsRequestInQueue()
{
if (this.rqoLinkedList.Count > 0)
return true;
return false;
}
}
public class RequestQueueObject
{
public int requestType;
public Dictionary<string,List<int>> createWorldSettings;
public Dictionary<string, List<int>> unpackedTensorDict;
public RequestQueueObject(EnvironmentRequest ero){
this.requestType = (int)ero.PayloadCase;
unpackedTensorDict = TensorUtilities.UnpackRequestTensor(ero);
}
}
}
// CreateWorldRequest create_world = 1;
// JoinWorldRequest join_world = 2;
// StepRequest step = 3;
// ResetRequest reset = 4;
// ResetWorldRequest reset_world = 5;
// LeaveWorldRequest leave_world = 6;
// DestroyWorldRequest destroy_world = 7;
// // If the environment supports a specialized request not covered above it
// // can be sent this way.
// //
// // Slot 15 is the last slot which can be encoded with one byte. See
// // https://developers.google.com/protocol-buffers/docs/proto3#assigning-field-numbers
// google.protobuf.Any extension = 15;