00001 #ifdef TEST
00002
00003 #include "headers.h"
00004
00005 const static string serviceTableCommandString = "st";
00006 const static string addServiceEntryCommandString = "addService";
00007 const static string removeServiceEntryCommandString = "removeService";
00008
00009 string
00010 ServiceTableCommand::getCommandString() {
00011 return serviceTableCommandString;
00012 }
00013
00014
00015 void
00016 ServiceTableCommand::run(std::ostream& s) {
00017 if (m_args[1].empty()) {
00018 getHelp(s);
00019 return;
00020 }
00021
00022 if (m_args[1] == showCommandString) {
00023 s << *GlobalObjects::instance()->getServiceTable();
00024 }
00025 else if (m_args[1] == addServiceEntryCommandString) {
00026 ServiceEntry* se = new ServiceEntry(GlobalObjects::instance()->getServiceTable());
00027
00028 GlobalObjects::instance()->getServiceTable()->addServiceEntry(se);
00029 s << "Added:\n" << *se << "\n";
00030 }
00031 else if (m_args[1] == removeServiceEntryCommandString) {
00032 if (GlobalObjects::instance()->getServiceTable()->removeServiceEntry(atoi(m_args[2].c_str()))) {
00033 s << "Removal successful\n";
00034 }
00035 else {
00036 s << "removal FAILED\n";
00037 }
00038 s << *(GlobalObjects::instance()->getServiceTable());
00039 }
00040 else {
00041 getHelp(s);
00042 return;
00043 }
00044 }
00045
00046 void
00047 ServiceTableCommand::getHtmlInterface(std::ostream& s) {
00048 s << "<h2>ServiceTable</h2>";
00049 beginUl(s);
00050 generateHtmlSubcmd(s, showCommandString, "show");
00051 generateHtmlSubcmd(s, addServiceEntryCommandString, "Add a service entry");
00052 generateHtmlSubcmdArg1(s, removeServiceEntryCommandString, "Remove service entry: ", "Remove");
00053 endUl(s);
00054 }
00055
00056
00057 void
00058 ServiceTableCommand::getHelp(std::ostream& s) {
00059 s << serviceTableCommandString << "\n"
00060 << " " << showCommandString << "\n";
00061 }
00062
00063 #endif
00064