highlighter application  1.1
HCE project utils : highlighter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
CrossThreadBuf.cpp
Go to the documentation of this file.
1 
12 #include <stdexcept>
13 
14 #include "CrossThreadBuf.hpp"
15 
17 {
18  if(index >= inOutData.size())
19  {
20  throw std::out_of_range(">>> CrossThreadBuf::getElem method");
21  }
22  return inOutData[index];
23 }
24 
25 std::string &CrossThreadBuf::getIntData(unsigned int &index, unsigned long long &id, unsigned long long &resCrc)
26 {
27  Poco::ScopedLock<Poco::FastMutex> sLock(mutex);
28  if(processingCount >= inOutData.size())
29  {
30  throw std::out_of_range(">>> CrossThreadBuf::getIntData method");
31  }
32  index = processingCount;
33  id = inOutData[processingCount].getId();
34  resCrc = inOutData[processingCount].getResCrc();
35  return inOutData[processingCount++].getInData();
36 }
37 
38 void CrossThreadBuf::setOutData(std::string &outData, unsigned int highlightCounter, unsigned int index)
39 {
40  Poco::ScopedLock<Poco::FastMutex> sLock(mutex);
41  if(index >= inOutData.size())
42  {
43  throw std::out_of_range(">>> CrossThreadBuf::setOutData method");
44  }
45  inOutData[index].setOutData(outData);
46  inOutData[index].setHighlightCounter(highlightCounter);
47  finishedCount++;
48 }
49 
50 void CrossThreadBuf::setTimeout(unsigned int _timeOut)
51 {
52  tStart.update();
53  timeOut = _timeOut;
54 }
55 
61 {
62  unsigned int ret = 0;
63  Poco::ScopedLock<Poco::FastMutex> sLock(mutex);
64  tCurr.update();
65  Poco::Timestamp::TimeDiff tDiff = tCurr - tStart;
66  if(tDiff < (timeOut * MICRO_SEC_MULTIPLIER))
67  {
68  ret = (timeOut * MICRO_SEC_MULTIPLIER - tDiff)/MICRO_SEC_MULTIPLIER;
69  }
70  return ret;
71 }
72 
74 {
75  cvMutex.lock();
76  cv.wait<Poco::FastMutex>(cvMutex);
77  cvMutex.unlock();
78 }
79 
80 void CrossThreadBuf::waitCv(long milliseconds)
81 {
82  cvMutex.lock();
83  try
84  {
85  cv.wait<Poco::FastMutex>(cvMutex, milliseconds);
86  }
87  catch(Poco::TimeoutException &excp)
88  {
89  }
90  cvMutex.unlock();
91 }
92 
94 {
95  cvMutex.lock();
96  cv.signal();
97  cvMutex.unlock();
98 }