MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LogHandlerList.cpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "LogHandlerList.hpp"
19 
20 #include <LogHandler.hpp>
21 
22 //
23 // PUBLIC
24 //
25 
27  m_size(0),
28  m_pHeadNode(NULL),
29  m_pTailNode(NULL),
30  m_pCurrNode(NULL)
31 {
32 }
33 
35 {
36  removeAll();
37 }
38 
39 bool
41 {
42  LogHandlerNode* pNode = new LogHandlerNode();
43  if (!pNode)
44  return false;
45 
46  if (m_pHeadNode == NULL)
47  {
48  m_pHeadNode = pNode;
49  pNode->pPrev = NULL;
50  }
51  else
52  {
53  m_pTailNode->pNext = pNode;
54  pNode->pPrev = m_pTailNode;
55  }
56  m_pTailNode = pNode;
57  pNode->pNext = NULL;
58  pNode->pHandler = pNewHandler;
59 
60  m_size++;
61 
62  return true;
63 }
64 
65 bool
67 {
68  LogHandlerNode* pNode = m_pHeadNode;
69  bool removed = false;
70  do
71  {
72  if (pNode->pHandler == pRemoveHandler)
73  {
74  removeNode(pNode);
75  removed = true;
76  break;
77  }
78  } while ( (pNode = next(pNode)) != NULL);
79 
80  return removed;
81 }
82 
83 void
85 {
86  while (m_pHeadNode != NULL)
87  {
88  removeNode(m_pHeadNode);
89  }
90 }
91 
92 LogHandler*
94 {
95  LogHandler* pHandler = NULL;
96  if (m_pCurrNode == NULL)
97  {
98  m_pCurrNode = m_pHeadNode;
99  if (m_pCurrNode != NULL)
100  {
101  pHandler = m_pCurrNode->pHandler;
102  }
103  }
104  else
105  {
106  m_pCurrNode = next(m_pCurrNode); // Next node
107  if (m_pCurrNode != NULL)
108  {
109  pHandler = m_pCurrNode->pHandler;
110  }
111  }
112 
113  return pHandler;
114 }
115 
116 int
118 {
119  return m_size;
120 }
121 
122 //
123 // PRIVATE
124 //
125 
126 LogHandlerList::LogHandlerNode*
127 LogHandlerList::next(LogHandlerNode* pNode)
128 {
129  LogHandlerNode* pCurr = pNode;
130  if (pNode->pNext != NULL)
131  {
132  pCurr = pNode->pNext;
133  }
134  else
135  {
136  // Tail
137  pCurr = NULL;
138  }
139  return pCurr;
140 }
141 
142 LogHandlerList::LogHandlerNode*
143 LogHandlerList::prev(LogHandlerNode* pNode)
144 {
145  LogHandlerNode* pCurr = pNode;
146  if (pNode->pPrev != NULL) // head
147  {
148  pCurr = pNode->pPrev;
149  }
150  else
151  {
152  // Head
153  pCurr = NULL;
154  }
155 
156  return pCurr;
157 }
158 
159 void
160 LogHandlerList::removeNode(LogHandlerNode* pNode)
161 {
162  if (pNode->pPrev == NULL) // If head
163  {
164  m_pHeadNode = pNode->pNext;
165  }
166  else
167  {
168  pNode->pPrev->pNext = pNode->pNext;
169  }
170 
171  if (pNode->pNext == NULL) // if tail
172  {
173  m_pTailNode = pNode->pPrev;
174  }
175  else
176  {
177  pNode->pNext->pPrev = pNode->pPrev;
178  }
179 
180  pNode->pNext = NULL;
181  pNode->pPrev = NULL;
182  delete pNode->pHandler; // Delete log handler
183  delete pNode;
184 
185  m_size--;
186 }