From 40adec3ab4b430a04855cbb2c7be82678c665cc6 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 27 Dec 1998 10:37:03 +0000 Subject: [PATCH] split session source file into header and c code git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1487 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Makefile.in | 5 +- src/engine/Session.c | 117 +-------------------------------- src/engine/Session.h | 144 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 118 deletions(-) create mode 100644 src/engine/Session.h diff --git a/src/engine/Makefile.in b/src/engine/Makefile.in index 0eb12ca4f2..478128eff6 100644 --- a/src/engine/Makefile.in +++ b/src/engine/Makefile.in @@ -32,8 +32,9 @@ CFLAGS = @CFLAGS@ ${INCLPATH} -fpic ###################################################################### # See Makefile.common for information about these variables. -INDEP_SRCS := AccInfo.c Account.c DateUtils.c FileIO.c Group.c LedgerUtils.c \ - QIFIO.c Query.c Scrub.c Transaction.c TransLog.c date.c util.c +INDEP_SRCS := AccInfo.c Account.c DateUtils.c FileIO.c Group.c \ + LedgerUtils.c QIFIO.c Query.c Scrub.c Session.h \ + Transaction.c TransLog.c date.c util.c ###################################################################### all: default diff --git a/src/engine/Session.c b/src/engine/Session.c index 1d0a0ca166..ccb0bdfd35 100644 --- a/src/engine/Session.c +++ b/src/engine/Session.c @@ -26,122 +26,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * \********************************************************************/ -#ifndef __XACC_SESSION_H__ -#define __XACC_SESSION_H__ - -#include "Group.h" - -/** STRUCTS *********************************************************/ -typedef struct _session Session; - -/** PROTOTYPES ******************************************************/ -/* - * The xaccMallocSession() routine simply mallocs memory for a session object. - * The xaccInitSession() routine initializes memry for a session object. - * The xaccSessionDestroy() routine frees the associated memory. - * Note that this routine does *not* free the account group! - */ -Session * xaccMallocSession (void); -void xaccInitSession (Session *); -void xaccSessionDestroy (Session *); - -/* - * The xaccSessionBegin() method begins a new session. It takes as an argument - * the sessionid. The session id must be a string in the form of a URI/URL. - * In the current implementation, only one type of URI is supported, and that - * is the file URI: anything of the form - * "file:/home/somewhere/somedir/file.xac" - * The path part must be a valid path. The file-part must be a valid - * xacc/gnucash-format file. Paths may be relativ or absolute. If the - * path is relative; that is, if the argument is - * "file:somefile.xac" - * then a sequence of search paths are checked for a file of this name. - * - * If the file exists, can be opened and read, then the AccountGroup - * will be returned. Otherwise, NULL is returned, and the reason for - * the NULL can be gotten with xaccSessionGetError(). Note that NULL - * does not always indicate an error ... e.g. if a new file is created, - * NULL is returned, and xaccSessionGetError returns 0. That's OK. - * - * If the file is succesfully opened and read, then a lock will have been - * obtained, and all other access to the file will be denied. This feature - * is intended to be a brute-force global lock to avoid multiple writers. - * - * The xaccSessionGetError() routine can be used to obtain the reason for - * any failure. Standard errno values are used. Calling this routine resets - * the error value. This routine allows an implementation of multiple - * error values, e.g. in a stack, where this routine pops the top value. - * The current implementation has a stack that is one-deep. - * - * Some important error values: - * EINVAL -- bad argument - * ETXTBSY -- session id is in use; its locked by someone else. - * ENOSYS -- unsupported URI type. - * ERANGE -- file path too long - * ENOLCK -- session not open when SessionSave() was called. - * - * - * The xaccSessionGetGroup() method will return the current top-level - * account group. - * - * The xaccSessionSetGroup() method will set the topgroup to a new value. - * - * The xaccSessionSave() method will commit all changes that have been made to - * the top-level account group. In the current implementation, this is nothing - * more than a write to the file of the current AccountGroup of the session. - * If the current AccountGroup is NULL, then the file will be deleted. - * This routine will never release the lock on the file under any - * circustances. - * - * The xaccSessionEnd() method will release the session lock. It will *not* - * save the account group to a file. Thus, this method acts as an "abort" or - * "rollback" primitive. - * - * EXAMPLE USAGE: - * To read, modify and save an existing file: - * ------------------------------------------ - * Session *sess = xaccMallocSession (); - * xaccSessionBegin (sess, "file:/some/file.xac"); - * AccountGroup *grp = xaccSessionGetGroup (sess); - * if (grp) { - * ... edit the session ... - * xaccSessionSave (sess); - * } else { - * int err = xaccSessionGetError (sess); - * printf ("%s\n", strerror (err)); - * } - * xaccSessionEnd (sess); - * xaccSessionDestroy (sess); - * - * To save an existing session to a file: - * -------------------------------------- - * AccountGroup * grp = ... - * ... edit accounts, transactions, etc ... - * Session *sess = xaccMallocSession (); - * xaccSessionBegin (sess, "file:/some/file.xac"); - * xaccSessionSetGroup (sess, grp); - * int err = xaccSessionGetError (sess); - * if (0 == err) { - * xaccSessionSave (sess); - * } else { - * printf ("%s\n", strerror (err)); - * } - * xaccSessionEnd (sess); - * xaccSessionDestroy (sess); - * - */ - -AccountGroup * xaccSessionBegin (Session *, char * sessionid); -int xaccSessionGetError (Session *); -AccountGroup * xaccSessionGetGroup (Session *); -void xaccSessionSetGroup (Session *, AccountGroup *topgroup); - -void xaccSessionSave (Session *); -void xaccSessionEnd (Session *); - - -#endif /* __XACC_SESSION_H__ */ - #include #include #include @@ -154,6 +38,7 @@ void xaccSessionEnd (Session *); #include "FileIO.h" #include "Group.h" +#include "Session.h" #include "util.h" struct _session { diff --git a/src/engine/Session.h b/src/engine/Session.h new file mode 100644 index 0000000000..fc73882a72 --- /dev/null +++ b/src/engine/Session.h @@ -0,0 +1,144 @@ +/* + * FILE: + * Session.h + * + * FUNCTION: + * Provide wrappers for initiating/concluding a file-editing session. + * + * HISTORY: + * Created by Linas Vepstas December 1998 + * Copyright (c) 1998 Linas Vepstas + */ + +/********************************************************************\ + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * +\********************************************************************/ + +#ifndef __XACC_SESSION_H__ +#define __XACC_SESSION_H__ + +#include "Group.h" + +/** STRUCTS *********************************************************/ +typedef struct _session Session; + +/** PROTOTYPES ******************************************************/ +/* + * The xaccMallocSession() routine simply mallocs memory for a session object. + * The xaccInitSession() routine initializes memry for a session object. + * The xaccSessionDestroy() routine frees the associated memory. + * Note that this routine does *not* free the account group! + */ +Session * xaccMallocSession (void); +void xaccInitSession (Session *); +void xaccSessionDestroy (Session *); + +/* + * The xaccSessionBegin() method begins a new session. It takes as an argument + * the sessionid. The session id must be a string in the form of a URI/URL. + * In the current implementation, only one type of URI is supported, and that + * is the file URI: anything of the form + * "file:/home/somewhere/somedir/file.xac" + * The path part must be a valid path. The file-part must be a valid + * xacc/gnucash-format file. Paths may be relativ or absolute. If the + * path is relative; that is, if the argument is + * "file:somefile.xac" + * then a sequence of search paths are checked for a file of this name. + * + * If the file exists, can be opened and read, then the AccountGroup + * will be returned. Otherwise, NULL is returned, and the reason for + * the NULL can be gotten with xaccSessionGetError(). Note that NULL + * does not always indicate an error ... e.g. if a new file is created, + * NULL is returned, and xaccSessionGetError returns 0. That's OK. + * + * If the file is succesfully opened and read, then a lock will have been + * obtained, and all other access to the file will be denied. This feature + * is intended to be a brute-force global lock to avoid multiple writers. + * + * The xaccSessionGetError() routine can be used to obtain the reason for + * any failure. Standard errno values are used. Calling this routine resets + * the error value. This routine allows an implementation of multiple + * error values, e.g. in a stack, where this routine pops the top value. + * The current implementation has a stack that is one-deep. + * + * Some important error values: + * EINVAL -- bad argument + * ETXTBSY -- session id is in use; its locked by someone else. + * ENOSYS -- unsupported URI type. + * ERANGE -- file path too long + * ENOLCK -- session not open when SessionSave() was called. + * + * + * The xaccSessionGetGroup() method will return the current top-level + * account group. + * + * The xaccSessionSetGroup() method will set the topgroup to a new value. + * + * The xaccSessionSave() method will commit all changes that have been made to + * the top-level account group. In the current implementation, this is nothing + * more than a write to the file of the current AccountGroup of the session. + * If the current AccountGroup is NULL, then the file will be deleted. + * This routine will never release the lock on the file under any + * circustances. + * + * The xaccSessionEnd() method will release the session lock. It will *not* + * save the account group to a file. Thus, this method acts as an "abort" or + * "rollback" primitive. + * + * EXAMPLE USAGE: + * To read, modify and save an existing file: + * ------------------------------------------ + * Session *sess = xaccMallocSession (); + * xaccSessionBegin (sess, "file:/some/file.xac"); + * AccountGroup *grp = xaccSessionGetGroup (sess); + * if (grp) { + * ... edit the session ... + * xaccSessionSave (sess); + * } else { + * int err = xaccSessionGetError (sess); + * printf ("%s\n", strerror (err)); + * } + * xaccSessionEnd (sess); + * xaccSessionDestroy (sess); + * + * To save an existing session to a file: + * -------------------------------------- + * AccountGroup * grp = ... + * ... edit accounts, transactions, etc ... + * Session *sess = xaccMallocSession (); + * xaccSessionBegin (sess, "file:/some/file.xac"); + * xaccSessionSetGroup (sess, grp); + * int err = xaccSessionGetError (sess); + * if (0 == err) { + * xaccSessionSave (sess); + * } else { + * printf ("%s\n", strerror (err)); + * } + * xaccSessionEnd (sess); + * xaccSessionDestroy (sess); + * + */ + +AccountGroup * xaccSessionBegin (Session *, char * sessionid); +int xaccSessionGetError (Session *); +AccountGroup * xaccSessionGetGroup (Session *); +void xaccSessionSetGroup (Session *, AccountGroup *topgroup); + +void xaccSessionSave (Session *); +void xaccSessionEnd (Session *); + + +#endif /* __XACC_SESSION_H__ */ +/* ==================== END OF FILE ================== */