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 _UCBHELPER_CONTENTBROKER_HXX
25 #define _UCBHELPER_CONTENTBROKER_HXX
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/uno/Sequence.h>
29 
30 namespace com { namespace sun { namespace star { namespace lang {
31 	class XMultiServiceFactory;
32 } } } }
33 
34 namespace com { namespace sun { namespace star { namespace ucb {
35 	class XContentIdentifierFactory;
36 	class XContentProvider;
37 	class XContentProviderManager;
38     class XCommandProcessor;
39 } } } }
40 #include <ucbhelper/registerucb.hxx>
41 #include "ucbhelper/ucbhelperdllapi.h"
42 
43 namespace ucbhelper
44 {
45 
46 class ContentBroker_Impl;
47 
48 //=========================================================================
49 
50 /**
51   * This class simplifies access to the Universal Content Broker (UCB).
52   * Currently there can only be one UCB instance per process. This class can
53   * be used to initialize and deinitialize the Broker and to access its
54   * interfaces directly.
55   */
56 class UCBHELPER_DLLPUBLIC ContentBroker
57 {
58 	ContentBroker_Impl* 	m_pImpl;
59 	// The "one and only" Broker.
60 	static ContentBroker* 	m_pTheBroker;
61 
62 private:
63 	UCBHELPER_DLLPRIVATE ContentBroker( const ContentBroker& ); 				// n.i.
64     UCBHELPER_DLLPRIVATE ContentBroker& operator=( const ContentBroker& ); 	// n.i.
65 
66 	/** Constructor.
67 	  *
68 	  * @param rxSMgr is a Service Manager.
69 	  *	@param rArguments are the arguments to pass to the
70 	  *	       com.sun.star.ucb.UniversalContentBroker service when creating it.
71 	  *	       Currently, this must be a sequence containing exactly two
72 	  *        strings, a primary and a secondary configuration key.
73 	  *        Refer to http://ucb.openoffice.org/docs/ucb-configuration.html
74 	  *        for more information on UCB configuration.
75 	  */
76 	UCBHELPER_DLLPRIVATE ContentBroker( const ::com::sun::star::uno::Reference<
77 			 		::com::sun::star::lang::XMultiServiceFactory >&	rSMgr,
78 				   const ::com::sun::star::uno::Sequence<
79 				    ::com::sun::star::uno::Any >& rArguments );
80 
81 	/** Constructor.
82 	  *
83 	  * @param rxSMgr is a Service Manager.
84       * @param rData are the data for the for the content providers for
85       *        the new UCB.
86 	  */
87 	UCBHELPER_DLLPRIVATE ContentBroker( const ::com::sun::star::uno::Reference<
88 			 		::com::sun::star::lang::XMultiServiceFactory >&	rSMgr,
89                    const ContentProviderDataList & rData );
90 
91 protected:
92 	/**
93 	  * Destructor.
94 	  */
95 	~ContentBroker();
96 
97 public:
98 	/** Initialize "the one and only" Broker.  This method must be called
99 	  *	exactly once, before the Broker is used in any way.
100 	  *
101 	  *	@param rSMgr is a factory to create services needed in the Broker's
102 	  *	       implementation.
103 	  *
104 	  *	@param rArguments are the arguments to pass to the
105 	  *	       com.sun.star.ucb.UniversalContentBroker service when creating
106 	  *        it. Currently, this must be a sequence containing exactly two
107 	  *        strings, a primary and a secondary configuration key.
108 	  *        Refer to http://ucb.openoffice.org/docs/ucb-configuration.html
109 	  *        for more information on UCB configuration.
110 	  *
111 	  *	@return True if creation and possible configuration of the Broker
112 	  *	        was successful.
113 	  */
114 	static sal_Bool
115 	initialize( const::com::sun::star::uno::Reference<
116 					::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
117 				const ::com::sun::star::uno::Sequence<
118 					::com::sun::star::uno::Any >& rArguments );
119 
120 	/** Initialize "the one and only" Broker.  This method must be called
121 	  *	exactly once, before the Broker is used in any way.
122 	  *
123 	  *	@param rSMgr is a factory to create services needed in the Broker's
124 	  *	       implementation.
125 	  *
126       * @param rData are the data for the for the content providers for
127       *        the UCB to initialize.
128 	  *
129 	  *	@return True if creation and possible configuration of the Broker
130 	  *	        was successful.
131 	  */
132 	static sal_Bool
133 	initialize( const::com::sun::star::uno::Reference<
134 					::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
135                 const ContentProviderDataList & rData );
136 
137 	/** Deinitialize "the one and only" Broker.  Once this method has been
138 	  *	called, the Broker must not be used any longer.
139 	  */
140 	static void
141 	deinitialize();
142 
143 	/**
144 	  * This method returns the Broker, if it was already initialized.
145 	  *
146 	  * @return the Broker or 0, if ContentBroker::initialize() was not yet
147 	  *         called or did fail.
148 	  */
149 	static ContentBroker*
150 	get();
151 
152 	/**
153 	  * This method returns the Service Manager used to instanciate the Broker.
154 	  *
155 	  * @return a Service Manager.
156 	  */
157 	::com::sun::star::uno::Reference<
158 		::com::sun::star::lang::XMultiServiceFactory >
159 	getServiceManager() const;
160 
161 	/**
162 	  * This method returns the XContentIdentifierFactory interface of the
163 	  * Broker.
164 	  *
165 	  * @return a XContentIdentifierFactory interface.
166 	  */
167 	::com::sun::star::uno::Reference<
168 		::com::sun::star::ucb::XContentIdentifierFactory >
169 	getContentIdentifierFactoryInterface() const;
170 
171 	/**
172 	  * This method returns the XContentProvider interface of the Broker.
173 	  *
174 	  * @return a XContentProvider interface.
175 	  */
176 	::com::sun::star::uno::Reference<
177 		::com::sun::star::ucb::XContentProvider >
178 	getContentProviderInterface() const;
179 
180 	/**
181 	  * This method returns the XContentProviderManager interface of the Broker.
182 	  *
183 	  * @return a XContentProviderManager interface.
184 	  */
185 	::com::sun::star::uno::Reference<
186 		::com::sun::star::ucb::XContentProviderManager >
187 	getContentProviderManagerInterface() const;
188 
189 	/**
190       * This method returns the XCommandProcessor interface of the Broker.
191 	  *
192       * @return a XCommandProcessor interface.
193 	  */
194 	::com::sun::star::uno::Reference<
195         ::com::sun::star::ucb::XCommandProcessor >
196     getCommandProcessorInterface() const;
197 };
198 
199 } /* namespace ucbhelper */
200 
201 #endif /* !_UCBHELPER_CONTENTBROKER_HXX */
202