Line | |
---|
1 | #include "sdolist.h"
|
---|
2 |
|
---|
3 | #include <iostream.h>
|
---|
4 |
|
---|
5 | ClassImp(PendingSDO);
|
---|
6 | ClassImp(PendingSDOList);
|
---|
7 |
|
---|
8 | PendingSDOList::PendingSDOList()
|
---|
9 | {
|
---|
10 | fFirst = new PendingSDO;
|
---|
11 | fLast = fFirst;
|
---|
12 | }
|
---|
13 |
|
---|
14 | PendingSDOList::~PendingSDOList()
|
---|
15 | {
|
---|
16 | DelAll();
|
---|
17 | delete fFirst;
|
---|
18 | }
|
---|
19 |
|
---|
20 | void PendingSDOList::DelAll()
|
---|
21 | {
|
---|
22 | fMux.Lock();
|
---|
23 |
|
---|
24 | PendingSDO *prev = fFirst;
|
---|
25 | PendingSDO *sdo;
|
---|
26 |
|
---|
27 | do
|
---|
28 | {
|
---|
29 | sdo = prev->Next;
|
---|
30 | delete prev;
|
---|
31 |
|
---|
32 | } while((prev=sdo));
|
---|
33 |
|
---|
34 | fFirst = new PendingSDO;
|
---|
35 | fLast = fFirst;
|
---|
36 |
|
---|
37 | fMux.UnLock();
|
---|
38 | }
|
---|
39 |
|
---|
40 | void PendingSDOList::Add(BYTE_t node, WORD_t idx, BYTE_t subidx)
|
---|
41 | {
|
---|
42 | PendingSDO *sdo = fFirst;
|
---|
43 |
|
---|
44 | fMux.Lock();
|
---|
45 | while ((sdo=sdo->Next))
|
---|
46 | if (sdo->Node==node && sdo->Idx==idx && sdo->Subidx==subidx)
|
---|
47 | {
|
---|
48 | cout << "Warning: SDO Node #" << dec << (int)node << ", 0x";
|
---|
49 | cout << hex << idx << "/" << (int)subidx;
|
---|
50 | cout << " still pending." << endl;
|
---|
51 | break;
|
---|
52 | }
|
---|
53 |
|
---|
54 | fLast->Next = new PendingSDO(node, idx, subidx);
|
---|
55 | fLast = fLast->Next;
|
---|
56 | fMux.UnLock();
|
---|
57 | }
|
---|
58 |
|
---|
59 | void PendingSDOList::Del(BYTE_t node, WORD_t idx, BYTE_t subidx)
|
---|
60 | {
|
---|
61 | PendingSDO *prev = fFirst;
|
---|
62 | PendingSDO *sdo;
|
---|
63 |
|
---|
64 | fMux.Lock();
|
---|
65 | while ((sdo=prev->Next))
|
---|
66 | {
|
---|
67 | if (sdo->Node!=node || sdo->Idx!=idx || sdo->Subidx!=subidx)
|
---|
68 | {
|
---|
69 | prev = sdo;
|
---|
70 | continue;
|
---|
71 | }
|
---|
72 |
|
---|
73 | prev->Next = sdo->Next;
|
---|
74 |
|
---|
75 | delete sdo;
|
---|
76 |
|
---|
77 | if (!prev->Next)
|
---|
78 | fLast = prev;
|
---|
79 |
|
---|
80 | break;
|
---|
81 | }
|
---|
82 | fMux.UnLock();
|
---|
83 | }
|
---|
84 |
|
---|
85 | int PendingSDOList::IsPending() const
|
---|
86 | {
|
---|
87 | return (int)fFirst->Next;
|
---|
88 | }
|
---|
89 |
|
---|
90 | int PendingSDOList::IsPending(BYTE_t node)
|
---|
91 | {
|
---|
92 | int rc = FALSE;
|
---|
93 | PendingSDO *sdo = fFirst;
|
---|
94 |
|
---|
95 | fMux.Lock();
|
---|
96 | while ((sdo=sdo->Next))
|
---|
97 | if (sdo->Node==node)
|
---|
98 | {
|
---|
99 | rc = TRUE;
|
---|
100 | break;
|
---|
101 | }
|
---|
102 | fMux.UnLock();
|
---|
103 |
|
---|
104 | return rc;
|
---|
105 | }
|
---|
106 |
|
---|
107 | int PendingSDOList::IsPending(BYTE_t node, WORD_t idx, BYTE_t subidx)
|
---|
108 | {
|
---|
109 | int rc = FALSE;
|
---|
110 | PendingSDO *sdo = fFirst;
|
---|
111 |
|
---|
112 | fMux.Lock();
|
---|
113 | while ((sdo=sdo->Next))
|
---|
114 | if (sdo->Node==node && sdo->Idx==idx && sdo->Subidx==subidx)
|
---|
115 | {
|
---|
116 | rc = TRUE;
|
---|
117 | break;
|
---|
118 | }
|
---|
119 | fMux.UnLock();
|
---|
120 |
|
---|
121 | return rc;
|
---|
122 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.