1
0
Fork 0
This repository has been archived on 2022-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
osmo-st-binding/OsmoVTY.st

205 lines
5.1 KiB
Smalltalk
Raw Normal View History

2010-09-11 06:12:00 +00:00
"Copyright placeholder"
CStruct subclass: Vty_app_info [
<category: 'libosmovty'>
2010-09-11 06:12:00 +00:00
<comment: 'I represent the vty_app_info... some structs are wrong'>
<declaration: #(
#(#name #string)
#(#version #string)
#(#copyright #string)
#(#tall_ctx #(#ptr #int))
#(#go_parent_cb #(#ptr #long))
#(#is_config_node #(#ptr #long))) >
2010-09-11 06:12:00 +00:00
]
CStruct subclass: Vty_vector [
<category: 'libosmovty'>
<comment: 'I am the struct _vector class'>
"the index is wrong but we do not need to access it"
<declaration: #(
#(#active #uInt)
#(#alloced #uInt)
#(#index #(#ptr #int))) >
]
CStruct subclass: Vty_cmd_element [
<category: 'libosmovty'>
<comment: 'I represent the lowlevel command'>
<declaration: #(
#(#name #string)
#(#func #(#ptr #int))
#(#doc #string)
#(#daemon #int)
#(#strvec #(#ptr #{Vty_vector}))
#(#cmdsize #uInt)
#(#config #string)
#(#subconfig #(#ptr #{Vty_vector}))
#(#attr #uChar))>
]
CStruct subclass: Vty_cmd_node [
<comment: 'I provide access to a cmd_node'>
<category: 'libosmovty'>
<declaration: #(
#(#node #int)
#(#prompt #string)
#(#vtysh #int)
#(#func #(#ptr #int))
#(#cmd_vector #(#ptr #{Vty_vector}))) >
]
Object subclass: NodeType [
<category: 'libosmovty'>
NodeType class >> AUTH_NODE [
^ 0
]
NodeType class >> VIEW_NODE [
^ 1
]
NodeType class >> AUTH_ENABLE_NODE [
^ 2
]
NodeType class >> ENABLE_NODE [
^ 3
]
NodeType class >> CONFIG_NODE [
^ 4
]
NodeType class >> SERVICE_NODE [
^ 5
]
NodeType class >> DEBUG_NODE [
^ 6
]
NodeType class >> VTY_NODE [
^ 7
]
]
2010-09-11 06:12:00 +00:00
Object subclass: OSMOVTY [
<comment: 'I provide access to the VTY code'>
<category: 'libosmovty'>
OSMOVTY class >> initialize [
DLD addLibrary: 'libosmovty.so.0'
]
OSMOVTY class >> vty_init: app_info [
<cCall: 'vty_init' returning: #void args: #(#cObject) >
]
OSMOVTY class >> vty_read_config_file: file_name priv: priv [
<cCall: 'vty_read_config_file' returning: #int args: #(#string (#ptr #long)) >
]
OSMOVTY class >> telnet_init: tall_context priv: priv port: aPort [
<cCall: 'telnet_init' returning: #int args: #(#cObject #cObject #int) >
]
OSMOVTY class >> install_node: aNode func: aFunc [
<cCall: 'install_node' returning: #void args: #(#cObject #cObject) >
]
OSMOVTY class >> install_default: aNode [
<cCall: 'install_default' returning: #void args: #(#int) >
]
OSMOVTY class >> install_element: aNode cmd: aCmd [
<cCall: 'install_element' returning: #void args: #(#int #{Vty_cmd_element}) >
]
OSMOVTY class >> install_element_ve: aCmd [
<cCall: 'install_element_ve' returning: #void args: #(#{Vty_cmd_element}) >
]
2010-09-13 10:02:27 +00:00
OSMOVTY class >> vty_out: aVty msg: aMsg [
<cCall: 'vty_out' returning: #int args: #(#cObject #string) >
]
OSMOVTY class >> vty_out_newline: aVty [
<cCall: 'vty_out_newline' returning: #int args: #(#cObject) >
]
OSMOVTY class >> initWith: aName version: aVersion license: aLicense port: aPort [
| app_info |
2010-09-11 06:12:00 +00:00
app_info := Vty_app_info new.
app_info name value: aName.
app_info version value: aVersion.
app_info copyright value: aLicense.
app_info tall_ctx value: 0.
app_info go_parent_cb value: 0.
app_info is_config_node value: 0.
2010-09-11 06:12:00 +00:00
OSMOVTY vty_init: app_info.
OSMOVTY telnet_init: nil priv: nil port: 4444.
]
]
2010-09-11 06:12:00 +00:00
Object subclass: VTYCommand [
<comment: 'I represent a vty command'>
<category: 'libosmovty-st'>
| command callback |
VTYCommand class >> initWith: aCommand help: aHelp [
<category: 'creation'>
"Create a new command. The memory is allocated permamently"
| command |
command := Vty_cmd_element new.
command name value: aCommand.
command doc value: aHelp.
^ (self new)
command: command;
yourself.
]
handleCommand: aCmd vty: aVty argc: aArgc argv: aArgv [
aCmd inspect.
aVty inspect.
aArgc inspect.
aArgv inspect.
Transcript show: 'abc'; nl.
^ 0
]
command: aCommand [
<category: 'private'>
"We need to know when we are removed as we will segfault soon"
self addToBeFinalized.
command := aCommand.
callback := CCallbackDescriptor
for: [ :cmd :vty :argc :argv | self handleCommand: cmd vty: vty argc: argc argv: argv.]
returning: #int
withArgs: #(#cObject #cObject #int #(#ptr #string)).
command func value: callback.
]
command [
<category: 'command'>
^ command
]
finalize [
Transcript show: 'Command is being removed... bad'.
super fianilize.
]
]
Eval [
OSMOVTY initialize.
2010-09-11 06:12:00 +00:00
]