Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/tntnet/framework/common/tnt/tntnet.h

00001 /*
00002  * Copyright (C) 2003-2007 Tommi Maekitalo
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 
00029 
00030 #ifndef TNT_TNTNET_H
00031 #define TNT_TNTNET_H
00032 
00033 #include <tnt/job.h>
00034 #include <tnt/poller.h>
00035 #include <tnt/dispatcher.h>
00036 #include <tnt/maptarget.h>
00037 #include <tnt/scopemanager.h>
00038 #include <cxxtools/condition.h>
00039 #include <cxxtools/mutex.h>
00040 #include <set>
00041 #include <fstream>
00042 
00043 namespace tnt
00044 {
00045   class ListenerBase;
00046   class Tntconfig;
00047 
00061   class Tntnet
00062   {
00063       friend class Worker;
00064 
00065       unsigned minthreads;
00066       unsigned maxthreads;
00067       unsigned long threadstartdelay;
00068       unsigned timersleep;
00069 
00070       Jobqueue queue;
00071 
00072       static bool stop;
00073       typedef std::set<ListenerBase*> listeners_type;
00074       listeners_type listeners;
00075       static listeners_type allListeners;
00076 
00077       cxxtools::AttachedThread pollerthread;
00078       Poller poller;
00079       Dispatcher dispatcher;
00080 
00081       ScopeManager scopemanager;
00082       std::string appname;
00083 
00084       std::ofstream accessLog;
00085       cxxtools::Mutex accessLogMutex;
00086 
00087       // noncopyable
00088       Tntnet(const Tntnet&);
00089       Tntnet& operator= (const Tntnet&);
00090 
00091       void timerTask();
00092 
00093       static cxxtools::Condition timerStopCondition;
00094       static cxxtools::Mutex timeStopMutex;
00095 
00096     public:
00098       Tntnet();
00099 
00101       void init(const Tntconfig& config);
00105       void listen(const std::string& ipaddr, unsigned short int port);
00109       void sslListen(const std::string& certificateFile, const std::string& keyFile, const std::string& ipaddr, unsigned short int port);
00115       void run();
00116 
00118       static void shutdown();
00120       static bool shouldStop()   { return stop; }
00121 
00123       Jobqueue&   getQueue()                  { return queue; }
00125       Poller&     getPoller()                 { return poller; }
00127       const Dispatcher& getDispatcher() const { return dispatcher; }
00129       ScopeManager& getScopemanager()         { return scopemanager; }
00130 
00132       unsigned getMinThreads() const          { return minthreads; }
00134       void setMinThreads(unsigned n);
00135 
00137       unsigned getMaxThreads() const          { return maxthreads; }
00139       void setMaxThreads(unsigned n)          { maxthreads = n; }
00140 
00142       unsigned getTimersleep() const          { return timersleep; }
00144       void setTimersleep(unsigned sec)        { timersleep = sec; }
00145 
00147       unsigned getThreadStartDelay() const    { return threadstartdelay; }
00149       void setThreadStartDelay(unsigned sec)  { threadstartdelay = sec; }
00150 
00152       unsigned getQueueSize() const           { return queue.getCapacity(); }
00154       void setQueueSize(unsigned n)           { queue.setCapacity(n); }
00155 
00159       Maptarget& mapUrl(const std::string& url, const std::string& ci)
00160         { return dispatcher.addUrlMapEntry(std::string(), url, Maptarget(ci)); }
00161       void mapUrl(const std::string& url, const std::string& pathinfo, const std::string& ci_)
00162       {
00163         Maptarget ci(ci_);
00164         ci.setPathInfo(pathinfo);
00165         dispatcher.addUrlMapEntry(std::string(), url, ci);
00166       }
00167       Maptarget& mapUrl(const std::string& url, const Maptarget& ci)
00168         { return dispatcher.addUrlMapEntry(std::string(), url, ci); }
00169       Maptarget& vMapUrl(const std::string& vhost, const std::string& url, const Maptarget& ci)
00170         { return dispatcher.addUrlMapEntry(vhost, url, ci); }
00171 
00185       void setAppName(const std::string& appname_)
00186         { appname = appname_; }
00187       const std::string& getAppName() const
00188         { return appname; }
00189 
00190       void setAccessLog(const std::string& accesslog)
00191       { accessLog.open(accesslog.c_str(), std::ios::out | std::ios::app); }
00192   };
00193 
00194 }
00195 
00196 #endif // TNT_TNTNET_H
00197 
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6