I have somewhat figured this out:
Accepting a var that equates to 'self' of the blessed class seems to allow
the calls to work.
Now - another question:
How do I access $self inside of the Tcl proc?
When I attempt to use and it is simply a string:
Test::IXIA2=HASH(0x812ec88),
but I would like to access the attributes of this object (I will add them
later) like in perl ($self->{var1}).
Can anyone help with this?
package Test::IXIA2;
use vars qw($self);
sub new {
my($class, %args) = @_;
my $self = bless {}, $class;
return $self;
}
use Inline Tcl => 'DATA';
1;
__DATA__
__Tcl__
proc _setupIxiaEnvironment {self} {
global env
global auto_path
set ixiaHome /home/uboscolo/cfg/install/ixia
set ixiaVersion 4.10.250.18
lappend auto_path [file join $ixiaHome "lib"]
set env(IXIA_HOME) /home/uboscolo/cfg/install/ixia
set env(IXIA_VERSION) 4.10.250.18
set env(IXIA_TCL_DIR) [file join $ixiaHome "lib"]
if { [catch {package require IxTclHal} res] != 0 } {
puts stderr "Can't load package IxTclHal: $res"
return 1
}
return 0
}
proc _connectToServer {self} {
puts "CONNECTING TO TclServer"
if { [catch {ixConnectToTclServer 10.1.213.251} res] != 0 } {
puts "Failed to connect to Tcl Server at 10.1.213.251] $res"
return 1
}
}
proc _loginToIxia {self} {
puts "CONNECTING TO CHASSIS 10.1.213.251"
if { [catch {ixConnectToChassis 10.1.213.251} res] !=0 } {
puts "Failed to connect to Ixia: $res"
}
puts $res
#puts "CONNECTED TO CHASSIS"
#set chassisID [ixGetChassisID 10.1.213.251]
#puts "CHASSIS ID $chassisID"
}
proc _takeOwnership {self ls} {
set ls1 [lindex $ls 0]
puts "ENTIRE LIST: $ls"
puts "LIST $ls1"
set el1 [lindex $ls1 0]
puts "EL1 $el1"
if { [ixLogin testuser ] != 0 } {
puts "Failed to login testuser to Ixia "
return 1
}
puts "logged into ixia"
if { [ixTakeOwnership $ls ] != 0 } {
puts "Failed to take ownership of $ls"
return 1
}
if { [ixClearOwnership $ls ] != 0 } {
puts "Failed to clear ownership of $ls "
return 1
} else {
puts "CLEARED OWNERSHIP OF $ls"
}
}
On Wed, May 28, 2008 at 11:17 AM, Darren Ball <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've been attempting to create a wrapper library for the IXIA product.
> Ixia only has TCL libraries.
>
>
> I believe this issue is not specific to Tcl.
>
> It seems to be a problem for me to call inline procs as via the object...
> I've had to include wrapper routines to every proc - which seems incorrect
> - I should be
> able to simply call them with something like $obj->procRoutine() should I
> not?
>
> Here is the library (brief):
>
> package Test::IXIA2;
>
> use vars qw($self);
> sub new {
> my($class, %args) = @_;
> my $self = bless {}, $class;
> return $self;
> }
>
>
> sub setupIxiaEnvironment{
> my($self)[EMAIL PROTECTED];
> &_setupIxiaEnvironment();
> }
>
>
> sub connectToChassis{
> my($self)[EMAIL PROTECTED];
> &_connectToChassis();
> }
>
> sub _takeOwnership{
> my($self)[EMAIL PROTECTED];
> &_takeOwnership();
> }
>
> use Inline Tcl => <<END;
>
> proc _setupIxiaEnvironment { } {
> global env
> global auto_path
>
> set ixiaHome /home/regress/cfg/install/ixia
> set ixiaVersion 4.10.250.18
>
> lappend auto_path [file join \$ixiaHome "lib"]
>
> set env(IXIA_HOME) /home/regress/cfg/install/ixia
> set env(IXIA_VERSION) 4.10.250.18
> set env(IXIA_TCL_DIR) [file join \$ixiaHome "lib"]
>
> puts \$::env(IXIA_HOME)
> puts \$::env(IXIA_VERSION)
> puts \$::env(IXIA_TCL_DIR)
>
> if { [catch {package require IxTclHal} res] != 0 } {
> puts stderr "Can't load package IxTclHal: \$res"
> return 1
> }
> return 0
>
> }
>
> proc _connectToChassis { } {
> if { [ixConnectToTclServer 10.1.213.251] != 0 } {
> puts "Failed to connect to Tcl Server at 10.1.213.251]"
> return 1
> }
> if { [ixConnectToChassis 10.1.213.251] != 0 } {
> puts "Failed to connect to Ixia at 10.1.213.251"
> return 1
> }
>
> }
> proc _takeOwnership { } {
> if { [ixLogin testuser ] != 0 } {
> puts "Failed to login testuser to Ixia "
> return 1
> }
> puts "logged into ixia"
> if { [ixTakeOwnership {{1 7 2}} "force"] != 0 } {
> puts "Failed to take ownership of {{1 7 1}}"
> return 1
> }
> if { [ixClearOwnership {{1 7 2}} ] != 0 } {
> puts "Failed to clear ownership of {{1 7 2}} "
> return 1
> }
> }
>
> END
>
> 1;
>
>
> And here is how I've tried to exercise it:
>
> #!/usr/bin/perl -w
>
> my $ixiaTest = new Test::IXIA2();
>
>
> # When I try the following, which are direct calls to the procs - it does
> not work
>
> $ixiaTest->_setupIxiaEnvironment();
> $ixiaTest->_connectToChassis();
> $ixiaTest->_takeOwnership();
>
> # When I use the wrapper routines - it does work
>
> $ixiaTest->setupIxiaEnvironment();
> $ixiaTest->connectToChassis();
> $ixiaTest->takeOwnership();
>
> exit 1;
>
>
>
> How can I make the first instance work (do I have to pass a reference to
> self into the procs?
>
>
> Any help would be appreciated.
>
> Thanks.
>
>