/**************************************************************************
 * Source Id :
 *
 * $Id: cserver.cpp,v 1.3 2001/04/20 10:15:01 georgetasker Exp $
 *-------------------------------------------------------------------------
 * Project Notes :
 *
 *  Diamond Base
 *  ============
 *      A solid database implementation, spurred on by the continuing
 *  Metal (Lead) Base saga.
 *
 *  Project Team :
 *        A. Davison
 *        K. Lentin
 *        D. Platt
 *
 *	Project Commenced : 05-02-1993
 *
 *-------------------------------------------------------------------------
 *  Module Notes :
 *
 *  Client server interface.  Used to build other multiple user interfaces
 *
 *  Original Author : Darren Platt
 *
 **************************************************************************/

// FOR NOW::
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#include <diamond/cserver.h>
#include <diamond/diagrel.h>

//
// By instantiating an instance of this class the C/S layer
// gets something with which it can talk to the database cleanly.
//
DiaClient::DiaClient(void)
{
}

//
// When destroyed, the DiaClient provides a service whereby it cleans
// up all the relation instances associated with this connection
//
DiaClient::~DiaClient()
{
	//
	// Find all the relations associated with this connection
	// and delete them
	//
	void *p;
	for(p = relIdLookup.first();!relIdLookup.last();p=relIdLookup.next()) {
		delete (diaGRel *)p;
	}
}

diaRel *DiaClient::createRel(const char *relName)
{
	//
	// This connection wants a new diaGRel, make one for them and
	// remember it for later.
	//
	diaGRel *gp = new diaGRel(relName);
	if (gp) {
		relIdLookup.add(gp->getRefId(),gp);
	}
	return gp;
}

void DiaClient::deleteRel(diaRel *theObject)
{
	//
	// This connection wants to destroy a diaGRel, make one for them and
	// remember it for later.
	//
	diaGRel *gp = (diaGRel *)relIdLookup[theObject->getRefId()];
	if (gp) {
		relIdLookup.del(gp->getRefId());
		delete gp;
	}
}

diaRel *DiaClient::findRel(int relId)
{
	//
	// The sods forgot the object pointer associated with this
	// relId.  Make sure that the relId beint32s to this connection
	// and if so, give them the diaRel pointer.
	//
	return (diaRel *)relIdLookup[relId];
}

//
// $Log: cserver.cpp,v $
// Revision 1.3  2001/04/20 10:15:01  georgetasker
// Cygwin compilation fixes, compilation speed enhancements
// Code modified to get rid of some compiler warnings
//
// Revision 1.2  2001/04/19 21:12:54  georgetasker
// cygwin compilation fixes
//
// Revision 1.1  2001/04/04 12:05:49  aleksandras
// forgotten diamond .cpps
//
// Revision 1.1  1996/02/01  21:30:16  dmb
// Initial revision
//
//
