#include <thread>
#include <iostream>
#include <typeinfo>
class Polymorphic {virtual void member(){}};
class TestAction;
static void SecondThread(TestAction *);
public:
TestAction(std::weak_ptr<drama::Task> theTask) : TAction(theTask) {}
~TestAction() {}
private:
#if 0
fprintf(stderr,"threadbasic::ActionThread() invoked, arg=%d, addr=%p\n",
(int)SdsIdType(obeyArg), (void *)(&obeyArg));
#endif
if (obeyArg)
{
std::string MyArgument;
obeyArg.
Get(
"Argument1", &MyArgument);
MessageUser(std::string(
"Obey Argument is:") + MyArgument);
}
else
{
}
std::thread childThread(SecondThread, this);
{
if (*Arg)
{
std::string MyArgument;
Arg->Get("Argument1", &MyArgument);
}
}
else
{
}
MessageUser(
"First thread Waiting to join child thread");
childThread.join();
outArg.Put("Argument1", "Completion Argument.");
#if 0
fprintf(stderr,"threadbasic::ActionThread() exiting\n");
#endif
}
};
static void SecondThread(TestAction *action)
{
action->MessageUser("Second thread running, sending trigger");
trigArg.Put("Argument1", "Hi there:");
trigArg.Put("Argument2", "Trigger from second thread");
action->SendTrigger(trigArg);
if (action->WaitForKickTimeoutIn(10, &Arg))
{
action->MessageUser("Second thread, received kick.");
if (*Arg)
{
std::string MyArgument;
Arg->Get("Argument1", &MyArgument);
action->MessageUser(MyArgument);
}
}
else
{
action->MessageUser("Second thread, wait for kick time out.");
}
}
private:
TestAction TestActionObj;
public:
ThreadBasic() :
drama::Task(
"THREADBASIC"), TestActionObj(TaskPtr()) {
}
~ThreadBasic() {
}
};
int main()
{
try
{
ThreadBasic task;
task.RunDrama();
}
{
}
catch (std::exception &e)
{
std::cerr << "std::exception thrown by task.RunDrama"
<< e.what()
<< std::endl;
exit(1);
}
return 0;
}