HP DECset for OpenVMS
Cookbook for an Integrated Project Development Environment


Previous Contents


Appendix B
CMS Event Handling Example

The following examples illustrate how all the reservations and replacements of an element (T.T) can be written to a file.

Example B-1 CMS_EVENT.C

/* 
**  FACILITY: 
** 
**      CMS_EVENT.C 
** 
**  ABSTRACT: 
** 
**      Event handler for CMS ACTION ACE mechanism - sets 3 global symbols: 
** 
**          CMS$$EVENT_LIBRARY_SPEC   - library_specification_id; 
**               = CMS Library Specification 
**          CMS$$EVENT_PARAMETER_ID   - ace_parameter_id; 
**               = the PARAMETER clause (any string value specified on the ACE) 
**          CMS$$EVENT_HISTORY_RECORD - history_record_id; 
**               = The history line 
** 
**      then calls CMS$HANDLER:CMS_ACTION.COM. 
*/ 
#include <descrip.h>    
#include <lib$routines.h> 
#include <ssdef.h> 
#include <stdio.h> 
#include <string.h> 
 
#define BUF_SIZE                2048 
#define DEL                     127 
#define LDB_SIZE                50 
#define LIB$K_CLI_GLOBAL_SYM    2 
 
typedef struct dsc$descriptor_s DESCRIPTOR; 
 
#define DESC_BLD(name) DESCRIPTOR name = {0,DSC$K_DTYPE_T,DSC$K_CLASS_D,0} 
#define DESC_FIL(name,str)                             \
        name.dsc$w_length = strlen(str);                \
        name.dsc$a_pointer = str 
 
/* 
** CMS$EVENT_ACTION should follow the rules for callback routines.  The 
** routine calling format and arguments are described in CMS Guide, section 
**   8.1.3 "Using Your Own Event Handler" 
*/ 
CMS$EVENT_ACTION( 
    library_data_block,        /* LDB for the current library */ 
    user_param,                /* user_arg value from callable CMS routine */ 
    library_specification_id,  /* string id for CMS library directory spec */ 
    ace_parameter_id,          /* string id from PARAMETER clause of ACE */ 
    history_record_id)         /* string id from history record */ 
 
/* 
** Allocating space for the library data block (LDB).  The LDB is a user- 
** allocated structure, CMS uses to maintain information about the library. 
*/ 
int         library_data_block [LDB_SIZE]; 
int         user_param; 
DESCRIPTOR  **library_specification_id; 
DESCRIPTOR  **ace_parameter_id; 
DESCRIPTOR  **history_record_id; 
 
{ 
int         i; 
int         status; 
char        hist_rec [BUF_SIZE]; 
DESCRIPTOR  hist_id; 
 
    $DESCRIPTOR(command,"@CMS$HANDLER:CMS_ACTION.COM"); 
    $DESCRIPTOR(library_symb,"CMS$$EVENT_LIBRARY_SPEC"); 
    $DESCRIPTOR(history_symb,"CMS$$EVENT_HISTORY_RECORD"); 
    $DESCRIPTOR(param_symb,"CMS$$EVENT_PARAMETER_ID"); 
 
    DESC_BLD(history_desc); 
 
    hist_id = **history_record_id; 
 
    /* Get history record specification */ 
    strncpy ( hist_rec, hist_id.dsc$a_pointer, hist_id.dsc$w_length); 
 
    /* Change embedded 'DEL' characters to spaces */ 
    for (i=hist_id.dsc$w_length; i>=0; i--) 
        { 
        if (hist_rec[i] == DEL) 
            { 
             hist_rec[i] = ' '; 
            } 
        } 
 
    DESC_FIL(history_desc, hist_rec); 
 
    /* Set the symbols */ 
    status = lib$set_symbol(&param_symb, *ace_parameter_id, 
        &LIB$K_CLI_GLOBAL_SYM); 
    if (! (status & SS$_NORMAL)) 
        { 
        lib$signal(status); 
        return status; 
        } 
 
    status = lib$set_symbol(&library_symb, *library_specification_id, 
        &LIB$K_CLI_GLOBAL_SYM); 
    if (! (status & SS$_NORMAL)) 
        { 
        lib$signal(status); 
        return status; 
        } 
 
    status = lib$set_symbol(&history_symb, &history_desc, 
        &LIB$K_CLI_GLOBAL_SYM); 
    if (! (status & SS$_NORMAL)) 
        { 
        lib$signal(status); 
        return status; 
        } 
 
    /* Call the command procedure */ 
    status = lib$spawn (&command); 
    if (! (status & SS$_NORMAL)) 
        { 
        lib$signal(status); 
        return status; 
        } 
 
    /* Delete the symbols */ 
    lib$delete_symbol(&library_symb,&LIB$K_CLI_GLOBAL_SYM); 
    lib$delete_symbol(&history_symb,&LIB$K_CLI_GLOBAL_SYM); 
    lib$delete_symbol(&param_symb,&LIB$K_CLI_GLOBAL_SYM); 
 
    return SS$_NORMAL; 
} 
 

Example B-2 CMS_ACTION.COM

$ VF = F$VERIFY(0) 
$! 
$! CMS_ACTION.COM 
$! 
$! Command procedure invoked by a CMS action routine.  Captures the library 
$! specification, history record, and ACE parameter in a file. 
$! 
$! Inputs : 3 symbols: CMS$$EVENT_LIBRARY_SPEC 
$!                     CMS$$EVENT_HISTORY_RECORD 
$!                   & CMS$$EVENT_PARARMETER_ID (string) 
$! 
$! Output File : EVENT_SEND.LIS 
$! 
$ DELETE := DELETE 
$ OPEN   := OPEN 
$ WRITE  := WRITE 
$ CLOSE  := CLOSE 
$! 
$ OPEN/WRITE tmp event_send.lis 
$ WRITE tmp "" 
$ WRITE tmp "An interesting event has occurred:" 
$ WRITE tmp "" 
$! 
$ WRITE tmp cms$$event_library_spec 
$ WRITE tmp "" 
$! 
$ IF F$TYPE (cms$$event_history_record) .NES. "" 
$ THEN 
$    WRITE tmp cms$$event_history_record 
$ ELSE 
$    ! No history - get name from the process's username 
$    who = F$EDIT (F$GETJPI(""USERNAME"),"TRIM") 
$    WRITE tmp "(No history record for action by ''who' at ''F$TIME()')" 
$ ENDIF 
$! 
$ WRITE tmp cms$$event_parameter_id 
$ WRITE tmp "" 
$! 
$ CLOSE tmp 
$ TYPE event_send.lis 
$ EXIT 
 

Previous Contents Contents