-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
I've mostly worked this out, but I keep running into areas where I want to be able to extend the functionality in the various modules without having to go to C land, to avoid the problems that come with keeping my own fork of tnm. I will try and put together an actual pull request, but just for anyone interested in how I'm doing this today, here is the bones of a solution.
mib-init.tcl
package require Tnm
rename ::Tnm::mib ::mib
interp hide {} mib
namespace eval ::Tnm::mib {
set ns [namespace current]
set builtins [list {*}{
access children compare defval description displayhint
enums exists file format index info label length load
macro member module name oid pack parent range scan size
split status subtree syntax type unpack variables walk
}]
foreach builtin $builtins {
# export the builtin
namespace export $builtin
# create alias to invoke hidden ::Tnm::mib command
interp alias {} ${ns}::$builtin {} interp invokehidden {} mib $builtin
}
namespace ensemble create -command ::Tnm::mib
# alternative implementation for slective dispatch between c-side sub-commands and
# and interp subcommands
if 0 {
proc ensembleUnknown {command args} {
variable builtins
if {$command in $builtins} {
tailcall [namespace current]::mib {*}$args
}
set badoptionerr {bad option "%s": must be %s, or %s}
set options [dict get keys [namespace ensemble configure -map]]
set optionsString [join [lrange $options 0 end-1] ", "]
set message [format $badoptionerr $optionsString [lindex $options end]]
return -code error $message
}
namespace ensemble create -command ::Tnm::mib -unknown ensembleUnknown
}
}
# ::Tnm::mib ensemble extensions
namespace eval ::Tnm::mib {
namespace export tables
proc tables {root} {
set tables {}
mib walk OID $root {
if {[mib type $OID] == {SEQUENCE OF}} {
lappend tables [mib type $OID] $OID
}
}
return $tables
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels