<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- /builddir/build/BUILD/libqxt-libqxt-v0.6.2/src/core/qxtfilelock.cpp --> <head> <title>QxtFileLock Class Reference</title> <link href="stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" valign="top" width="32"><a href="http://libqxt.org"><img src="images/qxt-logo.png" width="50" height="40" align="left" border="0" /></a></td> <td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a> · <a href="classes.html"><font color="#004faf">Classes</font></a> · <a href="namespaces.html"><font color="#004faf">Namespaces</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td> <td align="right" valign="top" width="230"></td></tr></table><h1 class="title">QxtFileLock Class Reference<br /><span class="small-subtitle">[<a href="qxtcore.html">QxtCore</a> module]</span> </h1> <p>The QxtFileLock class provides a crossplattform way to lock a <a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a>. <a href="#details">More...</a></p> <pre> #include <QxtFileLock></pre><p>Inherits <a href="http://doc.qtsoftware.com/4.5/qobject.html">QObject</a>.</p> <ul> <li><a href="qxtfilelock-members.html">List of all members, including inherited members</a></li> </ul> <a name="public-types"></a> <h3>Public Types</h3> <ul> <li><div class="fn"></div>enum <b><a href="qxtfilelock.html#Mode-enum">Mode</a></b> { ReadLock, WriteLock, ReadLockWait, WriteLockWait }</li> </ul> <a name="public-functions"></a> <h3>Public Functions</h3> <ul> <li><div class="fn"></div><b><a href="qxtfilelock.html#QxtFileLock">QxtFileLock</a></b> ( QFile * <i>file</i>, const off_t <i>offset</i>, const off_t <i>length</i>, const QxtFileLock::Mode <i>mode</i> = WriteLockWait )</li> <li><div class="fn"></div><b><a href="qxtfilelock.html#dtor.QxtFileLock">~QxtFileLock</a></b> ()</li> <li><div class="fn"></div>QFile * <b><a href="qxtfilelock.html#file">file</a></b> () const</li> <li><div class="fn"></div>bool <b><a href="qxtfilelock.html#isActive">isActive</a></b> () const</li> <li><div class="fn"></div>off_t <b><a href="qxtfilelock.html#length">length</a></b> () const</li> <li><div class="fn"></div>QxtFileLock::Mode <b><a href="qxtfilelock.html#mode">mode</a></b> () const</li> <li><div class="fn"></div>off_t <b><a href="qxtfilelock.html#offset">offset</a></b> () const</li> </ul> <ul> <li><div class="fn"></div>29 public functions inherited from <a href="http://doc.qtsoftware.com/4.5/qobject.html#public-functions">QObject</a></li> </ul> <a name="public-slots"></a> <h3>Public Slots</h3> <ul> <li><div class="fn"></div>bool <b><a href="qxtfilelock.html#lock">lock</a></b> ()</li> <li><div class="fn"></div>bool <b><a href="qxtfilelock.html#unlock">unlock</a></b> ()</li> </ul> <ul> <li><div class="fn"></div>1 public slot inherited from <a href="http://doc.qtsoftware.com/4.5/qobject.html#public-slots">QObject</a></li> </ul> <h3>Additional Inherited Members</h3> <ul> <li><div class="fn"></div>1 property inherited from <a href="http://doc.qtsoftware.com/4.5/qobject.html#properties">QObject</a></li> <li><div class="fn"></div>1 signal inherited from <a href="http://doc.qtsoftware.com/4.5/qobject.html#signals">QObject</a></li> <li><div class="fn"></div>1 public type inherited from <a href="http://doc.qtsoftware.com/4.5/qobject.html#public-variables">QObject</a></li> <li><div class="fn"></div>4 static public members inherited from <a href="http://doc.qtsoftware.com/4.5/qobject.html#static-public-members">QObject</a></li> <li><div class="fn"></div>7 protected functions inherited from <a href="http://doc.qtsoftware.com/4.5/qobject.html#protected-functions">QObject</a></li> <li><div class="fn"></div>2 protected variables inherited from <a href="http://doc.qtsoftware.com/4.5/qobject.html#protected-variables">QObject</a></li> </ul> <a name="details"></a> <hr /> <h2>Detailed Description</h2> <p>The QxtFileLock class provides a crossplattform way to lock a <a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a>.</p> <p>QxtFileLock supports range locking of a file. The File will take parentship of the lock. The lock gets cleaned up with the <a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a>, and it is released when the <a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a> is closed.</p> <p>Example usage:</p> <pre> off_t lockstart = 0x10; off_t locklength = 30 QFile file("test.lock"); <span class="comment"> //the lock gets deleted when file is cleaned up</span> QxtFileLock * writeLock = new QxtFileLock(&file,lockstart,locklength,QxtFileLock::WriteLock); if(file.open(QIODevice::ReadWrite)) { if(writeLock->lock()) { <span class="comment">// some write operations</span> writeLock->unlock(); } else <span class="comment">//lock failed</span> }</pre> <p><b>Note:</b> QxtFileLock behaves different than normal unix locks on *nix. A thread can writelock the region of a file only ONCE if it uses two different handles. A different thread can not writelock a region that is owned by a other thread even if it is the SAME process.</p> <p><b>Note:</b> On *nix this class uses fctnl to lock the file. This may not be compatible to other locking functions like flock and lockf</p> <p><b>Note:</b> Please do not mix QxtFileLock and native file lock calls on the same <a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a>. The behaviour is undefined</p> <p><b>Note:</b> QxtFileLock lives in the same thread as the passed <a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a></p> <p><b>Warning:</b> due to a refactoring issues of <a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a> this class will not work with Qt from version 4.3.0 to 4.3.2</p> <hr /> <h2>Member Type Documentation</h2> <h3 class="fn"><a name="Mode-enum"></a>enum QxtFileLock::Mode</h3> <p>The mode of the lock</p> <p><table border="1" cellpadding="2" cellspacing="1" width="100%"> <tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr> <tr><td valign="top"><tt>QxtFileLock::ReadLock</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">A non blocking read lock</td></tr> <tr><td valign="top"><tt>QxtFileLock::WriteLock</tt></td><td align="center" valign="top"><tt>3</tt></td><td valign="top">A non blocking write lock</td></tr> <tr><td valign="top"><tt>QxtFileLock::ReadLockWait</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">A blocking read lock. The <a href="qxtfilelock.html#lock">lock</a>() function will block until the lock is created.</td></tr> <tr><td valign="top"><tt>QxtFileLock::WriteLockWait</tt></td><td align="center" valign="top"><tt>2</tt></td><td valign="top">A blocking write lock. The <a href="qxtfilelock.html#lock">lock</a>() function will block until the lock is created.</td></tr> </table></p> <hr /> <h2>Member Function Documentation</h2> <h3 class="fn"><a name="QxtFileLock"></a>QxtFileLock::QxtFileLock ( <a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a> * <i>file</i>, const off_t <i>offset</i>, const off_t <i>length</i>, const <a href="qxtfilelock.html#Mode-enum">QxtFileLock::Mode</a> <i>mode</i> = WriteLockWait )</h3> <p>Contructs a new <a href="qxtfilelock.html">QxtFileLock</a>. The lock is not activated. <i>file</i> the file that should be locked <i>offset</i> the offset where the lock starts <i>length</i> the length of the lock <i>mode</i> the lockmode</p> <h3 class="fn"><a name="dtor.QxtFileLock"></a>QxtFileLock::~QxtFileLock ()</h3> <p>Destructs the file lock.</p> <h3 class="fn"><a name="file"></a><a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a> * QxtFileLock::file () const</h3> <p>Returns the file the lock is created on.</p> <h3 class="fn"><a name="isActive"></a>bool QxtFileLock::isActive () const</h3> <p>Returns <tt>true</tt> if the lock is active otherwise it returns <tt>false</tt></p> <h3 class="fn"><a name="length"></a>off_t QxtFileLock::length () const</h3> <p>Returns the length of the lock</p> <h3 class="fn"><a name="lock"></a>bool QxtFileLock::lock () <tt> [slot]</tt></h3> <p>Locks the file Returns <tt>true</tt> if succeeds, <tt>false</tt> otherwise.</p> <h3 class="fn"><a name="mode"></a><a href="qxtfilelock.html#Mode-enum">QxtFileLock::Mode</a> QxtFileLock::mode () const</h3> <p>Returns the mode of the lock</p> <h3 class="fn"><a name="offset"></a>off_t QxtFileLock::offset () const</h3> <p>Returns the offset of the lock</p> <h3 class="fn"><a name="unlock"></a>bool QxtFileLock::unlock () <tt> [slot]</tt></h3> <p>Unlocks the file. Returns <tt>true</tt> if succeeds, <tt>false</tt> otherwise.</p> <p /><address><hr /><div align="center"> <table width="100%" cellspacing="0" border="0"><tr class="address"> <td align="left">Copyright © 2007-2011 <a href="mailto:foundation@libqxt.org">Qxt Foundation</a></td> <td align="right"><div align="right"> <a href="http://libqxt.org">Qxt</a> 0.6.2</div></td> </tr></table></div></address></body> </html>