44d32cc28b17ffc297fb9ffba9da8a4176ec7cc7
[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
28 /**
29  * @namespace shibsp
30  * Shibboleth Service Provider Library
31  */
32 namespace shibsp {
33
34     class SHIBSP_API ServiceProvider;
35
36     /**
37      * Singleton object that manages library startup/shutdown.
38      */
39     class SHIBSP_API SPConfig
40     {
41     MAKE_NONCOPYABLE(SPConfig);
42     public:
43         virtual ~SPConfig() {}
44
45         /**
46          * Returns the global configuration object for the library.
47          * 
48          * @return reference to the global library configuration object
49          */
50         static SPConfig& getConfig();
51
52         /**
53          * Bitmask values representing subsystems of the library.
54          */
55         enum components_t {
56             Listener = 1,
57             Caching = 2,
58             Metadata = 4,
59             Trust = 8,
60             Credentials = 16,
61             AAP = 32,
62             RequestMapper = 64,
63             OutOfProcess = 128,
64             InProcess = 256,
65             Logging = 512
66         };
67         
68         /**
69          * Set a bitmask of subsystems to activate.
70          * 
71          * @param enabled   bitmask of component constants
72          */
73         void setFeatures(unsigned long enabled) {
74             m_features = enabled;
75         }
76
77         /**
78          * Test whether a subsystem is enabled.
79          * 
80          * @param feature   subsystem/component to test
81          * @return true iff feature is enabled
82          */
83         bool isEnabled(components_t feature) {
84             return (m_features & feature)>0;
85         }
86         
87         /**
88          * Initializes library
89          * 
90          * Each process using the library MUST call this function exactly once
91          * before using any library classes.
92          * 
93          * @param catalog_path  delimited set of schema catalog files to load
94          * @return true iff initialization was successful 
95          */
96         virtual bool init(const char* catalog_path)=0;
97         
98         /**
99          * Shuts down library
100          * 
101          * Each process using the library SHOULD call this function exactly once
102          * before terminating itself.
103          */
104         virtual void term()=0;
105         
106         /**
107          * Sets the global ServiceProvider instance.
108          * This method must be externally synchronized with any code that uses the object.
109          * Any previously set object is destroyed.
110          * 
111          * @param serviceProvider   new ServiceProvider instance to store
112          */
113         void setServiceProvider(ServiceProvider* serviceProvider);
114         
115         /**
116          * Returns the global ServiceProvider instance.
117          * 
118          * @return  global ServiceProvider or NULL
119          */
120         ServiceProvider* getServiceProvider() const {
121             return m_serviceProvider;
122         }
123
124     protected:
125         SPConfig() : m_serviceProvider(NULL) {}
126         
127         /** Global ServiceProvider instance. */
128         ServiceProvider* m_serviceProvider;
129
130     private:
131         unsigned long m_features;
132     };
133
134 };
135
136 #endif /* __shibsp_config_h__ */