Set fourth file version digit to signify rebuild.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / ObservableMetadataProvider.h
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * @file saml/saml2/metadata/ObservableMetadataProvider.h
23  * 
24  * A metadata provider that notifies interested parties of changes.
25  */
26
27 #ifndef __saml2_obsmetadataprov_h__
28 #define __saml2_obsmetadataprov_h__
29
30 #include <saml/saml2/metadata/MetadataProvider.h>
31
32 namespace xmltooling {
33     class XMLTOOL_API Mutex;
34 };
35
36 namespace opensaml {
37     
38     namespace saml2md {
39         
40 #if defined (_MSC_VER)
41         #pragma warning( push )
42         #pragma warning( disable : 4251 )
43 #endif
44         /**
45          * A metadata provider that notifies interested parties of changes.
46          */
47         class SAML_API ObservableMetadataProvider : public virtual MetadataProvider
48         {
49         protected:
50             /**
51              * Constructor.
52              * 
53              * @param e DOM to supply configuration for provider
54              */
55             ObservableMetadataProvider(const xercesc::DOMElement* e=nullptr);
56             
57             /**
58              * Convenience method for notifying every registered Observer of an event.
59              */
60             virtual void emitChangeEvent() const;
61
62             /**
63              * Convenience method for notifying every registered Observer of an event.
64              */
65             virtual void emitChangeEvent(const EntityDescriptor& entity) const;
66
67         public:
68             virtual ~ObservableMetadataProvider();
69             
70             /**
71              * An observer of metadata provider changes.
72              */
73             class SAML_API Observer {
74                 MAKE_NONCOPYABLE(Observer);
75             protected:
76                 Observer();
77             public:
78                 virtual ~Observer();
79         
80                 /**
81                  * Called when a provider signals an event has occured.
82                  * The provider is already locked. 
83                  * 
84                  * @param provider the provider being observed
85                  */
86                 virtual void onEvent(const ObservableMetadataProvider& provider) const=0;
87
88                 /**
89                  * Called when a provider signals an event has occured.
90                  * The provider is already locked. 
91                  * 
92                  * @param provider the provider being observed
93                  * @param entity the entity that underwent modification
94                  */
95                 virtual void onEvent(const ObservableMetadataProvider& provider, const EntityDescriptor& entity) const;
96             };
97             
98             /**
99              * Adds a metadata observer.
100              * 
101              * @param newObserver metadata observer to add
102              */
103             virtual void addObserver(const Observer* newObserver) const;
104
105             /**
106              * Removes a metadata observer.
107              * 
108              * @param oldObserver metadata observer to remove
109              * @return  the old observer
110              */
111             virtual const Observer* removeObserver(const Observer* oldObserver) const;
112
113         private:
114             mutable std::auto_ptr<xmltooling::Mutex> m_observerLock;
115             mutable std::vector<const Observer*> m_observers;
116         };
117
118 #if defined (_MSC_VER)
119         #pragma warning( pop )
120 #endif
121
122     };
123 };
124
125 #endif /* __saml2_obsmetadataprov_h__ */