2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file saml/saml2/metadata/ObservableMetadataProvider.h
20 * A metadata provider that notifies interested parties of changes.
23 #ifndef __saml2_obsmetadataprov_h__
24 #define __saml2_obsmetadataprov_h__
26 #include <saml/saml2/metadata/MetadataProvider.h>
27 #include <xmltooling/util/Threads.h>
33 #if defined (_MSC_VER)
34 #pragma warning( push )
35 #pragma warning( disable : 4251 )
38 * A metadata provider that notifies interested parties of changes.
40 class SAML_API ObservableMetadataProvider : public MetadataProvider
46 * @param e DOM to supply configuration for provider
48 ObservableMetadataProvider(const xercesc::DOMElement* e=NULL)
49 : MetadataProvider(e), m_observerLock(xmltooling::Mutex::create()) {
53 * Convenience method for notifying every registered Observer of an event.
55 virtual void emitChangeEvent() const {
56 xmltooling::Lock lock(m_observerLock);
57 for (std::vector<const Observer*>::const_iterator i=m_observers.begin(); i!=m_observers.end(); i++) {
63 virtual ~ObservableMetadataProvider() {
64 delete m_observerLock;
68 * An observer of metadata provider changes.
70 class SAML_API Observer {
71 MAKE_NONCOPYABLE(Observer);
75 virtual ~Observer() {}
78 * Called when a provider signals an event has occured.
79 * The provider is already locked.
81 * @param provider the provider being observed
83 virtual void onEvent(const ObservableMetadataProvider& provider) const=0;
87 * Adds a metadata observer.
89 * @param newObserver metadata observer to add
91 virtual void addObserver(const Observer* newObserver) const {
92 xmltooling::Lock lock(m_observerLock);
93 m_observers.push_back(newObserver);
97 * Removes a metadata observer.
99 * @param oldObserver metadata observer to remove
100 * @return the old observer
102 virtual const Observer* removeObserver(const Observer* oldObserver) const {
103 xmltooling::Lock lock(m_observerLock);
104 for (std::vector<const Observer*>::iterator i=m_observers.begin(); i!=m_observers.end(); i++) {
105 if (oldObserver==(*i)) {
106 m_observers.erase(i);
114 mutable xmltooling::Mutex* m_observerLock;
115 mutable std::vector<const Observer*> m_observers;
118 #if defined (_MSC_VER)
119 #pragma warning( pop )
125 #endif /* __saml2_obsmetadataprov_h__ */