boost changes and header fixes
[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         public:
63             virtual ~ObservableMetadataProvider();
64             
65             /**
66              * An observer of metadata provider changes.
67              */
68             class SAML_API Observer {
69                 MAKE_NONCOPYABLE(Observer);
70             protected:
71                 Observer();
72             public:
73                 virtual ~Observer();
74         
75                 /**
76                  * Called when a provider signals an event has occured.
77                  * The provider is already locked. 
78                  * 
79                  * @param provider the provider being observed
80                  */
81                 virtual void onEvent(const ObservableMetadataProvider& provider) const=0;
82             };
83             
84             /**
85              * Adds a metadata observer.
86              * 
87              * @param newObserver metadata observer to add
88              */
89             virtual void addObserver(const Observer* newObserver) const;
90
91             /**
92              * Removes a metadata observer.
93              * 
94              * @param oldObserver metadata observer to remove
95              * @return  the old observer
96              */
97             virtual const Observer* removeObserver(const Observer* oldObserver) const;
98
99         private:
100             std::auto_ptr<xmltooling::Mutex> m_observerLock;
101             mutable std::vector<const Observer*> m_observers;
102         };
103
104 #if defined (_MSC_VER)
105         #pragma warning( pop )
106 #endif
107
108     };
109 };
110
111 #endif /* __saml2_obsmetadataprov_h__ */