| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# KLockFile Class Reference

The KLockFile class provides NFS safe lockfiles. More...

`#include <klockfile.h>`

Inheritance diagram for KLockFile:

[legend]
Collaboration diagram for KLockFile:

[legend]
List of all members.

## Public Types
typedef KSharedPtr< KLockFile > | Ptr
enum | LockResult { LockOK = 0, LockFail, LockError, LockStale }
enum | LockOptions { LockNoBlock = 1, LockForce = 2 }
## Public Member Functions
| KLockFile (const QString &file)
| ~KLockFile ()
LockResult | lock (int options=0)
bool | isLocked () const
void | unlock ()
int | staleTime () const
void | setStaleTime (int _staleTime)
bool | getLockInfo (int &pid, QString &hostname, QString &appname)

## Detailed Description

The KLockFile class provides NFS safe lockfiles.

Author:
  Waldo Bastian <bastian@kde.org>

Since:
  3.3

Definition at line 33 of file klockfile.h.

## Member Enumeration Documentation

enum KLockFile::LockResult

  | Possible return values of the lock function. Enumeration values:
  LockOK | Lock was acquired successfully.
  LockFail | The lock could not be acquired because it is held by another process.
  LockError | The lock could not be acquired due to an error.
  LockStale | A stale lock has been detected.
Definition at line 48 of file klockfile.h.

enum KLockFile::LockOptions

  | Enumeration values:
  LockNoBlock | Return immediately, do not wait for the lock to become available.
  LockForce | Automatically remove a lock when a lock is detected that is stale for more than staleTime() seconds.
Definition at line 70 of file klockfile.h.

## Constructor & Destructor Documentation

KLockFile::~KLockFile | ( |  | ) |

| Destroys the object, releasing the lock if held. Definition at line 73 of file klockfile.cpp. References unlock().

## Member Function Documentation

KLockFile::LockResult KLockFile::lock | ( | int | options = `0` | ) |

  | Attempt to acquire the lock. Parameters:
  | options | A set of LockOptions OR'ed together.
Definition at line 199 of file klockfile.cpp. References QTextStream::atEnd(), LockError, LockFail, LockForce, LockNoBlock, LockOK, LockStale, KApplication::random(), and QTextStream::readLine().

bool KLockFile::isLocked | ( |  | ) | const

| Returns whether the lock is held or not. Definition at line 313 of file klockfile.cpp.

void KLockFile::unlock | ( |  | ) |

| Release the lock. Definition at line 318 of file klockfile.cpp. References QFile::encodeName(). Referenced by ~KLockFile().

int KLockFile::staleTime | ( |  | ) | const

| Return the time in seconds after which a lock is considered stale The default is 30. Definition at line 80 of file klockfile.cpp.

void KLockFile::setStaleTime | ( | int | _staleTime | ) |

| Set the time in seconds after which a lock is considered stale. Definition at line 87 of file klockfile.cpp.

bool KLockFile::getLockInfo | ( | int & | pid,
|  | QString & | hostname,
|  | QString & | appname
| ) |

| Returns the pid, hostname and appname of the process holding the lock after the lock functon has returned with LockStale. Returns: false if the pid and hostname could not be determined Definition at line 327 of file klockfile.cpp.

The documentation for this class was generated from the following files:

- klockfile.h
- klockfile.cpp

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:46 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003