Improve journaling... Add transactions.
This commit is contained in:
parent
66414fe6b8
commit
49628da177
27
Loggable.C
27
Loggable.C
|
@ -27,6 +27,7 @@
|
||||||
FILE *Loggable::_fp;
|
FILE *Loggable::_fp;
|
||||||
|
|
||||||
int Loggable::_log_id = 0;
|
int Loggable::_log_id = 0;
|
||||||
|
int Loggable::_level = 0;
|
||||||
|
|
||||||
vector <Loggable *> Loggable::_loggables;
|
vector <Loggable *> Loggable::_loggables;
|
||||||
|
|
||||||
|
@ -92,11 +93,11 @@ log_print( char **o, char **n )
|
||||||
/** compare elements of dumps s1 and s2, removing those elements
|
/** compare elements of dumps s1 and s2, removing those elements
|
||||||
of dst which are not changed from src */
|
of dst which are not changed from src */
|
||||||
static
|
static
|
||||||
void
|
bool
|
||||||
log_diff ( char **sa1, char **sa2 )
|
log_diff ( char **sa1, char **sa2 )
|
||||||
{
|
{
|
||||||
if ( ! sa1 )
|
if ( ! sa1 )
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
int w = 0;
|
int w = 0;
|
||||||
for ( int i = 0; sa1[ i ]; ++i )
|
for ( int i = 0; sa1[ i ]; ++i )
|
||||||
|
@ -117,6 +118,8 @@ log_diff ( char **sa1, char **sa2 )
|
||||||
|
|
||||||
sa1[ w ] = NULL;
|
sa1[ w ] = NULL;
|
||||||
sa2[ w ] = NULL;
|
sa2[ w ] = NULL;
|
||||||
|
|
||||||
|
return w == 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,8 +129,12 @@ log_diff ( char **sa1, char **sa2 )
|
||||||
void
|
void
|
||||||
Loggable::log_start ( void )
|
Loggable::log_start ( void )
|
||||||
{
|
{
|
||||||
if ( ! _old_state )
|
// if ( _old_state )
|
||||||
_old_state = log_dump();
|
// log_end();
|
||||||
|
if ( _old_state )
|
||||||
|
return;
|
||||||
|
|
||||||
|
_old_state = log_dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -137,11 +144,13 @@ Loggable::log_end ( void )
|
||||||
|
|
||||||
// if ( _old_state )
|
// if ( _old_state )
|
||||||
|
|
||||||
log_diff( _old_state, _new_state );
|
if ( log_diff( _old_state, _new_state ) )
|
||||||
|
{
|
||||||
|
indent();
|
||||||
|
printf( "%s 0x%X set ", class_name(), _id );
|
||||||
|
|
||||||
printf( "%s 0x%X set ", class_name(), _id );
|
log_print( _old_state, _new_state );
|
||||||
|
}
|
||||||
log_print( _old_state, _new_state );
|
|
||||||
|
|
||||||
free_sa( _old_state );
|
free_sa( _old_state );
|
||||||
if ( _new_state )
|
if ( _new_state )
|
||||||
|
@ -153,6 +162,7 @@ Loggable::log_end ( void )
|
||||||
void
|
void
|
||||||
Loggable::log_create ( void )
|
Loggable::log_create ( void )
|
||||||
{
|
{
|
||||||
|
indent();
|
||||||
printf( "%s 0x%X new ", class_name(), _id );
|
printf( "%s 0x%X new ", class_name(), _id );
|
||||||
|
|
||||||
char **sa = log_dump();
|
char **sa = log_dump();
|
||||||
|
@ -165,6 +175,7 @@ Loggable::log_create ( void )
|
||||||
void
|
void
|
||||||
Loggable::log_destroy ( void )
|
Loggable::log_destroy ( void )
|
||||||
{
|
{
|
||||||
|
indent();
|
||||||
printf( "%s 0x%X destroy ", class_name(), _id );
|
printf( "%s 0x%X destroy ", class_name(), _id );
|
||||||
|
|
||||||
char **sa = log_dump();
|
char **sa = log_dump();
|
||||||
|
|
29
Loggable.H
29
Loggable.H
|
@ -24,7 +24,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
@ -34,6 +34,7 @@ class Loggable
|
||||||
|
|
||||||
static FILE *_fp;
|
static FILE *_fp;
|
||||||
static int _log_id;
|
static int _log_id;
|
||||||
|
static int _level;
|
||||||
|
|
||||||
static vector <Loggable *> _loggables;
|
static vector <Loggable *> _loggables;
|
||||||
|
|
||||||
|
@ -43,10 +44,36 @@ private:
|
||||||
char **_old_state;
|
char **_old_state;
|
||||||
char **_new_state;
|
char **_new_state;
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
void indent ( void )
|
||||||
|
{
|
||||||
|
int n = Loggable::_level;
|
||||||
|
|
||||||
|
while ( n-- )
|
||||||
|
printf( "\t" );
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static bool open ( const char *filename );
|
static bool open ( const char *filename );
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
block_start ( void )
|
||||||
|
{
|
||||||
|
indent();
|
||||||
|
printf( "{\n" );
|
||||||
|
++Loggable::_level;
|
||||||
|
}
|
||||||
|
static
|
||||||
|
void
|
||||||
|
block_end ( void )
|
||||||
|
{
|
||||||
|
assert( --Loggable::_level >= 0 );
|
||||||
|
indent();
|
||||||
|
printf( "}\n" );
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
Loggable *
|
Loggable *
|
||||||
|
|
7
Region.C
7
Region.C
|
@ -184,12 +184,19 @@ Region::handle ( int m )
|
||||||
/* split */
|
/* split */
|
||||||
if ( ! copied )
|
if ( ! copied )
|
||||||
{
|
{
|
||||||
|
Loggable::block_start();
|
||||||
|
|
||||||
Region *copy = new Region( *this );
|
Region *copy = new Region( *this );
|
||||||
|
|
||||||
trim( RIGHT, X );
|
trim( RIGHT, X );
|
||||||
copy->trim( LEFT, X );
|
copy->trim( LEFT, X );
|
||||||
|
|
||||||
_track->add( copy );
|
_track->add( copy );
|
||||||
|
|
||||||
|
log_end();
|
||||||
|
|
||||||
|
Loggable::block_end();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue