xref: /trunk/main/sd/source/ui/inc/framework/ModuleController.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_FRAMEWORK_MODULE_CONTROLLER_HXX
25 #define SD_FRAMEWORK_MODULE_CONTROLLER_HXX
26 
27 #include "MutexOwner.hxx"
28 
29 #include <osl/mutex.hxx>
30 #include <com/sun/star/drawing/framework/XModuleController.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/frame/XController.hpp>
34 #include <cppuhelper/compbase2.hxx>
35 
36 #include <boost/scoped_ptr.hpp>
37 #include <set>
38 
39 namespace css = ::com::sun::star;
40 
41 namespace {
42 
43 typedef ::cppu::WeakComponentImplHelper2 <
44     css::drawing::framework::XModuleController,
45     css::lang::XInitialization
46     > ModuleControllerInterfaceBase;
47 
48 } // end of anonymous namespace.
49 
50 
51 
52 namespace sd { namespace framework {
53 
54 /** The ModuleController has to tasks:
55 
56     1. It reads the
57     org.openoffice.Office.Impress/MultiPaneGUI/Framework/ResourceFactories
58     configuration data that maps from resource URLs to service names of
59     factories that can create resources for the URLs.  When the
60     configuration controller wants to create a resource for which it does
61     not have a factory, it asks the ModuleController to provide one.  The
62     ModuleController looks up the service name registered for the URL of the
63     resource and instantiates this service.  The service is expected to
64     register on its creation a factory for the resource in question.
65 
66     2. The ModuleController reads on its creation
67     org.openoffice.Office.Impress/MultiPaneGUI/Framework/StartupServices
68     configuration data and instantiates all listed services.  These servces
69     can then register as listeners at the ConfigurationController or do
70     whatever they like.
71 */
72 class ModuleController
73     : private sd::MutexOwner,
74       public ModuleControllerInterfaceBase
75 {
76 public:
77     static css::uno::Reference<
78         css::drawing::framework::XModuleController>
79         CreateInstance (
80             const css::uno::Reference<css::uno::XComponentContext>&
81             rxContext);
82 
83     virtual void SAL_CALL disposing (void);
84 
85 
86     // XModuleController
87 
88     virtual void SAL_CALL requestResource(const ::rtl::OUString& rsResourceURL);
89 
90 
91     // XInitialization
92 
93     virtual void SAL_CALL initialize(
94         const css::uno::Sequence<css::uno::Any>& aArguments);
95 
96 private:
97     css::uno::Reference<
98         css::frame::XController> mxController;
99 
100     class ResourceToFactoryMap;
101     ::boost::scoped_ptr<ResourceToFactoryMap> mpResourceToFactoryMap;
102     class LoadedFactoryContainer;
103     ::boost::scoped_ptr<LoadedFactoryContainer> mpLoadedFactories;
104 
105     ModuleController (
106         const css::uno::Reference<css::uno::XComponentContext>& rxContext)
107         throw();
108     ModuleController (void); // Not implemented.
109     ModuleController (const ModuleController&); // Not implemented.
110     virtual ~ModuleController (void) throw();
111 
112     /** Load a list of URL to service mappings from the
113         /org.openoffice.Office.Impress/MultiPaneGUI/Framework/ResourceFactories
114         configuration entry.  The mappings are stored in the
115         mpResourceToFactoryMap member.
116     */
117     void LoadFactories (const css::uno::Reference<css::uno::XComponentContext>& rxContext);
118 
119     /** Called for every entry in the ResourceFactories configuration entry.
120     */
121     void ProcessFactory (const ::std::vector<css::uno::Any>& rValues);
122 
123     /** Instantiate all startup services that are found in the
124         /org.openoffice.Office.Impress/MultiPaneGUI/Framework/StartupServices
125         configuration entry.  This method is called once when a new
126         ModuleController object is created.
127     */
128     void InstantiateStartupServices (void);
129 
130     /** Called for one entry in the StartupServices configuration list this
131         method instantiates the service described by the entry.  It does not
132         hold references to the new object so that the object will be
133         destroyed on function exit when it does not register itself
134         somewhere.  It typically will register as
135         XConfigurationChangeListener at the configuration controller.
136     */
137     void ProcessStartupService (const ::std::vector<css::uno::Any>& rValues);
138 };
139 
140 } } // end of namespace sd::framework
141 
142 #endif
143