Convert from NULL macro to nullptr, remove unused zlib code.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / ObservableMetadataProvider.h
1 /*
2  *  Copyright 2001-2010 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file saml/saml2/metadata/ObservableMetadataProvider.h
19  * 
20  * A metadata provider that notifies interested parties of changes.
21  */
22
23 #ifndef __saml2_obsmetadataprov_h__
24 #define __saml2_obsmetadataprov_h__
25
26 #include <saml/saml2/metadata/MetadataProvider.h>
27
28 namespace xmltooling {
29     class XMLTOOL_API Mutex;
30 };
31
32 namespace opensaml {
33     
34     namespace saml2md {
35         
36 #if defined (_MSC_VER)
37         #pragma warning( push )
38         #pragma warning( disable : 4251 )
39 #endif
40         /**
41          * A metadata provider that notifies interested parties of changes.
42          */
43         class SAML_API ObservableMetadataProvider : public MetadataProvider
44         {
45         protected:
46             /**
47              * Constructor.
48              * 
49              * @param e DOM to supply configuration for provider
50              */
51             ObservableMetadataProvider(const xercesc::DOMElement* e=nullptr);
52             
53             /**
54              * Convenience method for notifying every registered Observer of an event.
55              */
56             virtual void emitChangeEvent() const;
57
58         public:
59             virtual ~ObservableMetadataProvider();
60             
61             /**
62              * An observer of metadata provider changes.
63              */
64             class SAML_API Observer {
65                 MAKE_NONCOPYABLE(Observer);
66             protected:
67                 Observer();
68             public:
69                 virtual ~Observer();
70         
71                 /**
72                  * Called when a provider signals an event has occured.
73                  * The provider is already locked. 
74                  * 
75                  * @param provider the provider being observed
76                  */
77                 virtual void onEvent(const ObservableMetadataProvider& provider) const=0;
78             };
79             
80             /**
81              * Adds a metadata observer.
82              * 
83              * @param newObserver metadata observer to add
84              */
85             virtual void addObserver(const Observer* newObserver) const;
86
87             /**
88              * Removes a metadata observer.
89              * 
90              * @param oldObserver metadata observer to remove
91              * @return  the old observer
92              */
93             virtual const Observer* removeObserver(const Observer* oldObserver) const;
94
95         private:
96             mutable xmltooling::Mutex* m_observerLock;
97             mutable std::vector<const Observer*> m_observers;
98         };
99
100 #if defined (_MSC_VER)
101         #pragma warning( pop )
102 #endif
103
104     };
105 };
106
107 #endif /* __saml2_obsmetadataprov_h__ */