AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
dramahello.cpp
/* D R A M A H E L L O
* Module name:
dramahello.cpp
* Function:
DRAMA 2 Hello World.
* Description:
Responds to the following commands
HELLO - Outputs message.
EXIT - Cause this task to exit.
* Language:
C++
* Copyright (c) Australian Astronomical Observatory, 2014.
Not to be used for commercial purposes without permission.
No warranty of any form unless subject to a specific agreement.
* Support: Tony Farrell, AAO
* @(#) $Id$
*/
static const char *rcsId="@(#) $Id$";
static void *use_rcsId = (0 ? (void *)(&use_rcsId) : (void *) &rcsId);
#include "drama.hh"
#include "drama/sds.hh"
#include "drama2_err.h"
class HelloAction : public drama::MessageHandler {
public:
private:
/*
* Send a message to the user. (Method of MessageHandler)
*/
MessageUserF("Hello World - from DRAMA 2, action {0}", GetActionName());
/*
* Access any argument to this action.
* (GetEntry() is a method of MesageHandler.)
*/
if (Arg)
{
/*
* Print the argument.
*/
/*
* If the message is in standard format, the name
* of the first item will be Argument1.
*/
std::string MyArgument;
Arg.Get("Argument1", &MyArgument);
MessageUserF(MyArgument);
/*
* Alternatively,
*/
/*
* And another version
*/
MessageUserF("Argument is \"{0}\"", MyArgument);
}
StatusType status = DRAMA2__TEST;
"Demonstration of error report with format of value {0}", 33);
/*
* Tell DRAMA the action has ended.
*/
}
};
class DramaHello : public drama::Task {
private:
HelloAction HelloActionObj;
public:
DramaHello() : drama::Task("DRAMAHELLO") {
Add("HELLO", drama::MessageHandlerPtr(&HelloActionObj, drama::nodel()));
}
}
};
int main()
{
try
{
// Make this program a DRAMA task named ticker
DramaHello task;
// Process DRAMA messages.
task.RunDrama();
}
catch (const drama::Exception &e)
{
fprintf(stderr,"DRAMA Exception thrown and caught in main\n");
fprintf(stderr,"%s\n", e.toString().c_str());
fprintf(stderr,"DRAMA Status = 0X%lx, %s\n",
static_cast<long int>(e.dramaStatus()),
e.dramaStatusStr().c_str());
exit (e.statusAsSysExitCode());
}
return 0;
}
sds::Id Argument() const
Return any SDS argument to the action entry.
Definition entryinfo.hh:147
virtual int statusAsSysExitCode() const
Return a system exit code based on the DRAMA Status.
Definition exception.hh:446
virtual std::string dramaStatusStr() const
Return the DRAMA Status code converted to a DRAMA.
virtual std::string toString(bool details=false) const
Return the exception string.
virtual StatusType dramaStatus() const
Return the DRAMA Status code associated with the exception.
Definition exception.hh:426
An Exception class for exceptions thrown by DRAMA V2 classes.
Definition exception.hh:183
void MessageUserF(const fmt::format_string< Args... > fmt, Args &&... args)
Use DRAMA to send a message to the user - format using fmt::format.
Definition messagehandler.hh:404
virtual const EntryInfo & GetEntry()
Return the action entry details.
Definition messagehandler.hh:427
virtual Request MessageReceived()=0
Method invoked by DRAMA to handle the message.
virtual const sds::PrintObjectCR & SdsListToUser() const
Get a reference to an SDS printer object which can be used to list an SDS object using MessageUser.
A class which implements a DRAMA Message Handler.
Definition messagehandler.hh:141
Class used by Obey and Kick handlers to indicate rescheduling requirements.
Definition request.hh:78
virtual void Add(const std::string &name, MessageHandlerPtr obj, const std::string &descr="")
Add an action to the task.
Definition task.hh:707
A class which implements a DRAMA task.
Definition task.hh:452
virtual void List() const
List the contents of the structure to standard output.
Definition sds.hh:2266
void Get(const unsigned long length, T *const data, unsigned long *actlen=nullptr, const unsigned long offset=0) const
Get data from an SDS item.
Definition sds.hh:1689
virtual std::string toString(int maxlen=200)
Convert the structure to a string.
Definition sds.hh:3213
A C++ Interface to the handling SDS structures.
Definition sds.hh:428
DRAMA 2 main include file.
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1339
std::shared_ptr< MessageHandler > MessageHandlerPtr
This type is used for passing MessageHandler object addresses around.
Definition messagehandler.hh:96
@ End
Request that the action complete.
void ErsReportF(StatusType *status, const fmt::format_string< Args... > fmt, Args &&... args)
Report a std::string via ERS, format using fmt::format.
Definition drama.hh:141
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:99
DRAMA 2 include file - Sds class definition.
Declare an operator to be used as a deletion operator by std::shared_ptr.
Definition task.hh:120