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 | pthread_mutex_init(&fMux, NULL);
|
---|
14 | }
|
---|
15 |
|
---|
16 | PendingSDOList::~PendingSDOList()
|
---|
17 | {
|
---|
18 | // pthread_mutex_lock(&fMux);
|
---|
19 |
|
---|
20 | DelAll();
|
---|
21 | delete fFirst;
|
---|
22 |
|
---|
23 | pthread_mutex_destroy(&fMux);
|
---|
24 | }
|
---|
25 |
|
---|
26 | void PendingSDOList::DelAll()
|
---|
27 | {
|
---|
28 | pthread_mutex_lock(&fMux);
|
---|
29 |
|
---|
30 | PendingSDO *prev = fFirst;
|
---|
31 | PendingSDO *sdo;
|
---|
32 |
|
---|
33 | do
|
---|
34 | {
|
---|
35 | sdo = prev->Next;
|
---|
36 | delete prev;
|
---|
37 |
|
---|
38 | } while((prev=sdo));
|
---|
39 |
|
---|
40 | fFirst = new PendingSDO;
|
---|
41 | fLast = fFirst;
|
---|
42 |
|
---|
43 | pthread_mutex_unlock(&fMux);
|
---|
44 | }
|
---|
45 |
|
---|
46 | void PendingSDOList::Add(BYTE_t node, WORD_t idx, BYTE_t subidx)
|
---|
47 | {
|
---|
48 | PendingSDO *sdo = fFirst;
|
---|
49 |
|
---|
50 | pthread_mutex_lock(&fMux);
|
---|
51 | while ((sdo=sdo->Next))
|
---|
52 | if (sdo->Node==node && sdo->Idx==idx && sdo->Subidx==subidx)
|
---|
53 | {
|
---|
54 | cout << "Warning: SDO Node #" << dec << (int)node << ", 0x";
|
---|
55 | cout << hex << idx << "/" << (int)subidx;
|
---|
56 | cout << " still pending." << endl;
|
---|
57 | break;
|
---|
58 | }
|
---|
59 |
|
---|
60 | fLast->Next = new PendingSDO(node, idx, subidx);
|
---|
61 | fLast = fLast->Next;
|
---|
62 | pthread_mutex_unlock(&fMux);
|
---|
63 | }
|
---|
64 |
|
---|
65 | void PendingSDOList::Del(BYTE_t node, WORD_t idx, BYTE_t subidx)
|
---|
66 | {
|
---|
67 | PendingSDO *prev = fFirst;
|
---|
68 | PendingSDO *sdo;
|
---|
69 |
|
---|
70 | pthread_mutex_lock(&fMux);
|
---|
71 | while ((sdo=prev->Next))
|
---|
72 | {
|
---|
73 | if (sdo->Node!=node || sdo->Idx!=idx || sdo->Subidx!=subidx)
|
---|
74 | {
|
---|
75 | prev = sdo;
|
---|
76 | continue;
|
---|
77 | }
|
---|
78 |
|
---|
79 | prev->Next = sdo->Next;
|
---|
80 |
|
---|
81 | delete sdo;
|
---|
82 |
|
---|
83 | if (!prev->Next)
|
---|
84 | fLast = prev;
|
---|
85 |
|
---|
86 | break;
|
---|
87 | }
|
---|
88 | pthread_mutex_unlock(&fMux);
|
---|
89 | }
|
---|
90 |
|
---|
91 | int PendingSDOList::IsPending() const
|
---|
92 | {
|
---|
93 | return (int)fFirst->Next;
|
---|
94 | }
|
---|
95 |
|
---|
96 | int PendingSDOList::IsPending(BYTE_t node)
|
---|
97 | {
|
---|
98 | int rc = FALSE;
|
---|
99 | PendingSDO *sdo = fFirst;
|
---|
100 |
|
---|
101 | pthread_mutex_lock(&fMux);
|
---|
102 | while ((sdo=sdo->Next))
|
---|
103 | if (sdo->Node==node)
|
---|
104 | {
|
---|
105 | rc = TRUE;
|
---|
106 | break;
|
---|
107 | }
|
---|
108 | pthread_mutex_unlock(&fMux);
|
---|
109 |
|
---|
110 | return rc;
|
---|
111 | }
|
---|
112 |
|
---|
113 | int PendingSDOList::IsPending(BYTE_t node, WORD_t idx, BYTE_t subidx)
|
---|
114 | {
|
---|
115 | int rc = FALSE;
|
---|
116 | PendingSDO *sdo = fFirst;
|
---|
117 |
|
---|
118 | pthread_mutex_lock(&fMux);
|
---|
119 | while ((sdo=sdo->Next))
|
---|
120 | if (sdo->Node==node && sdo->Idx==idx && sdo->Subidx==subidx)
|
---|
121 | {
|
---|
122 | rc = TRUE;
|
---|
123 | break;
|
---|
124 | }
|
---|
125 | pthread_mutex_unlock(&fMux);
|
---|
126 |
|
---|
127 | return rc;
|
---|
128 | }
|
---|