1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef SD_GLOBAL_RESOURCE_CONTAINER_HXX 29*cdf0e10cSrcweir #define SD_GLOBAL_RESOURCE_CONTAINER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "sdmod.hxx" 32*cdf0e10cSrcweir #include <memory> 33*cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/uno/XInterface.hpp> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir namespace css = ::com::sun::star; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir namespace sd { 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir class SdGlobalResource 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir public: 43*cdf0e10cSrcweir virtual ~SdGlobalResource (void) {}; 44*cdf0e10cSrcweir }; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir /** The purpose of this container is to hold references to resources that 47*cdf0e10cSrcweir are globally available to all interested objects and to destroy them 48*cdf0e10cSrcweir when the sd module is destroyed. Examples for resources can be 49*cdf0e10cSrcweir containers of bitmaps or the container of master pages used by the 50*cdf0e10cSrcweir MasterPagesSelector objects in the task panel. 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir It works like a singleton in that there is one instance per sd module. 53*cdf0e10cSrcweir Resources can be added (by themselves or their owners) to the 54*cdf0e10cSrcweir container. The main task of the container is the destruction of all 55*cdf0e10cSrcweir resources that have been added to it. 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir As you may note, there is no method to get a resource from the 58*cdf0e10cSrcweir container. It is the task of the resource to provide other means of 59*cdf0e10cSrcweir access to it. 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir The reason for this design is not to have to change the SdModule 62*cdf0e10cSrcweir destructor every time when there is a new resource. This is done by 63*cdf0e10cSrcweir reversing the dependency between module and resource: the resource knows 64*cdf0e10cSrcweir about the module--this container class to be more precisely--and tells 65*cdf0e10cSrcweir it to destroy the resource when the sd module is at the end of its 66*cdf0e10cSrcweir lifetime. 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir class SdGlobalResourceContainer 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir public: 71*cdf0e10cSrcweir static SdGlobalResourceContainer& Instance (void); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir /** Add a resource to the container. The ownership of the resource is 74*cdf0e10cSrcweir transferred to the container. The resource is destroyed when the 75*cdf0e10cSrcweir container is destroyed, i.e. when the sd module is destroyed. 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir When in doubt, use the shared_ptr variant of this method. 78*cdf0e10cSrcweir */ 79*cdf0e10cSrcweir void AddResource (::std::auto_ptr<SdGlobalResource> pResource); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir /** Add a resource to the container. By using a shared_ptr and 82*cdf0e10cSrcweir releasing it only when the SgGlobalResourceContainer is destroyed 83*cdf0e10cSrcweir the given resource is kept alive at least that long. When at the 84*cdf0e10cSrcweir time of the destruction of SgGlobalResourceContainer no other 85*cdf0e10cSrcweir references exist the resource is destroyed as well. 86*cdf0e10cSrcweir */ 87*cdf0e10cSrcweir void AddResource (::boost::shared_ptr<SdGlobalResource> pResource); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir /** Add a resource that is implemented as UNO object. Destruction 90*cdf0e10cSrcweir (when the sd modules is unloaded) is done by a) calling dispose() 91*cdf0e10cSrcweir when the XComponent is supported and by b) releasing the reference. 92*cdf0e10cSrcweir */ 93*cdf0e10cSrcweir void AddResource (const ::css::uno::Reference<css::uno::XInterface>& rxResource); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir protected: 96*cdf0e10cSrcweir friend class ::SdModule; 97*cdf0e10cSrcweir friend class ::std::auto_ptr<SdGlobalResourceContainer>; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir class Implementation; 100*cdf0e10cSrcweir ::std::auto_ptr<Implementation> mpImpl; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir SdGlobalResourceContainer (void); 103*cdf0e10cSrcweir ~SdGlobalResourceContainer (void); 104*cdf0e10cSrcweir }; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir } // end of namespace sd 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir #endif 109