Skip to content

Commit

Permalink
Receive command from multiple source
Browse files Browse the repository at this point in the history
  • Loading branch information
mhtvsSFrpHdE committed Aug 12, 2022
1 parent 6330f2c commit df211cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
32 changes: 19 additions & 13 deletions qpp/prefetch/Source/Input/Thread/loop_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@

LoopThread::LoopThread() {}

// Process input text
void LoopThread::receiveText(QString input)
{
// Find command and run command
if (commandMap.contains(input))
{
auto target = commandMap[input];
(*target)();
}
// Command not found
else
{
*StdOut::consoleOutput << "Invalid command"
<< endl;
StdOut::consoleOutput->flush();
}
}

void LoopThread::run()
{
while (true)
{
// Get input
auto input = StdIn::consoleInput->readLine();

// Find command and run command
if (commandMap.contains(input))
{
auto target = commandMap[input];
(*target)();
}
// Command not found
else
{
*StdOut::consoleOutput << "Invalid command"
<< endl;
StdOut::consoleOutput->flush();
}
receiveText(input);
}
}

Expand Down
4 changes: 4 additions & 0 deletions qpp/prefetch/Source/Input/Thread/loop_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class LoopThread : public QThread

void run() override;

public slots:
// Input from remote
void receiveText(QString input);

private:
// Convert stdin command to function pointer
static QMap<QString, void (*)()> commandMap;
Expand Down

0 comments on commit df211cf

Please sign in to comment.