00001 #ifdef TEST 00002 00003 #include "headers.h" 00004 00005 static const string ppqCommandString = "ppq"; 00006 static const string addCommandString = "add"; 00007 static const string removeCommandString = "remove"; 00008 00009 PriorityPacketQueueCommand::PriorityPacketQueueCommand() : Command() { 00010 m_ppq = new PriorityPacketQueue(); 00011 } 00012 00013 00014 void 00015 PriorityPacketQueueCommand::run(std::ostream& s) { 00016 if (m_args[1].empty()) { 00017 getHelp(s); 00018 return; 00019 } 00020 00021 if (m_args[1] == showCommandString) { 00022 m_ppq->print(s); 00023 } 00024 else if (m_args[1] == addCommandString) { 00025 NpPacket* packet; 00026 Node* fromNode = new Node(); 00027 00028 s << "Adding packets to queue...\n"; 00029 for (int i = 0; i < 2; i++) { 00030 packet = new NpPacket(); 00031 packet->setPacketType(NpPacket::Data); 00032 00033 s << "Adding: "; 00034 IpAddress tmp(fromNode->getSocketAddress()->getIpAddress()); 00035 s << tmp; 00036 s << "\n" << *packet << "\n"; 00037 00038 m_ppq->add(fromNode, packet); 00039 00040 packet = new NpPacket(); 00041 packet->setPacketType(NpPacket::Ping); 00042 00043 s << "Adding: "; 00044 tmp.setIpAddress(fromNode->getSocketAddress()->getIpAddress()); 00045 s << tmp; 00046 s << "\n" << *packet << "\n"; 00047 00048 m_ppq->add(fromNode, packet); 00049 } 00050 } 00051 else if (m_args[1] == removeCommandString) { 00052 s << "Removing packets from queue...\n"; 00053 NpPacket* packet; 00054 Node* fromNode; 00055 while (!m_ppq->isEmpty()) { 00056 m_ppq->getNext(&fromNode, &packet); 00057 IpAddress tmp(fromNode->getSocketAddress()->getIpAddress()); 00058 s << tmp; 00059 s << "\n" << *packet << "\n"; 00060 } 00061 } 00062 } 00063 00064 00065 string 00066 PriorityPacketQueueCommand::getCommandString() { 00067 return ppqCommandString; 00068 } 00069 00070 00071 void 00072 PriorityPacketQueueCommand::getHtmlInterface(std::ostream& s) { 00073 s << "<h2>Priority Packet Queue</h2>"; 00074 beginUl(s); 00075 generateHtmlSubcmd(s, showCommandString, "show"); 00076 generateHtmlSubcmd(s, addCommandString, "Add packets to queue"); 00077 generateHtmlSubcmd(s, removeCommandString, "Remove packets from Queue"); 00078 endUl(s); 00079 } 00080 00081 #endif 00082