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