1*c45d927aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c45d927aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c45d927aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c45d927aSAndrew Rist  * distributed with this work for additional information
6*c45d927aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c45d927aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c45d927aSAndrew Rist  * "License"); you may not use this file except in compliance
9*c45d927aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c45d927aSAndrew Rist  *
11*c45d927aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c45d927aSAndrew Rist  *
13*c45d927aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c45d927aSAndrew Rist  * software distributed under the License is distributed on an
15*c45d927aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c45d927aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c45d927aSAndrew Rist  * specific language governing permissions and limitations
18*c45d927aSAndrew Rist  * under the License.
19*c45d927aSAndrew Rist  *
20*c45d927aSAndrew Rist  *************************************************************/
21*c45d927aSAndrew Rist 
22*c45d927aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SD_FRAMEWORK_RESOURCE_MANAGER_HXX
25cdf0e10cSrcweir #define SD_FRAMEWORK_RESOURCE_MANAGER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfiguration.hpp>
28cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XResource.hpp>
29cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XResourceFactory.hpp>
30cdf0e10cSrcweir #include <boost/noncopyable.hpp>
31cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
32cdf0e10cSrcweir #include <map>
33cdf0e10cSrcweir #include <vector>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace css = ::com::sun::star;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace sd { namespace framework {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir class ConfigurationControllerBroadcaster;
40cdf0e10cSrcweir class ResourceFactoryManager;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir /** Manage the set of active resources.  Activate and deactivate resources.
43cdf0e10cSrcweir */
44cdf0e10cSrcweir class ConfigurationControllerResourceManager
45cdf0e10cSrcweir     : ::boost::noncopyable
46cdf0e10cSrcweir {
47cdf0e10cSrcweir public:
48cdf0e10cSrcweir     /** For every active resource both the resource itself as well as its
49cdf0e10cSrcweir         creating factory are remembered, so that on deactivation, the
50cdf0e10cSrcweir         resource can be deactivated by this factory.
51cdf0e10cSrcweir     */
52cdf0e10cSrcweir     class ResourceDescriptor
53cdf0e10cSrcweir     {
54cdf0e10cSrcweir     public:
55cdf0e10cSrcweir         css::uno::Reference<css::drawing::framework::XResource> mxResource;
56cdf0e10cSrcweir         css::uno::Reference<css::drawing::framework::XResourceFactory> mxResourceFactory;
57cdf0e10cSrcweir     };
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     /** A new ResourceManager object is created with the resource factory
60cdf0e10cSrcweir         container for creating resources and the event broadcaster for
61cdf0e10cSrcweir         notifying ConfigurationChangeListeners of activated or deactivated
62cdf0e10cSrcweir         resources.
63cdf0e10cSrcweir     */
64cdf0e10cSrcweir     ConfigurationControllerResourceManager (
65cdf0e10cSrcweir         const ::boost::shared_ptr<ResourceFactoryManager>& rpResourceFactoryContainer,
66cdf0e10cSrcweir         const ::boost::shared_ptr<ConfigurationControllerBroadcaster>& rpBroadcaster);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     ~ConfigurationControllerResourceManager (void);
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     /** Activate all the resources that are specified by resource ids in
71cdf0e10cSrcweir         rResources.  The resource ids of activated resources are added to
72cdf0e10cSrcweir         the given configuration.  Activated resources are notified to all
73cdf0e10cSrcweir         interested ConfigurationChangeListeners.
74cdf0e10cSrcweir     */
75cdf0e10cSrcweir     void ActivateResources (
76cdf0e10cSrcweir         const ::std::vector<
77cdf0e10cSrcweir             css::uno::Reference<css::drawing::framework::XResourceId> >& rResources,
78cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfiguration>& rxConfiguration);
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     /** Deactivate all the resources that are specified by resource ids in
81cdf0e10cSrcweir         rResources.  The resource ids of deactivated resources are removed
82cdf0e10cSrcweir         from the given configuration.  Activated resources are notified to all
83cdf0e10cSrcweir         interested ConfigurationChangeListeners.
84cdf0e10cSrcweir     */
85cdf0e10cSrcweir     void DeactivateResources (
86cdf0e10cSrcweir         const ::std::vector<
87cdf0e10cSrcweir             css::uno::Reference<css::drawing::framework::XResourceId> >& rResources,
88cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfiguration>& rxConfiguration);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     /** Return the descriptor for the specified resource.
91cdf0e10cSrcweir         @return
92cdf0e10cSrcweir             When there is no active resource for the given resource id then
93cdf0e10cSrcweir             an empty descriptor is returned.
94cdf0e10cSrcweir     */
95cdf0e10cSrcweir     ResourceDescriptor GetResource (
96cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir private:
99cdf0e10cSrcweir     osl::Mutex maMutex;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     class ResourceComparator
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir     public:
104cdf0e10cSrcweir         bool operator() (
105cdf0e10cSrcweir             const css::uno::Reference<css::drawing::framework::XResourceId>& rxId1,
106cdf0e10cSrcweir             const css::uno::Reference<css::drawing::framework::XResourceId>& rxId2) const;
107cdf0e10cSrcweir     };
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     typedef ::std::map<
110cdf0e10cSrcweir         css::uno::Reference<css::drawing::framework::XResourceId>,
111cdf0e10cSrcweir         ResourceDescriptor,
112cdf0e10cSrcweir         ResourceComparator> ResourceMap;
113cdf0e10cSrcweir     ResourceMap maResourceMap;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     ::boost::shared_ptr<ResourceFactoryManager> mpResourceFactoryContainer;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /** This broadcaster is used to notify the activation and deactivation
118cdf0e10cSrcweir         of resources.
119cdf0e10cSrcweir     */
120cdf0e10cSrcweir     ::boost::shared_ptr<ConfigurationControllerBroadcaster> mpBroadcaster;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     void ActivateResource (
123cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
124cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfiguration>& rxConfiguration);
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     void DeactivateResource (
127cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
128cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfiguration>& rxConfiguration);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     void AddResource (
131cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResource>& rxResource,
132cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceFactory>& rxFactory);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     ResourceDescriptor RemoveResource (
135cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId);
136cdf0e10cSrcweir };
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 
139cdf0e10cSrcweir } } // end of namespace sd::framework
140cdf0e10cSrcweir 
141cdf0e10cSrcweir #endif
142