static const char *rcsId="@(#) $Id$";
static void *use_rcsId = (0 ? (void *)(&use_rcsId) : (void *) &rcsId);
#include <iostream>
#include <chrono>
void MyThread(
drama::Task *task,
unsigned count,
bool regtest)
{
typedef std::chrono::high_resolution_clock::time_point myClock;
try
{
myClock initClock = std::chrono::high_resolution_clock::now();
for (unsigned i = 0; i < count ; ++i)
{
ticker.
Obey(&ufaceHandler,
"TICK");
}
std::chrono::duration<double> duration =
std::chrono::high_resolution_clock::now() - initClock;
ticker.
Obey(&ufaceHandler,
"EXIT");
if (regtest)
{
std::cout << "TOCKER:Completed "
<< count
<< " ticks"
<< std::endl;
}
else
{
std::cout << "TOCKER:Total time for "
<< count
<< " ticks is "
<< std::fixed << std::showpoint
<< std::setw(6)
<< std::setprecision(2)
<< duration.count()
<< "s, Ave Time = "
<< std::setprecision(4)
<< (duration.count()*1000.0/count)
<< "ms"
<< std::endl;
}
}
catch (...)
{
throw;
}
}
private:
public:
Tocker(
unsigned count,
bool regtest) :
drama::Task(
"TOCKER") {
_ufaceThreadFuture = std::async(std::launch::async, MyThread, this, count, regtest);
}
if (_ufaceThreadFuture.wait_for(std::chrono::seconds(seconds)) !=
std::future_status::ready)
{
"UFACE Thread did not complete");
}
_ufaceThreadFuture.get();
}
}
};
int main(int argc, char *argv[])
{
int count = 0;
bool regtest = false;
bool delay_loop_start = false;
if (argc > 1)
{
if (strcmp(argv[1], "-regtest") == 0)
regtest = true;
else
count = atoi(argv[1]);
}
if (count < 0)
{
delay_loop_start = true;
regtest = true;
}
if (count <= 0) count = 100;
try
{
Tocker task(count, regtest);
if (delay_loop_start)
{
fprintf(stderr,"Delaying start of DRAMA loop to check that works\n");
std::this_thread::sleep_for (std::chrono::seconds(1));
}
task.RunDrama();
task.WaitThreadExit(3);
}
{
}
catch (const std::exception &e)
{
std::cerr << "std::exception thrown by task.RunDrama"
<< e.what()
<< std::endl;
exit(1);
}
return 0;
}
virtual int statusAsSysExitCode() const
Return a system exit code based on the DRAMA Status.
Definition exception.hh:428
virtual void Print(FILE *file=stderr, bool include_stacktrace=false) const
Print exception details to a file.
An Exception class for exceptions thrown by DRAMA V2 classes.
Definition exception.hh:168
void Obey(thread::TMessHandler *action, const std::string &name, const sds::Id &argIn=sds::Id::CreateNullItem(), sds::IdPtr *const argOut=nullptr, MessageEventHandler *const eventProcessor=&_simpleEventProcessor)
Sends an obey message to a task and blocks the current thread until the action is complete.
Definition path.hh:1372
void GetPath(thread::TMessHandler *action, thread::TransEvtProcessor *const eventProcessor=&_getPathEventProcessor)
Get a path to a the task.
A Class which provides access to DRAMA's message sending facilities.
Definition path.hh:689
virtual void Add(const std::string &name, MessageHandlerPtr obj, const std::string &descr="")
Add an action to the task.
Definition task.hh:696
std::weak_ptr< Task > TaskPtr()
Returns a weak pointer to the task.
Definition task.hh:975
A class which implements a DRAMA task.
Definition task.hh:441
Constructing an object of this type will block all blockable UNIX signals in the current thread.
Definition thread.hh:586
A class which allows threads running in a User Interface or similar environments to send DRAMA messag...
Definition threaduface.hh:93
DRAMA 2 main include file.
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:93
void SignalDramaToExit(std::weak_ptr< Task > dramaTask, StatusType exitStatus=STATUS__OK)
Signal to DRAMA that this task should exit.
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1322
Request SimpleExitAction(drama::MessageHandler *messageHandler)
A function which implements a simple exit action.
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93