Browse Source

Cleanups.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
c1217e649b
5 changed files with 51 additions and 49 deletions
  1. +0
    -2
      Timeline/Loggable.H
  2. +11
    -44
      Timeline/Project.C
  3. +0
    -3
      Timeline/Project.H
  4. +37
    -0
      util/file.C
  5. +3
    -0
      util/file.h

+ 0
- 2
Timeline/Loggable.H View File

@@ -238,13 +238,11 @@ public:


void hold ( void ) void hold ( void )
{ {
printf( "hold\n" );
_this->_nest++; _this->_nest++;
} }


void release ( void ) void release ( void )
{ {
printf( "release\n" );
_this->_nest--; _this->_nest--;
assert( _this->_nest ); assert( _this->_nest );
} }


+ 11
- 44
Timeline/Project.C View File

@@ -24,9 +24,9 @@ project state belongs to Timeline and other classes. */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <errno.h> #include <errno.h>


#include "Loggable.H" #include "Loggable.H"
@@ -46,6 +46,7 @@ extern TLE *tle;
#define PROJECT_VERSION "0.28.0" #define PROJECT_VERSION "0.28.0"


#include "util/debug.h" #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 void
Project::set_name ( const char *name ) Project::set_name ( const char *name )
{ {
@@ -131,7 +92,7 @@ Project::close ( void )


*Project::_name = '\0'; *Project::_name = '\0';


release_lock( ".lock" );
release_lock( &_lockfd, ".lock" );


return true; return true;
} }
@@ -220,7 +181,7 @@ Project::open ( const char *name )


chdir( name ); chdir( name );


if ( ! get_lock( ".lock" ) )
if ( ! acquire_lock( &_lockfd, ".lock" ) )
{ {
WARNING( "Could not open project: locked by another process!" ); WARNING( "Could not open project: locked by another process!" );
return Project::E_LOCKED; return Project::E_LOCKED;
@@ -242,6 +203,8 @@ Project::open ( const char *name )


timeline->zoom_fit(); timeline->zoom_fit();


MESSAGE( "Loaded project \"%s\"", name );

return 0; return 0;
} }


@@ -280,8 +243,12 @@ Project::create ( const char *name, const char *template_name )
timeline->beats_per_minute( 0, 120 ); timeline->beats_per_minute( 0, 120 );
timeline->time( 0, 4, 4 ); timeline->time( 0, 4, 4 );


MESSAGE( "Created project \"%s\" from template \"%s\"", name, template_name );
return true; return true;
} }
else else
{
WARNING( "Failed to open newly created project" );
return false; return false;
}
} }

+ 0
- 3
Timeline/Project.H View File

@@ -28,9 +28,6 @@ class Project
static char _name[256]; static char _name[256];
static char _path[512]; static char _path[512];


static bool get_lock ( const char *filename );
static void release_lock ( const char *filename );

public: public:


enum enum


+ 37
- 0
util/file.C View File

@@ -17,6 +17,7 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/ /*******************************************************************************/


#include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@@ -49,3 +50,39 @@ size ( const char *file )


return st.st_size; 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;
}

+ 3
- 0
util/file.h View File

@@ -20,3 +20,6 @@
unsigned long mtime ( const char *file ); unsigned long mtime ( const char *file );
bool newer ( const char *file1, const char *file2 ); bool newer ( const char *file1, const char *file2 );
unsigned long size ( const char *file ); 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 );

Loading…
Cancel
Save