.ad 8
.bm 8
.fm 4
.bt $Copyright by Software AG, 1994$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$vos902c$
.tt 2 $$$
.tt 3 $$                                       $1996-11-25$
***********************************************************
.nf


    ========== licence begin LGPL
    Copyright (C) 2002 SAP AG

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    ========== licence end

.fo
.nf
.sp
Module  :       controlling and monitoring of kernel tasks/threads
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :

.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :

.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :

.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  :
.sp
.cp 3
Created :
.sp
.cp 3
Version : 1994-06-01
.sp
.cp 3
Release :  6.2 	 Date : 1996-11-25
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:

.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:

.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:

.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
/*PRETTY*/

#define MOD__ "vos902c"

#include <ctype.h>

/**\
--------------------------------------- MF__ MOD__ (controlling)
\**/

/**\
--------------------------------------- MF__ MOD__ (monitoring)
\**/

typedef struct KernelMonitorT {
    teo4_monitor_object super;
    XCONS_REC           consoleRec;
    int                 requestTag;
} KernelMonitorT;

    #undef MF__
    #define MF__ MOD__"allocMonitor_MF"
static KernelMonitorT *
allocMonitor_MF (
    tsp9_rte_xerror* xerror)
{
    KernelMonitorT * result;
    int rc;
    
    result = (KernelMonitorT*) malloc (sizeof (KernelMonitorT));
    if (result == NULL) {
        eo44anyError (xerror, "Out of memory");
        return NULL;
    }
    result->consoleRec.ulShmSize = sizeof (CONSOLE_REC);
    rc = sql41c_create_shrd_mem ( (PVOID*) &result->consoleRec.pConsoleRec,
                        result->consoleRec.ulShmSize, NULL, NULL, NULL, 0 );
    if (rc != NO_ERROR) {
        eo44anyError (xerror, "Allocation of shared memory failed");
        return NULL;
    }
    return result;
}

    #undef MF__
    #define MF__ MOD__"monitorTasks_MF"
void
monitorTasks_MF (
    KernelMonitorT* processes,
    tsp9_rte_readdirection flag,
    char* outbuf,
    int bufSize,
    tsp9_rte_xerror* xerror)
{
}

    #undef MF__
    #define MF__ MOD__"os902allTasks"
teo4_monitor_object*
os902allTasks (
    tsp9_cstr args,
    int flags,
    tsp9_rte_xerror* xerror)
{
    KernelMonitorT* kernelMonitor;

    kernelMonitor = allocMonitor_MF (xerror);
    if (kernelMonitor == NULL) {
        return;
    }
    USEVAR_LINT (args);
    USEVAR_LINT (flags);
    kernelMonitor->super.nextRecord = (teo4_monitor_function*)monitorTasks_MF;
    kernelMonitor->super.description = "";
    return &kernelMonitor->super;
}

    #undef MF__
    #define MF__ MOD__"showState_MF"
static void
showState_MF (
    KernelMonitorT* state,
    tsp9_rte_readdirection direction,
    char* outbuf,
    int bufSize,
    tsp9_rte_xerror* xerror)
{
    tsp9_cstr result;

    USEVAR_LINT (direction);
    if (!state->super.started) {
        state->super.started = TRUE;
        switch (state->consoleRec->StateInfo.DatabaseState) {
            case SERVER_STARTING:
                result = XCONS_SHOW_STATE_STARTING ;
                break;
            case SERVER_COLD:
                result = XCONS_SHOW_STATE_COLD;
                break;
            case SERVER_WARM:
                result = XCONS_SHOW_STATE_WARM;
                break;
            case SERVER_SHUTDOWN:
                result = XCONS_SHOW_STATE_SHTDWN;
                break;
            case SERVER_SHUTDOWNREINIT:
                result = XCONS_SHOW_STATE_SHTDWNREI;
                break;
            case SERVER_SHUTDOWNKILL:
                result = XCONS_SHOW_STATE_SHTDWNKIL;
                break;
            case SERVER_STOP:
                result = XCONS_SHOW_STATE_STOP;
                break;
            case SERVER_KILL:
                result = XCONS_SHOW_STATE_KILL;
                break;
            case SERVER_ABORT:
                result = XCONS_SHOW_STATE_ABORT;
                break;
            default:
                result = XCONS_SHOW_STATE_UNKNOWN;
                break;
         }
         if ((int) strlen (result) + 1 <= bufSize) {
            sprintf (outbuf, "%s\n", result);
        }
        else {
            eo44anyError (xerror, "buffer too small");
        }
    }
    else {
        eo44eoshowError (xerror);
    }
}

    #undef MF__
    #define MF__ MOD__"os902state"
teo4_monitor_object*
os902state (
    tsp9_cstr args,
    int flags,
    tsp9_rte_xerror* xerror)
{
    KernelMonitorT* result;
    int rc;

    result = allocMonitor_MF (xerror);
    if (result == NULL) {
        return result;
    }
    USEVAR_LINT (args);
    USEVAR_LINT (flags);
    result->super.nextRecord = (teo4_monitor_function*)showState_MF;
    result->super.description = "State";
    result->requestTag = CON_REQ_STATE;
    return &result->super;
}

    #undef MF__
    #define MF__ MOD__"os902getRemoteInfo"
void
os902getRemoteInfo (
    teo4_monitor_object* monitorHandle,
    tsp9_rte_xerror* xerror)
{
    int                 rc;
    KernelMonitorT     *monitor = (KernelMonitorT*) monitorHandle;
    XCONS_REC          *pcxr = &monitor->consoleRec;
    BOOL                fReturnCodeAvailable;
    
    memset ( pxcr->pConsoleRec, 0, pxcr->ulShmSize );
    rc = sql92c_send (pcxr, monitor->requestTag, 
        &fReturnCodeAvailable);
    if (rc != NO_ERROR) {
        eo44anyError (xerror, "Exchange of shared memory failed");
    }
}

    #undef MF__
    #define MF__ MOD__"sqlxknlclosemonitor"
void
sqlxknlclosemonitor (
    void* monitorHandle)
{
    PVOID memAddr = NULL;
    HANDLE memHandle = 0;
    
    /* gen value from record */
    sql41c_free_shrd_mem (memAddr, memHandle);
    free (monitorHandle);
}

.CM *-END-* code ----------------------------------------
.sp 2
***********************************************************
*-PRETTY-*  statements    :
*-PRETTY-*  lines of code :
*-PRETTY-*  lines in file :
.pa
