alaCarte Maps
Renderer for OpenStreetMap tiles
stylesheet_manager.hpp
Go to the documentation of this file.
1 
21 #pragma once
22 #ifndef STYLESHEET_MANAGER_HPP
23 #define STYLESHEET_MANAGER_HPP
24 
25 #include <boost/asio.hpp>
26 #include <boost/thread/thread.hpp>
27 #include <boost/unordered_map.hpp>
28 #include "../extras/dirwatch/dir_monitor.hpp"
29 #include <boost/filesystem/path.hpp>
30 
31 #include "settings.hpp"
32 
33 class RequestManager;
34 class Stylesheet;
35 class Configuration;
36 class Geodata;
37 
38 namespace fs = boost::filesystem;
39 
46  : public boost::enable_shared_from_this<StylesheetManager>
47  , public boost::noncopyable
48 {
49 public:
55  StylesheetManager(const shared_ptr<Configuration>& config);
56 
64  TESTABLE void startStylesheetObserving(const shared_ptr<RequestManager>& manager);
65 
72 
79  TESTABLE shared_ptr<Stylesheet> getStylesheet(const string& path);
80  TESTABLE bool hasStylesheet(const string& path);
81 
82 private:
87  TESTABLE void onNewStylesheet(const fs::path& stylesheet_path);
88 
92  TESTABLE void onRemovedStylesheet(const fs::path& stylesheet_path);
93 
97  TESTABLE void onFileSystemEvent(const boost::system::error_code &ec, const boost::asio::dir_monitor_event &ev);
98 
99 private:
100  shared_ptr<Configuration> config;
101  weak_ptr<RequestManager> manager;
102 
103  boost::shared_mutex stylesheetsLock;
104  boost::unordered_map<fs::path, shared_ptr<Stylesheet> > parsedStylesheets;
105 
107 
108  static shared_ptr<Stylesheet> makeFallbackStylesheet(const shared_ptr<Geodata>& geodata);
109 
110  boost::asio::io_service ioService;
111  boost::thread monitorThread;
112  boost::scoped_ptr<boost::asio::dir_monitor> monitorService;
113 };
114 
115 
116 #endif
TESTABLE bool hasStylesheet(const string &path)
boost::thread monitorThread
TESTABLE void onRemovedStylesheet(const fs::path &stylesheet_path)
removes the Stylesheet from the Stylesheet Cache and the prerendered tiles from the Cache...
TESTABLE void stopStylesheetObserving()
Stops the folder observation.
boost::scoped_ptr< boost::asio::dir_monitor > monitorService
TESTABLE void startStylesheetObserving(const shared_ptr< RequestManager > &manager)
starts observing the Stylesheet directory.
The StylesheetManager provides an interface to get arbitrary Stylesheets from the stylesheet director...
A Stylesheet parses a given MapCSS Stylesheet file and stores the defined rules.
Definition: stylesheet.hpp:39
boost::shared_mutex stylesheetsLock
static shared_ptr< Stylesheet > makeFallbackStylesheet(const shared_ptr< Geodata > &geodata)
TESTABLE void onFileSystemEvent(const boost::system::error_code &ec, const boost::asio::dir_monitor_event &ev)
handler method for dirwatch, forwards only .mapcss files to onNewStylesheet and onRemovedStylesheet ...
TESTABLE shared_ptr< Stylesheet > getStylesheet(const string &path)
Returns the Stylesheet Object for the Stylesheet specified.
shared_ptr< Configuration > config
TESTABLE void onNewStylesheet(const fs::path &stylesheet_path)
tries to read and parse the given file.
StylesheetManager(const shared_ptr< Configuration > &config)
Creates a new StylesheetManager with the given Configuration.
weak_ptr< RequestManager > manager
boost::asio::io_service ioService
Represents a set of options accessible via strings.
#define TESTABLE
Definition: settings.hpp:85
boost::unordered_map< fs::path, shared_ptr< Stylesheet > > parsedStylesheets