      ******************************************************************
      *
      * Copyright (C) 1984-2005 Micro Focus International Ltd.
      * All rights reserved.
      *
      ******************************************************************
       working-storage section.

       copy "cbltypes.cpy".
       copy "mfctf.cpy".

       78  MAX-TRACE-DATA              value 5.
       78  THIS-COMPONENT              value "MF.DEMO".

      *----------------------------------------------------------------
      *    THIS-COMPONENT's tracer properties
      *----------------------------------------------------------------
       78  PROPID-ALL                  value 1.

       78  PROPNAME-ALL                value "ALL".
       78  PROPNAME-APPLES             value "APPLES".
       78  PROPNAME-BANANAS            value "BANANAS".
       78  PROPNAME-ORANGES            value "ORANGES".

       01  ws-prop-names.
           03                          pic x(10) value PROPNAME-ALL.
           03                          pic x(10) value PROPNAME-APPLES.
           03                          pic x(10) value PROPNAME-BANANAS.
           03                          pic x(10) value PROPNAME-ORANGES.
           03                          pic x(10) value spaces.
       01  ws-prop-name                redefines ws-prop-names
                                       pic x(10) occurs 5.
      *----------------------------------------------------------------
      *    THIS-COMPONENT's events
      *----------------------------------------------------------------
       78  EVENT-PROCESSING-START      value 0.
       78  EVENT-PROCESSING-END        value 1.
       78  EVENT-APPLE-SIMPLE          value 2.
       78  EVENT-APPLE-TEXT            value 3.
       78  EVENT-BANANA-SIMPLE         value 4.
       78  EVENT-BANANA-BUNCH          value 5.
       78  EVENT-ORANGE-SIMPLE         value 6.
       78  EVENT-ORANGE-JUICY          value 7.

      *----------------------------------------------------------------
      *    Trace flags for THIS-COMPONENT. Each bit of these flags
      *    corresponds to a property being set (non-zero value) for 
      *    THIS-COMPONENT. The actual bit set for a given property
      *    corresponds to the position-1 of the property's name in the
      *    'ws-prop-name' table above. For example, if bit 0 is set,
      *    it indicates that the 'APPLES' property was set. If the 'ALL'
      *    property is set, then all bits of 'trace_flags' will be set.
      *
      *    N.B. This is just an example of how properties and their
      *    values may be processed by a component.How properties are
      *    processed is completely transparent to CTF.
      *----------------------------------------------------------------
       78  TRACE-FLAGS-APPLES          value h'00000001'.
       78  TRACE-FLAGS-BANANAS         value h'00000002'.
       78  TRACE-FLAGS-ORANGES         value h'00000004'.

       01  ctf-config-data.
           03  ctf-trace-level         pic x(4) comp-5.
           03  ctf-trace-flags         pic x(4) comp-5 value 0.

      *----------------------------------------------------------------
      *    Variables required for CTF event generation
      *----------------------------------------------------------------
       01  ctf-event-data.
           03  ctf-tracer-handle       pic x(4) comp-5.
           03  ctf-trace-event         cblt-trc-event.
           03  ctf-trace-event-lens    pic x(4) comp-5
                                       occurs MAX-TRACE-DATA.
           03  ctf-trace-event-types   pic x(4) comp-5
                                       occurs MAX-TRACE-DATA.
           03  ctf-trace-event-ptrs    pointer
                                       occurs MAX-TRACE-DATA.

      *****************************************************************
       local-storage section.
       01  ls-data.
           03  ls-api-flags            pic x(4) comp-5.
           03  ls-bunch-size           pic x(4) comp-5.
           03  ls-comp-name            pic x(16).
           03  ls-install-param        cblt-trc-notif-install.
           03  ls-net-size             pic x(4) comp-5.
           03  ls-prop-id              pic x(4) comp-5.
           03  ls-prop-value           pic x(4) comp-5.
           03  ls-trace-data-count     pic x(4) comp-5.
           03  ls-trace-data-desc      pic x(40).
           03  ls-trace-event          pic x(4) comp-5.
           03  ls-trace-level          pic x(4) comp-5.
           03  ls-work-var             pic x(4) comp-5.

      *****************************************************************
       linkage section.
       01  lk-ctf-tracer-handle        pic x(4) comp-5.
       01  lk-ctf-notif-type           pic x(4) comp-5.

       01  lk-ctf-notif-param          pic x.
       01  lk-ctf-notif-param-level    redefines lk-ctf-notif-param
                                       pic x(4) comp-5.
       01  lk-ctf-notif-param-property redefines lk-ctf-notif-param
                                       cblt-trc-notif-prop-change.
       01  lk-ctf-property-name        pic x.
       01  lk-ctf-property-value       pic x.

      *****************************************************************
       procedure division.
           perform initialise-tracing
           perform do-processing
           goback
           .

      *****************************************************************
      *    Set appropriate trace flags bit
      *****************************************************************
       apply-property-value section.
           if ls-prop-id = PROPID-ALL
               if ls-prop-value not = 0
                  compute ctf-trace-flags = ctf-trace-flags b-or
                                            h'FFFFFFFF'
               else
                  move 0 to ctf-trace-flags
               end-if
           else
               compute ls-work-var = 2 ** (ls-prop-id - 2)

               if ls-prop-value not = 0
                   compute ctf-trace-flags = ctf-trace-flags b-or
                                             ls-work-var
               else
                   compute ctf-trace-flags = ctf-trace-flags b-and b-not
                                             ls-work-var
               end-if
           end-if
           .

      *****************************************************************
      *  THIS-COMPONENT tracer callback. Processes THIS-COMPONENT's
      *  property and trace level changes.
      *
      *  lk-ctf-tracer-handle  =  tracer handle
      *
      *  lk-ctf-notif-type     =  notification type
      *
      *                           0 = property change
      *                           1 = trace level change
      *
      *  lk-ctf-notif-info     =  address of item whose type is
      *                           dependent upon notification type
      *
      *                           type 0 = cblt-trc-notif-prop-change
      *                           type 1 = pic x(4) comp-5
      *****************************************************************
       ctf-tracer-notif-callback section.
           entry "ctf-tracer-notif-callback" using
                                      by value     lk-ctf-tracer-handle
                                      by value     lk-ctf-notif-type
                                      by reference lk-ctf-notif-param.
           evaluate lk-ctf-notif-type
               when 78-TRC-NOTIF-TYPE-PROP-CHANGE
                   perform ctf-tracer-notif-property

               when 78-TRC-NOTIF-TYPE-LEVEL-CHANGE
                   move lk-ctf-notif-param-level to ctf-trace-level

               when other
                    continue
           end-evaluate

           goback
           .

      *-----------------------------------------------------------------
      *    Tracer property changed
      *-----------------------------------------------------------------
       ctf-tracer-notif-property section.
           set address of lk-ctf-property-name to
               cblte-tnpc-name of lk-ctf-notif-param-property

           perform varying ls-prop-id from 1 by 1
                     until ws-prop-name(ls-prop-id) = spaces


               if ws-prop-name(ls-prop-id) =
                  lk-ctf-property-name
                   (1:cblte-tnpc-namelen of lk-ctf-notif-param-property)

                   move cblte-tnpc-valint of lk-ctf-notif-param-property
                        to ls-prop-value

                   perform apply-property-value
                   exit perform
               end-if
           end-perform
           .
      *****************************************************************
      *  Do some processing, tracing according to which trace flags
      *  have been set
      *****************************************************************
       do-processing section.
           *>
           *>  This event will be output if the trace level is >= 'info'
           *>
           if 78-CTF-FLAG-LEVEL-INFO >= ctf-trace-level
               move EVENT-PROCESSING-START to ls-trace-event
               move 78-CTF-FLAG-LEVEL-INFO to ls-trace-level
               perform trace-event
           end-if

           *>
           *>  This event will be output if the 'apples' property has
           *>  been set and the trace level is >= 'info'
           *>
           if (TRACE-FLAGS-APPLES b-and ctf-trace-flags) not = 0
           and 78-CTF-FLAG-LEVEL-INFO >= ctf-trace-level
               move EVENT-APPLE-SIMPLE to ls-trace-event
               move 78-CTF-FLAG-LEVEL-INFO to ls-trace-level
               perform trace-event
           end-if

           *>
           *>  This event will be output if the 'apples' property has
           *>  been set and the trace level is >= 'info'. The event will
           *>  have 1 piece of trace data associated with it
           *>
           if (TRACE-FLAGS-APPLES b-and ctf-trace-flags) not = 0
           and 78-CTF-FLAG-LEVEL-INFO >= ctf-trace-level
               move EVENT-APPLE-TEXT to ls-trace-event
               move 78-CTF-FLAG-LEVEL-INFO to ls-trace-level
               perform trace-event
           end-if

           *>
           *>  This event will be output if the 'bananas' property has
           *>  been set and the trace level is >= 'info'
           *>
           if (TRACE-FLAGS-BANANAS b-and ctf-trace-flags) not = 0
           and 78-CTF-FLAG-LEVEL-INFO >= ctf-trace-level
               move EVENT-BANANA-SIMPLE to ls-trace-event
               move 78-CTF-FLAG-LEVEL-INFO to ls-trace-level
               perform trace-event
           end-if

           *>
           *>  This event will be output if the 'bananas' property has
           *>  been set and the trace level is >= 'warning'. The event
           *>  will have 2 pieces of trace data associated with it
           *>
           if (TRACE-FLAGS-BANANAS b-and ctf-trace-flags) not = 0
           and 78-CTF-FLAG-LEVEL-WARN >= ctf-trace-level
               move EVENT-BANANA-BUNCH to ls-trace-event
               move 78-CTF-FLAG-LEVEL-WARN to ls-trace-level
               perform trace-event
           end-if

           *>
           *>  This event will be output if the 'oranges' property has
           *>  been set and the trace level is >= 'info'
           *>
           if (TRACE-FLAGS-ORANGES b-and ctf-trace-flags) not = 0
           and 78-CTF-FLAG-LEVEL-INFO >= ctf-trace-level
               move EVENT-ORANGE-SIMPLE to ls-trace-event
               move 78-CTF-FLAG-LEVEL-INFO to ls-trace-level
               perform trace-event
           end-if

           *>
           *>  This event will be output if the 'oranges' property has
           *>  been set and the trace level is >= 'error'. The event
           *>  will have 3 pieces of trace data associated with it
           *>
           if (TRACE-FLAGS-ORANGES b-and ctf-trace-flags) not = 0
           and 78-CTF-FLAG-LEVEL-ERROR >= ctf-trace-level
               move EVENT-ORANGE-JUICY to ls-trace-event
               move 78-CTF-FLAG-LEVEL-ERROR to ls-trace-level
               perform trace-event
           end-if

           *>
           *>  This event will be output if the trace level is >= 'info'
           *>
           if 78-CTF-FLAG-LEVEL-INFO >= ctf-trace-level
               move EVENT-PROCESSING-END to ls-trace-event
               move 78-CTF-FLAG-LEVEL-INFO to ls-trace-level
               perform trace-event
           end-if
           .

      *****************************************************************
      *  Initialise tracing for THIS-COMPONENT.
      *
      *  On exit from this section 'ctf-tracer-handle',
      *  'ctf-trace-flags' and 'ctf-race-level' will be set for
      *  THIS-COMPONENT
      *****************************************************************
       initialise-tracing section.
           *>
           *>  Pick up THIS-COMPONENT's tracer handle
           *>
           move 78-CTF-FLAG-COMP-NAME-NULL-TERM to ls-api-flags
           move THIS-COMPONENT & x"00" to ls-comp-name

           call "CBL_CTF_TRACER_GET" using
                                     by value     ls-api-flags
                                     by reference ls-comp-name
                                     by reference ctf-tracer-handle

           if return-code not = 0
               display "CBL_CTF_TRACER_GET (rc = "
                       return-code
                       ")"
               stop run
           end-if

           *>
           *>  Get THIS-COMPONENT's tracer properties.
           *>
           *>  For the purpose of this demo, all properties are
           *>  expected to have integer values, so if the property
           *>  exists, but has a non-integer value it will be ignored.
           *>
           move 78-CTF-FLAG-PROP-INT-VALUE to ls-api-flags

           perform varying ls-prop-id from 1 by 1
                     until ws-prop-name(ls-prop-id) = spaces

               call "CBL_CTF_COMP_PROPERTY_GET" using
                              by value     ls-api-flags
                              by reference ctf-tracer-handle
                              by reference ws-prop-name(ls-prop-id)
                              by value     0
                              by reference ls-prop-value

               if return-code = 0
                   perform apply-property-value
               end-if
           end-perform

           *>
           *>  Get THIS-COMPONENT's tracer trace level
           *>
           move 0 to ls-api-flags

           call "CBL_CTF_TRACER_LEVEL_GET" using
                                       by value     ls-api-flags
                                       by reference ctf-tracer-handle
                                       by reference ctf-trace-level

           if return-code not = 0
               display "CBL_TRACER_LEVEL_GET (rc = "
                       return-code
                       ")"
               stop run
           end-if

           *>
           *> Install tracer notification callback
           *>
           *> N.B. Only need to this for dynamic CTF configuration
           *>
           move low-values to ls-install-param
           move ctf-tracer-handle to
                cblte-tni-handle of ls-install-param
           set cblte-tni-callback of ls-install-param to
               entry "ctf-tracer-notif-callback"

           call "CBL_CTF_TRACER_NOTIFY" using
                                        by value 0
                                        by reference ls-install-param

           if return-code not = 0
               display "CBL_CTF_TRACER_NOTIFY (rc = "
                       return-code
                       ")"
               stop run
           end-if

           *>
           *> Initialise fixed fields in trace event structure
           *>
           move low-values to ctf-trace-event

           set cblte-trcevt-event-len of ctf-trace-event to
               address of ctf-trace-event-lens(1)
           set cblte-trcevt-event-type of ctf-trace-event to
               address of ctf-trace-event-types(1)
           set cblte-trcevt-event-data of ctf-trace-event to
               address of ctf-trace-event-ptrs(1)
           .

      *****************************************************************
      *    Output trace event
      *****************************************************************
       trace-event section.
           move 78-TRACE-EVENT-FLAGS-NONE to
                cblte-trcevt-flags of ctf-trace-event
           move ls-trace-event to
                cblte-trcevt-event-id of ctf-trace-event
           move ls-trace-level to
                cblte-trcevt-level of ctf-trace-event

           move 0 to ls-trace-data-count

           evaluate ls-trace-event
               when EVENT-APPLE-TEXT
                   perform trace-event-apple-text

               when EVENT-BANANA-BUNCH
                   perform trace-event-banana-bunch

               when EVENT-ORANGE-JUICY
                   perform trace-event-orange-juicy

               when EVENT-PROCESSING-START
               when EVENT-PROCESSING-END
               when EVENT-APPLE-SIMPLE
               when EVENT-BANANA-SIMPLE
               when EVENT-ORANGE-SIMPLE
                   continue
           end-evaluate

           move ls-trace-data-count to
                cblte-trcevt-data-count of ctf-trace-event

           call "CBL_CTF_TRACE" using by value     0
                                      by reference ctf-tracer-handle
                                      by reference ctf-trace-event

           if return-code not = 0
               display "CBL_CTF_TRACE (rc = "
                       return-code
                       ")"
           end-if
           .

      *-----------------------------------------------------------------
      *    Set up trace data for EVENT-APPLE-TEXT
      *-----------------------------------------------------------------
       trace-event-apple-text section.
           *>
           *>  Apple description
           *>
           move "Some lovely apples" to ls-trace-data-desc

           set ctf-trace-event-ptrs(1) to 
               address of ls-trace-data-desc

           move 18 to ctf-trace-event-lens(1)

           move 78-TRACE-EVENT-TYPE-TEXT to
                ctf-trace-event-types(1)

           add 1 to ls-trace-data-count
           .

      *-----------------------------------------------------------------
      *    Set up trace data for EVENT-BANANA-BUNCH
      *-----------------------------------------------------------------
       trace-event-banana-bunch section.
           *>
           *>  Banana description
           *>
           move "Some ripe bananas" to ls-trace-data-desc

           set ctf-trace-event-ptrs(1) to 
               address of ls-trace-data-desc

           move 17 to ctf-trace-event-lens(1)

           move 78-TRACE-EVENT-TYPE-TEXT to
                ctf-trace-event-types(1)

           add 1 to ls-trace-data-count

           *>
           *>  Size of bunch
           *>
           move 12 to ls-bunch-size

           set ctf-trace-event-ptrs(2) to 
               address of ls-bunch-size

           move length of ls-bunch-size to
                ctf-trace-event-lens(2)

           move 78-TRACE-EVENT-TYPE-COMP5 to
                ctf-trace-event-types(2)

           add 1 to ls-trace-data-count
           .

      *-----------------------------------------------------------------
      *    Set up trace data for EVENT-ORANGE-JUICY
      *-----------------------------------------------------------------
       trace-event-orange-juicy section.
           *>
           *>  Orange description
           *>
           move "Some juicy oranges" to ls-trace-data-desc

           set ctf-trace-event-ptrs(1) to 
               address of ls-trace-data-desc

           move 18 to ctf-trace-event-lens(1)

           move 78-TRACE-EVENT-TYPE-TEXT to
                ctf-trace-event-types(1)

           add 1 to ls-trace-data-count

           *>
           *>  Orange net size
           *>
           move 9 to ls-net-size

           set ctf-trace-event-ptrs(2) to 
               address of ls-net-size

           move length of ls-net-size to
                ctf-trace-event-lens(2)

           move 78-TRACE-EVENT-TYPE-COMP5 to
                ctf-trace-event-types(2)

           add 1 to ls-trace-data-count

           *>
           *>  Orange description address
           *>
           set ctf-trace-event-ptrs(3) to 
               address of ls-trace-data-desc

           move length of ctf-trace-event-ptrs(3) to
                ctf-trace-event-lens(3)

           move 78-TRACE-EVENT-TYPE-ADDRESS to
                ctf-trace-event-types(3)

           add 1 to ls-trace-data-count
           .