Shell of new SP object interface to replace old IConfig layer.
[shibboleth/sp.git] / shibsp / SPConfig.h
1 /*
2  *  Copyright 2001-2006 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 shibsp/SPConfig.h
19  * 
20  * Library configuration 
21  */
22
23 #ifndef __shibsp_config_h__
24 #define __shibsp_config_h__
25
26 #include <shibsp/base.h>
27 #include <xmltooling/PluginManager.h>
28 #include <xercesc/dom/DOM.hpp>
29
30 /**
31  * @namespace shibsp
32  * Shibboleth Service Provider Library
33  */
34 namespace shibsp {
35
36     class SHIBSP_API ListenerService;
37     class SHIBSP_API ServiceProvider;
38
39 #if defined (_MSC_VER)
40     #pragma warning( push )
41     #pragma warning( disable : 4250 4251 )
42 #endif
43
44     /**
45      * Singleton object that manages library startup/shutdown.
46      */
47     class SHIBSP_API SPConfig
48     {
49     MAKE_NONCOPYABLE(SPConfig);
50     public:
51         virtual ~SPConfig() {}
52
53         /**
54          * Returns the global configuration object for the library.
55          * 
56          * @return reference to the global library configuration object
57          */
58         static SPConfig& getConfig();
59
60         /**
61          * Bitmask values representing subsystems of the library.
62          */
63         enum components_t {
64             Listener = 1,
65             Caching = 2,
66             Metadata = 4,
67             Trust = 8,
68             Credentials = 16,
69             AAP = 32,
70             RequestMapper = 64,
71             OutOfProcess = 128,
72             InProcess = 256,
73             Logging = 512
74         };
75         
76         /**
77          * Set a bitmask of subsystems to activate.
78          * 
79          * @param enabled   bitmask of component constants
80          */
81         void setFeatures(unsigned long enabled) {
82             m_features = enabled;
83         }
84
85         /**
86          * Test whether a subsystem is enabled.
87          * 
88          * @param feature   subsystem/component to test
89          * @return true iff feature is enabled
90          */
91         bool isEnabled(components_t feature) {
92             return (m_features & feature)>0;
93         }
94         
95         /**
96          * Initializes library
97          * 
98          * Each process using the library MUST call this function exactly once
99          * before using any library classes.
100          * 
101          * @param catalog_path  delimited set of schema catalog files to load
102          * @return true iff initialization was successful 
103          */
104         virtual bool init(const char* catalog_path)=0;
105         
106         /**
107          * Shuts down library
108          * 
109          * Each process using the library SHOULD call this function exactly once
110          * before terminating itself.
111          */
112         virtual void term()=0;
113         
114         /**
115          * Sets the global ServiceProvider instance.
116          * This method must be externally synchronized with any code that uses the object.
117          * Any previously set object is destroyed.
118          * 
119          * @param serviceProvider   new ServiceProvider instance to store
120          */
121         void setServiceProvider(ServiceProvider* serviceProvider);
122         
123         /**
124          * Returns the global ServiceProvider instance.
125          * 
126          * @return  global ServiceProvider or NULL
127          */
128         ServiceProvider* getServiceProvider() const {
129             return m_serviceProvider;
130         }
131
132         /**
133          * Manages factories for ListenerService plugins.
134          */
135         xmltooling::PluginManager<ListenerService,const xercesc::DOMElement*> ListenerServiceManager;
136
137         /**
138          * Manages factories for ServiceProvider plugins.
139          */
140         xmltooling::PluginManager<ServiceProvider,const xercesc::DOMElement*> ServiceProviderManager;
141
142     protected:
143         SPConfig() : m_serviceProvider(NULL) {}
144         
145         /** Global ServiceProvider instance. */
146         ServiceProvider* m_serviceProvider;
147
148     private:
149         unsigned long m_features;
150     };
151
152 #if defined (_MSC_VER)
153     #pragma warning( pop )
154 #endif
155
156 };
157
158 #endif /* __shibsp_config_h__ */