Textractor_test/GUI/host/textthread.h

45 lines
974 B
C
Raw Normal View History

#pragma once
// textthread.h
// 8/23/2013 jichi
// Branch: ITH/TextThread.h, rev 120
2018-08-23 00:24:55 +08:00
#include "common.h"
2018-08-25 00:50:20 +08:00
#include "types.h"
2018-07-19 11:40:44 +08:00
class TextThread
{
2018-08-23 23:53:23 +08:00
typedef std::function<std::wstring(TextThread*, std::wstring)> ThreadOutputCallback;
public:
2018-08-23 23:53:23 +08:00
TextThread(ThreadParam tp, DWORD status);
2018-08-25 00:50:20 +08:00
~TextThread();
2018-08-25 00:50:20 +08:00
std::wstring GetStore();
void AddText(const BYTE* data, int len);
void AddSentence(std::wstring sentence);
2018-08-22 10:43:30 +08:00
void RegisterOutputCallBack(ThreadOutputCallback cb) { Output = cb; }
const int64_t handle;
2018-09-21 10:32:47 +08:00
const std::wstring name;
const ThreadParam tp;
inline static int FlushDelay = 250; // flush every 250ms by default
2018-09-24 10:29:33 +08:00
inline static int MaxBufferSize = 500;
inline static int ThreadCounter = 0;
2018-09-22 09:27:59 +08:00
private:
2018-08-26 04:02:16 +08:00
void Flush();
2018-08-22 10:43:30 +08:00
std::wstring buffer;
2018-07-20 11:22:55 +08:00
std::wstring storage;
std::recursive_mutex ttMutex;
std::thread flusher = std::thread([] {});
HANDLE cancelFlushEvent = CreateEventW(nullptr, TRUE, TRUE, NULL);
2018-08-24 23:32:10 +08:00
2018-08-22 11:56:16 +08:00
ThreadOutputCallback Output;
2018-07-20 11:22:55 +08:00
DWORD status;
};
// EOF