Subversion Repositories heating

Rev

Rev 40 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2015 by Andreas Theofilu. All rights reserved!
 *
 * All rights reserved. No warranty, explicit or implicit, provided.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Andreas Theofilu and his suppliers, if any.
 * The intellectual and technical concepts contained
 * herein are proprietary to Andreas Theofilu and its suppliers and
 * may be covered by European and Foreign Patents, patents in process,
 * and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Andreas Theofilu.
 * 
 * Author: Andreas Theofilu <andreas@theosys.at>
 */
#ifndef __HTML_H__
#define __HTML_H__

#include <microhttpd.h>
#include <iostream>
#include <string.h>
#include <vector>
#include "controller.h"
#include "helper.h"

class html : public helper
{
        public:
                typedef struct HTCONF
                {
                        // By config file set variables
                        char rname[32];
                        int rnum;
                        double soll;                    // The temperature that should be
                        double night;                   // The reduced temperature for night
                        double minimal;                 // The minimal temperature
                        time_t start1;                  // The time the heating should have reached the "soll" temperature (if normal is set)
                        time_t end1;                    // The time the heating should end normal mode and start "night" mode.
                        time_t start2;                  // The time the heating stop and the value for night gets active (if normal is set)
                        time_t end2;                    // The time the heating should end night mode and start "normal" mode.
                        HTCONF *next;
                }HTCONF;

        public:
                html();
                ~html();
                void run();
                HTCONF *addConfig(HTCONF *ht);
                void setGlobals(double night, double absent, bool m) { glb_night = night; glb_absent = absent; mode = m; }
                void doStop() { stop = true; }
                void addController(Controller *controller);
                // Functions to return the actual settings
                double getGlbNight() { return glb_night; }
                double getGlbAbsent() { return glb_absent; }
                bool getRunMode() { return mode; }
                HTCONF *getHConfig() { return HeatConf; }

                inline bool hasChanged()
                {
                        if (datar)
                        {
                                datar = false;
                                return true;
                        }

                        return false;
                }

        protected:
                void setLocGlbNight(double d) { glb_night = d; }

                static int request_handler(void * cls, struct MHD_Connection * connection,
                                                           const char * url, const char * method, const char * version,
                                                           const char * upload_data, size_t * upload_data_size, void ** ptr);
                static void request_completed (void *cls, struct MHD_Connection *connection,
                                                                void **con_cls, enum MHD_RequestTerminationCode toe);

        private:
                void initPages();

                HTCONF *HeatConf;
                double glb_night, glb_absent;
                bool mode;
                struct MHD_Daemon *daemon;
                std::string mainPage;
                static std::string intErrorPage;
                bool stop;
                int room;                                               // The currently selected room
                static bool datar;                              // if true, something has changed
                /** List of controllers this server has. */
                std::vector<Controller*> controllers;
};

#endif