1
0
Fork 0

VTY: Handle the argv correctly, call a block with the strings, use gc for the comamnd

The low level struct is kept by the the VTYCommand so we can allocate
this with normal garbage collection and prepare for the day where a
command can be removed from the vty.
This commit is contained in:
Holger Hans Peter Freyther 2010-09-14 02:08:44 +08:00
parent 87ec0f7401
commit c12cd3abdf
1 changed files with 28 additions and 11 deletions

View File

@ -149,29 +149,39 @@ Object subclass: VTYCommand [
<comment: 'I represent a vty command'>
<category: 'libosmovty-st'>
| command callback |
| command callback handler |
VTYCommand class >> initWith: aCommand help: aHelp [
VTYCommand class >> initWith: aCommand help: aHelp handler: aBlock[
<category: 'creation'>
"Create a new command. The memory is allocated permamently"
| command |
command := Vty_cmd_element new.
command := Vty_cmd_element gcNew.
command name value: aCommand.
command doc value: aHelp.
^ (self new)
command: command;
handler: aBlock;
yourself.
]
handleCommand: aCmd vty: aVty argc: aArgc argv: aArgv [
aCmd inspect.
aVty inspect.
aArgc inspect.
aArgv inspect.
Transcript show: 'abc'; nl.
^ 0
| str strings |
str := aArgv castTo: CStringType.
strings := OrderedCollection new.
0 to: (aArgc - 1) do: [ :each |
strings add: (str at: each).
].
^ handler value: aVty value: strings.
]
handler: aBlock [
<category: 'private'>
handler := aBlock.
]
command: aCommand [
@ -182,9 +192,11 @@ Object subclass: VTYCommand [
command := aCommand.
callback := CCallbackDescriptor
for: [ :cmd :vty :argc :argv | self handleCommand: cmd vty: vty argc: argc argv: argv.]
for: [ :cmd :vty :argc :argv |
self handleCommand: cmd vty: vty argc: argc argv: argv.
]
returning: #int
withArgs: #(#cObject #cObject #int #(#ptr #string)).
withArgs: #(#cObject #cObject #int #cObject).
command func value: callback.
]
@ -196,6 +208,11 @@ Object subclass: VTYCommand [
finalize [
self error: 'The command can not be removed. A crash will happen soon.'
]
install_ve [
<category: 'install'>
OSMOVTY install_element_ve: command.
]
]
Eval [