Created
September 25, 2012 14:49
-
-
Save jamerfort/3782394 to your computer and use it in GitHub Desktop.
Use this TPS proc to save each message to its own, unique file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use this TPS proc to save each message to its own, unique file. | |
# | |
# To use this proc: | |
# - set the outbound thread's protocol to 'fileset-local' | |
# - set the outbound directory to the desired directory | |
# - set the outbound file to the prefix of the files that the messages will be placed in | |
# | |
# Output filename format: <DIRECTORY>/<FILE>.<DATE>-<COUNTER> | |
# where: | |
# DIRECTORY is the fileset-local outbound "Directory" setting | |
# FILE is the fileset-local outbound "File" setting | |
# DATE is the current date in the following format: %Y%m%d%H%M%S | |
# COUNTER is an increasing integer (starting at "0" for each unique DATE value) | |
# to keep the filename unique. | |
# | |
# Assuming that you set the directory to "/outdir" and the file to "out.msg", each message will | |
# go in a unique file with filenames similar to: | |
# /outdir/out.msg.20120925104819-0 | |
# /outdir/out.msg.20120925104819-1 | |
# /outdir/out.msg.20120925111528-0 | |
proc single_msg_per_file {args} { | |
# set the procedure name | |
# This is used for error messages | |
set procname [lindex [info level [info level]] 0] | |
# bring some common variables into the scope of this proc | |
global HciSite HciSiteDir HciProcessesDir HciConnName HciRootDir ibdir | |
# fetch mode | |
keylget args MODE mode | |
# keylget args ARGS.ARGNAME argname | |
switch -exact -- $mode { | |
start { | |
# Perform special init functions | |
# N.B.: there may or may not be a MSGID key in args | |
set thread_data [netconfig get connection data $HciConnName] | |
set obfile_prefix [keylget thread_data PROTOCOL.OBFILE] | |
if { ![info exists ::__SingleMsgPerFile] } { | |
array set ::__SingleMsgPerFile {} | |
} | |
set ::__SingleMsgPerFile($HciConnName.prefix) $obfile_prefix | |
set ::__SingleMsgPerFile($HciConnName.last_time) "" | |
set ::__SingleMsgPerFile($HciConnName.last_counter) "" | |
} | |
run { | |
# 'run' mode always has a MSGID; fetch and process it | |
keylget args MSGID msgid | |
# get the prefix and last value for this thread | |
set prefix $::__SingleMsgPerFile($HciConnName.prefix) | |
set last_time $::__SingleMsgPerFile($HciConnName.last_time) | |
set last_counter $::__SingleMsgPerFile($HciConnName.last_counter) | |
# calculate uniq value | |
set time [clock format [clock seconds] -format %Y%m%d%H%M%S] | |
set counter 0 | |
if { $time == $last_time } { | |
set counter [expr {$last_counter + 1}] | |
} | |
set ::__SingleMsgPerFile($HciConnName.last_time) $time | |
set ::__SingleMsgPerFile($HciConnName.last_counter) $counter | |
set driverctl [msgmetaget $msgid DRIVERCTL] | |
keylset driverctl FILESET.OBFILE "${prefix}.${time}-${counter}" | |
msgmetaset $msgid DRIVERCTL $driverctl | |
return "{CONTINUE $msgid}" | |
} | |
time { | |
# Timer-based processing | |
# N.B.: there may or may not be a MSGID key in args | |
} | |
shutdown { | |
# Do some clean-up work | |
} | |
default { | |
error "Unknown mode in $procname: $mode" | |
return "" ;# Dont know what to do | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment