Wexus2 0.20
wexus2.src/wexus/Site.h
00001 
00002 /*
00003  * Copyright (c) 2011 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_WEXUS_SITE_H__
00009 #define __INCLUDED_WEXUS_SITE_H__
00010 
00011 #include <QString>
00012 
00013 #include <wexus/HTTPHandlerStack.h>
00014 #include <wexus/HTTPServer.h>
00015 #include <wexus/FileHTTPHandler.h>
00016 
00017 namespace wexus
00018 {
00019   class Site;
00020 
00021   class Application; //fwd
00022 }
00023 
00024 /**
00025  * This is the core engine class of wexus.
00026  * A wexus::Site represents 1 or more running wexus::Application 
00027  * instanced groupped with a wexus::HTTPServer.
00028  *
00029  * This will instante certain singltons too, if needed:
00030  * MimeTypes.
00031  *
00032  * @author Aleksander Demko
00033  */ 
00034 class wexus::Site : public wexus::HTTPHandlerStack
00035 {
00036   public:
00037     // exceptions
00038     class error {};
00039   public:
00040     /**
00041      * Creates site instance based on the given siteDir.
00042      * The siteDir can be empty or already populated with a site.
00043      *
00044      * Exceptions are thrown on errors.
00045      *
00046      * You should call start() when you want to start the internal httpserver.
00047      *
00048      * @author Aleksander Demko
00049      */ 
00050     Site(const QString &siteDir, const wexus::HTTPParams &params = wexus::HTTPParams());
00051     /// destructor
00052     ~Site();
00053 
00054     /// is the web server currently running?
00055     bool isRunning(void) const;
00056     /// starts the web server
00057     void start(void);
00058     /// notifies the web server to stop. you should still do a wait()
00059     /// this function may or may not block
00060     void quit(void);
00061     /// waits until the server finishes
00062     void wait(void);
00063 
00064     /**
00065      * Adds an already instantiated application to the given mount point.
00066      * The mountpoint must end in a '/'. The root mountpoint, "/" is fine too.
00067      *
00068      * @author Aleksander Demko
00069      */ 
00070     void addApplication(const QString &mountpoint, std::shared_ptr<wexus::Application> app);
00071 
00072   private:
00073     // all members here are RO (readonly)
00074     // that is, set during startup in the main thread
00075     bool dm_madeMimeTypes;
00076 
00077     QString dm_siteDir;
00078     wexus::HTTPParams dm_httpparms;
00079     std::shared_ptr<wexus::HTTPServer> dm_httpserver;
00080 
00081     // helper handlers
00082     std::shared_ptr<wexus::FileHTTPHandler> dm_filehandler;
00083 
00084     class ApplicationHandler;
00085 };
00086 
00087 #endif
00088 
 All Classes Namespaces Functions Variables Enumerations Enumerator