summaryrefslogtreecommitdiff
path: root/rotord/src/rotord.h
blob: ea065c0052462b4c29af6f3287ad5df497fb341f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPRequestHandler.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/UUIDGenerator.h"
#include "Poco/Timestamp.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/DateTimeFormat.h"
#include "Poco/Exception.h"
#include "Poco/ThreadPool.h"
#include "Poco/Task.h"
#include "Poco/NotificationCenter.h"
#include "Poco/TaskManager.h"
#include "Poco/Util/ServerApplication.h"
#include "Poco/Util/Option.h"
#include "Poco/Util/OptionSet.h"
#include "Poco/Util/HelpFormatter.h"
#include "Poco/FileStream.h"
#include "Poco/StreamCopier.h"
#include "Poco/Net/HTTPStreamFactory.h"
#include <iostream>

#include <sstream>
#include "Poco/URI.h"
#include "Poco/Channel.h"
#include "Poco/SplitterChannel.h"
#include "Poco/ConsoleChannel.h"
#include "Poco/FormattingChannel.h"
#include "Poco/FileChannel.h"
#include "Poco/Message.h"
#include "Poco/Formatter.h"
#include "Poco/PatternFormatter.h"
#include "Poco/AutoPtr.h"

using Poco::Net::ServerSocket;
using Poco::Net::HTTPResponse;
using Poco::Net::HTTPRequestHandler;
using Poco::Net::HTTPRequestHandlerFactory;
using Poco::Net::HTTPServer;
using Poco::Net::HTTPServerRequest;
using Poco::Net::HTTPServerResponse;
using Poco::Net::HTTPServerParams;
using Poco::Timestamp;
using Poco::DateTimeFormatter;
using Poco::DateTimeFormat;
using Poco::ThreadPool;
using Poco::TaskManager;
using Poco::Util::ServerApplication;
using Poco::Util::Application;
using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::OptionCallback;
using Poco::Util::HelpFormatter;
using Poco::Net::HTTPStreamFactory;
using Poco::Logger;
using Poco::Channel;
using Poco::SplitterChannel;
using Poco::ConsoleChannel;
using Poco::FormattingChannel;
using Poco::Formatter;
using Poco::PatternFormatter;
using Poco::FileChannel;
using Poco::Message;
using Poco::AutoPtr;


#include "rendercontext.h"


class RenderContextHandler: public HTTPRequestHandler
{
	public:
		RenderContextHandler(string _content,HTTPServerResponse::HTTPStatus _status);
		void handleRequest(HTTPServerRequest& request,HTTPServerResponse& response);
	private:
		std::string content;
		HTTPServerResponse::HTTPStatus status;
};

class RotorRequestHandlerFactory: public HTTPRequestHandlerFactory
{
	public:
		HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request);
	private:
		
		std::unordered_map<std::string,Rotor::Render_context> context;
		std::unordered_map<std::string,std::string> renders;
		Poco::UUIDGenerator idGen;
		Poco::TaskManager manager;
};

class RotorServer: public Poco::Util::ServerApplication
{
	public:
		RotorServer();
		~RotorServer();
	protected:
		void initialize(Application& self);
		void uninitialize();
		void defineOptions(OptionSet& options);
		void handleHelp(const std::string& name, const std::string& value);
		int main(const std::vector<std::string>& args);
	private:
		bool _helpRequested;
};

RotorServer app; //needs to be global for logger

int main(int argc, char** argv)
{
	AutoPtr<SplitterChannel> splitterChannel(new SplitterChannel());
    AutoPtr<Channel> consoleChannel(new ConsoleChannel());
    AutoPtr<Channel> fileChannel(new FileChannel("Rotord.log"));
    AutoPtr<FileChannel> rotatedFileChannel(new FileChannel("Rotord_R.log"));

    rotatedFileChannel->setProperty("rotation", "100");
    rotatedFileChannel->setProperty("archive", "timestamp");

    splitterChannel->addChannel(consoleChannel);
    splitterChannel->addChannel(fileChannel);
    splitterChannel->addChannel(rotatedFileChannel);

    AutoPtr<Formatter> formatter(new PatternFormatter("%d-%m-%Y %H:%M:%S %s: %t"));
    AutoPtr<Channel> formattingChannel(new FormattingChannel(formatter, splitterChannel));

    Logger& sLog = Logger::create("Rotor", formattingChannel, Message::PRIO_TRACE);

	Logger& logger = Logger::get("Rotor");
	logger.information("starting rendering daemon");

	HTTPStreamFactory::registerFactory();
	
	return app.run(argc, argv);
}