forked from xcore/tool_axe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChanEndpoint.cpp
43 lines (39 loc) · 922 Bytes
/
ChanEndpoint.cpp
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
// Copyright (c) 2011, Richard Osborne, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>
#include "ChanEndpoint.h"
ChanEndpoint::ChanEndpoint() :
junkIncoming(true),
source(0)
{
}
bool ChanEndpoint::claim(ChanEndpoint *newSource, bool &junkPacket)
{
if (junkIncoming) {
junkPacket = true;
return true;
}
// Check if the route is already open.
if (source == newSource) {
return true;
}
// Check if we are already in the middle of a packet.
if (source) {
queue.push(newSource);
return false;
}
// Claim the channel
source = newSource;
return true;
}
void ChanEndpoint::release(ticks_t time)
{
if (queue.empty()) {
source = 0;
return;
}
source = queue.front();
queue.pop();
source->notifyDestClaimed(time);
}