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

NodeCommand.cpp

Go to the documentation of this file.
00001 #ifdef TEST
00002 
00003 #include "headers.h"
00004 
00005 const static string nodeCommandString = "node";
00006 const static string setIpAddrCommandString = "setIpAddr";
00007 const static string setPortCommandString = "setPort";
00008 const static string readCommandString = "read";
00009 const static string writeCommandString = "write";
00010 
00011 NodeCommand::NodeCommand() : Command() {
00012     m_node = new Node();
00013 }
00014 
00015 
00016 void
00017 NodeCommand::getHtmlInterface(std::ostream& s) {
00018     s << "<h2>Node</h2>";
00019     beginUl(s);
00020     generateHtmlSubcmd(s, showCommandString, "show");
00021     generateHtmlSubcmdArg1(s, readCommandString, "Read node config from file: ", "Read");
00022     generateHtmlSubcmdArg1(s, writeCommandString, "Write node config to file: ", "Write");
00023     generateHtmlSubcmdArg1(s, setIpAddrCommandString, "Set node IP addr: ", "Set");
00024     generateHtmlSubcmdArg1(s, setPortCommandString, "Set node port: ", "Set");
00025     endUl(s);
00026 }
00027 
00028 
00029 void
00030 NodeCommand::run(std::ostream& s) {
00031     ofstream cfgFile; 
00032     ifstream sameFile;
00033 
00034     if (m_args[1] == showCommandString) {
00035         s << *m_node;
00036     }
00037     else if (m_args[1] == readCommandString) {
00038         sameFile.open(m_args[2].c_str());
00039         sameFile >> *m_node;
00040         s << "Read node:" << "\n";
00041         s << *m_node;
00042     }
00043     else if (m_args[1] == writeCommandString) {
00044         cfgFile.open(m_args[2].c_str());
00045         cfgFile << *m_node;
00046         cfgFile.close();
00047         s << "wrote node: "<< "\n" << *m_node;
00048     }
00049     else if (m_args[1] == setIpAddrCommandString) {
00050       IpAddress ip(m_args[2]);
00051       unsigned short port = m_node->getSocketAddress()->getPort();
00052       SocketAddress socketAddress(ip, port);
00053       m_node->setSocketAddress(&socketAddress);
00054     }
00055     else if (m_args[1] == setPortCommandString) {
00056         SocketAddress socketAddress = *m_node->getSocketAddress();
00057         socketAddress.setPort(m_args[2]);
00058         m_node->setSocketAddress(&socketAddress);
00059     }
00060 }
00061 
00062 
00063 string
00064 NodeCommand::getCommandString() {
00065     return nodeCommandString;
00066 }
00067 
00068 #endif
00069 

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