1 #include "../../include/http/httpthread.h"
\r
2 #include "../../include/option.h"
\r
3 #include "../../include/stringfunctions.h"
\r
4 #include "../../include/http/pages/homepage.h"
\r
12 HTTPThread::HTTPThread()
\r
16 std::string portstr;
\r
17 Option::Instance()->Get("HTTPListenPort",portstr);
\r
18 StringFunctions::Convert(portstr,port);
\r
20 m_pagehandlers.push_back(new HomePage());
\r
23 m_ctx=shttpd_init(NULL,"listen_ports",portstr.c_str(),NULL);
\r
24 shttpd_listen(m_ctx,port,false);
\r
26 shttpd_register_uri(m_ctx,"*",HTTPThread::PageCallback,this);
\r
30 HTTPThread::~HTTPThread()
\r
34 for(std::vector<IPageHandler *>::iterator i=m_pagehandlers.begin(); i!=m_pagehandlers.end(); i++)
\r
41 void HTTPThread::PageCallback(shttpd_arg *arg)
\r
44 HTTPThread *thread=(HTTPThread *)arg->user_data;
\r
46 for(std::vector<IPageHandler *>::iterator i=thread->m_pagehandlers.begin(); i!=thread->m_pagehandlers.end(); )
\r
48 if((*i)->Handle(arg)==true)
\r
50 i=thread->m_pagehandlers.end();
\r
60 void HTTPThread::Run()
\r
62 m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread started.");
\r
66 shttpd_poll(m_ctx,1000);
\r
67 }while(!IsCancelled());
\r
69 m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread exiting.");
\r