-
Notifications
You must be signed in to change notification settings - Fork 11
/
console_input_buffer.cc
79 lines (64 loc) · 2.24 KB
/
console_input_buffer.cc
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
//---------------------------------------------------------------------------
#include "console_input_buffer.h"
#include "console.h"
#include <string.h>
//---------------------------------------------------------------------------
ConsoleInputBuffer::ConsoleInputBufferData ConsoleInputBuffer::instance;
//---------------------------------------------------------------------------
inline QueueEntry<ConsoleInputBuffer::EntryData> *
ConsoleInputBuffer::ConsoleInputBufferData::CreateEntry(
const void *data, size_t length, ConnectionId connectionId,
uint16_t connectionHandle) {
QueueEntry<EntryData> *entry = new (length) QueueEntry<EntryData>;
entry->data.connectionId = connectionId;
entry->data.connectionHandle = connectionHandle;
entry->data.length = length;
entry->next = nullptr;
memcpy(entry->data.data, data, length);
return entry;
}
//---------------------------------------------------------------------------
void ConsoleInputBuffer::ConsoleInputBufferData::Add(
const uint8_t *data, size_t length, ConnectionId connectionId,
uint16_t connectionHandle) {
AddEntry(CreateEntry(data, length, connectionId, connectionHandle));
}
void ConsoleInputBuffer::ConsoleInputBufferData::Process() {
if (!head) {
return;
}
#if JAVELIN_SPLIT
if (Split::IsSlave() && isConnected) {
// This will be dealt with using UpdateBuffer() instead.
return;
}
#endif
while (head) {
ConsoleWriter::SetConnection(head->data.connectionId,
head->data.connectionHandle);
Console::instance.HandleInput(head->data.data, head->data.length);
RemoveHead();
Console::Flush();
}
ConsoleWriter::SetConnection(ConnectionId::ACTIVE, 0);
}
#if JAVELIN_SPLIT
#if JAVELIN_SPLIT_IS_MASTER
void ConsoleInputBuffer::ConsoleInputBufferData::OnDataReceived(
const void *data, size_t length) {
Add((const uint8_t *)data, length, ConnectionId::USB_PAIR);
}
#else
void ConsoleInputBuffer::ConsoleInputBufferData::UpdateBuffer(
TxBuffer &buffer) {
while (head) {
if (!buffer.Add(SplitHandlerId::CONSOLE, head->data.data,
head->data.length)) {
return;
}
RemoveHead();
}
}
#endif
#endif
//---------------------------------------------------------------------------