diff options
Diffstat (limited to 'rotord/src/rotord.h')
| -rwxr-xr-x | rotord/src/rotord.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/rotord/src/rotord.h b/rotord/src/rotord.h new file mode 100755 index 0000000..7656c28 --- /dev/null +++ b/rotord/src/rotord.h @@ -0,0 +1,136 @@ +#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/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 "rotor.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; + 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); +} |
