X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fthreadcontroller.cpp;fp=src%2Fthreadcontroller.cpp;h=8bfb7b59621ac1fe79991803b6ebe1c6c435b934;hb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;hp=0000000000000000000000000000000000000000;hpb=37a8d59548287dcad78ef00e7b18058721eb9935;p=fms.git diff --git a/src/threadcontroller.cpp b/src/threadcontroller.cpp new file mode 100644 index 0000000..8bfb7b5 --- /dev/null +++ b/src/threadcontroller.cpp @@ -0,0 +1,132 @@ +#include "../include/threadcontroller.h" +#include "../include/option.h" +#include "../include/freenet/freenetmasterthread.h" +#include "../include/nntp/nntplistener.h" +#include "../include/http/httpthread.h" + +#ifdef XMEM + #include +#endif + +ThreadController::~ThreadController() +{ + ShutdownThreads(); +} + +void ThreadController::ReadConfig() +{ + + std::string tempval=""; + Option::Instance()->Get("StartFreenetUpdater",tempval); + if(tempval=="true") + { + m_startfreenet=true; + } + else + { + m_startfreenet=false; + } + + tempval=""; + Option::Instance()->Get("StartNNTP",tempval); + if(tempval=="true") + { + m_startnntp=true; + } + else + { + m_startnntp=false; + } + + tempval=""; + Option::Instance()->Get("StartHHTP",tempval); + if(tempval=="true") + { + m_starthttp=true; + } + else + { + m_starthttp=false; + } + +} + +void ThreadController::RestartThreads() +{ + ShutdownThreads(); + StartThreads(); +} + +void ThreadController::ShutdownFreenetThread() +{ + if(m_freenetthread) + { + m_freenetthread->Cancel(); + m_freenetthread->Join(); + delete m_freenetthread; + m_freenetthread=NULL; + } +} + +void ThreadController::ShutdownHTTPThread() +{ + if(m_httpthread) + { + m_httpthread->Cancel(); + m_httpthread->Join(); + delete m_httpthread; + m_httpthread=NULL; + } +} + +void ThreadController::ShutdownNNTPThread() +{ + if(m_nntpthread) + { + m_nntpthread->Cancel(); + m_nntpthread->Join(); + delete m_nntpthread; + m_nntpthread=NULL; + } +} + +void ThreadController::ShutdownThreads() +{ + ShutdownFreenetThread(); + ShutdownNNTPThread(); + ShutdownHTTPThread(); +} + +void ThreadController::StartFreenetThread() +{ + m_freenetthread=new PThread::Thread(new FreenetMasterThread()); +} + +void ThreadController::StartHTTPThread() +{ + m_httpthread=new PThread::Thread(new HTTPThread()); +} + +void ThreadController::StartNNTPThread() +{ + m_nntpthread=new PThread::Thread(new NNTPListener()); +} + +void ThreadController::StartThreads() +{ + ReadConfig(); + + if(m_startfreenet) + { + StartFreenetThread(); + } + if(m_startnntp) + { + StartNNTPThread(); + } + if(m_starthttp) + { + StartHTTPThread(); + } +} +