星期二, 11月 07, 2023

2006-02-06 如何讓 QSYSOPR 訊息佇列於畫面上自動更新?


如何讓 QSYSOPR 訊息佇列於畫面上自動更新?

此範例是從討論區取得:
http://www.iseriesnetwork.com/isnetforums/showpost.php?p=159391&postcount=7


File   : QRPGLESRC
Member : signal_h
Type   :  RPGLE
Desc   : Copy member

      /if DEFINED(SIGNAL_H_INCLUDED)
      /eof
      /endif
      /define SIGNAL_H_INCLUDED

      *--------------------------------------------------------
      * Available signals
      *--------------------------------------------------------
     D SIGABRT         C                   const(1)
     D SIGIOT          C                   const(1)
     D SIGLOST         C                   const(1)
     D SIGFPE          C                   const(2)
     D SIGILL          C                   const(3)
     D SIGINT          C                   const(4)
     D SIGSEGV         C                   const(5)
     D SIGTERM         C                   const(6)
     D SIGUSR1         C                   const(7)
     D SIGUSR2         C                   const(8)
     D SIGIO           C                   const(9)
     D SIGAIO          C                   const(9)
     D SIGPTY          C                   const(9)
     D SIGALL          C                   const(10)
     D SIGOTHER        C                   const(11)
     D SIGKILL         C                   const(12)
     D SIGPIPE         C                   const(13)
     D SIGALRM         C                   const(14)
     D SIGHUP          C                   const(15)
     D SIGQUIT         C                   const(16)
     D SIGSTOP         C                   const(17)
     D SIGTSTP         C                   const(18)
     D SIGCONT         C                   const(19)
     D SIGCHLD         C                   const(20)
     D SIGCLD          C                   const(20)
     D SIGTTIN         C                   const(21)
     D SIGTTOU         C                   const(22)
     D SIGURG          C                   const(23)
     D SIGIOINT        C                   const(23)
     D SIGPOLL         C                   const(24)
     D SIGPCANCEL      C                   const(25)
     D SIGPALRM        C                   const(26)
     D SIGBUS          C                   const(32)
     D SIGDANGER       C                   const(33)
     D SIGPRE          C                   const(34)
     D SIGSYS          C                   const(35)
     D SIGTRAP         C                   const(36)
     D SIGPROF         C                   const(37)
     D SIGVTALRM       C                   const(38)
     D SIGXCPU         C                   const(39)
     D SIGXFSZ         C                   const(40)

      *--------------------------------------------------------
      * flags
      *--------------------------------------------------------
     D SA_NOCLDSTOP    c                   const(1)
     D SA_NODEFER      c                   const(2)
     D SA_RESETHAND    c                   const(4)
     D SA_SIGINFO      c                   const(8)

      *--------------------------------------------------------
      * sigprocmask() "how" argument
      *--------------------------------------------------------
     D SIG_BLOCK       c                   const(0)
     D SIG_UNBLOCK     c                   const(1)
     D SIG_SETMASK     c                   const(2)

      *--------------------------------------------------------
      * setitimer() "which" argument
      *--------------------------------------------------------
     D ITIMER_REAL     C                   1
     D ITIMER_VIRTUAL  C                   2
     D ITIMER_PROF     C                   2

      *--------------------------------------------------------
      *  sigset_t: signal set data structure
      *  ===================================
      *
      *  Note: There's not much point in trying to copy the
      *        way this is done in the ILE C header files,
      *        since RPG doesn't support integers that are
      *        1-bit long. Instead, I've defined the mask as
      *        one big field, and you can test/set bits with
      *        the %bitand() and %bitor() BIFs
      *--------------------------------------------------------
     D sigset_t        s             20U 0 based(TEMPLATE)

      *--------------------------------------------------------
      * sigaction_t: signal action data structure
      *
      * Prototype for signal handler (only if not SA_SIGINFO)
      *   D sa_handler      PR
      *   D   signo                       10I 0 value
      *
      * Prototype for signal action handler (only if SA_SIGINFO)
      *
      *   D sa_sigaction    PR
      *   D   signo                       10I 0 value
      *   D   info                              likeds(siginfo_t)
      *   D   context                       *   value
      *--------------------------------------------------------
     D sigaction_t     ds                  qualified
     D                                     align
     D                                     based(TEMPLATE)
     D   sa_handler                    *   procptr
     D   sa_mask                           like(sigset_t)
     D   sa_flags                    10I 0
     D   sa_sigaction                  *   procptr


      *--------------------------------------------------------
      * siginfo_t: signal information data structure
      *--------------------------------------------------------
     D siginfo_t       ds                  qualified
     D                                     align
     D                                     based(TEMPLATE)
     D   si_signo                    10I 0
     D   si_bits                      5U 0
     D   si_data_size                 5I 0
     D   si_time                      8A
     D   si_job                      10A
     D   si_user                     10A
     D   si_jobno                     6A
     D                                4A
     D   si_code                     10I 0
     D   si_errno                    10I 0
     D   si_pid                      10I 0
     D   si_uid                      10U 0
     D   si_data                      1A

      *--------------------------------------------------------
      * itimerval: interval timer value
      *--------------------------------------------------------
     D it_timeval      ds                  qualified
     D                                     based(template)
     D    tv_sec                     10I 0
     D    tv_usec                    10I 0
     D itimerval       ds                  qualified
     D                                     based(template)
     D    int_tv_sec                 10I 0
     D    int_tv_usec                10I 0
     D    val_tv_sec                 10I 0
     D    val_tv_usec                10I 0

      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * alarm(): Send an alarm signal after XX seconds
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D alarm           PR            10U 0 extproc('alarm')
     D   secs                        10U 0 value

      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * Qp0sEnableSignals():  Enable a process for signals
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D Qp0sEnableSignals...
     D                 PR            10I 0 extproc('Qp0sEnableSignals')

      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * Qp0sDisableSignals(): Disable signals
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D Qp0sDisableSignals...
     D                 PR            10I 0 extproc('Qp0sEnableSignals')

      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * default signal handlers
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D C_sig_err       PR                  extproc('_C_sig_err')
     D   signal                      10I 0 value
     D SIG_ERR         S               *   procptr inz(%paddr(C_sig_err))

     D C_sig_dfl       PR                  extproc('_C_sig_dfl')
     D   signal                      10I 0 value
     D SIG_DFL         S               *   procptr inz(%paddr(C_sig_dfl))

     D C_sig_ign       PR                  extproc('_C_sig_ign')
     D   signal                      10I 0 value
     D SIG_IGN         S               *   procptr inz(%paddr(C_sig_ign))

      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigaction():  Set signal action
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigaction       PR                  extproc('sigaction')
     D   sig                         10I 0 value
     D   act                               likeds(sigaction_t) const
     D                                     options(*omit)
     D   oact                              likeds(sigaction_t)
     D                                     options(*omit)

      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigaddset():  add signal to signal set
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigaddset       PR            10I 0 extproc('sigaddset')
     D   set                               like(sigset_t)
     D   signo                       10I 0 value


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigdelset():  remove signal from signal set
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigdelset       PR            10I 0 extproc('sigdelset')
     D   set                               like(sigset_t)
     D   signo                       10I 0 value


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigemptyset(): initialize an empty signal set
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigemptyset     PR            10I 0 extproc('sigemptyset')
     D   set                               like(sigset_t)


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigfillset(): initialize a full signal set
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigfillset      PR            10I 0 extproc('sigfillset')
     D   set                               like(sigset_t)


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigismember(): test if signal is in signal set
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigismember     PR            10I 0 extproc('sigismember')
     D   set                               like(sigset_t)
     D   signo                       10I 0 value


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * signal(): set signal action (simplified version of
      *           sigaction() API)
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D signal          PR              *   procptr
     D                                     extproc('signal')
     D   sig                         10I 0 value
     D   handler                       *   procptr value


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigpending(): examine pending signals
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigpending      PR            10I 0 extproc('sigpending')
     D   set                               like(sigset_t)


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigprocmask(): Examine and change blocked signals
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigprocmask     PR            10I 0 extproc('sigprocmask')
     D   how                         10I 0 value
     D   set                               like(sigset_t)
     D                                     const
     D   oset                              like(sigset_t)


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigsuspend(): replace signal mask and suspend
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigsuspend      PR            10I 0 extproc('sigsuspend')
     D   mask                              like(sigset_t)   const


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * sigwait(): wait for a signal in a set
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D sigwait         PR            10I 0 extproc('sigwait')
     D   set                               like(sigset_t)   const


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * setitimer(): set value for interval timer
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D setitimer       PR            10I 0 extproc('setitimer')
     D   which                       10I 0 value
     D   value                             like(itimerval) const
     D   ovalue                            like(itimerval) options(*omit)


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * getitimer(): Get value of interval timer
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D getitimer       PR            10I 0 extproc('getitimer')
     D   which                       10I 0 value
     D   value                             like(itimerval)


File   : QRPGLESRC
Member : refresh
Type   : RPGLE
Desc   : re-display QSYSOPR automatically
Usage  : CRTBNDRPG REFRESH
OS Version: 由於此程式是 free format version 所以編譯時需要指定 
        TGTRLS(TARGET release) 為 V5R1M0 以上(含V5R1M0) 
Usage  : CALL REFRESH
         此程式是預設 5 秒更新一次, 你可以更改 DISPLAY_SECS 參數預設值, 
         30 ==> 30 秒,600 ==> 10 分鐘, 重新編譯
         

      *
      *  Sample of re-displaying the QSYSOPR message queue
      *                           Scott Klement, January 19, 2006
      *
      *  To Compile:
      *   - Make sure SIGNAL_H member is in QRPGLESRC and in your
      *     library list.
      *   - type: CRTBNDRPG REFRESH SRCFILE(xxx/QRPGLESRC) DBGVIEW(*LIST)
      *
      * (WARNING: Change the ACTGRP at your own risk!)
     H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('QC2LE')

      * Change the following number if you'd like to change how
      * often QSYSOPR is re-displayed.  30 = 30 seconds,
      * 600 = every 10 minutes, etc.
      *
     D DISPLAY_SECS    C                   CONST(5)

      /copy signal_h

     D QCMDEXC         PR                  extpgm('QCMDEXC')
     D   command                  32702A   const options(*Varsize)
     D   len                         15P 5 const
     D   igc                          3A   const options(*nopass)

     D CEE4RAGE        PR
     D   procedure                     *   procptr const
     D   feedback                    12A   options(*omit)

     D displaymsg      PR             1N
     D killcmd         PR
     D stop_the_kill   PR
     D rmvmsgs         PR

     D act             ds                  likeds(sigaction_t)
     D Interval        ds                  likeds(itimerval)
     D cmd             s           2000A   varying
     D timeout         s              1N
     D MsgKey          s              4A
     D status          s             10I 0

      /free

          // ---------------------------------------------------
          // Tell system that the killcmd() subprocedure
          // should be called whenever an alarm signal is
          // received.
          // ---------------------------------------------------

           sigemptyset(act.sa_mask);
           sigaddset(act.sa_mask: SIGALRM);

           act.sa_handler   = %paddr(killcmd);
           act.sa_flags     = 0;
           act.sa_sigaction = *NULL;

           sigaction(SIGALRM: act: *omit);


          // ---------------------------------------------------
          // Tell system to send an alarm signal every minute:
          // ---------------------------------------------------

          Interval = *ALLx'00';
          Interval.int_tv_sec = DISPLAY_SECS;
          Interval.val_tv_sec = DISPLAY_SECS;

          setitimer(ITIMER_REAL: Interval: *omit);

          CEE4RAGE(%paddr(stop_the_kill): *omit);


          // ---------------------------------------------------
          // Tell system to send an alarm signal every minute:
          // ---------------------------------------------------
          dou displaymsg() = *OFF;
          enddo;

          *inlr = *on;
          return;

      /end-free


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  This performs a DSPMSG on the QSYSOPR message queue
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P displaymsg      B
     D displaymsg      PI             1N
      /free
          timeout = *OFF;
          monitor;
             cmd = 'DSPMSG MSGQ(QSYSOPR) OUTPUT(*)';
             QCMDEXC(cmd: %len(cmd));
          on-error 202;
             rmvmsgs();
          endmon;
          return timeout;
      /end-free
     P                 E


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * Send an escape message to the DSPMSG command in order to
      * cause it to stop, so we can re-display it.
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P killcmd         B
     D killcmd         PI

     D QMHSNDPM        PR                  ExtPgm('QMHSNDPM')
     D   MessageID                    7A   Const
     D   QualMsgF                    20A   Const
     D   MsgData                    256A   Const
     D   MsgDtaLen                   10I 0 Const
     D   MsgType                     10A   Const
     D   CallStkEnt                  10A   Const
     D   CallStkCnt                  10I 0 Const
     D   MessageKey                   4A
     D   ErrorCode                 1024A   options(*varsize)

     D ErrorCode       ds                  qualified
     D    BytesProv                  10I 0 inz(0)
     D    BytesAvail                 10I 0 inz(0)

      /free
          timeout = *on;

          QMHSNDPM( 'CPF9897'
                  : 'QCPFMSG   *LIBL'
                  : 'This is sent to kill the DSPMSG command'
                  : 256
                  : '*ESCAPE'
                  : 'DISPLAYMSG'
                  : 0
                  : MsgKey
                  : ErrorCode );
      /end-free
     P                 E


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  stop_the_kill():  Disable the timer so that we no longer
      *                    kill any active command after 1 minute.
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P stop_the_kill   B
     D stop_the_kill   PI
      /free
          Interval = *ALLx'00';
          setitimer(ITIMER_REAL: Interval: *omit);
      /end-free
     P                 E


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * Remove annoying error messages from job log
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P rmvmsgs         B
     D rmvmsgs         PI

     D QMHRCVPM        PR                  extpgm('QMHRCVPM')
     D   RcvVar                   32767A   options(*varsize)
     D   RcvVarLen                   10I 0 const
     D   Format                       8A   const
     D   StackEnt                    10A   const
     D   StackCount                  10I 0 const
     D   MsgType                     10A   const
     D   MsgKey                       4A   const
     D   WaitTime                    10I 0 const
     D   Action                      10A   const
     D   ErrorCode                32767A   options(*varsize)

     D ErrorCode       ds                  qualified
     D    BytesProv                  10I 0 inz(0)
     D    BytesAvail                 10I 0 inz(0)

     D RCVM0100        ds                  qualified
     D   BytesRtn                    10I 0
     D   BytesAvail                  10I 0
     D   MsgSev                      10I 0
     D   MsgID                        7A
     D   MsgType                      2A
     D   MsgKey                       4A
     D                                7A
     D   conv_ind                    10I 0
     D   CCSID                       10I 0
     D   DtaLen                      10I 0
     D   DtaLenAvail                 10I 0
     D   MsgDta                   32719A

      /free
         QMHRCVPM( RCVM0100
                 : %Size(RCVM0100)
                 : 'RCVM0100'
                 : 'DISPLAYMSG'
                 : 0
                 : '*ESCAPE'
                 : MsgKey
                 : -1
                 : '*REMOVE'
                 : ErrorCode );
      /end-free
     P                 E
         



沒有留言: