/* * Removal of this header is illegal. * Written by Scott Auge scott_auge@yahoo.com sauge@amduus.com * Copyright (c) 2004 Amduus Information Works, Inc. www.amduus.com * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Amduus Information Works * Inc. and its contributors. * 4. Neither the name of Amduus Information Works, Inc. nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY AMDUUS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AMDUUS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ &IF DEFINED(objmgr_i) = 0 &THEN &GLOBAL-DEFINE objmgr_i YEP DEF VAR RCSVersion_objmgr_i AS CHARACTER INIT "$Header$" NO-UNDO. &ENDIF {ttobj.i {1}} DEF VARIABLE OM_cErrCode AS CHARACTER NO-UNDO. DEF VARIABLE OM_cErrMsg AS CHARACTER NO-UNDO. /*****************************************************************************/ /* This is the procedure programmers should call into initialize an object */ /* 1 is the programmer name the object should be called by. */ /* 2 is the program the object resides in. */ /* NOTE: This routine automatically calls Constructor in the object. Use */ /* BaseAddObjMgr if you wish to manually start up the object. */ /* NOTE: The object does not need Constructor defined. */ /*****************************************************************************/ PROCEDURE OMAdd: DEF INPUT PARAMETER cName AS CHARACTER NO-UNDO. DEF INPUT PARAMETER cPrgName AS CHARACTER NO-UNDO. DEF VAR hTemp AS HANDLE NO-UNDO. RUN VALUE(cPrgName) PERSISTENT SET hTemp NO-ERROR. RUN BaseAddObjMgr (INPUT cName, INPUT hTemp). IF OM_cErrCode <> "000" THEN RETURN. RUN Init IN hTemp (INPUT cName) NO-ERROR. END. /* AddObjMgr */ /*****************************************************************************/ /* This is the basic table management for the creation of an object. The */ /* programmer would need to manually instance the object and call the con- */ /* structor, etc. to manage the object. Best to use AddObjMgr. */ /*****************************************************************************/ PROCEDURE BaseAddObjMgr: DEF INPUT PARAMETER cName AS CHARACTER NO-UNDO. DEF INPUT PARAMETER hHandle AS HANDLE NO-UNDO. ASSIGN OM_cErrCode = "000" OM_cErrMsg = "No Error". FIND ttObjMgr NO-LOCK WHERE ttObjMgr.ObjName = cName NO-ERROR. IF AVAILABLE ttObjMgr THEN DO: ASSIGN OM_cErrCode = "100" OM_cErrMsg = "Object by than name already exists". RETURN. END. /* IF AVAILABLE ttObjMgr */ CREATE ttObjMgr. ASSIGN ttObjMgr.ObjName = cName. ASSIGN ttObjMgr.ObjHandle = hHandle. END. /* PROCEDURE AddObjMgr */ /*****************************************************************************/ /* This is the procedure programmers should call into remove an object */ /* 1 is the programmer name the object should be called by. */ /* NOTE: This routine automatically calls Destroy in the object. Use */ /* BaseDelObjMgr if you wish to manually stop up the object. */ /* NOTE: The object does not need Destroy defined. */ /*****************************************************************************/ PROCEDURE OMDel: DEF INPUT PARAMETER cName AS CHARACTER NO-UNDO. FIND ttObjMgr NO-LOCK WHERE ttObjMgr.ObjName = cName NO-ERROR. IF NOT AVAILABLE ttObjMgr THEN DO: ASSIGN OM_cErrCode = "101" OM_cErrMsg = "Cannot find object entry". RETURN. END. /* IF NOT AVAILABLE ttObjMgr */ RUN Destroy IN ttObjMgr.ObjHandle NO-ERROR. RUN BaseDelObjMgr (INPUT cName). END. /* PROCEDURE DelObjMgr */ /*****************************************************************************/ /* This is a lower level object deletion routine. It is best that the pro- */ /* grammer use the DelObjMgr routine so all the destroy routines are called. */ /*****************************************************************************/ PROCEDURE BaseDelObjMgr: DEF INPUT PARAMETER cName AS CHARACTER NO-UNDO. ASSIGN OM_cErrCode = "000" OM_cErrMsg = "No Error". FIND ttObjMgr EXCLUSIVE-LOCK WHERE ttObjMgr.ObjName = cName NO-ERROR. IF NOT AVAILABLE ttObjMgr THEN DO: ASSIGN OM_cErrCode = "101" OM_cErrMsg = "Cannot find object entry". RETURN. END. /* IF NOT AVAILABLE ttObjMgr */ DELETE PROCEDURE ttObjMgr.ObjHandle. ASSIGN ttObjMgr.ObjHandle = ?. /* Odd... To prevent memory leaks */ DELETE ttObjMgr. END. /* PROCEDURE DelObjMgr */ /*****************************************************************************/ /* This funtion lets the programmer remember their objects by name instead */ /* by handle. This way the programmer can have multiple instances of the */ /* same object. */ /*****************************************************************************/ FUNCTION OMGH RETURNS HANDLE (INPUT cName AS CHARACTER): FIND ttObjMgr NO-LOCK WHERE ttObjMgr.ObjName = cName NO-ERROR. IF NOT AVAILABLE ttObjMgr THEN RETURN ?. ELSE RETURN ttObjMgr.ObjHandle. END. /* FUNCTION ObjMgrGH */