Work on moving journaling into engine process.

This commit is contained in:
Jonathan Moore Liles 2008-03-27 00:58:31 -05:00
parent 6abd18c4ca
commit db29b21d2c
5 changed files with 75 additions and 125 deletions

View File

@ -47,8 +47,11 @@ Loggable::open ( const char *filename )
return true; return true;
} }
/** sigh. parse a string of ":name value :name value" pairs into an array of strings, one per pair */ /** sigh. parse a string of ":name value :name value" pairs into an
// FIXME: doesn't handle the case of :name ":foo bar". Also, quotes should be removed here, not in client code. * array of strings, one per pair */
// FIXME: doesn't handle the case of :name ":foo bar", nested quotes
// or other things it should. Also, quotes should be removed here, not
// in client code.
static static
char ** char **
parse_alist( const char *s ) parse_alist( const char *s )
@ -108,68 +111,66 @@ void free_sa ( char **sa )
free( sa ); free( sa );
} }
/* void */ /** 'do' a message like "Region 0xF1 set :r 123" */
/* Loggable::redo ( const char *s ) */ bool
/* { */ Loggable::do_this ( const char *s, bool reverse )
/* int id; */ {
/* sscanf( s, "%*s %X ", &id ); */ int id;
/* Loggable *l = find( id ); */ sscanf( s, "%*s %X ", &id );
/* // assert( l ); */ Loggable *l = find( id );
// assert( l );
/* char classname[40]; */ char classname[40];
/* char command[40]; */ char command[40];
/* char *arguments; */ char *arguments;
/* sscanf( s, "%s %*X %s %*[^\n<] << %a[^\n]", classname, command, &arguments ); */ const char *create, *destroy;
if ( reverse )
{
sscanf( s, "%s %*X %s %*[^\n<] %a[^\n]", classname, command, &arguments );
create = "destroy";
destroy = "create";
}
else
{
sscanf( s, "%s %*X %s %a[^\n<]", classname, command, &arguments );
create = "create";
destroy = "destroy";
}
/* int ui = _undo_index; */ if ( ! strcmp( command, destroy ) )
{
int id = l->id();
delete l;
_loggables[ id ] = NULL;
}
else if ( ! strcmp( command, "set" ) )
{
printf( "got set command.\n" );
char **sa = parse_alist( arguments );
/* if ( ! l ) */ l->log_start();
/* { */ l->set( sa );
/* printf( "corrupt undo?\n" ); */ l->log_end();
/* abort(); */ }
/* } */ else if ( ! strcmp( command, create ) )
{
char **sa = parse_alist( arguments );
if ( ! _class_map[ string( classname ) ] )
printf( "error class %s is unregistered!\n", classname );
else
{
/* create */
Loggable *l = _class_map[ string( classname ) ]( sa );
l->update_id( id );
l->log_create();
}
}
/* if ( ! strcmp( command, "destroy" ) ) */ }
/* { */
/* char **sa = parse_alist( arguments ); */
/* if ( ! _class_map[ string( classname ) ] ) */
/* printf( "error class %s is unregistered!\n", classname ); */
/* else */
/* { */
/* /\* create *\/ */
/* Loggable *l = _class_map[ string( classname ) ]( sa ); */
/* l->update_id( id ); */
/* } */
/* } */
/* else */
/* if ( ! strcmp( command, "set" ) ) */
/* { */
/* printf( "got set command.\n" ); */
/* char **sa = parse_alist( arguments ); */
/* l->log_start(); */
/* l->set( sa ); */
/* l->log_end(); */
/* } */
/* else */
/* if ( ! strcmp( command, "create" ) ) */
/* { */
/* int id = l->id(); */
/* delete l; */
/* _loggables[ id ] = NULL; */
/* } */
/* } */
void void
Loggable::undo ( void ) Loggable::undo ( void )
@ -210,16 +211,8 @@ Loggable::undo ( void )
} }
s++; s++;
buf[ len ] = NULL; buf[ len ] = NULL;
// fsync( fileno( _fp ) );
/* pop the entry off the end */
/* fseek( _fp, 0 - i, SEEK_END ); */
/* ftruncate( fileno( _fp ), ftell( _fp ) ); */
if ( ! strlen( s ) ) if ( ! strlen( s ) )
{ {
printf( "corrupt undo file or no undo entries.\n" ); printf( "corrupt undo file or no undo entries.\n" );
@ -268,58 +261,7 @@ Loggable::undo ( void )
printf( "undoing \"%s\"\n", s ); printf( "undoing \"%s\"\n", s );
int id; do_this( s, true );
sscanf( s, "%*s %X ", &id );
Loggable *l = find( id );
// assert( l );
char classname[40];
char command[40];
char *arguments;
sscanf( s, "%s %*X %s %*[^\n<] << %a[^\n]", classname, command, &arguments );
/* if ( ! l ) */
/* { */
/* printf( "corrupt undo?\n" ); */
/* abort(); */
/* } */
if ( ! strcmp( command, "destroy" ) )
{
char **sa = parse_alist( arguments );
if ( ! _class_map[ string( classname ) ] )
printf( "error class %s is unregistered!\n", classname );
else
{
/* create */
Loggable *l = _class_map[ string( classname ) ]( sa );
l->update_id( id );
l->log_create();
}
}
else
if ( ! strcmp( command, "set" ) )
{
printf( "got set command.\n" );
char **sa = parse_alist( arguments );
l->log_start();
l->set( sa );
l->log_end();
}
else
if ( ! strcmp( command, "create" ) )
{
int id = l->id();
delete l;
_loggables[ id ] = NULL;
}
s -= 2; s -= 2;
} }

View File

@ -156,6 +156,9 @@ public:
virtual void set ( char **sa ) = 0; virtual void set ( char **sa ) = 0;
// void log ( const char *module, const char *action, const char *fmt, ... ); // void log ( const char *module, const char *action, const char *fmt, ... );
static bool do_this ( const char *s, bool reverse );
protected: protected:
void log_start ( void ); void log_start ( void );

View File

@ -31,7 +31,6 @@
/* Timeline Server. /* Timeline Server.
The timeline server runs in its own thread and manages communication The timeline server runs in its own thread and manages communication
between the engine and any connected timeline editors. between the engine and any connected timeline editors.
@ -71,5 +70,7 @@ Timeline_Server::handle_request ( int s, const char *buf, int l )
{ {
printf( "request: %s", buf ); printf( "request: %s", buf );
// Loggable::do( buf );
send( s, "fuckoff\n", strlen( "fuckoff\n" ), 0 ); send( s, "fuckoff\n", strlen( "fuckoff\n" ), 0 );
} }

View File

@ -62,12 +62,16 @@ int
main ( int argc, char **argv ) main ( int argc, char **argv )
{ {
/* Timeline_Server tls( 6110 ); */ if ( ! fork() )
{
/* tls.run(); */
Peak_Server pks( 6111 ); Peak_Server pks( 6111 );
pks.run(); pks.run();
exit( 0 );
}
Timeline_Server tls( 6110 );
tls.run();
} }