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