thread linker doesn't append sentences anymore

This commit is contained in:
Akash Mozumdar 2020-04-25 20:34:53 -06:00
parent 535dac480a
commit 9711ce94c9
4 changed files with 15 additions and 1 deletions

View File

@ -70,6 +70,14 @@ void TextThread::Push(BYTE* data, int length)
}
}
void TextThread::Push(const wchar_t* data)
{
std::scoped_lock lock(bufferMutex);
// not sure if this should filter repetition
lastPushTime = GetTickCount();
buffer += data;
}
void TextThread::Flush()
{
{

View File

@ -19,6 +19,7 @@ public:
void Stop();
void AddSentence(std::wstring sentence);
void Push(BYTE* data, int length);
void Push(const wchar_t* data);
Synchronized<std::wstring> storage;
const int64_t handle;

View File

@ -105,6 +105,10 @@ namespace
std::array<InfoForExtension, 10> GetSentenceInfo(TextThread& thread)
{
void (*AddText)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* text)
{
QMetaObject::invokeMethod(This, [number, text = std::wstring(text)] { if (TextThread* thread = Host::GetThread(number)) thread->Push(text.c_str()); });
};
void (*AddSentence)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* sentence)
{
// pointer from Host::GetThread may not stay valid unless on main thread
@ -121,6 +125,7 @@ namespace
{ "text handle", thread.handle },
{ "text name", (int64_t)thread.name.c_str() },
{ "void (*AddSentence)(int64_t number, const wchar_t* sentence)", (int64_t)AddSentence },
{ "void (*AddText)(int64_t number, const wchar_t* text)", (int64_t)AddText },
{ "DWORD (*GetSelectedProcessId)()", (int64_t)GetSelectedProcessId },
{ nullptr, 0 } // nullptr marks end of info array
} };

View File

@ -62,7 +62,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
int64_t textHandle = sentenceInfo["text number"];
for (auto linkedHandle : linkedTextHandles[textHandle])
((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddSentence)(int64_t number, const wchar_t* sentence)"])(linkedHandle, sentence.c_str());
((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddText)(int64_t number, const wchar_t* text)"])(linkedHandle, sentence.c_str());
return false;
}