we have a initial working loging in version. Doesn't do much, but its
[spider.git] / perl / DXChannel.pm
index d4b20a2bedffe94f48dc1ab40e5fd83215259133..b661510040eebe5954bf7063b24169a2a435fa5c 100644 (file)
@@ -10,6 +10,9 @@ package DXChannel;
 require Exporter;
 @ISA = qw(Exporter);
 
+use Msg;
+use DXUtil;
+
 %connects = undef;
 
 # create a new connection object [$obj = Connect->new($call, $msg_conn_obj, $user_obj)]
@@ -18,7 +21,7 @@ sub new
   my ($pkg, $call, $conn, $user) = @_;
   my $self = {};
   
-  die "trying to create a duplicate Connect for call $call\n" if $connects{$call};
+  die "trying to create a duplicate channel for $call" if $connects{$call};
   $self->{call} = $call;
   $self->{conn} = $conn;
   $self->{user} = $user;
@@ -61,5 +64,55 @@ sub del
   delete $connects{$self->{call}};
 }
 
+
+# handle out going messages
+sub send_now
+{
+  my $self = shift;
+  my $sort = shift;
+  my $call = $self->{call};
+  my $conn = $self->{conn};
+  my $line;
+
+  foreach $line (@_) {
+    my $t = atime;
+       chomp $line;
+    print main::DEBUG "$t > $sort $call $line\n" if defined DEBUG;
+       print "> $sort $call $line\n";
+    $conn->send_now("$sort$call|$line");
+  }
+}
+
+sub send_later
+{
+  my $self = shift;
+  my $sort = shift;
+  my $call = $self->{call};
+  my $conn = $self->{conn};
+  my $line;
+
+  foreach $line (@_) {
+    my $t = atime;
+       chomp $line;
+    print main::DEBUG "$t > $sort $call $line\n" if defined DEBUG;
+    print "> $sort $call $line\n";
+    $conn->send_later("$sort$call|$line");
+  }
+}
+
+# send a file (always later)
+sub send_file
+{
+  my ($self, $fn) = @_;
+  my $call = $self->{call};
+  my $conn = $self->{conn};
+  my @buf;
+  
+  open(F, $fn) or die "can't open $fn for sending file ($!)";
+  @buf = <F>;
+  close(F);
+  $self->send_later('D', @buf);
+}
+
 1;
 __END__;