Update ooo320-m1
[ooovba.git] / desktop / source / app / lockfile.hxx
blob8a65ae22a56b6c805d72bf338a3651184b18374a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lockfile.hxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 /* Information:
32 * This class implements a mechanism to lock a users installation directory,
33 * which is necessesary because instances of staroffice could be running on
34 * different hosts while using the same directory thus causing data
35 * inconsistency.
36 * When an existing lock is detected, the user will be asked whether he wants
37 * to continue anyway, thus removing the lock and replacing it with a new one
39 * ideas:
40 * - store information about user and host and time in the lockfile and display
41 * these when asking whether to remove the lockfile.
42 * - periodically check the lockfile and warn the user when it gets replaced
46 #include "sal/types.h"
47 #include "rtl/ustring.hxx"
49 class ByteString;
51 #define LOCKFILE_SUFFIX rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/.lock" ) )
52 #define LOCKFILE_GROUP ByteString( "Lockdata" )
53 #define LOCKFILE_USERKEY ByteString( "User" )
54 #define LOCKFILE_HOSTKEY ByteString( "Host" )
55 #define LOCKFILE_STAMPKEY ByteString( "Stamp" )
56 #define LOCKFILE_TIMEKEY ByteString( "Time" )
57 #define LOCKFILE_IPCKEY ByteString( "IPCServer" )
59 namespace desktop {
61 class Lockfile;
62 bool Lockfile_execWarning( Lockfile * that );
64 class Lockfile
66 public:
68 // contructs a new lockfile onject
69 Lockfile( bool bIPCserver = true );
71 // separating GUI code:
72 typedef bool (* fpExecWarning)( Lockfile * that );
74 // checks the lockfile, asks user when lockfile is
75 // found (iff gui) and returns false when we may not continue
76 sal_Bool check( fpExecWarning execWarning );
78 // removes the lockfile. should only be called in exceptional situations
79 void clean(void);
81 // removes the lockfile
82 ~Lockfile(void);
84 private:
85 bool m_bIPCserver;
86 // full qualified name (file://-url) of the lockfile
87 rtl::OUString m_aLockname;
88 // flag whether the d'tor should delete the lock
89 sal_Bool m_bRemove;
90 sal_Bool m_bIsLocked;
91 // ID
92 rtl::OUString m_aId;
93 rtl::OUString m_aDate;
94 // access to data in file
95 void syncToFile(void) const;
96 sal_Bool isStale(void) const;
97 friend bool Lockfile_execWarning( Lockfile * that );