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         throw (css::uno::RuntimeException);
90 
91 
92     // XInitialization
93 
94     virtual void SAL_CALL initialize(
95         const css::uno::Sequence<css::uno::Any>& aArguments)
96         throw (css::uno::Exception, css::uno::RuntimeException);
97 
98 private:
99     css::uno::Reference<
100         css::frame::XController> mxController;
101 
102     class ResourceToFactoryMap;
103     ::boost::scoped_ptr<ResourceToFactoryMap> mpResourceToFactoryMap;
104     class LoadedFactoryContainer;
105     ::boost::scoped_ptr<LoadedFactoryContainer> mpLoadedFactories;
106 
107     ModuleController (
108         const css::uno::Reference<css::uno::XComponentContext>& rxContext)
109         throw();
110     ModuleController (void); // Not implemented.
111     ModuleController (const ModuleController&); // Not implemented.
112 	virtual ~ModuleController (void) throw();
113 
114     /** Load a list of URL to service mappings from the
115         /org.openoffice.Office.Impress/MultiPaneGUI/Framework/ResourceFactories
116         configuration entry.  The mappings are stored in the
117         mpResourceToFactoryMap member.
118     */
119     void LoadFactories (const css::uno::Reference<css::uno::XComponentContext>& rxContext);
120 
121     /** Called for every entry in the ResourceFactories configuration entry.
122     */
123     void ProcessFactory (const ::std::vector<css::uno::Any>& rValues);
124 
125     /** Instantiate all startup services that are found in the
126         /org.openoffice.Office.Impress/MultiPaneGUI/Framework/StartupServices
127         configuration entry.  This method is called once when a new
128         ModuleController object is created.
129     */
130     void InstantiateStartupServices (void);
131 
132     /** Called for one entry in the StartupServices configuration list this
133         method instantiates the service described by the entry.  It does not
134         hold references to the new object so that the object will be
135         destroyed on function exit when it does not register itself
136         somewhere.  It typically will register as
137         XConfigurationChangeListener at the configuration controller.
138     */
139     void ProcessStartupService (const ::std::vector<css::uno::Any>& rValues);
140 };
141 
142 } } // end of namespace sd::framework
143 
144 #endif
145