tobicore  7.0.0
 All Classes Functions Variables Typedefs Enumerator Friends Groups Pages
IDAsClient.cpp
1 /*
2  Copyright (C) 2009-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
3  Michele Tavella <michele.tavella@epfl.ch>
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef IDASCLIENT_CPP
20 #define IDASCLIENT_CPP
21 
22 #include "IDAsClient.hpp"
23 
25 }
26 
28 }
29 
30 void IDAsClient::Enqueue(const IDMessage message, bool updatefidx) {
31  this->_queue.push_back(message);
32  if(updatefidx)
34 }
35 
36 bool IDAsClient::Dequeue(IDMessage* message, const IDFtype type,
37  const IDevent event, const int direction) {
38  if(message == NULL)
39  throw TCException("iD message needs to be allocated",
40  #ifdef _WIN32
41  __FUNCSIG__
42  #else
43  __PRETTY_FUNCTION__
44  #endif
45  );
46  if(direction != IDAsClient::BlockAll && TCBlock::IsSetBlockIdx() == false)
47  throw TCException("Block number must be set for searching Prev/Next",
48  #ifdef _WIN32
49  __FUNCSIG__
50  #else
51  __PRETTY_FUNCTION__
52  #endif
53  );
54 
55  if(this->Size() == 0)
56  return false;
57 
58  int t_blockidx = TCBlock::BlockIdxUnset;
59  IDFtype t_type;
60  IDevent t_event;
61  bool fmatch = false, tmatch = false, ematch = false;
62  for(unsigned int i = 0; i < this->_queue.size(); i++) {
63  t_blockidx = (this->_queue.at(i)).GetBlockIdx();
64  t_type = (this->_queue.at(i)).GetFamilyType();
65  t_event = (this->_queue.at(i)).GetEvent();
66 
67  // Match frame
68  switch(direction) {
70  fmatch = (t_blockidx == TCBlock::GetBlockIdx());
71  break;
73  fmatch = (t_blockidx > TCBlock::GetBlockIdx());
74  break;
76  fmatch = (t_blockidx < TCBlock::GetBlockIdx());
77  break;
78  default:
80  fmatch = true;
81  break;
82  }
83 
84  // Match type
85  switch(type) {
86  case IDMessage::FamilyBiosig:
87  tmatch = (type == t_type);
88  break;
89  default:
90  case IDMessage::FamilyUndef:
91  tmatch = true;
92  break;
93  }
94 
95  // Match event
96  switch(event) {
97  case IDMessage::EventNull:
98  ematch = true;
99  break;
100  default:
101  ematch = (event == t_event);
102  break;
103  }
104 
105  if(tmatch && ematch && fmatch) {
106  message->Copy(&(this->_queue.at(i)));
107  this->_queue.erase(this->_queue.begin() + i);
108  return true;
109  }
110  }
111 
112  return false;
113 }
114 
115 unsigned int IDAsClient::Size(void) const {
116  return this->_queue.size();
117 }
118 
119 unsigned int IDAsClient::Clear(void) {
120  this->_queue.clear();
121  return this->Size();
122 }
123 
124 void IDAsClient::Dump(void) const {
125  for(unsigned int i = 0; i < this->_queue.size(); i++)
126  (this->_queue.at(i)).Dump();
127 }
128 
129 #endif