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_MODULE_CONTROLLER_HXX
25cdf0e10cSrcweir #define SD_FRAMEWORK_MODULE_CONTROLLER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "MutexOwner.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <osl/mutex.hxx>
30cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XModuleController.hpp>
31cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
32cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
33cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
34cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
37cdf0e10cSrcweir #include <set>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace css = ::com::sun::star;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper2 <
44cdf0e10cSrcweir     css::drawing::framework::XModuleController,
45cdf0e10cSrcweir     css::lang::XInitialization
46cdf0e10cSrcweir     > ModuleControllerInterfaceBase;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir } // end of anonymous namespace.
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir namespace sd { namespace framework {
53cdf0e10cSrcweir 
54cdf0e10cSrcweir /** The ModuleController has to tasks:
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     1. It reads the
57cdf0e10cSrcweir     org.openoffice.Office.Impress/MultiPaneGUI/Framework/ResourceFactories
58cdf0e10cSrcweir     configuration data that maps from resource URLs to service names of
59cdf0e10cSrcweir     factories that can create resources for the URLs.  When the
60cdf0e10cSrcweir     configuration controller wants to create a resource for which it does
61cdf0e10cSrcweir     not have a factory, it asks the ModuleController to provide one.  The
62cdf0e10cSrcweir     ModuleController looks up the service name registered for the URL of the
63cdf0e10cSrcweir     resource and instantiates this service.  The service is expected to
64cdf0e10cSrcweir     register on its creation a factory for the resource in question.
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     2. The ModuleController reads on its creation
67cdf0e10cSrcweir     org.openoffice.Office.Impress/MultiPaneGUI/Framework/StartupServices
68cdf0e10cSrcweir     configuration data and instantiates all listed services.  These servces
69cdf0e10cSrcweir     can then register as listeners at the ConfigurationController or do
70cdf0e10cSrcweir     whatever they like.
71cdf0e10cSrcweir */
72cdf0e10cSrcweir class ModuleController
73cdf0e10cSrcweir     : private sd::MutexOwner,
74cdf0e10cSrcweir       public ModuleControllerInterfaceBase
75cdf0e10cSrcweir {
76cdf0e10cSrcweir public:
77cdf0e10cSrcweir     static css::uno::Reference<
78cdf0e10cSrcweir         css::drawing::framework::XModuleController>
79cdf0e10cSrcweir         CreateInstance (
80cdf0e10cSrcweir             const css::uno::Reference<css::uno::XComponentContext>&
81cdf0e10cSrcweir             rxContext);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     virtual void SAL_CALL disposing (void);
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     // XModuleController
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     virtual void SAL_CALL requestResource(const ::rtl::OUString& rsResourceURL)
89cdf0e10cSrcweir         throw (css::uno::RuntimeException);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     // XInitialization
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     virtual void SAL_CALL initialize(
95cdf0e10cSrcweir         const css::uno::Sequence<css::uno::Any>& aArguments)
96cdf0e10cSrcweir         throw (css::uno::Exception, css::uno::RuntimeException);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir private:
99cdf0e10cSrcweir     css::uno::Reference<
100cdf0e10cSrcweir         css::frame::XController> mxController;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     class ResourceToFactoryMap;
103cdf0e10cSrcweir     ::boost::scoped_ptr<ResourceToFactoryMap> mpResourceToFactoryMap;
104cdf0e10cSrcweir     class LoadedFactoryContainer;
105cdf0e10cSrcweir     ::boost::scoped_ptr<LoadedFactoryContainer> mpLoadedFactories;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     ModuleController (
108cdf0e10cSrcweir         const css::uno::Reference<css::uno::XComponentContext>& rxContext)
109cdf0e10cSrcweir         throw();
110cdf0e10cSrcweir     ModuleController (void); // Not implemented.
111cdf0e10cSrcweir     ModuleController (const ModuleController&); // Not implemented.
112cdf0e10cSrcweir 	virtual ~ModuleController (void) throw();
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     /** Load a list of URL to service mappings from the
115cdf0e10cSrcweir         /org.openoffice.Office.Impress/MultiPaneGUI/Framework/ResourceFactories
116cdf0e10cSrcweir         configuration entry.  The mappings are stored in the
117cdf0e10cSrcweir         mpResourceToFactoryMap member.
118cdf0e10cSrcweir     */
119cdf0e10cSrcweir     void LoadFactories (const css::uno::Reference<css::uno::XComponentContext>& rxContext);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     /** Called for every entry in the ResourceFactories configuration entry.
122cdf0e10cSrcweir     */
123cdf0e10cSrcweir     void ProcessFactory (const ::std::vector<css::uno::Any>& rValues);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     /** Instantiate all startup services that are found in the
126cdf0e10cSrcweir         /org.openoffice.Office.Impress/MultiPaneGUI/Framework/StartupServices
127cdf0e10cSrcweir         configuration entry.  This method is called once when a new
128cdf0e10cSrcweir         ModuleController object is created.
129cdf0e10cSrcweir     */
130cdf0e10cSrcweir     void InstantiateStartupServices (void);
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     /** Called for one entry in the StartupServices configuration list this
133cdf0e10cSrcweir         method instantiates the service described by the entry.  It does not
134cdf0e10cSrcweir         hold references to the new object so that the object will be
135cdf0e10cSrcweir         destroyed on function exit when it does not register itself
136cdf0e10cSrcweir         somewhere.  It typically will register as
137cdf0e10cSrcweir         XConfigurationChangeListener at the configuration controller.
138cdf0e10cSrcweir     */
139cdf0e10cSrcweir     void ProcessStartupService (const ::std::vector<css::uno::Any>& rValues);
140cdf0e10cSrcweir };
141cdf0e10cSrcweir 
142cdf0e10cSrcweir } } // end of namespace sd::framework
143cdf0e10cSrcweir 
144cdf0e10cSrcweir #endif
145