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 <core/threading/mutex_locker.h>
23 #include <utils/time/time.h>
24 #include <webview/request_manager.h>
25 #include <webview/server.h>
26 
27 namespace fawkes {
28 
29 /** @class WebRequestManager <webview/nav_manager.h>
30  * Probides information about ongoing requests.
31  * Will take a server at run-time and query it for request information.
32  * This class can persists even though the server does not, which is
33  * required fr the WebviewAspect.
34  * @author Tim Niemueller
35  */
36 
37 /** Constructor. */
39 {
40  mutex_ = new Mutex();
41  server_ = 0;
42 }
43 
44 /** Destructor. */
46 {
47  delete mutex_;
48 }
49 
50 void
51 WebRequestManager::set_server(WebServer *server)
52 {
53  MutexLocker lock(mutex_);
54  server_ = server;
55 }
56 
57 /** Get number of currently active requests.
58  * @return number of currently active requests.
59  */
60 unsigned int
62 {
63  MutexLocker lock(mutex_);
64  if (server_) {
65  return server_->active_requests();
66  } else {
67  return 0;
68  }
69 }
70 
71 /** Get time when last request was completed.
72  * If the number of active requests is zero this gives the time of
73  * last activity. Otherwise just says when the last request was
74  * completed.
75  * @return time when last request was completed
76  */
77 Time
79 {
80  MutexLocker lock(mutex_);
81  if (server_) {
82  return server_->last_request_completion_time();
83  } else {
84  return Time(0, 0);
85  }
86 }
87 
88 } // end namespace fawkes
Mutex locking helper.
Definition: mutex_locker.h:34
Mutex mutual exclusion lock.
Definition: mutex.h:33
A class for handling time.
Definition: time.h:93
Time last_request_completion_time() const
Get time when last request was completed.
unsigned int num_active_requests() const
Get number of currently active requests.
Encapsulation of the libmicrohttpd webserver.
Definition: server.h:44
Time last_request_completion_time() const
Get time when last request was completed.
Definition: server.cpp:308
unsigned int active_requests() const
Get number of active requests.
Definition: server.cpp:299
Fawkes library namespace.