From db29b21d2c79218a0fe1affca312b5751b825321 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 27 Mar 2008 00:58:31 -0500 Subject: [PATCH] Work on moving journaling into engine process. --- Engine/Loggable.C | 174 +++++++++++++-------------------------- Engine/Loggable.H | 3 + Engine/Peaks.H | 8 +- Engine/Timeline_Server.C | 3 +- Engine/main.C | 12 ++- 5 files changed, 75 insertions(+), 125 deletions(-) diff --git a/Engine/Loggable.C b/Engine/Loggable.C index 6bd680e..6b078ab 100644 --- a/Engine/Loggable.C +++ b/Engine/Loggable.C @@ -47,8 +47,11 @@ Loggable::open ( const char *filename ) return true; } -/** sigh. parse a string of ":name value :name value" pairs into an array of strings, one per pair */ -// FIXME: doesn't handle the case of :name ":foo bar". Also, quotes should be removed here, not in client code. +/** sigh. parse a string of ":name value :name value" pairs into an + * 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 char ** parse_alist( const char *s ) @@ -108,68 +111,66 @@ void free_sa ( char **sa ) free( sa ); } -/* void */ -/* Loggable::redo ( const char *s ) */ -/* { */ -/* int id; */ -/* sscanf( s, "%*s %X ", &id ); */ -/* Loggable *l = find( id ); */ -/* // assert( l ); */ +/** 'do' a message like "Region 0xF1 set :r 123" */ +bool +Loggable::do_this ( const char *s, bool reverse ) +{ + int id; + sscanf( s, "%*s %X ", &id ); + Loggable *l = find( id ); +// assert( l ); -/* char classname[40]; */ -/* char command[40]; */ -/* char *arguments; */ + char classname[40]; + char command[40]; + 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 ) */ -/* { */ -/* printf( "corrupt undo?\n" ); */ -/* abort(); */ -/* } */ + l->log_start(); + l->set( sa ); + l->log_end(); + } + 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 Loggable::undo ( void ) @@ -210,16 +211,8 @@ Loggable::undo ( void ) } s++; - 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 ) ) { printf( "corrupt undo file or no undo entries.\n" ); @@ -268,58 +261,7 @@ Loggable::undo ( void ) printf( "undoing \"%s\"\n", s ); - int id; - 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; - } + do_this( s, true ); s -= 2; } diff --git a/Engine/Loggable.H b/Engine/Loggable.H index 1bd43e0..a1b336e 100644 --- a/Engine/Loggable.H +++ b/Engine/Loggable.H @@ -156,6 +156,9 @@ public: virtual void set ( char **sa ) = 0; // void log ( const char *module, const char *action, const char *fmt, ... ); + + static bool do_this ( const char *s, bool reverse ); + protected: void log_start ( void ); diff --git a/Engine/Peaks.H b/Engine/Peaks.H index a2747aa..46e03ba 100644 --- a/Engine/Peaks.H +++ b/Engine/Peaks.H @@ -35,16 +35,16 @@ class Peaks struct peakdata { - int chunksize; /* should always be a power of 2 */ + int chunksize; /* should always be a power of 2 */ Peak data[]; }; struct peakbuffer { - size_t size; /* total allocation size */ - size_t len; /* number of peaks */ - nframes_t offset; /* starting sample */ + size_t size; /* total allocation size */ + size_t len; /* number of peaks */ + nframes_t offset; /* starting sample */ peakdata *buf; diff --git a/Engine/Timeline_Server.C b/Engine/Timeline_Server.C index e59bbfd..3cbb013 100644 --- a/Engine/Timeline_Server.C +++ b/Engine/Timeline_Server.C @@ -31,7 +31,6 @@ /* Timeline Server. - The timeline server runs in its own thread and manages communication 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 ); + // Loggable::do( buf ); + send( s, "fuckoff\n", strlen( "fuckoff\n" ), 0 ); } diff --git a/Engine/main.C b/Engine/main.C index 1ba4598..6f27b5f 100644 --- a/Engine/main.C +++ b/Engine/main.C @@ -62,12 +62,16 @@ int main ( int argc, char **argv ) { -/* Timeline_Server tls( 6110 ); */ + if ( ! fork() ) + { + Peak_Server pks( 6111 ); -/* tls.run(); */ + pks.run(); + exit( 0 ); + } + Timeline_Server tls( 6110 ); - Peak_Server pks( 6111 ); + tls.run(); - pks.run(); }