Fawkes API  Fawkes Development Version
nav_manager.cpp
1 
2 /***************************************************************************
3  * url_manager.cpp - Web URL manager
4  *
5  * Created: Thu Nov 25 21:56:19 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 #include <core/exception.h>
24 #include <core/threading/mutex.h>
25 #include <core/threading/mutex_locker.h>
26 #include <webview/nav_manager.h>
27 
28 namespace fawkes {
29 
30 /** @class WebNavManager <webview/nav_manager.h>
31  * Manage visible navigation entries.
32  * This class maintains a map from URLs to names, which are to be added to
33  * the page navigation.
34  * @author Tim Niemueller
35  */
36 
37 /** Constructor. */
39 {
40  mutex_ = new Mutex();
41 }
42 
43 /** Destructor. */
45 {
46  delete mutex_;
47 }
48 
49 /** Add a navigation entry.
50  * @param baseurl URL for the navigation target
51  * @param name name to display to the user
52  * @exception Exception thrown if navigation entry already exists
53  */
54 void
55 WebNavManager::add_nav_entry(std::string baseurl, std::string name)
56 {
57  MutexLocker lock(mutex_);
58  if (nav_entries_.find(baseurl) != nav_entries_.end()) {
59  throw Exception("Navigation entry for %s has already been added", baseurl.c_str());
60  }
61  nav_entries_[baseurl] = name;
62 }
63 
64 /** Remove a navigation entry.
65  * @param baseurl URL for which to remove the navigation entry.
66  */
67 void
68 WebNavManager::remove_nav_entry(std::string baseurl)
69 {
70  MutexLocker lock(mutex_);
71  nav_entries_.erase(baseurl);
72 }
73 
74 } // end namespace fawkes
Fawkes library namespace.
WebNavManager()
Constructor.
Definition: nav_manager.cpp:38
Mutex locking helper.
Definition: mutex_locker.h:33
Base class for exceptions in Fawkes.
Definition: exception.h:35
void add_nav_entry(std::string baseurl, std::string name)
Add a navigation entry.
Definition: nav_manager.cpp:55
void remove_nav_entry(std::string baseurl)
Remove a navigation entry.
Definition: nav_manager.cpp:68
Mutex mutual exclusion lock.
Definition: mutex.h:32
~WebNavManager()
Destructor.
Definition: nav_manager.cpp:44