| 1 | # -*- tcl -*- |
|---|
| 2 | # -- $Id: writer_tpc.tcl,v 1.1 2005/09/28 04:51:22 andreas_kupries Exp $ --- |
|---|
| 3 | # |
|---|
| 4 | # PAGE plugin - writer - TPC ~ Tcl Peg Container |
|---|
| 5 | # |
|---|
| 6 | |
|---|
| 7 | # ### ### ### ######### ######### ######### |
|---|
| 8 | ## Imported API |
|---|
| 9 | |
|---|
| 10 | # -----------------+-- |
|---|
| 11 | # page_wdata | Access to processed input stream. |
|---|
| 12 | # -----------------+-- |
|---|
| 13 | # page_info | Reporting to the user. |
|---|
| 14 | # page_warning | |
|---|
| 15 | # page_error | |
|---|
| 16 | # -----------------+-- |
|---|
| 17 | # page_log_error | Reporting of internals. |
|---|
| 18 | # page_log_warning | |
|---|
| 19 | # page_log_info | |
|---|
| 20 | # -----------------+-- |
|---|
| 21 | |
|---|
| 22 | # ### ### ### ######### ######### ######### |
|---|
| 23 | ## Exported API |
|---|
| 24 | |
|---|
| 25 | # -----------------+-- |
|---|
| 26 | # page_wfeature | Query for special plugin features page might wish to use. |
|---|
| 27 | # page_wtime | Activate collection of timing statistics. |
|---|
| 28 | # page_wgettime | Return the collected timing statistics. |
|---|
| 29 | # page_wlabel | User readable label for the plugin. |
|---|
| 30 | # page_whelp | Doctools help text for plugin. |
|---|
| 31 | # page_woptions | Options understood by plugin. |
|---|
| 32 | # page_wconfigure | Option (re)configuration. |
|---|
| 33 | # page_wrun | Generate output from data per plugin configuration and hardwiring. |
|---|
| 34 | # -----------------+-- |
|---|
| 35 | |
|---|
| 36 | # ### ### ### ######### ######### ######### |
|---|
| 37 | ## Requisites |
|---|
| 38 | |
|---|
| 39 | package require page::gen::peg::cpkg |
|---|
| 40 | package require struct::tree ; # Data structure. |
|---|
| 41 | |
|---|
| 42 | global usec |
|---|
| 43 | global timed |
|---|
| 44 | set timed 0 |
|---|
| 45 | |
|---|
| 46 | # ### ### ### ######### ######### ######### |
|---|
| 47 | ## Implementation of exported API |
|---|
| 48 | |
|---|
| 49 | proc page_wlabel {} { |
|---|
| 50 | return {Tcl PEG Container (Package)} |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | proc page_wfeature {key} { |
|---|
| 54 | return [string eq $key timeable] |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | proc page_wtime {} { |
|---|
| 58 | global timed |
|---|
| 59 | set timed 1 |
|---|
| 60 | return |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | proc page_wgettime {} { |
|---|
| 64 | global usec |
|---|
| 65 | return $usec |
|---|
| 66 | } |
|---|
| 67 | proc page_whelp {} { |
|---|
| 68 | return {} |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | proc page_woptions {} { |
|---|
| 72 | return {} |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | proc page_wconfigure {option value} { |
|---|
| 76 | return -code error "Cannot set value of unknown option \"$option\"" |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | proc page_wrun {chan data} { |
|---|
| 80 | global timed usec |
|---|
| 81 | page_log_info "writer/tpc/run/" |
|---|
| 82 | |
|---|
| 83 | if {$timed} { |
|---|
| 84 | set usec [lindex [time { |
|---|
| 85 | ::struct::tree ::tree deserialize $data |
|---|
| 86 | page::gen::peg::cpkg ::tree $chan |
|---|
| 87 | }] 0] ; #{} |
|---|
| 88 | } else { |
|---|
| 89 | ::struct::tree ::tree deserialize $data |
|---|
| 90 | page::gen::peg::cpkg ::tree $chan |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | page_log_info "writer/tpc/run/ok" |
|---|
| 94 | |
|---|
| 95 | ::tree destroy |
|---|
| 96 | return |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | # ### ### ### ######### ######### ######### |
|---|
| 100 | ## Internal helper code. |
|---|
| 101 | |
|---|
| 102 | # ### ### ### ######### ######### ######### |
|---|
| 103 | ## Initialization |
|---|
| 104 | |
|---|
| 105 | package provide page::writer::tpc 0.1 |
|---|