Fawkes API  Fawkes Development Version
request_manager.cpp
1 
2 /***************************************************************************
3  * request_manager.cpp - Web Request manager
4  *
5  * Created: Fri Feb 07 16:52:20 2014
6  * Copyright 2006-2014 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #include <webview/request_manager.h>
23 #include <core/threading/mutex_locker.h>
24 #include <webview/server.h>
25 #include <utils/time/time.h>
26 
27 namespace fawkes {
28 #if 0 /* just to make Emacs auto-indent happy */
29 }
30 #endif
31 
32 
33 /** @class WebRequestManager <webview/nav_manager.h>
34  * Probides information about ongoing requests.
35  * Will take a server at run-time and query it for request information.
36  * This class can persists even though the server does not, which is
37  * required fr the WebviewAspect.
38  * @author Tim Niemueller
39  */
40 
41 /** Constructor. */
43 {
44  mutex_ = new Mutex();
45  server_ = 0;
46 }
47 
48 
49 /** Destructor. */
51 {
52  delete mutex_;
53 }
54 
55 
56 void
57 WebRequestManager::set_server(WebServer *server)
58 {
59  MutexLocker lock(mutex_);
60  server_ = server;
61 }
62 
63 
64 /** Get number of currently active requests.
65  * @return number of currently active requests.
66  */
67 unsigned int
69 {
70  MutexLocker lock(mutex_);
71  if (server_) {
72  return server_->active_requests();
73  } else {
74  return 0;
75  }
76 }
77 
78 
79 /** Get time when last request was completed.
80  * If the number of active requests is zero this gives the time of
81  * last activity. Otherwise just says when the last request was
82  * completed.
83  * @return time when last request was completed
84  */
85 Time
87 {
88  MutexLocker lock(mutex_);
89  if (server_) {
90  return server_->last_request_completion_time();
91  } else {
92  return Time(0,0);
93  }
94 }
95 
96 
97 } // end namespace fawkes
unsigned int active_requests() const
Get number of active requests.
Definition: server.cpp:252
Encapsulation of the libmicrohttpd webserver.
Definition: server.h:43
unsigned int num_active_requests() const
Get number of currently active requests.
Fawkes library namespace.
Mutex locking helper.
Definition: mutex_locker.h:33
A class for handling time.
Definition: time.h:91
WebRequestManager()
Constructor.
Time last_request_completion_time() const
Get time when last request was completed.
Definition: server.cpp:261
Time last_request_completion_time() const
Get time when last request was completed.
Mutex mutual exclusion lock.
Definition: mutex.h:32