/*
 * themeserver.h - built-in http server. currently for webkit themes support
 * Copyright (C) 2010-2017 Sergey Ilinykh
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */

#ifndef THEMESERVER_H
#define THEMESERVER_H

#include <QHash>
#include <QSharedPointer>
#include <functional>

#include "qhttpserver.hpp"
#include "qhttpserverrequest.hpp"
#include "qhttpserverresponse.hpp"

class Theme;

class ThemeServer : public qhttp::server::QHttpServer
{
	Q_OBJECT

	int handlerSeed;
public:

	typedef std::function<bool(qhttp::server::QHttpRequest* req, qhttp::server::QHttpResponse* res)> Handler;

	ThemeServer(QObject *parent = 0);
	quint16 serverPort() const;
	QHostAddress serverAddress() const;

	QUrl serverUrl();

	QString registerSessionHandler(const Handler &handler);
	void unregisterSessionHandler(const QString &path);
	void registerPathHandler(const char *path, const Handler &handler);
private:

	QHash<QString,Handler> sessionHandlers;
	QList<QPair<QString,Handler>> pathHandlers;

};

#endif // THEMESERVER_H
