Fawkes API  Fawkes Development Version
url_manager.h
1 
2 /***************************************************************************
3  * url_manager.h - Web URL manager
4  *
5  * Created: Thu Nov 25 21:53:07 2010
6  * Copyright 2006-2010 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef _LIBS_WEBVIEW_URL_MANAGER_H_
24 #define _LIBS_WEBVIEW_URL_MANAGER_H_
25 
26 #include <webview/request.h>
27 #include <webview/router.h>
28 
29 #include <list>
30 #include <mutex>
31 
32 namespace fawkes {
33 
34 class Mutex;
35 class WebReply;
36 template <typename T>
37 class WebviewRouter;
38 
39 class WebUrlManager
40 {
41  friend WebRequestDispatcher;
42 
43 public:
44  /** Function type for handling requests. */
45  typedef std::function<WebReply *(const WebRequest *)> Handler;
46 
47  WebUrlManager();
49 
50  void add_handler(WebRequest::Method method, const std::string &path, Handler handler);
51  void remove_handler(WebRequest::Method method, const std::string &path);
52 
53  void add_handler(WebRequest::Method method, const std::string &path, Handler handler, int weight);
54 
55 private:
56  WebReply *process_request(WebRequest *request);
57 
58 private:
59  std::mutex mutex_;
60  std::shared_ptr<WebviewRouter<Handler>> router_;
61 };
62 
63 } // end namespace fawkes
64 
65 #endif
fawkes::WebUrlManager::add_handler
void add_handler(WebRequest::Method method, const std::string &path, Handler handler)
Add a request processor.
Definition: url_manager.cpp:58
fawkes::WebUrlManager::~WebUrlManager
~WebUrlManager()
Destructor.
Definition: url_manager.cpp:46
fawkes::WebRequest
Definition: request.h:40
fawkes::WebUrlManager::remove_handler
void remove_handler(WebRequest::Method method, const std::string &path)
Remove a request processor.
Definition: url_manager.cpp:88
fawkes::WebUrlManager::WebUrlManager
WebUrlManager()
Constructor.
Definition: url_manager.cpp:41
fawkes
fawkes::WebRequest::Method
Method
HTTP transfer methods.
Definition: request.h:46
fawkes::WebUrlManager::Handler
std::function< WebReply *(const WebRequest *)> Handler
Function type for handling requests.
Definition: url_manager.h:49
fawkes::WebReply
Definition: reply.h:37