xref: /aoo41x/main/desktop/source/app/lockfile.hxx (revision 0a1e2f0e)
1*0a1e2f0eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*0a1e2f0eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*0a1e2f0eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*0a1e2f0eSAndrew Rist  * distributed with this work for additional information
6*0a1e2f0eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*0a1e2f0eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*0a1e2f0eSAndrew Rist  * "License"); you may not use this file except in compliance
9*0a1e2f0eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*0a1e2f0eSAndrew Rist  *
11*0a1e2f0eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*0a1e2f0eSAndrew Rist  *
13*0a1e2f0eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*0a1e2f0eSAndrew Rist  * software distributed under the License is distributed on an
15*0a1e2f0eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*0a1e2f0eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*0a1e2f0eSAndrew Rist  * specific language governing permissions and limitations
18*0a1e2f0eSAndrew Rist  * under the License.
19*0a1e2f0eSAndrew Rist  *
20*0a1e2f0eSAndrew Rist  *************************************************************/
21*0a1e2f0eSAndrew Rist 
22*0a1e2f0eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir /* Information:
25cdf0e10cSrcweir  * This class implements a mechanism to lock a users installation directory,
26cdf0e10cSrcweir  * which is necessesary because instances of staroffice could be running on
27cdf0e10cSrcweir  * different hosts while using the same directory thus causing data
28cdf0e10cSrcweir  * inconsistency.
29cdf0e10cSrcweir  * When an existing lock is detected, the user will be asked whether he wants
30cdf0e10cSrcweir  * to continue anyway, thus removing the lock and replacing it with a new one
31cdf0e10cSrcweir  *
32cdf0e10cSrcweir  * ideas:
33cdf0e10cSrcweir  * - store information about user and host and time in the lockfile and display
34cdf0e10cSrcweir  * these when asking whether to remove the lockfile.
35cdf0e10cSrcweir  * - periodically check the lockfile and warn the user when it gets replaced
36cdf0e10cSrcweir  *
37cdf0e10cSrcweir  */
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "sal/types.h"
40cdf0e10cSrcweir #include "rtl/ustring.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class ByteString;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace desktop {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	class Lockfile;
47cdf0e10cSrcweir 	bool Lockfile_execWarning( Lockfile * that );
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	class Lockfile
50cdf0e10cSrcweir 	{
51cdf0e10cSrcweir 	public:
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 		// contructs a new lockfile onject
54cdf0e10cSrcweir 		Lockfile( bool bIPCserver = true );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir         // separating GUI code:
57cdf0e10cSrcweir         typedef bool (* fpExecWarning)( Lockfile * that );
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 		// checks the lockfile, asks user when lockfile is
60cdf0e10cSrcweir 		// found (iff gui) and returns false when we may not continue
61cdf0e10cSrcweir 		sal_Bool check( fpExecWarning execWarning );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 		// removes the lockfile. should only be called in exceptional situations
64cdf0e10cSrcweir 		void clean(void);
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 		// removes the lockfile
67cdf0e10cSrcweir 		~Lockfile(void);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	private:
70cdf0e10cSrcweir 		// data in lockfile
71cdf0e10cSrcweir 		static const ByteString Group();
72cdf0e10cSrcweir 		static const ByteString Userkey();
73cdf0e10cSrcweir 		static const ByteString Hostkey();
74cdf0e10cSrcweir 		static const ByteString Stampkey();
75cdf0e10cSrcweir 		static const ByteString Timekey();
76cdf0e10cSrcweir 		static const ByteString IPCkey();
77cdf0e10cSrcweir 		// lockfilename
78cdf0e10cSrcweir 		static const rtl::OUString Suffix();
79cdf0e10cSrcweir 		bool m_bIPCserver;
80cdf0e10cSrcweir 		// full qualified name (file://-url) of the lockfile
81cdf0e10cSrcweir 		rtl::OUString m_aLockname;
82cdf0e10cSrcweir 		// flag whether the d'tor should delete the lock
83cdf0e10cSrcweir 		sal_Bool m_bRemove;
84cdf0e10cSrcweir 		sal_Bool m_bIsLocked;
85cdf0e10cSrcweir 		// ID
86cdf0e10cSrcweir 		rtl::OUString m_aId;
87cdf0e10cSrcweir 		rtl::OUString m_aDate;
88cdf0e10cSrcweir 		// access to data in file
89cdf0e10cSrcweir 		void syncToFile(void) const;
90cdf0e10cSrcweir 		sal_Bool isStale(void) const;
91cdf0e10cSrcweir         friend bool Lockfile_execWarning( Lockfile * that );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	};
94cdf0e10cSrcweir 
95cdf0e10cSrcweir }
96