[LON-CAPA-cvs] cvs: loncom / LondTransaction.pm

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 13 May 2003 01:01:49 -0000


foxr		Mon May 12 21:01:49 2003 EDT

  Modified files:              
    /loncom	LondTransaction.pm 
  Log:
  Completed coding.
  
  
Index: loncom/LondTransaction.pm
diff -u loncom/LondTransaction.pm:1.2 loncom/LondTransaction.pm:1.3
--- loncom/LondTransaction.pm:1.2	Mon May  5 19:58:05 2003
+++ loncom/LondTransaction.pm	Mon May 12 21:01:49 2003
@@ -1,7 +1,7 @@
 #   This module defines and implements a class that represents
 #   a connection to a lond daemon.
 #
-# $Id: LondTransaction.pm,v 1.2 2003/05/05 23:58:05 foxr Exp $
+# $Id: LondTransaction.pm,v 1.3 2003/05/13 01:01:49 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -27,12 +27,15 @@
 #
 
 =pod
-=HEAD1 Synopsis
+
+=head1 Synopsis
+
   LondTransaction objectifies the state of a transaction between lonc and
   lond (loncnew really).  
 
 =cut
 
+package LondTransaction;
 
 =pod
 =head1 Description
@@ -52,7 +55,7 @@
 
 =item londSocket
 
-If the request is not a deferred one (deferred = false),
+If the request is active,
 this member contains the LondConnection object reference that
 this request is being processed on.
 
@@ -78,28 +81,160 @@
 
 =head2  Operational functions
 
+=cut
+
+=pod
+
 =item new
 
 Creates a new transaction object.
 
+=cut
+
+sub new {
+    my $class       = shift;
+    my $Transaction = shift;
+
+    
+    my $self   = {request     => $Transaction,
+		  active      => 0,
+		  deferred    => 0};
+    bless($self, $class);
+}
+=pod
+
 =item Activate
 
 Activates the transaction by assigning it to a LondConnection object
 
+Parameters:
+
+=over 3
+
+=item  Connection
+
+
+Reference to the LondConnection object along which the transaction
+will be carried.
+
+=back 
+
+=cut
+sub Activate {
+    my $self       = shift;
+    my $Connection = shift;	# Reference to a lond connection.
+
+    $self->{londSocket} = $Connection; # Store the connection object and
+    $self->{active}     = 1;	       # Indicate it's active.
+
+}
+
+=pod
+
 =item Retire
 
-Retires a transaction after successful completion.
+
+Retires a transaction after successful completion.  If the
+transaction is deferred, the deferred file is destroyed.
+Otherwise this is a noop.
+
+=cut
+sub Retire {
+    my $self     = shift;
+
+    if($self->{deferred}) {
+	unlink $self->{DeferredFile};
+    }
+
+    #  Destroy my member data to release reference counts.
+
+    delete $self->{londSocket};
+    delete $self->{clientSocket};
+    delete $self->{DeferredFile};
+
+}
+
+=pod
 
 =item SetDeferred
 
 Sets the state of a transaction to deferred, the deferred member
 is set true, clientSocket is undefined, and DeferredFile is set.
 
-=item SetClient
+Parameters:
+ 
+=over 3
+
+=item File
+
+Name of the file that holds the deferred transaction.
+
+=back 
+
+=cut
+sub SetDeferred {
+    my $self   = shift;
+    my $File   = shift;
+
+    $self->{deferred}      = 1;
+    $self->{DeferrredFile} = $File;
+}
+
+=pod
+
+=item  SetClient
 
 Sets the state of a transaction to not deferred.  The deferred member
 is set false, clientSocket is set and DeferredFile is undefined.
 
+Parameters:
+
+=over 3
+
+=item Socket
+
+  The socket open on the client.
+
+=back
+
+=cut
+sub SetClient {
+    my $self   = shift;
+    my $Client = shift;
+    
+    $self->{deferred}     = 0;
+    $self->{clientSocket} = $Client; 
+}
+
+=pod
+
+=item WroteSome
+
+ Called to indicate that some bytes were writtne to lond.
+ The request is trimmed by the number of bytes written.
+ If no bytes are left, nonzero is returned, else 0.
+
+Parameters:
+
+=over 3
+
+=item Count
+
+Number of bytes written
+
+=back
+
+=cut
+sub WroteSome {
+    my $self   = shift;
+    my $Count  = shift;
+
+    substr($self->{request}, length($self->{request}), $Count);
+
+    return (length($self->{request]) == 0);
+
+=pod
+
 =head2  Selectors
 
 
@@ -107,13 +242,42 @@
 
 Returns the state of the deferred member.
 
+=cut
+sub isDeferred {
+    my $self   = shift;
+    return $self->{deferred};
+}
+
+=pod
+
 =item isActive
 
-Returns the staate of the active member.
+Returns the value of the active member.
+
+=cut
+sub isActive {
+    my $self = shift;
+    return $self->{active};
+}
+
+=pod
 
 =item getClient
 
-if not deferred returns the client socket, else returns undef.
+If not deferred returns the client socket, else returns undef.
+
+=cut
+sub getClient {
+    my $self = shift;
+    if($self->{deferred}) {
+	return undef;
+    } else {
+	return $self->{clientSocket};
+    }
+}
+
+
+=pod
 
 =item getFile
 
@@ -121,3 +285,43 @@
 returns undef.
 
 =cut
+sub getFile {
+    my $self = shift;
+    if($self->{deferred}) {
+	return $self->{DeferredFile};
+    } else {
+	return undef;
+    }
+}
+
+
+=pod
+
+=item getServer
+
+  If active returns the lond server socket else undef.
+
+=cut
+sub getServer {
+    my $self  = shift;
+
+    if($self->{active}) {
+	return $self->{londSocket};
+    } else {
+	return undef;
+    }
+}
+
+=pod
+
+=item getRequest
+
+  Returns the remaining request text.
+
+=cut
+sub getRequest {
+    my $self = shift;
+    return $self->{request};
+}
+
+