source: trunk/Cosy/candrv/sdolist.cc@ 12679

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