|
From: <bo...@us...> - 2009-11-09 06:11:44
|
Revision: 458
http://gearbox.svn.sourceforge.net/gearbox/?rev=458&view=rev
Author: borax00
Date: 2009-11-09 06:11:37 +0000 (Mon, 09 Nov 2009)
Log Message:
-----------
MR Changes
Modified Paths:
--------------
gearbox/trunk/src/gbxserialacfr/lockfile/lockfile.cpp
gearbox/trunk/src/gbxserialacfr/lockfile/lockfile.h
gearbox/trunk/src/gbxserialacfr/serial.cpp
Modified: gearbox/trunk/src/gbxserialacfr/lockfile/lockfile.cpp
===================================================================
--- gearbox/trunk/src/gbxserialacfr/lockfile/lockfile.cpp 2009-11-08 11:51:23 UTC (rev 457)
+++ gearbox/trunk/src/gbxserialacfr/lockfile/lockfile.cpp 2009-11-09 06:11:37 UTC (rev 458)
@@ -109,7 +109,8 @@
{
unlink(pbuf);
stringstream ss; ss << "device " << dev << " is already locked by process PID " << pidOfLocker;
- throw LockFileException( ss.str() );
+ // Throw a special exception which indicates this case
+ throw LockedByOtherProcessException( ss.str() );
}
else if ( errno == ESRCH )
{
Modified: gearbox/trunk/src/gbxserialacfr/lockfile/lockfile.h
===================================================================
--- gearbox/trunk/src/gbxserialacfr/lockfile/lockfile.h 2009-11-08 11:51:23 UTC (rev 457)
+++ gearbox/trunk/src/gbxserialacfr/lockfile/lockfile.h 2009-11-09 06:11:37 UTC (rev 458)
@@ -23,15 +23,24 @@
{
std::string message_;
public:
- LockFileException(const char *message)
+ LockFileException( const std::string &message )
: message_(message) {}
- LockFileException(const std::string &message)
- : message_(message) {}
~LockFileException()throw(){}
virtual const char* what() const throw() { return message_.c_str(); }
};
//!
+//! @brief Thrown when we try to lock a resource which has been locked by another process.
+//!
+class LockedByOtherProcessException : public LockFileException
+{
+public:
+ LockedByOtherProcessException( const std::string &message )
+ : LockFileException(message) {}
+ ~LockedByOtherProcessException()throw(){}
+};
+
+//!
//! Creates a lock-file (in /var/lock) which can be used to prevent multiple access to
//! a unique resource (eg "/dev/xxx").
//! Stores the PID of the locking process (lockPid), so it can check for stale lock-files.
Modified: gearbox/trunk/src/gbxserialacfr/serial.cpp
===================================================================
--- gearbox/trunk/src/gbxserialacfr/serial.cpp 2009-11-08 11:51:23 UTC (rev 457)
+++ gearbox/trunk/src/gbxserialacfr/serial.cpp 2009-11-09 06:11:37 UTC (rev 458)
@@ -349,11 +349,17 @@
try {
lockFile_ = new lockfile::LockFile( dev );
}
+ catch ( const lockfile::LockedByOtherProcessException &e )
+ {
+ stringstream ss;
+ ss << "Couldn't get lock for device " << dev << ": " << e.what();
+ throw lockfile::LockedByOtherProcessException( ss.str() );
+ }
catch ( const lockfile::LockFileException &e )
{
stringstream ss;
ss << "Couldn't get lock for device " << dev << ": " << e.what();
- throw SerialException( ss.str() );
+ throw lockfile::LockFileException( ss.str() );
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|