Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ThreadMessageQueueCommand.cpp

Go to the documentation of this file.
00001 #ifdef TEST
00002 
00003 #include "headers.h"
00004 
00005 static const string tmqCommandString = "tmq";
00006 static const string constructCommandString = "construct";
00007 static const string destructCommandString = "destruct";
00008 static const string addCommandString = "add";
00009 static const string getNextCommandString = "getNext";
00010 static const string getLengthCommandString = "getLength";
00011 static const string isEmptyCommandString = "isEmpty";
00012 
00013 ThreadMessageQueueCommand::ThreadMessageQueueCommand() {
00014     m_queue = NULL;
00015 }
00016 
00017 
00018 void
00019 ThreadMessageQueueCommand::getHtmlInterface(std::ostream& s) {
00020     s << "<h2>Thread Message Queue</h2>";
00021     beginUl(s);
00022     generateHtmlSubcmd(s, constructCommandString, "construct");
00023     generateHtmlSubcmd(s, destructCommandString, "destruct");
00024     generateHtmlSubcmd(s, showCommandString, "show");
00025     generateHtmlSubcmd(s, addCommandString, "Add an object to the queue");
00026     generateHtmlSubcmd(s, getNextCommandString, "getNext (warning: may block)");
00027     generateHtmlSubcmd(s, getLengthCommandString, "getLength");
00028     generateHtmlSubcmd(s, isEmptyCommandString, "isEmpty");
00029     endUl(s);
00030 }
00031 
00032 
00033 string
00034 ThreadMessageQueueCommand::getCommandString() {
00035     return tmqCommandString;
00036 }
00037 
00038 
00039 void
00040 ThreadMessageQueueCommand::run(std::ostream& s) {
00041     if (m_args[1].empty()) {
00042         getHelp(s);
00043         return;
00044     }
00045 
00046     TRanrotBGenerator randomNumberGenerator;
00047 
00048     if (m_args[1] == constructCommandString) {
00049         m_queue = new ThreadMessageQueue<int>();
00050         s << "Constructed.\n";
00051     }
00052     else if (m_args[2] == destructCommandString) {
00053         delete m_queue;
00054         m_queue = NULL;
00055         s << "Destroyed.\n";
00056     }
00057     else if (m_args[1] == showCommandString) { 
00058         s << "Contents of the queue:\n";
00059         m_queue->print(s);
00060     }
00061     else if(m_args[1] == addCommandString) { 
00062         int* foo = new int(randomNumberGenerator.IRandom(0, 10));
00063         m_queue->add(foo);  
00064         s << "Added " << *foo << " to the queue\n";
00065     }
00066     else if(m_args[1] == getNextCommandString) { 
00067         int* bar = m_queue->getNext();
00068         s << "Got " << *bar << " from the queue.\n";
00069     }
00070     else if(m_args[1] == getLengthCommandString) {
00071         s << "Length = " << m_queue->getLength() << "\n";
00072     }
00073     else if(m_args[1] == isEmptyCommandString) {
00074         s << "isEmpty? = " << m_queue->isEmpty() << "\n";
00075     }
00076     else {
00077         getHelp(s);
00078     }
00079 }
00080 
00081 
00082 void
00083 ThreadMessageQueueCommand::getHelp(std::ostream& s) {
00084 }
00085 
00086 
00087 #endif
00088 

Generated at Thu Jul 11 13:31:52 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001