-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOLCB_Link.cpp
78 lines (70 loc) · 2.15 KB
/
OLCB_Link.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
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
#include "OLCB_Link.h"
void OLCB_Link::update(void)//called repeatedly
{
//call all our handler's update functions
//Updated to only call one at a time, to permit faster message handling.
static OLCB_Virtual_Node *iter = _handlers;
//while(iter)
//{
iter->update();
iter = iter->next;
if(!iter) //reached end of list
iter = _handlers; //return to beginning for next time.
//}
}
void OLCB_Link::addVNode(OLCB_Virtual_Node *vnode)
{
//Serial.println("link adding vnode");
//Serial.println((int)_handlers, HEX);
vnode->next = _handlers;
_handlers = vnode;
//Serial.println((int)_handlers, HEX);
//Serial.println((int)(_handlers->next), HEX);
}
void OLCB_Link::removeVNode(OLCB_Virtual_Node *vnode)
{
// //Serial.println("Removing Handler ");
if(!_handlers) //nothing to remove!
return;
// //Serial.println((uint16_t)handler, HEX);
// //Serial.println("====");
OLCB_Virtual_Node *iter = _handlers;
// while(iter != NULL)
// {
// //Serial.println((uint16_t)iter, HEX);
// iter = iter->next;
// }
// //Serial.println("====");
//Looking for the handler that comes before handler.
// iter = _handlers;
if(iter == vnode)
{
// //Serial.println("The first item is the one to remove!");
_handlers = vnode->next;
vnode->next = NULL;
}
else
{
while(iter->next != NULL)
{
if(iter->next == vnode)
{
// //Serial.print("Found the one before: ");
// //Serial.println((uint16_t)iter, HEX);
//remove it from the list
iter->next = vnode->next;
vnode->next = NULL;
break;
}
iter = iter->next;
}
}
// //Serial.println("==*==");
// iter = _handlers;
// while(iter != NULL)
// {
// //Serial.println((uint16_t)iter, HEX);
// iter = iter->next;
// }
// //Serial.println("==*==");
}