/*
 ******************************************************************************
 *  Copyright 1984-1993 United States Data Corporation. All Rights Reserved.
 ******************************************************************************
 *                                - NOTICE -
 *
 *  The information contained herein is confidential information of United
 *  States Data Corporation, a Delaware corporation, and is protected by
 *  United States copyright and trade secret law and international treaties.
 *  This information is not to be disclosed, used or copied by or transferred
 *  to any individual, corporation, company or other person without the
 *  express written permission of United States Data Corporation.
 ******************************************************************************
 *
 * Module:	HDT_DBSM.H
 *
 *	Header file for database session manager API.
 *
 * History:
 *		bjc 04/29/93	Created. 
 */


#ifndef _DBSM_INCLUDED
#define _DBSM_INCLUDED

#include <hdt_base.h>		/* Base Definitions for the API */
#include <hdt_dbs.h>	

/*
 ************************************************************************
 *                              Constants                               * 
 ************************************************************************
 */

#define DBSM_NOSESSION	(-2)	/* unable to find session to detach */

/*
 ************************************************************************
 *                              Structures                              * 
 ************************************************************************
 */

/* 
 * DBSM - DataBase Session Manager structure
 *
 * A database session structure manager performs the book keeping for 
 * all open sessions.  When the task requests a session from the session
 * manager, the session manager searches through the open connections for
 * a equivalent session.  If found, te database session manager (DBSM) 
 * returns the existing session and increments the session's attachment
 * count.  If not found, the DBSM opens a new connection.
 *
 * On the disconnect half, a session is only closed when the attachments
 * to the session equal zero.
 * 
 */

typedef struct 
{
	DBS 	*sessions;		/* open database sessions */
	int 	sess_cnt;		/* number of sessions */
	DBS	*next_dbs; 		/* place holder for get_first|next */
} DBSM;


/*
 ************************************************************************
 *                              Macros                                  *       
 ************************************************************************
 */

#define dbsm_get_sess_cnt(p)		((p)->sess_cnt)


/*
 ************************************************************************
 *                         Function Prototypes                          * 
 ************************************************************************
 */


#ifdef __cplusplus
extern "C" {
#endif

extern DBSM*	dbsm_create(void);
extern void	dbsm_destroy(DBSM *dbsm);
extern DBS*	dbsm_attach(DBSM *dbsm, char *alias, 
		            TAG *send_mbx, TAG *recv_mbx, id_t task_id);
extern DBS*	dbsm_get_first(DBSM *dbsm);
extern DBS*	dbsm_get_next(DBSM *dbsm);
extern int	dbsm_detach(DBSM *dbsm, DBS *dbs);
extern int	dbsm_commit(DBSM *dbsm, int force);
extern int	dbsm_commit_mode(DBSM *dbsm, int force, int mode);

#ifdef __cplusplus
}
#endif

#endif

