/*static char *SCCSID = "@(#)logevent.c 6.1 90/11/17";*/
/*static char *SCCSID = "@(#)logevent.c      13.2 90/01/25";*/
// @75229 - move to _BTXT seg
#define _BTXT _BTXT

#include <os2def.h>

#include "const.h"
#include "misc.h"
#include "buf.h"
#include "chain.h"
#include "dir.h"
#include "volume.h"
#include "frame.h"
#include "lw.h"
#include "storage.h"
#include "fsdata.h"
#include "tables.h"
#include "log.h"

#include "pr_misc.h"
#include "pr_debug.h"

#if defined (LOGGING) || defined (DEBUG)

/*
 *** Log
 *  LogEvent( PSZ pszFunc,
 *            USHORT iLine,
 *            char chOp,
 *            char chObj,
 *            PVOID pvObj,
 *            USHORT tid,
 *            USHORT usUserDef )
 *
 * Logs events into the log buffer
 *
 * Entry:
 *
 *     pszFunc  = pointer to name of func doing the logging.
 *     iLine    = line number where LogEvent(...) is found in the file
 *     chOp     = ASCII char code for event being logged
 *     chObj    = Type of object being logged
 *     pvObj    = Address of object being logged
 *     tid      = Thread ID of logger
 *     usUserDef= user defined data (2 bytes)
 *
 *
 */
#define PLOGNEXT(p) ((p) == &alogHistory[MAXLOGBUF-1] ? &alogHistory[0] : (p) + 1)

// @76193 - make this a FAR call
void far
LogEvent( char *pszFunc,
          USHORT iLine,
          char chOp,
          char chObj,
          PVOID pvObj,
          USHORT usUserDef )
{
#ifndef PRINT_LOG
    int cbFnc;
    PLOG plogTmp;

    /* bump log ptr */
    plogCurrent = PLOGNEXT (plogCurrent);

    /*
     * set log info
     */

    /* clear name field to all spaces */
    memset( plogCurrent->achFunc, ' ', sizeof(plogCurrent->achFunc) );

    cbFnc = MIN( fstrlen( pszFunc ), sizeof(plogCurrent->achFunc) );
    memcpy( plogCurrent->achFunc, pszFunc, cbFnc );

    plogCurrent->iLine = iLine;
    plogCurrent->chOperation = chOp;
    plogCurrent->chObject = chObj;
    plogCurrent->pvObject = pvObj;
//@76193    plogCurrent->tid = pfrm->usID;
    plogCurrent->tid = GetSlot();
    plogCurrent->usUserDefined = usUserDef;

    if (chObj == LOB_BUF)  // @76193  If this is a buffer, add another info line
    {
       plogCurrent = PLOGNEXT (plogCurrent);           // bump pointer
       memset (plogCurrent, 0, sizeof (*plogCurrent)); // fill it with 0's
       plogCurrent->iLine = ((PBUFNODE)pvObj)->cLocked; //@114986 cLocked is now 2BYTES!
       plogCurrent->chOperation = ((PBUFNODE)pvObj)->bDirtMask;
       plogCurrent->chObject = ((PBUFNODE)pvObj)->fFlag; //@114986 Grab flags too!
       plogCurrent->pvObject = ((PBUFNODE)pvObj)->pblkData;
       (ULONG)(plogCurrent->tid) = ((PBUFNODE)pvObj)->lsnSec;
    }

    plogTmp = PLOGNEXT (plogCurrent);
    memset (plogTmp, -1, sizeof (*plogTmp));

#else
    char *psz, *pszObj;

    dprintf( "<LOG> %s(%d)[slot:%d]:\t", (char *)pszFunc, iLine, pfrm->usID );
    switch( chOp ) {
        case LOP_BLOCK:
            psz = "Block    ";
            break;

        case LOP_WAKEUP:
            psz = "Wakeup   ";
            break;

        case LOP_FLAG:
            psz = "Set Flags";
            break;

        case LOP_UNFLAG:
            psz = "Clr Flags";
            break;

        case LOP_LOCK:
            psz = "Lock     ";
            break;

        case LOP_UNLOCK:
            psz = "UnLock   ";
            break;

        case LOP_INCH:
            psz = "INCR_HOLD";
            break;

        case LOP_DECH:
            psz = "DECR_HOLD";
            break;

        default:
            psz = "x:Operat ";
            psz[0] = chOp;
    }

    switch( chObj ) {
        case LOB_SEM:
            pszObj = "Semaphore ";
            break;

        case LOB_SBD:
            pszObj = "SubDir    ";
            break;

        case LOB_OFT:
            pszObj = "OFT       ";
            break;
        case LOB_BUF:
            pszObj = "Buffer    ";
            break;
        case LOB_TRANS:
            pszObj = "TransList ";
            break;
        case LOB_SPDBUF:
            pszObj = "SPDBUF    ";
            break;

/* @76903 Add Lazywrite object */
        case LOB_LAZYWRT:
            pszObj = "LazyWrite ";
            break;

        default:
            pszObj = "x:Object  ";
            pszObj[0] = chObj;
    }

    dprintf( "%s on %s (%p) [%d]\n", psz, pszObj, pvObj, usUserDef );
#endif
}

#endif
