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 /* Information: 25 * This class implements a mechanism to lock a users installation directory, 26 * which is necessesary because instances of staroffice could be running on 27 * different hosts while using the same directory thus causing data 28 * inconsistency. 29 * When an existing lock is detected, the user will be asked whether he wants 30 * to continue anyway, thus removing the lock and replacing it with a new one 31 * 32 * ideas: 33 * - store information about user and host and time in the lockfile and display 34 * these when asking whether to remove the lockfile. 35 * - periodically check the lockfile and warn the user when it gets replaced 36 * 37 */ 38 39 #include "sal/types.h" 40 #include "rtl/ustring.hxx" 41 42 class ByteString; 43 44 namespace desktop { 45 46 class Lockfile; 47 bool Lockfile_execWarning( Lockfile * that ); 48 49 class Lockfile 50 { 51 public: 52 53 // constructs a new lockfile onject 54 Lockfile( bool bIPCserver = true ); 55 56 // separating GUI code: 57 typedef bool (* fpExecWarning)( Lockfile * that ); 58 59 // checks the lockfile, asks user when lockfile is 60 // found (iff gui) and returns false when we may not continue 61 sal_Bool check( fpExecWarning execWarning ); 62 63 // removes the lockfile. should only be called in exceptional situations 64 void clean(void); 65 66 // removes the lockfile 67 ~Lockfile(void); 68 69 private: 70 // data in lockfile 71 static const ByteString Group(); 72 static const ByteString Userkey(); 73 static const ByteString Hostkey(); 74 static const ByteString Stampkey(); 75 static const ByteString Timekey(); 76 static const ByteString IPCkey(); 77 // lockfilename 78 static const rtl::OUString Suffix(); 79 bool m_bIPCserver; 80 // full qualified name (file://-url) of the lockfile 81 rtl::OUString m_aLockname; 82 // flag whether the d'tor should delete the lock 83 sal_Bool m_bRemove; 84 sal_Bool m_bIsLocked; 85 // ID 86 rtl::OUString m_aId; 87 rtl::OUString m_aDate; 88 // access to data in file 89 void syncToFile(void) const; 90 sal_Bool isStale(void) const; 91 friend bool Lockfile_execWarning( Lockfile * that ); 92 93 }; 94 95 } 96