From c1217e649bf2cbc89e653016c8ff097286e7654a Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Tue, 17 Jun 2008 22:41:15 -0500 Subject: [PATCH] Cleanups. --- Timeline/Loggable.H | 2 -- Timeline/Project.C | 55 +++++++++------------------------------------ Timeline/Project.H | 3 --- util/file.C | 37 ++++++++++++++++++++++++++++++ util/file.h | 3 +++ 5 files changed, 51 insertions(+), 49 deletions(-) diff --git a/Timeline/Loggable.H b/Timeline/Loggable.H index 70f5536..6793d08 100644 --- a/Timeline/Loggable.H +++ b/Timeline/Loggable.H @@ -238,13 +238,11 @@ public: void hold ( void ) { - printf( "hold\n" ); _this->_nest++; } void release ( void ) { - printf( "release\n" ); _this->_nest--; assert( _this->_nest ); } diff --git a/Timeline/Project.C b/Timeline/Project.C index 816e11e..a8cc49f 100644 --- a/Timeline/Project.C +++ b/Timeline/Project.C @@ -24,9 +24,9 @@ project state belongs to Timeline and other classes. */ #include #include #include -#include #include -#include +#include +#include #include #include "Loggable.H" @@ -46,6 +46,7 @@ extern TLE *tle; #define PROJECT_VERSION "0.28.0" #include "util/debug.h" +#include "util/file.h" @@ -56,46 +57,6 @@ int Project::_lockfd = 0; -bool -Project::get_lock ( const char *filename ) -{ - struct flock fl; - - fl.l_type = F_WRLCK; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; - - assert( ! _lockfd ); - - _lockfd = ::creat( filename, 0777 ); - - if ( fcntl( _lockfd, F_SETLK, &fl ) != 0 ) - return false; - - return true; -} - -void -Project::release_lock ( const char *filename ) -{ - unlink( filename ); - - ::close( _lockfd ); - - _lockfd = 0; -} - -static int -exists ( const char *name ) -{ - struct stat st; - - return 0 == stat( name, &st ); -} - - - void Project::set_name ( const char *name ) { @@ -131,7 +92,7 @@ Project::close ( void ) *Project::_name = '\0'; - release_lock( ".lock" ); + release_lock( &_lockfd, ".lock" ); return true; } @@ -220,7 +181,7 @@ Project::open ( const char *name ) chdir( name ); - if ( ! get_lock( ".lock" ) ) + if ( ! acquire_lock( &_lockfd, ".lock" ) ) { WARNING( "Could not open project: locked by another process!" ); return Project::E_LOCKED; @@ -242,6 +203,8 @@ Project::open ( const char *name ) timeline->zoom_fit(); + MESSAGE( "Loaded project \"%s\"", name ); + return 0; } @@ -280,8 +243,12 @@ Project::create ( const char *name, const char *template_name ) timeline->beats_per_minute( 0, 120 ); timeline->time( 0, 4, 4 ); + MESSAGE( "Created project \"%s\" from template \"%s\"", name, template_name ); return true; } else + { + WARNING( "Failed to open newly created project" ); return false; + } } diff --git a/Timeline/Project.H b/Timeline/Project.H index 359344d..2c9f2a4 100644 --- a/Timeline/Project.H +++ b/Timeline/Project.H @@ -28,9 +28,6 @@ class Project static char _name[256]; static char _path[512]; - static bool get_lock ( const char *filename ); - static void release_lock ( const char *filename ); - public: enum diff --git a/util/file.C b/util/file.C index 6beedd7..e201cf1 100644 --- a/util/file.C +++ b/util/file.C @@ -17,6 +17,7 @@ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*******************************************************************************/ +#include #include #include #include @@ -49,3 +50,39 @@ size ( const char *file ) return st.st_size; } + +int +exists ( const char *name ) +{ + struct stat st; + + return 0 == stat( name, &st ); +} + +bool +acquire_lock ( int *lockfd, const char *filename ) +{ + struct flock fl; + + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + + *lockfd = ::creat( filename, 0777 ); + + if ( fcntl( *lockfd, F_SETLK, &fl ) != 0 ) + return false; + + return true; +} + +void +release_lock ( int *lockfd, const char *filename ) +{ + unlink( filename ); + + ::close( *lockfd ); + + *lockfd = 0; +} diff --git a/util/file.h b/util/file.h index be1ae1a..d0411c0 100644 --- a/util/file.h +++ b/util/file.h @@ -20,3 +20,6 @@ unsigned long mtime ( const char *file ); bool newer ( const char *file1, const char *file2 ); unsigned long size ( const char *file ); +int exists ( const char *name ); +bool acquire_lock ( int *lockfd, const char *filename ); +void release_lock ( int *lockfd, const char *filename );