Work on moving entity tables into sessions.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5475 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-10-09 06:56:26 +00:00
parent 981bb4fbec
commit 48ac2e2dcb
9 changed files with 75 additions and 42 deletions

View File

@ -119,8 +119,11 @@ struct uiFreqTypeTuple uiFreqTypeStrs[] = {
/** /**
* Struct passed around as user-data when parsing the FreqSpec. * Struct passed around as user-data when parsing the FreqSpec.
**/ **/
typedef struct _freqSpecParseData { typedef struct
{
FreqSpec *fs; /* FreqSpec we're parsing into. */ FreqSpec *fs; /* FreqSpec we're parsing into. */
GNCSession *session; /* Session we're loading into. */
/* fields used in the union of unions... :) */ /* fields used in the union of unions... :) */
GDate once_day; /* once */ GDate once_day; /* once */
gint64 interval; /* all [except once] */ gint64 interval; /* all [except once] */
@ -143,8 +146,6 @@ fspd_init( fsParseData *fspd )
g_date_clear( &fspd->once_day, 1 ); g_date_clear( &fspd->once_day, 1 );
} }
FreqSpec *dom_tree_to_freqSpec(xmlNodePtr node);
xmlNodePtr xmlNodePtr
gnc_freqSpec_dom_tree_create( FreqSpec *fs ) gnc_freqSpec_dom_tree_create( FreqSpec *fs )
{ {
@ -396,7 +397,7 @@ fs_subelement_handler( xmlNodePtr node, gpointer data )
fsParseData *fspd = data; fsParseData *fspd = data;
FreqSpec *fs; FreqSpec *fs;
gboolean successful; gboolean successful;
fs = dom_tree_to_freqSpec( node ); fs = dom_tree_to_freqSpec( node, fspd->session );
if ( fs == NULL ) if ( fs == NULL )
return FALSE; return FALSE;
fspd->list = g_list_append( fspd->list, fs ); fspd->list = g_list_append( fspd->list, fs );
@ -556,6 +557,7 @@ gnc_freqSpec_end_handler(gpointer data_for_children,
sixtp_gdv2 *globaldata = (sixtp_gdv2*)global_data; sixtp_gdv2 *globaldata = (sixtp_gdv2*)global_data;
fspd_init( &fspd ); fspd_init( &fspd );
fspd.session = globaldata->session;
/* this won't actually get invoked [FreqSpecs aren't top-level /* this won't actually get invoked [FreqSpecs aren't top-level
elements]; see dom_tree_to_freqSpec(), below. */ elements]; see dom_tree_to_freqSpec(), below. */
@ -567,7 +569,7 @@ gnc_freqSpec_end_handler(gpointer data_for_children,
g_return_val_if_fail( tree, FALSE ); g_return_val_if_fail( tree, FALSE );
fspd.fs = xaccFreqSpecMalloc(); fspd.fs = xaccFreqSpecMalloc(globaldata->session);
successful = dom_tree_generic_parse( tree, fs_dom_handlers, &fspd ); successful = dom_tree_generic_parse( tree, fs_dom_handlers, &fspd );
if (!successful) { if (!successful) {
xmlElemDump( stdout, NULL, tree ); xmlElemDump( stdout, NULL, tree );
@ -586,14 +588,14 @@ gnc_freqSpec_sixtp_parser_create(void)
} }
FreqSpec* FreqSpec*
dom_tree_to_freqSpec(xmlNodePtr node) dom_tree_to_freqSpec(xmlNodePtr node, GNCSession *session)
{ {
gboolean successful; gboolean successful;
fsParseData fspd; fsParseData fspd;
fspd_init( &fspd ); fspd_init( &fspd );
fspd.fs = xaccFreqSpecMalloc(); fspd.fs = xaccFreqSpecMalloc(session);
successful = dom_tree_generic_parse( node, fs_dom_handlers, &fspd ); successful = dom_tree_generic_parse( node, fs_dom_handlers, &fspd );
if ( !successful ) { if ( !successful ) {
xaccFreqSpecFree( fspd.fs ); xaccFreqSpecFree( fspd.fs );

View File

@ -358,7 +358,7 @@ sx_freqspec_handler( xmlNodePtr node, gpointer sx_pdata )
g_return_val_if_fail( node, FALSE ); g_return_val_if_fail( node, FALSE );
fs = dom_tree_to_freqSpec( xmlGetLastChild( node ) ); fs = dom_tree_to_freqSpec( xmlGetLastChild( node ), pdata->session );
xaccSchedXactionSetFreqSpec( sx, fs ); xaccSchedXactionSetFreqSpec( sx, fs );
return TRUE; return TRUE;

View File

@ -43,7 +43,7 @@ GUID* dom_tree_to_guid(xmlNodePtr node);
gnc_commodity* dom_tree_to_commodity_ref(xmlNodePtr node, GNCSession *session); gnc_commodity* dom_tree_to_commodity_ref(xmlNodePtr node, GNCSession *session);
gnc_commodity *dom_tree_to_commodity_ref_no_engine(xmlNodePtr node); gnc_commodity *dom_tree_to_commodity_ref_no_engine(xmlNodePtr node);
FreqSpec* dom_tree_to_freqSpec( xmlNodePtr node ); FreqSpec* dom_tree_to_freqSpec( xmlNodePtr node, GNCSession *session );
Timespec* dom_tree_to_timespec(xmlNodePtr node); Timespec* dom_tree_to_timespec(xmlNodePtr node);
GDate* dom_tree_to_gdate(xmlNodePtr node); GDate* dom_tree_to_gdate(xmlNodePtr node);

View File

@ -133,7 +133,7 @@ void subSpecsListMapDelete( gpointer data, gpointer user_data );
/** Local Prototypes *****/ /** Local Prototypes *****/
static void xaccFreqSpecInit( FreqSpec *fs );
static const char * static const char *
get_wday_name(guint day) get_wday_name(guint day)
@ -173,21 +173,29 @@ get_abbrev_month_name(guint month)
**/ **/
static void static void
xaccFreqSpecInit( FreqSpec *fs ) xaccFreqSpecInit( FreqSpec *fs, GNCSession *session )
{ {
g_return_if_fail( fs ); g_return_if_fail( fs );
g_return_if_fail (session);
xaccGUIDNew( &fs->guid ); xaccGUIDNew( &fs->guid );
xaccStoreEntity( fs, &fs->guid, GNC_ID_FREQSPEC ); xaccStoreEntity( fs, &fs->guid, GNC_ID_FREQSPEC );
fs->type = INVALID; fs->type = INVALID;
fs->uift = UIFREQ_ONCE; fs->uift = UIFREQ_ONCE;
memset( &(fs->s), 0, sizeof(fs->s) ); memset( &(fs->s), 0, sizeof(fs->s) );
} }
FreqSpec* FreqSpec*
xaccFreqSpecMalloc(void) xaccFreqSpecMalloc(GNCSession *session)
{ {
FreqSpec *fs = g_new0(FreqSpec, 1); FreqSpec *fs;
xaccFreqSpecInit( fs );
g_return_val_if_fail (session, NULL);
fs = g_new0(FreqSpec, 1);
xaccFreqSpecInit( fs, session );
/* FIXME:event */ /* FIXME:event */
gnc_engine_generate_event( &fs->guid, GNC_EVENT_CREATE ); gnc_engine_generate_event( &fs->guid, GNC_EVENT_CREATE );
return fs; return fs;

View File

@ -30,6 +30,7 @@
#include <glib.h> #include <glib.h>
#include "GNCId.h" #include "GNCId.h"
#include "gnc-engine.h"
/** /**
* Frequency specification. * Frequency specification.
@ -84,7 +85,7 @@ typedef struct gncp_freq_spec FreqSpec;
/** /**
* Allocates memory for a FreqSpec and initializes it. * Allocates memory for a FreqSpec and initializes it.
**/ **/
FreqSpec* xaccFreqSpecMalloc(void); FreqSpec* xaccFreqSpecMalloc(GNCSession *session);
/** /**
* destroys any private data belonging to the FreqSpec. * destroys any private data belonging to the FreqSpec.

View File

@ -53,7 +53,7 @@ xaccSchedXactionInit( SchedXaction *sx, GNCSession *session)
AccountGroup *ag; AccountGroup *ag;
char *name; char *name;
sx->freq = xaccFreqSpecMalloc(); sx->freq = xaccFreqSpecMalloc(session);
book = gnc_session_get_book (session); book = gnc_session_get_book (session);

View File

@ -9,11 +9,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <glib.h> #include <glib.h>
#include <guile/gh.h>
#include "test-stuff.h" #include "test-stuff.h"
#include "FreqSpec.h" #include "FreqSpec.h"
#include "GNCIdP.h" #include "GNCIdP.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-module.h"
#include "gnc-session.h"
static GNCSession *session;
static void static void
test_once (void) test_once (void)
@ -22,7 +27,7 @@ test_once (void)
guint32 i, start_julian; guint32 i, start_julian;
GDate date1, date2, next_date; GDate date1, date2, next_date;
fs = xaccFreqSpecMalloc(); fs = xaccFreqSpecMalloc(session);
for( start_julian = 1; start_julian < 1000; ++start_julian ) { for( start_julian = 1; start_julian < 1000; ++start_julian ) {
g_date_set_julian( &date1, start_julian ); g_date_set_julian( &date1, start_julian );
@ -48,7 +53,7 @@ test_daily (void)
FreqSpec *fs; FreqSpec *fs;
GDate date1, date2, next_date; GDate date1, date2, next_date;
fs = xaccFreqSpecMalloc(); fs = xaccFreqSpecMalloc(session);
g_date_set_dmy( &date1, 1, 1, 2000 ); g_date_set_dmy( &date1, 1, 1, 2000 );
@ -96,7 +101,7 @@ test_weekly (void)
FreqSpec *fs; FreqSpec *fs;
GDate date1, date2, next_date; GDate date1, date2, next_date;
fs = xaccFreqSpecMalloc(); fs = xaccFreqSpecMalloc(session);
/* Use this to test any specific cases which fail, /* Use this to test any specific cases which fail,
* for easy access in the debugger. */ * for easy access in the debugger. */
@ -156,7 +161,7 @@ test_monthly (void)
FreqSpec *fs; FreqSpec *fs;
GDate date0, date1, date2, next_date; GDate date0, date1, date2, next_date;
fs = xaccFreqSpecMalloc(); fs = xaccFreqSpecMalloc(session);
/* Use this to test any specific cases which fail, /* Use this to test any specific cases which fail,
* for easy access in the debugger. */ * for easy access in the debugger. */
@ -229,7 +234,7 @@ test_month_relative (void)
FreqSpec *fs; FreqSpec *fs;
GDate date0, date1, date2, next_date; GDate date0, date1, date2, next_date;
fs = xaccFreqSpecMalloc(); fs = xaccFreqSpecMalloc(session);
/* Use this to test any specific cases which fail, /* Use this to test any specific cases which fail,
* for easy access in the debugger. */ * for easy access in the debugger. */
@ -344,7 +349,7 @@ test_composite (void)
FreqSpec *fs, *fs2; FreqSpec *fs, *fs2;
GDate date0, date1, date2, next_date; GDate date0, date1, date2, next_date;
fs = xaccFreqSpecMalloc(); fs = xaccFreqSpecMalloc(session);
/* Use this to test any specific cases which fail, /* Use this to test any specific cases which fail,
* for easy access in the debugger. */ * for easy access in the debugger. */
@ -366,17 +371,17 @@ test_composite (void)
xaccFreqSpecSetComposite( fs ); xaccFreqSpecSetComposite( fs );
fs2 = xaccFreqSpecMalloc(); fs2 = xaccFreqSpecMalloc(session);
g_date_set_dmy( &date0, 29, 3, 2001 ); /* Wednesday */ g_date_set_dmy( &date0, 29, 3, 2001 ); /* Wednesday */
xaccFreqSpecSetWeekly( fs2, &date0, 2 ); xaccFreqSpecSetWeekly( fs2, &date0, 2 );
xaccFreqSpecCompositeAdd( fs, fs2 ); xaccFreqSpecCompositeAdd( fs, fs2 );
fs2 = xaccFreqSpecMalloc(); fs2 = xaccFreqSpecMalloc(session);
g_date_set_dmy( &date0, 3, 4, 2001 ); /* Tuesday */ g_date_set_dmy( &date0, 3, 4, 2001 ); /* Tuesday */
xaccFreqSpecSetWeekly( fs2, &date0, 2 ); xaccFreqSpecSetWeekly( fs2, &date0, 2 );
xaccFreqSpecCompositeAdd( fs, fs2 ); xaccFreqSpecCompositeAdd( fs, fs2 );
fs2 = xaccFreqSpecMalloc(); fs2 = xaccFreqSpecMalloc(session);
g_date_set_dmy( &date0, 7, 4, 2001 ); /* Saturday */ g_date_set_dmy( &date0, 7, 4, 2001 ); /* Saturday */
xaccFreqSpecSetWeekly( fs2, &date0, 2 ); xaccFreqSpecSetWeekly( fs2, &date0, 2 );
xaccFreqSpecCompositeAdd( fs, fs2 ); xaccFreqSpecCompositeAdd( fs, fs2 );
@ -387,12 +392,14 @@ test_composite (void)
g_date_set_dmy( &date0, 26, 3, 2001 ); g_date_set_dmy( &date0, 26, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 ); xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 29, 3, 2001 ); g_date_set_dmy( &date2, 29, 3, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "first date in sequence" ); do_test( g_date_compare( &date1, &date2 ) == 0,
"first date in sequence" );
g_date_set_dmy( &date0, 27, 3, 2001 ); g_date_set_dmy( &date0, 27, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 ); xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
g_date_set_dmy( &date2, 29, 3, 2001 ); g_date_set_dmy( &date2, 29, 3, 2001 );
do_test( g_date_compare( &date1, &date2 ) == 0, "first date in sequence" ); do_test( g_date_compare( &date1, &date2 ) == 0,
"first date in sequence" );
g_date_set_dmy( &date0, 28, 3, 2001 ); g_date_set_dmy( &date0, 28, 3, 2001 );
xaccFreqSpecGetNextInstance( fs, &date0, &date1 ); xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
@ -517,16 +524,18 @@ test_composite (void)
xaccFreqSpecFree(fs); xaccFreqSpecFree(fs);
} }
int static void
main( int argc, char* argv[] ) guile_main( int argc, char* argv[] )
{ {
gnc_module_load("gnucash/engine", 0);
g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING ); g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
#if 0 #if 0
set_success_print(TRUE); set_success_print(TRUE);
#endif #endif
gnc_engine_init (argc, argv); session = gnc_session_new ();
test_once(); test_once();
@ -540,6 +549,16 @@ main( int argc, char* argv[] )
test_composite(); test_composite();
gnc_session_destroy (session);
print_test_results(); print_test_results();
return get_rv(); exit (get_rv());
}
int
main (int argc, char **argv)
{
gh_enter (argc, argv, guile_main);
return 0;
} }

View File

@ -21,16 +21,17 @@
* * * *
\********************************************************************/ \********************************************************************/
#include <math.h>
#include "config.h" #include "config.h"
#include <time.h>
#include <glib.h> #include <glib.h>
#include <math.h>
#include <time.h>
#include "FreqSpec.h"
#include "dialog-utils.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "gnc-frequency.h" #include "gnc-frequency.h"
#include "dialog-utils.h" #include "gnc-ui-util.h"
#include "FreqSpec.h"
static short module = MOD_SX; static short module = MOD_SX;
@ -611,7 +612,7 @@ gnc_frequency_save_state( GNCFrequency *gf, FreqSpec *fs, GDate *outStartDate )
for ( i=1; i<6; i++ ) { for ( i=1; i<6; i++ ) {
*gd2 = *gd; *gd2 = *gd;
g_date_add_days( gd2, i ); g_date_add_days( gd2, i );
tmpFS = xaccFreqSpecMalloc(); tmpFS = xaccFreqSpecMalloc(gnc_get_current_session ());
xaccFreqSpecSetWeekly( tmpFS, gd2, tmpInt ); xaccFreqSpecSetWeekly( tmpFS, gd2, tmpInt );
xaccFreqSpecCompositeAdd( fs, tmpFS ); xaccFreqSpecCompositeAdd( fs, tmpFS );
} }
@ -638,7 +639,8 @@ gnc_frequency_save_state( GNCFrequency *gf, FreqSpec *fs, GDate *outStartDate )
o = glade_xml_get_widget( gf->gxml, str ); o = glade_xml_get_widget( gf->gxml, str );
if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(o) ) ) { if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(o) ) ) {
tmpFS = xaccFreqSpecMalloc(); tmpFS = xaccFreqSpecMalloc
(gnc_get_current_session ());
xaccFreqSpecSetUIType( tmpFS, uift ); xaccFreqSpecSetUIType( tmpFS, uift );
/* struct-copy is expected to work, here */ /* struct-copy is expected to work, here */
/* [wish we didn't have to know about the GDate implementation...] */ /* [wish we didn't have to know about the GDate implementation...] */
@ -670,7 +672,7 @@ gnc_frequency_save_state( GNCFrequency *gf, FreqSpec *fs, GDate *outStartDate )
o = glade_xml_get_widget( gf->gxml, "semimonthly_first" ); o = glade_xml_get_widget( gf->gxml, "semimonthly_first" );
day = gnc_option_menu_get_active( GTK_WIDGET(o) )+1; day = gnc_option_menu_get_active( GTK_WIDGET(o) )+1;
tmpFS = xaccFreqSpecMalloc(); tmpFS = xaccFreqSpecMalloc(gnc_get_current_session ());
tmpTm = g_new0( struct tm, 1 ); tmpTm = g_new0( struct tm, 1 );
g_date_to_struct_tm( gd, tmpTm ); g_date_to_struct_tm( gd, tmpTm );
if ( day >= tmpTm->tm_mday ) { if ( day >= tmpTm->tm_mday ) {
@ -687,7 +689,7 @@ gnc_frequency_save_state( GNCFrequency *gf, FreqSpec *fs, GDate *outStartDate )
o = glade_xml_get_widget( gf->gxml, "semimonthly_second" ); o = glade_xml_get_widget( gf->gxml, "semimonthly_second" );
day = gnc_option_menu_get_active( GTK_WIDGET(o) )+1; day = gnc_option_menu_get_active( GTK_WIDGET(o) )+1;
tmpFS = xaccFreqSpecMalloc(); tmpFS = xaccFreqSpecMalloc(gnc_get_current_session ());
tmpTimeT = gnome_date_edit_get_date( gf->startDate ); tmpTimeT = gnome_date_edit_get_date( gf->startDate );
gd = g_date_new(); gd = g_date_new();
g_date_set_time( gd, tmpTimeT ); g_date_set_time( gd, tmpTimeT );
@ -799,7 +801,8 @@ static void
update_cal( GNCFrequency *gf, GtkCalendar *cal ) update_cal( GNCFrequency *gf, GtkCalendar *cal )
{ {
FreqSpec *fs; FreqSpec *fs;
fs = xaccFreqSpecMalloc();
fs = xaccFreqSpecMalloc(gnc_get_current_session ());
gnc_frequency_save_state( gf, fs, NULL ); gnc_frequency_save_state( gf, fs, NULL );
mark_calendar( cal, fs ); mark_calendar( cal, fs );
xaccFreqSpecFree( fs ); xaccFreqSpecFree( fs );

View File

@ -250,7 +250,7 @@ sxftd_compute_sx(SXFromTransInfo *sxfti)
g_date_set_time(&date, trans_t); g_date_set_time(&date, trans_t);
fs = xaccFreqSpecMalloc(); fs = xaccFreqSpecMalloc(gnc_get_current_session ());
/* get the frequency */ /* get the frequency */
@ -274,7 +274,7 @@ sxftd_compute_sx(SXFromTransInfo *sxfti)
case FREQ_WEEKLY: case FREQ_WEEKLY:
g_date_add_days(&date, 7); g_date_add_days(&date, 7);
tmpfs = xaccFreqSpecMalloc(); tmpfs = xaccFreqSpecMalloc(gnc_get_current_session ());
xaccFreqSpecSetComposite(fs); xaccFreqSpecSetComposite(fs);
xaccFreqSpecSetWeekly(tmpfs, &date, 1); xaccFreqSpecSetWeekly(tmpfs, &date, 1);
xaccFreqSpecSetUIType(fs, UIFREQ_WEEKLY); xaccFreqSpecSetUIType(fs, UIFREQ_WEEKLY);