highlighter application  1.1
HCE project utils : highlighter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
CrossThreadBuf.hpp
Go to the documentation of this file.
1 
13 #ifndef CROSS_THREAD_BUF_HPP
14 #define CROSS_THREAD_BUF_HPP
15 
16 #include <Poco/Condition.h>
17 #include <Poco/Mutex.h>
18 #include <Poco/Random.h>
19 #include <Poco/ScopedLock.h>
20 #include <Poco/SharedPtr.h>
21 #include <Poco/Timestamp.h>
22 #include <iostream>
23 #include <vector>
24 
25 #include <msgpack.hpp>
26 
27 #include "InDataStruct.hpp"
28 
29 #define MICRO_SEC_MULTIPLIER 1000
30 
32 {
33  public:
34  class ResElement
35  {
36  private:
37  std::string inData;
38  std::string outData;
39  unsigned int highlightCounter;
40  unsigned long long id;
41  unsigned long long resCrc;
42  msgpack::sbuffer msgPackBuf;
43  public:
44  ResElement(const ResElement &element): inData(element.inData), outData(element.outData), highlightCounter(element.highlightCounter), id(element.id), resCrc(element.resCrc), msgPackBuf() {}
45  ResElement():inData(""), outData(""), highlightCounter(0), id(0), resCrc(0), msgPackBuf() {}
46  std::string &getInData() {return inData;}
47  std::string &getOutData() {return outData;}
48  unsigned int getHighlightCounter() const {return highlightCounter;}
49  unsigned long long getId() const {return id;}
50  unsigned long long getResCrc() const {return resCrc;}
51  msgpack::sbuffer &getMsgPackBuff() {return msgPackBuf;}
53  {
54  inData = elem.inData;
55  outData = elem.outData;
56  highlightCounter = elem.highlightCounter;
57  id = elem.id;
58  resCrc = elem.resCrc;
59  msgPackBuf.write(elem.msgPackBuf.data(), elem.msgPackBuf.size());
60  return (*this);
61  }
62  void setInData(std::string _inData) {inData = _inData;}
63  void setOutData(std::string _outData) {outData = _outData;}
64  void setId(unsigned long long _id) {id = _id;}
65  void setResCrc(unsigned long long _resCrc) {resCrc = _resCrc;}
66  void setHighlightCounter(unsigned int _highlightCounter) {highlightCounter = _highlightCounter;}
68  };
69  protected:
70  Poco::FastMutex mutex;
71  Poco::FastMutex cvMutex;
72  Poco::Condition cv;
73  Poco::Timestamp tStart;
74  Poco::Timestamp tCurr;
75  std::vector<ResElement> inOutData;
76  unsigned int timeOut;
77  unsigned int processingCount;
78  unsigned int finishedCount;
80  public:
82  void addInOutData(ResElement &inOutDataElem) {inOutData.push_back(inOutDataElem);}
83  unsigned int elemsCount() const {return inOutData.size();}
84  bool isTaskFinished() const {return (finishedCount == inOutData.size());}
85  void setIsSendWordsMapBack(bool _isSendWordsMapBack) {isSendWordsMapBack = _isSendWordsMapBack;}
87  ResElement& getElem(unsigned int index);
88  std::string &getIntData(unsigned int &index, unsigned long long &id, unsigned long long &resCrc);
89  void setOutData(std::string &outData, unsigned int highlightCounter, unsigned int index);
90  void setTimeout(unsigned int _timeOut);
91  unsigned int getRestTimeout();
92  void waitCv();
93  void waitCv(long milliseconds);
94  void signal();
95  void lock() {mutex.lock();}
96  void unlock() {mutex.unlock();}
98 };
99 #endif