![]() |
VR-Forces 4.0.4 Class Documentation
|
The MySimCommand is a new class that implements a simulation command that prints a message to the console when executed
/******************************************************************************* ** Copyright (c) 2006 MAK Technologies, Inc. ** All rights reserved. *******************************************************************************/ /******************************************************************************* ** $RCSfile: mySimCommand.h,v $ $Revision: 1.3 $ $State: Exp $ *******************************************************************************/ //\file consoleMessageCommand.h //\brief DtConsoleMessageCommand. #ifndef consoleMessageCommand_h #define consoleMessageCommand_h #include "vrfplan/simCommand.h" #include "vrfutil/rwString.h" #include <vlutil/vlPrint.h> #include "vrftasks/radioMsgTypes.h" const int MySimCommandType = MIN_USER_RADIO_MESSAGE_TYPE + 200; const char MySimCommandTypeString[] = "my-sim-command"; //\brief DtSimCommand which causes a console message to be printed. //This command will simply print a message to the back-end console class MySimCommand : public DtSimCommand { public: //Default constructor MySimCommand(); //Usual constructor MySimCommand(const DtString& writeName, DtReaderWriterRegistry* parentRegistry = NULL); //copy constructor MySimCommand(const DtString & writeName, const MySimCommand& orig, DtReaderWriterRegistry* parentRegistry = NULL); //destructor virtual ~MySimCommand(); //assignment operator MySimCommand& operator=(const MySimCommand& orig); //\return MySimCommandType. int type() const; //\return A new instance of this class, copied from the original. virtual DtSimCommand * clone(const DtString & name, DtReaderWriterRegistry * parentRegistry = 0) const; //Message to print to console virtual DtString messageText() const; virtual void setMessageText(const DtString& text); //Text representation of this command. virtual DtString stringRep() const; //\copydoc DtSimCommand::netRepSize() virtual int netRepSize() const; //\copydoc DtSimCommand::setFromNet() virtual bool setFromNet(const char* contentBuffer, unsigned contentSize); //\copydoc DtSimCommand::setToNet() virtual bool setToNet(); //Returns a new instance of this class. static DtSimCommand* creator(); protected: DtRwString myMessageText; }; #endif
/******************************************************************************* ** Copyright (c) 2006 MAK Technologies, Inc. ** All rights reserved. *******************************************************************************/ /******************************************************************************* ** $RCSfile: mySimCommand.cxx,v $ $Revision: 1.1 $ $State: Exp $ *******************************************************************************/ #include "../addSimCommandSim/mySimCommand.h" #include "vrfutil/bufferSerialize.h" #include "vrftasks/radioMsgTypes.h" using namespace DtBufferSerialize; MySimCommand::MySimCommand() : DtSimCommand(), myMessageText("text", &myRegistry) { } MySimCommand::MySimCommand(const DtString& writeName, DtReaderWriterRegistry* parentRegistry) : DtSimCommand(writeName, parentRegistry), myMessageText("text", &myRegistry) { } MySimCommand::MySimCommand(const DtString & writeName, const MySimCommand& orig, DtReaderWriterRegistry* parentRegistry) : DtSimCommand(writeName, orig, parentRegistry), myMessageText(orig.myMessageText.name(), &myRegistry) { myMessageText = orig.myMessageText; } MySimCommand::~MySimCommand() { } MySimCommand& MySimCommand::operator=(const MySimCommand& orig) { if (this != &orig) { DtSimCommand::operator =(orig); myMessageText = orig.myMessageText; } return *this; } int MySimCommand::type() const { return MySimCommandType; } DtSimCommand * MySimCommand::clone(const DtString & name, DtReaderWriterRegistry * parentRegistry) const { return new MySimCommand(name, *this, parentRegistry); } DtString MySimCommand::messageText() const { return myMessageText; } void MySimCommand::setMessageText(const DtString& text) { myMessageText = text; } DtString MySimCommand::stringRep() const { DtString str; str += "Print Console Message: "; str += myMessageText; return str; } int MySimCommand::netRepSize() const { int size = DtSimCommand::netRepSize(); size += getSize(myMessageText); return size; } bool MySimCommand::setFromNet(const char* contentBuffer, unsigned contentSize) { if (!DtSimCommand::setFromNet(contentBuffer, contentSize)) { return false; } contentBuffer += DtSimCommand::netRepSize(); contentBuffer = decode(myMessageText, contentBuffer); return true; } bool MySimCommand::setToNet() { if (!DtSimCommand::setToNet()) { return false; } char* buffer = netRep(); buffer += DtSimCommand::netRepSize(); buffer = encode(myMessageText, buffer); return true; } DtSimCommand* MySimCommand::creator() { return new MySimCommand(); }