xref: /aoo41x/main/desktop/source/app/lockfile.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 /* Information:
29  * This class implements a mechanism to lock a users installation directory,
30  * which is necessesary because instances of staroffice could be running on
31  * different hosts while using the same directory thus causing data
32  * inconsistency.
33  * When an existing lock is detected, the user will be asked whether he wants
34  * to continue anyway, thus removing the lock and replacing it with a new one
35  *
36  * ideas:
37  * - store information about user and host and time in the lockfile and display
38  * these when asking whether to remove the lockfile.
39  * - periodically check the lockfile and warn the user when it gets replaced
40  *
41  */
42 
43 #include "sal/types.h"
44 #include "rtl/ustring.hxx"
45 
46 class ByteString;
47 
48 namespace desktop {
49 
50 	class Lockfile;
51 	bool Lockfile_execWarning( Lockfile * that );
52 
53 	class Lockfile
54 	{
55 	public:
56 
57 		// contructs a new lockfile onject
58 		Lockfile( bool bIPCserver = true );
59 
60         // separating GUI code:
61         typedef bool (* fpExecWarning)( Lockfile * that );
62 
63 		// checks the lockfile, asks user when lockfile is
64 		// found (iff gui) and returns false when we may not continue
65 		sal_Bool check( fpExecWarning execWarning );
66 
67 		// removes the lockfile. should only be called in exceptional situations
68 		void clean(void);
69 
70 		// removes the lockfile
71 		~Lockfile(void);
72 
73 	private:
74 		// data in lockfile
75 		static const ByteString Group();
76 		static const ByteString Userkey();
77 		static const ByteString Hostkey();
78 		static const ByteString Stampkey();
79 		static const ByteString Timekey();
80 		static const ByteString IPCkey();
81 		// lockfilename
82 		static const rtl::OUString Suffix();
83 		bool m_bIPCserver;
84 		// full qualified name (file://-url) of the lockfile
85 		rtl::OUString m_aLockname;
86 		// flag whether the d'tor should delete the lock
87 		sal_Bool m_bRemove;
88 		sal_Bool m_bIsLocked;
89 		// ID
90 		rtl::OUString m_aId;
91 		rtl::OUString m_aDate;
92 		// access to data in file
93 		void syncToFile(void) const;
94 		sal_Bool isStale(void) const;
95         friend bool Lockfile_execWarning( Lockfile * that );
96 
97 	};
98 
99 }
100