xref: /trunk/main/extensions/inc/ucbhelper/ext_content.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*46dbaceeSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*46dbaceeSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*46dbaceeSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*46dbaceeSAndrew Rist  * distributed with this work for additional information
6*46dbaceeSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*46dbaceeSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*46dbaceeSAndrew Rist  * "License"); you may not use this file except in compliance
9*46dbaceeSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*46dbaceeSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*46dbaceeSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*46dbaceeSAndrew Rist  * software distributed under the License is distributed on an
15*46dbaceeSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*46dbaceeSAndrew Rist  * KIND, either express or implied.  See the License for the
17*46dbaceeSAndrew Rist  * specific language governing permissions and limitations
18*46dbaceeSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*46dbaceeSAndrew Rist  *************************************************************/
21*46dbaceeSAndrew Rist 
22*46dbaceeSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #ifndef _UCBHELPER_CONTENT_HXX_
26cdf0e10cSrcweir #define _UCBHELPER_CONTENT_HXX_
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <rtl/string.hxx>
29cdf0e10cSrcweir #include <rtl/ustring>
30cdf0e10cSrcweir #include <osl/mutex.hxx>
31cdf0e10cSrcweir #include <osl/thread.h>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
34cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandTaskProcessor.hpp>
35cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
36cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ucb/XPropertyTaskProcessor.hpp>
38cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifier.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
40cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <list>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace cppu;
45cdf0e10cSrcweir using namespace com::sun::star::ucb;
46cdf0e10cSrcweir using namespace com::sun::star::uno;
47cdf0e10cSrcweir using namespace com::sun::star::beans;
48cdf0e10cSrcweir using namespace com::sun::star::lang;
49cdf0e10cSrcweir using namespace std;
50cdf0e10cSrcweir using namespace rtl;
51cdf0e10cSrcweir using namespace osl;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir template <class Type> class safe_list : public osl::Mutex, public std::list< Type > {};
56cdf0e10cSrcweir 
57cdf0e10cSrcweir class OSimpleContentIdentifier :    public OWeakObject,
58cdf0e10cSrcweir                                     public XContentIdentifier
59cdf0e10cSrcweir {
60cdf0e10cSrcweir private:
61cdf0e10cSrcweir     OUString    Identifier;
62cdf0e10cSrcweir     OUString    ProviderScheme;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir public:
65cdf0e10cSrcweir     OSimpleContentIdentifier( const OUString& rIdentifier, const OUString& rProviderScheme );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     // XInterface
68cdf0e10cSrcweir     virtual Any         SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
69cdf0e10cSrcweir     virtual void        SAL_CALL acquire() throw(RuntimeException);
70cdf0e10cSrcweir     virtual void        SAL_CALL release() throw(RuntimeException);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     // XContentIdentifier
73cdf0e10cSrcweir     virtual OUString    SAL_CALL getContentIdentifier() throw(RuntimeException);
74cdf0e10cSrcweir     virtual OUString    SAL_CALL getContentProviderScheme() throw(RuntimeException);
75cdf0e10cSrcweir };
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
78cdf0e10cSrcweir //---------------------------------------------------------------------------
79cdf0e10cSrcweir //
80cdf0e10cSrcweir //  FileSystemContent
81cdf0e10cSrcweir //
82cdf0e10cSrcweir //---------------------------------------------------------------------------
83cdf0e10cSrcweir 
84cdf0e10cSrcweir class OContent :
85cdf0e10cSrcweir public OWeakObject,
86cdf0e10cSrcweir public XContent,
87cdf0e10cSrcweir public XCommandTaskProcessor,
88cdf0e10cSrcweir public XPropertyTaskProcessor,
89cdf0e10cSrcweir public XCommandInfo,
90cdf0e10cSrcweir public XPropertySetInfo,
91cdf0e10cSrcweir public XComponent
92cdf0e10cSrcweir {
93cdf0e10cSrcweir public:
94cdf0e10cSrcweir     struct PropertyChangeEventInfo
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir         OUString    Name;
97cdf0e10cSrcweir         long        Handle;
98cdf0e10cSrcweir 
PropertyChangeEventInfoOContent::PropertyChangeEventInfo99cdf0e10cSrcweir         PropertyChangeEventInfo() : Handle( -1 ) {}
100cdf0e10cSrcweir 
operator ==OContent::PropertyChangeEventInfo101cdf0e10cSrcweir         inline int operator ==( const PropertyChangeEventInfo& crInfo ) const
102cdf0e10cSrcweir         { return Handle == crInfo.Handle && Handle > 0 || Name == crInfo.Name; }
103cdf0e10cSrcweir     #ifdef __SUNPRO_CC
operator <OContent::PropertyChangeEventInfo104cdf0e10cSrcweir         inline int operator <( const PropertyChangeEventInfo& crInfo ) const
105cdf0e10cSrcweir         { return Handle != crInfo.Handle ? Handle < crInfo.Handle : Name < crInfo.Name; }
106cdf0e10cSrcweir     #endif
107cdf0e10cSrcweir     };
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     struct PropertyChangeListenerInfo
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         Reference< XPropertiesChangeListener >  xListener;
112cdf0e10cSrcweir         list< PropertyChangeEventInfo >         aEventInfos;
113cdf0e10cSrcweir 
operator ==OContent::PropertyChangeListenerInfo114cdf0e10cSrcweir         inline int operator ==( const PropertyChangeListenerInfo& crInfo ) const
115cdf0e10cSrcweir         { return xListener == crInfo.xListener; }
116cdf0e10cSrcweir     #ifdef __SUNPRO_CC
operator <OContent::PropertyChangeListenerInfo117cdf0e10cSrcweir         inline int operator <( const PropertyChangeListenerInfo& crInfo ) const
118cdf0e10cSrcweir         { return xListener < crInfo.xListener; }
119cdf0e10cSrcweir     #endif
120cdf0e10cSrcweir     };
121cdf0e10cSrcweir 
122cdf0e10cSrcweir protected:
123cdf0e10cSrcweir     Sequence< PropertyChangeEvent > matchListenerEvents( const Sequence< PropertyChangeEvent >& crEvents, const PropertyChangeListenerInfo & crInfo );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     safe_list< Reference< XContentEventListener > > m_aContentListeners;
126cdf0e10cSrcweir     safe_list< Reference< XEventListener > >        m_aComponentListeners;
127cdf0e10cSrcweir     safe_list< PropertyChangeListenerInfo >         m_aPropertyChangeListeners;
128cdf0e10cSrcweir public:
~OContent()129cdf0e10cSrcweir     virtual ~OContent() {}
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     virtual void broadcastContentEvent( const ContentEvent & crEvent );
132cdf0e10cSrcweir     virtual void broadcastPropertiesChangeEvents( const Sequence< PropertyChangeEvent >& crEvents );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     // To be implemented by inheritents
135cdf0e10cSrcweir     virtual Any doCommand( const Command & crCommand ) = 0;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     // XInterface
138cdf0e10cSrcweir     virtual Any         SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     virtual void SAL_CALL acquire() throw(RuntimeException);
141cdf0e10cSrcweir     virtual void SAL_CALL release() throw(RuntimeException);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     // XContent
144cdf0e10cSrcweir     virtual void SAL_CALL addContentEventListener( const Reference< XContentEventListener >& rListener ) throw();
145cdf0e10cSrcweir     virtual void SAL_CALL removeContentEventListener( const Reference< XContentEventListener >& rListener ) throw();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     // XComponent
148cdf0e10cSrcweir     virtual void SAL_CALL dispose() throw();
149cdf0e10cSrcweir     virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw();
150cdf0e10cSrcweir     virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& xListener ) throw();
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     // XCommmandTaskProcessor
153cdf0e10cSrcweir     virtual Reference< XCommandInfo > SAL_CALL getCommandsInfo() throw();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     // XCommandInfo
156cdf0e10cSrcweir     virtual CommandInfo SAL_CALL getCommandInfoByName( const OUString& rName ) throw( UnsupportedCommandException );
157cdf0e10cSrcweir     virtual CommandInfo SAL_CALL getCommandInfoByHandle( long nHandle ) throw( UnsupportedCommandException );
158cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasCommandByName( const OUString& rName ) throw();
159cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasCommandByHandle( long nHandle ) throw();
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     // XPropertyTaskProcessor
162cdf0e10cSrcweir     virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw();
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     // XPropertySetInfo
165cdf0e10cSrcweir     virtual Property SAL_CALL getPropertyByName( const OUString& Name ) throw( UnknownPropertyException );
166cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw();
167cdf0e10cSrcweir     virtual void SAL_CALL addPropertiesChangeListener( const Sequence< OUString >& Names, const Reference< XPropertiesChangeListener >& xListener ) throw();
168cdf0e10cSrcweir     virtual void SAL_CALL removePropertiesChangeListener( const Sequence< OUString >& Names, const Reference< XPropertiesChangeListener >& xListener ) throw();
169cdf0e10cSrcweir };
170cdf0e10cSrcweir 
171cdf0e10cSrcweir //---------------------------------------------------------------------------
172cdf0e10cSrcweir //
173cdf0e10cSrcweir //  FolderContent
174cdf0e10cSrcweir //
175cdf0e10cSrcweir //---------------------------------------------------------------------------
176cdf0e10cSrcweir 
177cdf0e10cSrcweir // supported Commands
178cdf0e10cSrcweir static const sal_Int32 OPEN     = 0;
179cdf0e10cSrcweir static const sal_Int32 CLOSE    = 1;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir class OFolderContent : public OContent
182cdf0e10cSrcweir {
183cdf0e10cSrcweir protected:
184cdf0e10cSrcweir     // Already provided children
185cdf0e10cSrcweir     safe_list< XContent >   m_aChildList;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     // OContent
188cdf0e10cSrcweir     virtual Any doCommand( const Command & crCommand );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     // new methods, can be overloaded
191cdf0e10cSrcweir     virtual Any doOpenCommand();
192cdf0e10cSrcweir     virtual Any doCloseCommand();
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     // To be implemented by inheritants
195cdf0e10cSrcweir     virtual Sequence< XContent > getAllChildren() = 0;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir public:
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     // XCommmandTaskProcessor
200cdf0e10cSrcweir     virtual Reference< XCommandTask > SAL_CALL createCommandTask(const Command& rCommand, const Reference< XContentTaskEnvironment >& rEnvironment ) throw();
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     // XCommandInfo
203cdf0e10cSrcweir     virtual Sequence< CommandInfo > SAL_CALL getCommands() throw();
204cdf0e10cSrcweir };
205cdf0e10cSrcweir 
206cdf0e10cSrcweir //---------------------------------------------------------------------------
207cdf0e10cSrcweir //
208cdf0e10cSrcweir //  OContentTask
209cdf0e10cSrcweir //
210cdf0e10cSrcweir //---------------------------------------------------------------------------
211cdf0e10cSrcweir 
212cdf0e10cSrcweir class OContentTask :
213cdf0e10cSrcweir public OWeakObject,
214cdf0e10cSrcweir public XContentTask
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     Guard< OContent >                       m_aContentGuard;
217cdf0e10cSrcweir protected:
218cdf0e10cSrcweir     OContent                                *m_pContent;
219cdf0e10cSrcweir     Reference< XContentTaskEnvironment >    m_xEnvironment;
220cdf0e10cSrcweir     ContentTaskStatus                       m_eStatus;
221cdf0e10cSrcweir     oslThread                               m_aThread;
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     static void executeWorker( void * );
224cdf0e10cSrcweir     virtual ContentTaskStatus setStatus( ContentTaskStatus eStatus );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     // To be implemented by inheritants
227cdf0e10cSrcweir     virtual void doExecute() = 0;
228cdf0e10cSrcweir public:
229cdf0e10cSrcweir     OContentTask(  const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent );
230cdf0e10cSrcweir     virtual ~OContentTask();
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     // XInterface
233cdf0e10cSrcweir     virtual Any         SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     virtual void SAL_CALL acquire() throw(RuntimeException);
236cdf0e10cSrcweir     virtual void SAL_CALL release() throw(RuntimeException);
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     // XContentTask
239cdf0e10cSrcweir     virtual void SAL_CALL start() throw();
240cdf0e10cSrcweir     virtual void SAL_CALL execute() throw( Exception );
241cdf0e10cSrcweir     virtual void SAL_CALL abort() throw();
242cdf0e10cSrcweir     virtual ContentTaskStatus SAL_CALL getStatus() throw();
243cdf0e10cSrcweir     virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw();
244cdf0e10cSrcweir };
245cdf0e10cSrcweir 
246cdf0e10cSrcweir //---------------------------------------------------------------------------
247cdf0e10cSrcweir //
248cdf0e10cSrcweir //  OCommandTask
249cdf0e10cSrcweir //
250cdf0e10cSrcweir //---------------------------------------------------------------------------
251cdf0e10cSrcweir 
252cdf0e10cSrcweir class OCommandTask :
253cdf0e10cSrcweir public OContentTask,
254cdf0e10cSrcweir public XCommandTask
255cdf0e10cSrcweir {
256cdf0e10cSrcweir protected:
257cdf0e10cSrcweir     Command             m_aCommand;
258cdf0e10cSrcweir     Any                 m_aResult;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir public:
261cdf0e10cSrcweir     OCommandTask( const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent, const Command& rCommand );
262cdf0e10cSrcweir     virtual ~OCommandTask();
263cdf0e10cSrcweir 
264cdf0e10cSrcweir     virtual void doExecute();
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     // XInterface
267cdf0e10cSrcweir     virtual Any         SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
268cdf0e10cSrcweir     virtual void        SAL_CALL acquire() throw(RuntimeException);
269cdf0e10cSrcweir     virtual void        SAL_CALL release() throw(RuntimeException);
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     // XContentTask
272cdf0e10cSrcweir     virtual void SAL_CALL start() throw();
273cdf0e10cSrcweir     virtual void SAL_CALL execute() throw( Exception );
274cdf0e10cSrcweir     virtual void SAL_CALL abort() throw();
275cdf0e10cSrcweir     virtual ContentTaskStatus SAL_CALL getStatus() throw();
276cdf0e10cSrcweir     virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw();
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     // XCommandTask
279cdf0e10cSrcweir     virtual Command SAL_CALL getCommand() throw();
280cdf0e10cSrcweir     virtual Any SAL_CALL getResult() throw();
281cdf0e10cSrcweir };
282cdf0e10cSrcweir 
283cdf0e10cSrcweir //---------------------------------------------------------------------------
284cdf0e10cSrcweir //
285cdf0e10cSrcweir //  OPropertyTask
286cdf0e10cSrcweir //
287cdf0e10cSrcweir //---------------------------------------------------------------------------
288cdf0e10cSrcweir 
289cdf0e10cSrcweir class OPropertyTask :
290cdf0e10cSrcweir public OContentTask,
291cdf0e10cSrcweir public XPropertyTask
292cdf0e10cSrcweir {
293cdf0e10cSrcweir protected:
294cdf0e10cSrcweir     Sequence< PropertyValueInfo >   m_aProperties;
295cdf0e10cSrcweir     PropertyTaskType                m_eType;
296cdf0e10cSrcweir public:
297cdf0e10cSrcweir     OPropertyTask(const Reference< XContentTaskEnvironment >& Environment, OContent *pContent, const Sequence< PropertyValue >& Properties, PropertyTaskType Type );
298cdf0e10cSrcweir     virtual ~OPropertyTask();
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     virtual void doExecute();
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     // To be implemented by inheritants
303cdf0e10cSrcweir     virtual Any setPropertyValue( PropertyValueInfo & rProperty ) = 0;
304cdf0e10cSrcweir     virtual void getPropertyValue( PropertyValueInfo & rProperty ) = 0;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir     // XInterface
307cdf0e10cSrcweir     virtual Any         SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
308cdf0e10cSrcweir     virtual void        SAL_CALL acquire() throw(RuntimeException);
309cdf0e10cSrcweir     virtual void        SAL_CALL release() throw(RuntimeException);
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     // XContentTask
312cdf0e10cSrcweir     virtual void SAL_CALL start() throw();
313cdf0e10cSrcweir     virtual void SAL_CALL execute() throw( Exception );
314cdf0e10cSrcweir     virtual void SAL_CALL abort() throw();
315cdf0e10cSrcweir     virtual ContentTaskStatus SAL_CALL getStatus() throw();
316cdf0e10cSrcweir     virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw();
317cdf0e10cSrcweir 
318cdf0e10cSrcweir     // XPropertyTask
319cdf0e10cSrcweir     PropertyTaskType SAL_CALL getType() throw();
320cdf0e10cSrcweir     Sequence< PropertyValueInfo > SAL_CALL getProperties() throw();
321cdf0e10cSrcweir };
322cdf0e10cSrcweir 
323cdf0e10cSrcweir #endif // _UCBHELPER_CONTENT_HXX_
324