work on drawserv from 05/25/2004 thru 06/03/2004

[email protected] Fri, 4 Jun 2004 09:00:39 -0700
Newsgroups gmane.comp.lib.ivtools.patches
Message-ID <[email protected]>
--Apple-Mail-4-683457111
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="ivtools-040525-johnston-082"
Content-Disposition: attachment;
	filename=ivtools-040525-johnston-082

Patch:    ivtools-040525-johnston-082
For:      ivtools-1.1.3
Author:   [email protected]
Subject:  drawserv work
Requires: 

This is an intermediate patch to ivtools-1.1.3.  To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:

	patch -p0 <ThisFile

Summary of Changes:

Index: ComTerp/comterp.c
diff -c ComTerp/comterp.c:1.5 ComTerp/comterp.c:1.6
*** ComTerp/comterp.c:1.5	Fri Apr 30 09:26:11 2004
--- src/ComTerp/comterp.c	Tue May 25 12:11:38 2004
***************
*** 907,912 ****
--- 907,913 ----
        if (top_before == _stack_top)
  	status = 2;
        err_str( _errbuf, BUFSIZ, "comterp" );
+       errno = 0;
        if (strlen(_errbuf)==0) {
  	if (quitflag()) {
  	  status = -1;
***************
*** 939,944 ****
--- 940,949 ----
    if (status==1 && _pfnum==0) status=2;
    if (status==1 && !errorflag) status=3;
    if (nested && status!=2) _stack_top--;
+   if (errno == EPIPE) {
+     status = -1;
+     fprintf(stderr, "broken pipe detected: comterp quit\n");
+   }
    return status;
  }
  
Index: config_iv/iv-darwin.cf
diff -c config_iv/iv-darwin.cf:1.1 config_iv/iv-darwin.cf:1.2
*** config_iv/iv-darwin.cf:1.1	Fri Jan  9 11:46:51 2004
--- config/InterViews/iv-darwin.cf	Tue May 25 12:12:25 2004
***************
*** 4,12 ****
   */
  
  #if LibStdCPlusPlusV3
! #define OptimizeCCFlags -O2
  #else
! #define OptimizeCCFlags -O2
  #endif
  #define TIFFOptimizeCFlags -O
  #define TIFFStdCDefines -DHAVE_IEEEFP
--- 4,12 ----
   */
  
  #if LibStdCPlusPlusV3
! #define OptimizeCCFlags 
  #else
! #define OptimizeCCFlags 
  #endif
  #define TIFFOptimizeCFlags -O
  #define TIFFStdCDefines -DHAVE_IEEEFP
Index: DrawServ/Imakefile
diff -c DrawServ/Imakefile:1.8 DrawServ/Imakefile:1.9
*** DrawServ/Imakefile:1.8	Fri Mar 26 16:22:59 2004
--- src/DrawServ/Imakefile	Tue May 25 12:12:08 2004
***************
*** 19,24 ****
--- 19,25 ----
  #define Obj26(file) MakeObjectFromSrcFlags(file,)
  #define Obj26A(file) MakeObjectFromSrcFlags(file, -D__ACE_INLINE__)
  
+ Obj26A(ackback-handler)
  Obj26(drawcatalog)
  Obj26(drawcreator)
  Obj26(drawcomps)
Index: DrawServ/ackback-handler.c
diff -c /dev/null DrawServ/ackback-handler.c:1.1
*** /dev/null	Tue May 25 12:12:10 2004
--- src/DrawServ/ackback-handler.c	Tue May 25 12:12:08 2004
***************
*** 0 ****
--- 1,131 ----
+ /*
+  * Copyright (c) 2004 Scott E. Johnston
+  *
+  * Permission to use, copy, modify, distribute, and sell this software and
+  * its documentation for any purpose is hereby granted without fee, provided
+  * that the above copyright notice appear in all copies and that both that
+  * copyright notice and this permission notice appear in supporting
+  * documentation, and that the names of the copyright holders not be used in
+  * advertising or publicity pertaining to distribution of the software
+  * without specific, written prior permission.  The copyright holders make
+  * no representations about the suitability of this software for any purpose.
+  * It is provided "as is" without express or implied warranty.
+  *
+  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
+  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  * 
+  */
+ 
+ #ifdef HAVE_ACE
+ 
+ #include <DrawServ/ackback-handler.h>
+ #include <DrawServ/drawlink.h>
+ #include <DrawServ/drawserv.h>
+ #include <vector.h>
+ #include <err.h>
+ 
+ /*****************************************************************************/
+ 
+ // Default constructor.
+ 
+ AckBackHandler::AckBackHandler ()
+ {
+   _timer_started = false;
+   _ackback_arrived = false;
+ }
+ 
+ AckBackHandler::~AckBackHandler() {
+   fprintf(stderr, "AckBackHandler deleted\n");
+ }
+ 
+ // Called when input becomes available on fd.
+ 
+ int AckBackHandler::handle_input (ACE_HANDLE fd)
+ {
+   if (drawlink() && drawlink()->socket()) {
+     vector<char> inv;
+     char ch;
+     int status;
+     while((status = read(fd, &ch, 1))==1) inv.push_back(ch);
+     inv.push_back('\0');
+     if (status == 0) {
+       cerr << "AckBack (end of file):  [" << (char*)&inv[0] << "]\n";
+       drawlink()->ackhandler(nil);
+       ((DrawServ*)unidraw)->linkdown(drawlink());
+       return -1;
+     } else if (errno != EAGAIN)
+       warn(nil);
+     else {
+       cerr << "AckBack:  [" << (char*)&inv[0] << "]\n";
+       _ackback_arrived = true;
+     }
+     return 0;
+   } else {
+     fprintf(stderr, "unexpected missing socket\n");
+     return -1;
+   }
+ }
+ 
+ void AckBackHandler::start_timer() {
+   if (!_timer_started) {
+     _timerid = ComterpHandler::reactor_singleton()->schedule_timer
+       (this, (const void *) this, ACE_Time_Value (5), ACE_Time_Value (5));
+     _timer_started = true;
+     _ackback_arrived = false;
+   }
+ 
+ }
+ 
+ int AckBackHandler::handle_timeout (const ACE_Time_Value &,
+ 				    const void *arg)
+ {
+   if(_timer_started && !ComterpHandler::reactor_singleton()->cancel_timer(_timerid, nil))
+     cerr << "unable to cancel timerid " << _timerid << "\n";
+   _timer_started = false;
+   if (!_ackback_arrived) {
+     fprintf(stderr, "ackback timeout\n");
+     drawlink()->ackhandler(nil);
+     ((DrawServ*)unidraw)->linkdown(drawlink());
+     return -1;
+   }
+ 
+   return 0;
+ }
+ 
+ // Get the I/O handle.
+ ACE_HANDLE AckBackHandler::get_handle (void) const {
+   return _handle;
+ }
+ 
+  // Set the I/O handle.
+ void AckBackHandler::set_handle (ACE_HANDLE handle) {
+   _handle = handle;
+ }
+ 
+ 
+ // Called when the object is about to be removed from the Dispatcher
+ // tables.
+ 
+ int  AckBackHandler::handle_close (ACE_HANDLE handle, ACE_Reactor_Mask mask)
+ {
+   fprintf(stderr, "AckBackHandler::handle_close called with mask 0x%x\n", mask);
+   if(_timer_started && !ComterpHandler::reactor_singleton()->cancel_timer(_timerid, nil))
+     cerr << "unable to cancel timerid " << _timerid << "\n";
+   else
+     _timer_started = false;
+   if (mask == ACE_Event_Handler::TIMER_MASK || mask == ACE_Event_Handler::READ_MASK) {
+     if (mask == ACE_Event_Handler::TIMER_MASK)
+       if (ComterpHandler::reactor_singleton()->remove_handler(this, ACE_Event_Handler::READ_MASK|ACE_Event_Handler::TIMER_MASK)==-1)
+ 	cerr << "drawserv: error removing ackback handler\n";
+     delete this;
+   }
+   
+   return 0;
+ }
+ 
+ #endif /* HAVE_ACE */
Index: DrawServ/ackback-handler.h
diff -c /dev/null DrawServ/ackback-handler.h:1.1
*** /dev/null	Tue May 25 12:12:10 2004
--- src/DrawServ/ackback-handler.h	Tue May 25 12:12:08 2004
***************
*** 0 ****
--- 1,82 ----
+ /*
+  * Copyright (c) 2004 Scott E. Johnston
+  *
+  * Permission to use, copy, modify, distribute, and sell this software and
+  * its documentation for any purpose is hereby granted without fee, provided
+  * that the above copyright notice appear in all copies and that both that
+  * copyright notice and this permission notice appear in supporting
+  * documentation, and that the names of the copyright holders not be used in
+  * advertising or publicity pertaining to distribution of the software
+  * without specific, written prior permission.  The copyright holders make
+  * no representations about the suitability of this software for any purpose.
+  * It is provided "as is" without express or implied warranty.
+  *
+  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
+  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  * 
+  */
+ 
+ #ifdef HAVE_ACE
+ 
+ #ifndef _ackback_handler_
+ #define _ackback_handler_
+ 
+ #include <ace/Event_Handler.h>
+ 
+ class DrawLink;
+ 
+ //: specialized ACE_EventHandler for monitoring responses from outgoing connection
+ class AckBackHandler : public ACE_Event_Handler
+ {
+ 
+ public:
+   // = Initialization and termination methods.
+   AckBackHandler ();
+ 
+   virtual ~AckBackHandler ();
+ 
+   DrawLink* drawlink() { return _drawlink; }
+   // get DrawLink associated with this handler
+   void drawlink(DrawLink* link) { _drawlink = link; }
+   // set DrawLink associated with this handler
+ 
+   virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);
+   // Called when input events occur (e.g., connection or data).
+ 
+   virtual int handle_timeout (const ACE_Time_Value &tv, 
+ 			      const void *arg); 
+   // called when timer goes off.
+ 
+   virtual int handle_close (ACE_HANDLE handle,
+                             ACE_Reactor_Mask close_mask);
+   // Called when a <handle_*()> method returns -1 or when the
+   // <remove_handler> method is called on an <ACE_Reactor>.  The
+   // <close_mask> indicates which event has triggered the
+   // <handle_close> method callback on a particular <handle>.
+ 
+   virtual ACE_HANDLE get_handle (void) const;
+   // Get the I/O handle.
+ 
+   virtual void set_handle (ACE_HANDLE);
+   // Set the I/O handle.
+ 
+   void start_timer();
+   // Start timer waiting for ackback
+ 
+ protected:
+   DrawLink* _drawlink;
+   int _timer_started;
+   int _ackback_arrived;
+   long _timerid;
+   ACE_HANDLE _handle;
+ 
+ };
+ 
+ #endif /* _ackback_handler_ */
+ 
+ #endif /* HAVE_ACE */
Index: DrawServ/drawlink.c
diff -c DrawServ/drawlink.c:1.18 DrawServ/drawlink.c:1.19
*** DrawServ/drawlink.c:1.18	Fri Apr 30 09:26:36 2004
--- src/DrawServ/drawlink.c	Tue May 25 12:12:08 2004
***************
*** 25,30 ****
--- 25,31 ----
   * Implementation of Drawlink class.
   */
  
+ #include <DrawServ/ackback-handler.h>
  #include <DrawServ/drawlink.h>
  #include <DrawServ/drawserv.h>
  #include <DrawServ/drawserv-handler.h>
***************
*** 53,59 ****
    _socket = nil;
    _conn = nil;
  
!   _handler = nil;
    _incomingsidtable = new IncomingSidTable(32);
  }
  
--- 54,61 ----
    _socket = nil;
    _conn = nil;
  
!   _comhandler = nil;
!   _ackhandler = nil;
    _incomingsidtable = new IncomingSidTable(32);
  }
  
***************
*** 82,87 ****
--- 84,97 ----
      return -1;
    } else {
      _socket->enable(ACE_NONBLOCK);
+ 
+     /* set up handler to monitor backtalk */
+     ackhandler(new AckBackHandler);
+     ackhandler()->drawlink(this);
+     ackhandler()->set_handle(_socket->get_handle());
+     if (ComterpHandler::reactor_singleton()->register_handler(ackhandler(), ACE_Event_Handler::READ_MASK|ACE_Event_Handler::TIMER_MASK)==-1)
+       fprintf(stderr, "drawserv: error registering ackback handler (handle==%d)\n", _socket->get_handle());
+ 
      fileptr_filebuf obuf(_socket->get_handle(), ios_base::out, false, static_cast<size_t>(BUFSIZ));
      ostream out(&obuf);
      out << "drawlink(\"";
***************
*** 104,109 ****
--- 114,123 ----
      out << ")\n";
      out.flush();
      _ok = true;
+ 
+     /* schedule timer on ackback link, to detect timeout */
+     ackhandler()->start_timer();
+ 
      return 0;
    }
  #else
***************
*** 115,122 ****
  int DrawLink::close() {
    fprintf(stderr, "Closing link to %s (%s) port # %d (lid=%d, rid=%d)\n", 
  	  hostname(), althostname(), portnum(), local_linkid(), remote_linkid());
!   if (handler()) handler()->drawlink(nil);
    if (_socket) {
      if (_socket->close () == -1)
        ACE_ERROR ((LM_ERROR, "%p\n", "close"));
    }
--- 129,143 ----
  int DrawLink::close() {
    fprintf(stderr, "Closing link to %s (%s) port # %d (lid=%d, rid=%d)\n", 
  	  hostname(), althostname(), portnum(), local_linkid(), remote_linkid());
!   if (comhandler()) comhandler()->drawlink(nil);
    if (_socket) {
+     if (ackhandler()) {
+       if (ackhandler()->get_handle() !=-1)
+ 	if (ComterpHandler::reactor_singleton()->remove_handler(ackhandler(), ACE_Event_Handler::READ_MASK|ACE_Event_Handler::TIMER_MASK)==-1)
+ 	  cerr << "drawserv: error removing ackback handler\n";
+       delete ackhandler();
+       ackhandler(nil);
+     }
      if (_socket->close () == -1)
        ACE_ERROR ((LM_ERROR, "%p\n", "close"));
    }
Index: DrawServ/drawlink.h
diff -c DrawServ/drawlink.h:1.13 DrawServ/drawlink.h:1.14
*** DrawServ/drawlink.h:1.13	Fri Apr  2 12:55:02 2004
--- src/DrawServ/drawlink.h	Tue May 25 12:12:08 2004
***************
*** 29,37 ****
--- 29,39 ----
  
  #include <InterViews/observe.h>
  
+ class AckBackHandler;
  class DrawServ;
  class DrawServHandler;
  
+ 
  #include <OS/table.h>
  declareTable(IncomingSidTable,unsigned int,unsigned int)
  
***************
*** 92,103 ****
      void remote_linkid(int id) { _remote_linkid = id; }
      // get remote DrawLink id
  
!     void handler(DrawServHandler* handler) { _handler = handler; }
      // set DrawServHandler associated with incoming connection
  
!     DrawServHandler* handler() { return _handler; }
      // get DrawServHandler associated with incoming connection
  
      IncomingSidTable* incomingsidtable() { return _incomingsidtable; }
      // return pointer to table mapping incoming sessionid's to locally unique sessionid's
  
--- 94,111 ----
      void remote_linkid(int id) { _remote_linkid = id; }
      // get remote DrawLink id
  
!     void comhandler(DrawServHandler* handler) { _comhandler = handler; }
      // set DrawServHandler associated with incoming connection
  
!     DrawServHandler* comhandler() { return _comhandler; }
      // get DrawServHandler associated with incoming connection
  
+     void ackhandler(AckBackHandler* handler) { _ackhandler = handler; }
+     // set AckBackHandler associated with incoming connection
+ 
+     AckBackHandler* ackhandler() { return _ackhandler; }
+     // get AckBackHandler associated with incoming connection
+ 
      IncomingSidTable* incomingsidtable() { return _incomingsidtable; }
      // return pointer to table mapping incoming sessionid's to locally unique sessionid's
  
***************
*** 107,112 ****
--- 115,123 ----
      int state() { return _state; }
      // get state of DrawLink
  
+     ACE_SOCK_Stream* socket() { return _socket; }
+     // return pointer to connected socket.
+ 
  protected:
      const char* _host;
      const char* _althost;
***************
*** 124,130 ****
      ACE_SOCK_Stream* _socket;
  #endif
  
!     DrawServHandler* _handler;
  };
  
  #endif
--- 135,142 ----
      ACE_SOCK_Stream* _socket;
  #endif
  
!     DrawServHandler* _comhandler;
!     AckBackHandler* _ackhandler;
  };
  
  #endif
Index: DrawServ/drawserv-handler.c
diff -c DrawServ/drawserv-handler.c:1.3 DrawServ/drawserv-handler.c:1.4
*** DrawServ/drawserv-handler.c:1.3	Sat Feb 28 09:02:30 2004
--- src/DrawServ/drawserv-handler.c	Tue May 25 12:12:08 2004
***************
*** 1,5 ****
  /*
!  * Copyright (c) 1996 Vectaport Inc.
   *
   * Permission to use, copy, modify, distribute, and sell this software and
   * its documentation for any purpose is hereby granted without fee, provided
--- 1,5 ----
  /*
!  * Copyright (c) 2004 Scott E. Johnston
   *
   * Permission to use, copy, modify, distribute, and sell this software and
   * its documentation for any purpose is hereby granted without fee, provided
***************
*** 26,44 ****
--- 26,77 ----
  #include <DrawServ/drawserv.h>
  #include <DrawServ/drawserv-handler.h>
  
+ int DrawServHandler::_sigpipe_handler_initialized = 0;
+ 
  /*****************************************************************************/
  
  // Default constructor.
  
  DrawServHandler::DrawServHandler () : UnidrawComterpHandler()
  {
+   _drawlink = nil;
+   if (!_sigpipe_handler_initialized) {
+     if (ComterpHandler::reactor_singleton()->register_handler 
+ 	(SIGPIPE, this) == -1)
+       ACE_DEBUG ((LM_ERROR, 
+ 		  "(%P|%t) can't register signal handler with reactor\n"));
+     _sigpipe_handler_initialized = 1;
+     _sigpipe_handler = 1;
+   } else
+     _sigpipe_handler = 0;
+ }
+ 
+ int DrawServHandler::open (void * ptr)
+ {
+   ComterpHandler::open(ptr);
+   return 0;
  }
  
  void DrawServHandler::destroy (void) {
+   if (_sigpipe_handler) {
+     if (ComterpHandler::reactor_singleton()->remove_handler 
+ 	(SIGPIPE, (ACE_Sig_Action*)nil) == -1)
+       ACE_DEBUG ((LM_ERROR, 
+ 		  "(%P|%t) can't remove signal handler from reactor\n"));
+     _sigpipe_handler = _sigpipe_handler_initialized = 0;
+   }
    ComterpHandler::destroy();
    if (drawlink()) {
      ((DrawServ*)unidraw)->linkdown(drawlink());
      drawlink(nil);
    }
+ }
+ 
+ int DrawServHandler::handle_signal(int signum, siginfo_t* s, ucontext_t* u) {
+   if (signum==SIGPIPE) {
+     fprintf(stderr, "ignoring SIGPIPE because we don't know what handle it is on\n");
+   } else
+     fprintf(stderr, "unknown signal handled %d\n", signum);
+   return 0;
  }
  #endif /* HAVE_ACE */
Index: DrawServ/drawserv-handler.h
diff -c DrawServ/drawserv-handler.h:1.2 DrawServ/drawserv-handler.h:1.3
*** DrawServ/drawserv-handler.h:1.2	Fri Feb 27 09:41:36 2004
--- src/DrawServ/drawserv-handler.h	Tue May 25 12:12:08 2004
***************
*** 1,5 ****
  /*
!  * Copyright (c) 1996,1999 Vectaport Inc.
   *
   * Permission to use, copy, modify, distribute, and sell this software and
   * its documentation for any purpose is hereby granted without fee, provided
--- 1,5 ----
  /*
!  * Copyright (c) 2004 Scott E. Johnston
   *
   * Permission to use, copy, modify, distribute, and sell this software and
   * its documentation for any purpose is hereby granted without fee, provided
***************
*** 28,33 ****
--- 28,34 ----
  
  #include <ComUnidraw/comterp-acehandler.h>
  
+ class AckBackHandler;
  class DrawLink;
  
  //: specialized UnidrawComterpHandler for integration into DrawServ
***************
*** 46,53 ****
--- 47,62 ----
    virtual void destroy (void);
    // traps disconnects
  
+   virtual int open (void *);
+   // open handler hook.
+ 
+   virtual int handle_signal(int, siginfo_t*, ucontext_t*);
+   // handle signals
+ 
  protected:
    DrawLink* _drawlink;
+   static int _sigpipe_handler_initialized;
+   int _sigpipe_handler;
  
  };
  
Index: DrawServ/drawserv.c
diff -c DrawServ/drawserv.c:1.49 DrawServ/drawserv.c:1.50
*** DrawServ/drawserv.c:1.49	Fri Apr  2 12:55:02 2004
--- src/DrawServ/drawserv.c	Tue May 25 12:12:08 2004
***************
*** 25,30 ****
--- 25,31 ----
   * Implementation of DrawServ class.
   */
  
+ #include <DrawServ/ackback-handler.h>
  #include <DrawServ/draweditor.h>
  #include <DrawServ/drawlink.h>
  #include <DrawServ/drawlinklist.h>
***************
*** 117,126 ****
      link->remote_linkid(remote_id);
      if (state==DrawLink::one_way && comterp && comterp->handler()) {
        ((DrawServHandler*)comterp->handler())->drawlink(link);
!       link->handler((DrawServHandler*)comterp->handler());
      }
!     link->open();
!     if (link && link->ok()) {
        _linklist->add_drawlink(link);
        return link;
      } else {
--- 118,126 ----
      link->remote_linkid(remote_id);
      if (state==DrawLink::one_way && comterp && comterp->handler()) {
        ((DrawServHandler*)comterp->handler())->drawlink(link);
!       link->comhandler((DrawServHandler*)comterp->handler());
      }
!     if (link->open()==0 && link->ok()) {
        _linklist->add_drawlink(link);
        return link;
      } else {
***************
*** 143,149 ****
        curlink->state(DrawLink::two_way);
        if (comterp && comterp->handler()) {
  	((DrawServHandler*)comterp->handler())->drawlink(curlink);
! 	curlink->handler((DrawServHandler*)comterp->handler());
        }
        fprintf(stderr, "link up with %s(%s) via port %d\n", 
  	      curlink->hostname(), curlink->althostname(), portnum);
--- 143,149 ----
        curlink->state(DrawLink::two_way);
        if (comterp && comterp->handler()) {
  	((DrawServHandler*)comterp->handler())->drawlink(curlink);
! 	curlink->comhandler((DrawServHandler*)comterp->handler());
        }
        fprintf(stderr, "link up with %s(%s) via port %d\n", 
  	      curlink->hostname(), curlink->althostname(), portnum);
***************
*** 164,172 ****
  }
  
  int DrawServ::linkdown(DrawLink* link) {
!   if (_linklist->Includes(link)) {
      _linklist->Remove(link);
      link->close();
      delete link;
      return 0;
    } else
--- 164,173 ----
  }
  
  int DrawServ::linkdown(DrawLink* link) {
!   if (link && _linklist->Includes(link)) {
      _linklist->Remove(link);
      link->close();
+     remove_sids(link);
      delete link;
      return 0;
    } else
***************
*** 334,340 ****
    _linklist->First(i);
    while (!_linklist->Done(i)) {
      DrawLink* link = _linklist->GetDrawLink(i);
!     if (link) {
        int fd = link->handle();
        if (fd>=0) {
  	fileptr_filebuf fbuf(fd, ios_base::out, false, static_cast<size_t>(BUFSIZ));
--- 335,341 ----
    _linklist->First(i);
    while (!_linklist->Done(i)) {
      DrawLink* link = _linklist->GetDrawLink(i);
!     if (link && link->state()==DrawLink::two_way) {
        int fd = link->handle();
        if (fd>=0) {
  	fileptr_filebuf fbuf(fd, ios_base::out, false, static_cast<size_t>(BUFSIZ));
***************
*** 342,347 ****
--- 343,349 ----
  	out << cmdstring;
  	out << "\n";
  	out.flush();
+ 	link->ackhandler()->start_timer();
        }
      }
      _linklist->Next(i);
***************
*** 359,364 ****
--- 361,367 ----
        out << cmdstring;
        out << "\n";
        out.flush();
+       link->ackhandler()->start_timer();
      }
    }
  }
***************
*** 568,573 ****
--- 571,590 ----
  	   link ? link->local_linkid() : 9999, link ? link->remote_linkid() : 9999, 
  	   sid->pid(), sid->hostid(), sid->username(), sid->hostname());
      it.next();
+   }
+ }
+ 
+ void DrawServ::remove_sids(DrawLink* link) {
+   SessionIdTable* table = sessionidtable();
+   SessionIdTable_Iterator it(*table);
+   while(it.more()) {
+     SessionId* sid = (SessionId*)it.cur_value();
+     DrawLink* testlink = sid->drawlink();
+     unsigned int altid = it.cur_key();
+     it.next();
+     if (testlink==link) 
+       if (!table->find_and_remove((void*)sid, altid)) 
+ 	fprintf(stderr, "unable to remove SessionId's associated with DrawLink\n");
    }
  }
  
Index: DrawServ/drawserv.h
diff -c DrawServ/drawserv.h:1.25 DrawServ/drawserv.h:1.26
*** DrawServ/drawserv.h:1.25	Fri Apr  2 12:55:02 2004
--- src/DrawServ/drawserv.h	Tue May 25 12:12:08 2004
***************
*** 116,121 ****
--- 116,124 ----
    unsigned int sessionid() { return _sessionid; }
    // current unique session id.
  
+   void remove_sids(DrawLink*);
+   // remove all SessionId's associated with this DrawLink
+ 
    void grid_message(GraphicId* grid);
    // generate graphic id selection message
  
Index: DrawServ/rcdialog.c
diff -c DrawServ/rcdialog.c:1.5 DrawServ/rcdialog.c:1.6
*** DrawServ/rcdialog.c:1.5	Fri Apr  2 12:55:02 2004
--- src/DrawServ/rcdialog.c	Tue May 25 12:12:08 2004
***************
*** 35,40 ****
--- 35,41 ----
  #include <Unidraw/editor.h>
  #include <Unidraw/iterator.h>
  
+ #include <IVGlyph/gdialogs.h>
  #include <IVGlyph/stredit.h>
  #include <IVGlyph/textedit.h>
  #include <IVGlyph/textview.h>
***************
*** 70,76 ****
    StrEditDialog::action_custom(new RemoteConnectAction(dialog), nil);
  #else
      WidgetKit& kit = *WidgetKit::instance();
!     ConnectionsDialog* dlog = new ConnectionsDialog(((DrawServ*)unidraw)->linklist(), &kit, kit.style());
      dlog->ref();
      dlog->map_for(_editor->GetWindow());
  #endif
--- 71,77 ----
    StrEditDialog::action_custom(new RemoteConnectAction(dialog), nil);
  #else
      WidgetKit& kit = *WidgetKit::instance();
!     ConnectionsDialog* dlog = new ConnectionsDialog(_editor, ((DrawServ*)unidraw)->linklist(), &kit, kit.style());
      dlog->ref();
      dlog->map_for(_editor->GetWindow());
  #endif
***************
*** 126,138 ****
      void update_text(boolean);
  };
  
! ConnectionsDialog::ConnectionsDialog(DrawLinkList* list, WidgetKit* kit, Style* s) 
  : Dialog(nil, s)
  {
    impl_ = new ConnectionsDialogImpl;
    ConnectionsDialogImpl& adi = *impl_;
    adi.kit_ = kit;
    adi.init(list, this, s);
  }
  
  ConnectionsDialog::~ConnectionsDialog() {
--- 127,140 ----
      void update_text(boolean);
  };
  
! ConnectionsDialog::ConnectionsDialog(Editor* ed, DrawLinkList* list, WidgetKit* kit, Style* s) 
  : Dialog(nil, s)
  {
    impl_ = new ConnectionsDialogImpl;
    ConnectionsDialogImpl& adi = *impl_;
    adi.kit_ = kit;
    adi.init(list, this, s);
+   _ed = ed;
  }
  
  ConnectionsDialog::~ConnectionsDialog() {
***************
*** 224,230 ****
    if (hoststr->length() > 0) {
      int portnum=20002;
      if (portstr->length() > 0) portnum = atoi(portstr->string());
!     ((DrawServ*)unidraw)->linkup(hoststr->string(), portnum, 0);
    }
  }
  
--- 226,236 ----
    if (hoststr->length() > 0) {
      int portnum=20002;
      if (portstr->length() > 0) portnum = atoi(portstr->string());
!     if(((DrawServ*)unidraw)->linkup(hoststr->string(), portnum, 0)==nil) {
!       char buffer[BUFSIZ];
!       snprintf(buffer, BUFSIZ, "%s:%d", hoststr->string(), portnum);
!       GAcknowledgeDialog::map(dialog_->GetEditor()->GetWindow(), "Connection refused", buffer, "Connection refused");
!     }
    }
  }
  
Index: DrawServ/rcdialog.h
diff -c DrawServ/rcdialog.h:1.5 DrawServ/rcdialog.h:1.6
*** DrawServ/rcdialog.h:1.5	Fri Apr  2 12:55:02 2004
--- src/DrawServ/rcdialog.h	Tue May 25 12:12:09 2004
***************
*** 59,74 ****
  
  class ConnectionsDialogImpl;
  class DrawLinkList;
  class Style;
  class WidgetKit;
  
  //: dialog for editing list of current connections
  class ConnectionsDialog : public Dialog {
  public:
!     ConnectionsDialog(DrawLinkList*, WidgetKit*, Style*);
      virtual ~ConnectionsDialog();
  protected:
      ConnectionsDialogImpl* impl_;
  };
  
  #include <InterViews/_leave.h>
--- 59,77 ----
  
  class ConnectionsDialogImpl;
  class DrawLinkList;
+ class Editor;
  class Style;
  class WidgetKit;
  
  //: dialog for editing list of current connections
  class ConnectionsDialog : public Dialog {
  public:
!     ConnectionsDialog(Editor*, DrawLinkList*, WidgetKit*, Style*);
      virtual ~ConnectionsDialog();
+     Editor* GetEditor() { return _ed; }
  protected:
      ConnectionsDialogImpl* impl_;
+     Editor* _ed;
  };
  
  #include <InterViews/_leave.h>
Index: drawserv_/main.c
diff -c drawserv_/main.c:1.8 drawserv_/main.c:1.9
*** drawserv_/main.c:1.8	Fri Apr  2 12:55:04 2004
--- src/drawserv_/main.c	Tue May 25 12:12:11 2004
***************
*** 216,221 ****
--- 216,222 ----
  
  int main (int argc, char** argv) {
  
+ #if 0
      /* ignore broken pipe, so socket writes that are in error return EPIPE */
  #if 0
      struct sigaction oldaction, newaction;
***************
*** 230,235 ****
--- 231,237 ----
      func = signal(SIGPIPE, &handle_badpipe);
      if (func==SIG_ERR) 
        fprintf(stderr, "SIG_ERR returned from signal, errno = %d\n", errno);
+ #endif
  #endif
    
  #ifdef HAVE_ACE
Index: IVGlyph/gdialogs.c
diff -c IVGlyph/gdialogs.c:1.1 IVGlyph/gdialogs.c:1.2
*** IVGlyph/gdialogs.c:1.1	Fri Jan  9 11:43:13 2004
--- src/IVGlyph/gdialogs.c	Tue May 25 12:11:47 2004
***************
*** 98,103 ****
--- 98,120 ----
  }
  
  
+ void GAcknowledgeDialog::map(Window* window, const char* message, 
+ 			     const char* submsg, const char* title) {
+   WidgetKit& kit = *WidgetKit::instance();
+   if (title) {
+     Style* ts = new Style(kit.style());
+     ts->attribute("name", title);
+     kit.push_style(ts);
+   }
+   
+   GAcknowledgeDialog* dialog = new GAcknowledgeDialog(message, submsg);
+   // Resource::ref(dialog);
+   dialog->map_for(window);
+   if (title)
+     kit.pop_style();
+ }
+ 
+ 
  /** class GAcknowledgeDialogImpl **/
  
  void GAcknowledgeDialogImpl::init(GAcknowledgeDialog* d, Style* s, const char* c1, const char* c2) {
Index: IVGlyph/gdialogs.h
diff -c IVGlyph/gdialogs.h:1.1 IVGlyph/gdialogs.h:1.2
*** IVGlyph/gdialogs.h:1.1	Fri Jan  9 11:43:13 2004
--- src/IVGlyph/gdialogs.h	Tue May 25 12:11:47 2004
***************
*** 43,48 ****
--- 43,51 ----
      static void post(Window*, const char* message, 
  		     const char* submsg=nil, const char* title=nil);
  
+     static void map(Window*, const char* message, 
+ 		    const char* submsg=nil, const char* title=nil);
+ 
  private:
      GAcknowledgeDialogImpl* impl_;
  };
Index: IVGlyph/stredit.c
diff -c IVGlyph/stredit.c:1.2 IVGlyph/stredit.c:1.3
*** IVGlyph/stredit.c:1.2	Tue Mar 30 11:05:29 2004
--- src/IVGlyph/stredit.c	Tue May 25 12:11:47 2004
***************
*** 135,141 ****
    }
    
    StrEditDialog* dialog = new StrEditDialog(message, string, extra, custom);
!   Resource::ref(dialog);
    dialog->map_for(window);
    if (title)
      kit.pop_style();
--- 135,141 ----
    }
    
    StrEditDialog* dialog = new StrEditDialog(message, string, extra, custom);
!   // Resource::ref(dialog);
    dialog->map_for(window);
    if (title)
      kit.pop_style();
Index: top_ivtools/MANIFEST
diff -c top_ivtools/MANIFEST:1.7 top_ivtools/MANIFEST:1.8
*** top_ivtools/MANIFEST:1.7	Fri Mar  5 10:53:08 2004
--- ./MANIFEST	Tue May 25 12:11:33 2004
***************
*** 274,279 ****
--- 274,281 ----
  ivtools-1.1/src/Dispatch/rpcwriter.c
  ivtools-1.1/src/DrawServ/Imakefile
  ivtools-1.1/src/DrawServ/Makefile
+ ivtools-1.1/src/DrawServ/ackback-handler.c
+ ivtools-1.1/src/DrawServ/ackback-handler.h
  ivtools-1.1/src/DrawServ/drawcatalog.c
  ivtools-1.1/src/DrawServ/drawcatalog.h
  ivtools-1.1/src/DrawServ/drawclasses.h
Index: top_ivtools/MANIFEST.perceps
diff -c top_ivtools/MANIFEST.perceps:1.6 top_ivtools/MANIFEST.perceps:1.7
*** top_ivtools/MANIFEST.perceps:1.6	Fri Mar  5 10:53:08 2004
--- ./MANIFEST.perceps	Tue May 25 12:11:33 2004
***************
*** 65,70 ****
--- 65,71 ----
  ComUtil/comutil.h
  ComUtil/util.h
  Dispatch/netinet_in.h
+ DrawServ/ackback-handler.h
  DrawServ/drawcatalog.h
  DrawServ/drawclasses.h
  DrawServ/drawcomps.h
*** /dev/null	 Tue May 25 12:12:27 PDT 2004
--- patches/ivtools-040525-johnston-082
*************** patches/ivtools-040525-johnston-082
*** 0 ****
--- 1 ----
+ ivtools-040525-johnston-082

--Apple-Mail-4-683457111
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="ivtools-040601-johnston-083"
Content-Disposition: attachment;
	filename=ivtools-040601-johnston-083

Patch:    ivtools-040601-johnston-083
For:      ivtools-1.1.3
Author:   [email protected]
Subject:  drawserv work
Requires: 

This is an intermediate patch to ivtools-1.1.3.  To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:

	patch -p0 <ThisFile

Summary of Changes:

Index: Attribute/attrlist.c
diff -c Attribute/attrlist.c:1.1 Attribute/attrlist.c:1.2
*** Attribute/attrlist.c:1.1	Fri Jan  9 11:42:18 2004
--- src/Attribute/attrlist.c	Tue Jun  1 17:52:27 2004
***************
*** 203,213 ****
  	Attribute* attr = attrlist->GetAttr(i);
  	out << " :" << attr->Name() << " ";
  
- 	char* string;
  	AttributeValue* attrval = attr->Value();
  #if 1
  	out << *attrval;
  #else
          switch(attr->Value()->type()) {
  	    case AttributeValue::SymbolType:
  	        out << attrval->symbol_ptr();
--- 203,213 ----
  	Attribute* attr = attrlist->GetAttr(i);
  	out << " :" << attr->Name() << " ";
  
  	AttributeValue* attrval = attr->Value();
  #if 1
  	out << *attrval;
  #else
+ 	char* string;
          switch(attr->Value()->type()) {
  	    case AttributeValue::SymbolType:
  	        out << attrval->symbol_ptr();
Index: DrawServ/ackback-handler.c
diff -c DrawServ/ackback-handler.c:1.1 DrawServ/ackback-handler.c:1.2
*** DrawServ/ackback-handler.c:1.1	Tue May 25 12:12:08 2004
--- src/DrawServ/ackback-handler.c	Tue Jun  1 17:52:55 2004
***************
*** 24,31 ****
--- 24,37 ----
  #ifdef HAVE_ACE
  
  #include <DrawServ/ackback-handler.h>
+ #include <DrawServ/draweditor.h>
+ #include <DrawServ/drawkit.h>
  #include <DrawServ/drawlink.h>
  #include <DrawServ/drawserv.h>
+ 
+ #include <IVGlyph/gdialogs.h>
+ #include <InterViews/window.h>
+ 
  #include <vector.h>
  #include <err.h>
  
***************
*** 37,42 ****
--- 43,49 ----
  {
    _timer_started = false;
    _ackback_arrived = false;
+   _eof_expected = false;
  }
  
  AckBackHandler::~AckBackHandler() {
***************
*** 53,59 ****
--- 60,78 ----
      int status;
      while((status = read(fd, &ch, 1))==1) inv.push_back(ch);
      inv.push_back('\0');
+     if (strcmp((char*)&inv[0], "ackback(cycle)\n")==0) {
+       char buffer[BUFSIZ];
+       snprintf(buffer, BUFSIZ, "%s:%d", drawlink()->hostname(), drawlink()->portnum());
+       GAcknowledgeDialog::map(DrawKit::Instance()->GetEditor()->GetWindow(), "Redundant connection rejected", buffer, "Redundant connection rejected");
+       _eof_expected = true;
+     }
      if (status == 0) {
+       if (!_eof_expected) {
+ 	char buffer[BUFSIZ];
+ 	snprintf(buffer, BUFSIZ, "%s:%d", drawlink()->hostname(), drawlink()->portnum());
+ 	GAcknowledgeDialog::map(DrawKit::Instance()->GetEditor()->GetWindow(), "Unexpected end-of-file on connection", buffer, "Unexpected end-of-file on connection");
+       } else
+ 	_eof_expected = false;
        cerr << "AckBack (end of file):  [" << (char*)&inv[0] << "]\n";
        drawlink()->ackhandler(nil);
        ((DrawServ*)unidraw)->linkdown(drawlink());
Index: DrawServ/ackback-handler.h
diff -c DrawServ/ackback-handler.h:1.1 DrawServ/ackback-handler.h:1.2
*** DrawServ/ackback-handler.h:1.1	Tue May 25 12:12:08 2004
--- src/DrawServ/ackback-handler.h	Tue Jun  1 17:52:55 2004
***************
*** 74,79 ****
--- 74,80 ----
    int _ackback_arrived;
    long _timerid;
    ACE_HANDLE _handle;
+   int _eof_expected;
  
  };
  
Index: DrawServ/drawcomps.c
diff -c DrawServ/drawcomps.c:1.1 DrawServ/drawcomps.c:1.2
*** DrawServ/drawcomps.c:1.1	Fri Jan  9 11:45:18 2004
--- src/DrawServ/drawcomps.c	Tue Jun  1 17:52:55 2004
***************
*** 279,283 ****
    catalog->graph_finish();
    return 0;
  }
- 
- 
--- 279,281 ----
Index: DrawServ/drawcomps.h
diff -c DrawServ/drawcomps.h:1.1 DrawServ/drawcomps.h:1.2
*** DrawServ/drawcomps.h:1.1	Fri Jan  9 11:45:18 2004
--- src/DrawServ/drawcomps.h	Tue Jun  1 17:52:55 2004
***************
*** 53,58 ****
--- 53,59 ----
  
      void AppendEdge(EdgeComp*);
      // add edge component to the graph.
+ 
  protected:
      UList* _graphedges;
      int _num_edge;
Index: DrawServ/draweditor.c
diff -c DrawServ/draweditor.c:1.7 DrawServ/draweditor.c:1.8
*** DrawServ/draweditor.c:1.7	Mon Mar 22 11:21:25 2004
--- src/DrawServ/draweditor.c	Tue Jun  1 17:52:55 2004
***************
*** 88,92 ****
--- 88,93 ----
    comterp->add_command("drawlink", new DrawLinkFunc(comterp, this));
    comterp->add_command("sid", new SessionIdFunc(comterp, this));
    comterp->add_command("grid", new GraphicIdFunc(comterp, this));
+   comterp->add_command("chgid", new ChangeIdFunc(comterp, this));
  }
  
Index: DrawServ/drawfunc.c
diff -c DrawServ/drawfunc.c:1.28 DrawServ/drawfunc.c:1.29
*** DrawServ/drawfunc.c:1.28	Fri Apr 30 09:26:36 2004
--- src/DrawServ/drawfunc.c	Tue Jun  1 17:52:55 2004
***************
*** 32,37 ****
--- 32,38 ----
  #include <Attribute/attrlist.h>
  #include <Attribute/attrvalue.h>
  
+ #include <fstream.h>
  #define TITLE "DrawLinkFunc"
  
  /*****************************************************************************/
***************
*** 61,66 ****
--- 62,69 ----
    ComValue ridv(stack_key(rid_sym));
    static int close_sym = symbol_add("close");
    ComValue closev(stack_key(close_sym));
+   static int dump_sym = symbol_add("dump");
+   ComValue dumpv(stack_key(dump_sym));
    static int pid_sym = symbol_add("pid");
    ComValue pidv(stack_key(pid_sym));
    static int sid_sym = symbol_add("sid");
***************
*** 85,90 ****
--- 88,97 ----
  	((DrawServ*)unidraw)->cycletest
  	(sidv.uint_val(), hostv.string_ptr(), userv.string_ptr(), pidv.int_val())) {
  #if 1
+       fileptr_filebuf obuf(comterp()->handler()->get_handle(), ios_base::out, false, static_cast<size_t>(BUFSIZ));
+       ostream out(&obuf);
+       out << "ackback(cycle)\n";
+       out.flush();
        comterp()->quit();
  #else
        comterp()->handler()->destroy();
***************
*** 111,123 ****
      link = ((DrawServ*)unidraw)->linkget
        (lidv.is_known() ? lidv.int_val() : -1, 
         ridv.is_known() ? ridv.int_val() : -1);
! 
      /* close if that flag is set. */
      if (link && closev.is_true()) {
        ((DrawServ*)unidraw)->linkdown(link);
        link = nil;
      }
      
    }
  
    /* set state to complete linkup */
--- 118,134 ----
      link = ((DrawServ*)unidraw)->linkget
        (lidv.is_known() ? lidv.int_val() : -1, 
         ridv.is_known() ? ridv.int_val() : -1);
!     
      /* close if that flag is set. */
      if (link && closev.is_true()) {
        ((DrawServ*)unidraw)->linkdown(link);
        link = nil;
      }
      
+     else if (link && dumpv.is_true()) {
+       link->dump(stderr);
+     }
+     
    }
  
    /* set state to complete linkup */
***************
*** 162,167 ****
--- 173,180 ----
  #else
    static int all_sym = symbol_add("all");
    ComValue allv(stack_key(all_sym));
+   static int remap_sym = symbol_add("remap");
+   ComValue remapv(stack_key(remap_sym));
  
    static int pid_sym = symbol_add("pid");
    ComValue pidv(stack_key(pid_sym));
***************
*** 191,201 ****
    }
  
    if (sidv.is_known() && osidv.is_known()) {
!     ((DrawServ*)unidraw)->sessionid_register_handle
!       (link, sidv.uint_val(), osidv.uint_val(), pidv.int_val(), 
!        userv.string_ptr(), hostv.string_ptr(), 
!        hostidv.int_val());
!     
    } else {
      ((DrawServ*)unidraw)->print_sidtable();
    }
--- 204,216 ----
    }
  
    if (sidv.is_known() && osidv.is_known()) {
!     if (remapv.is_false()) 
!       ((DrawServ*)unidraw)->sessionid_register_handle
! 	(link, sidv.uint_val(), osidv.uint_val(), pidv.int_val(), 
! 	 userv.string_ptr(), hostv.string_ptr(), 
! 	 hostidv.int_val());
!     else
!       link->sid_insert(osidv.uint_val(), sidv.uint_val());
    } else {
      ((DrawServ*)unidraw)->print_sidtable();
    }
***************
*** 241,243 ****
--- 256,281 ----
      ((DrawServ*)unidraw)->print_gridtable();
    }
  }
+ 
+ /*****************************************************************************/
+ 
+ ChangeIdFunc::ChangeIdFunc(ComTerp* comterp, DrawEditor* ed) : UnidrawFunc(comterp, ed) {
+ }
+ 
+ void ChangeIdFunc::execute() {
+ 
+   ComValue idv(stack_arg(0));
+   reset_stack();
+ 
+   DrawServHandler* handler = comterp() ? (DrawServHandler*)comterp()->handler() : nil;
+   DrawLink* link = handler ? (DrawLink*)handler->drawlink() : nil;
+   
+   if (idv.is_known()) {
+     unsigned int id = idv.uint_val();
+     link->sid_change(id);
+     ComValue result(id, ComValue::UIntType);
+     push_stack(result);
+   }
+ }
+ 
+ 
Index: DrawServ/drawfunc.h
diff -c DrawServ/drawfunc.h:1.8 DrawServ/drawfunc.h:1.9
*** DrawServ/drawfunc.h:1.8	Fri Mar 19 12:03:28 2004
--- src/DrawServ/drawfunc.h	Tue Jun  1 17:52:55 2004
***************
*** 28,50 ****
  #include <ComUnidraw/unifunc.h>
  
  //: command to connect to another drawserv
! // drawlink(hoststr :port portnum :state num :lid nu :rid num :close) -- connect to remote drawserv
  class DrawLinkFunc : public UnidrawFunc {
  public:
      DrawLinkFunc(ComTerp*,DrawEditor*);
      virtual void execute();
      virtual const char* docstring() { 
! 	return "%s(hoststr :port portnum :state num :lid num :rid num :close) -- connect to remote drawserv"; }
  };
  
  //: command to reserve unique session id
! // sessionid([sid osid] :all) -- command to manage session id's
  class SessionIdFunc : public UnidrawFunc {
  public:
      SessionIdFunc(ComTerp*,DrawEditor*);
      virtual void execute();
      virtual const char* docstring() { 
! 	return "%s([sid osid] :all) -- command to manage session id's"; }
  };
  
  //: command to send message between remote selections
--- 28,50 ----
  #include <ComUnidraw/unifunc.h>
  
  //: command to connect to another drawserv
! // drawlink([hoststr] :port portnum :state num :lid nu :rid num :close :dump) -- connect to remote drawserv
  class DrawLinkFunc : public UnidrawFunc {
  public:
      DrawLinkFunc(ComTerp*,DrawEditor*);
      virtual void execute();
      virtual const char* docstring() { 
! 	return "%s([hoststr] :port portnum :state num :lid num :rid num :close :dump) -- connect to remote drawserv"; }
  };
  
  //: command to reserve unique session id
! // sid([sid osid :pid pid :user namestr :host hoststr :hostid hostid :remap] |  :all) -- command to manage session id's
  class SessionIdFunc : public UnidrawFunc {
  public:
      SessionIdFunc(ComTerp*,DrawEditor*);
      virtual void execute();
      virtual const char* docstring() { 
! 	return "%s([sid osid :pid pid :user namestr :host hoststr :hostid hostid :remap] | :all) -- command to manage session id's"; }
  };
  
  //: command to send message between remote selections
***************
*** 55,60 ****
--- 55,70 ----
      virtual void execute();
      virtual const char* docstring() { 
  	return "%s(id selector :state selected :request newselector :grant oldselector) -- command to send message between remote selections"; }
+ };
+ 
+ //: command to change session (or graphic id) to use local session id
+ // chgid(id) -- command to change session (or graphic id) to use local session id
+ class ChangeIdFunc : public UnidrawFunc {
+ public:
+     ChangeIdFunc(ComTerp*,DrawEditor*);
+     virtual void execute();
+     virtual const char* docstring() { 
+ 	return "%s(id) -- command to change session (or graphic id) to use local session id"; }
  };
  
  #endif /* !defined(_drawfunc_h) */
Index: DrawServ/drawlink.c
diff -c DrawServ/drawlink.c:1.19 DrawServ/drawlink.c:1.20
*** DrawServ/drawlink.c:1.19	Tue May 25 12:12:08 2004
--- src/DrawServ/drawlink.c	Tue Jun  1 17:52:55 2004
***************
*** 57,62 ****
--- 57,63 ----
    _comhandler = nil;
    _ackhandler = nil;
    _incomingsidtable = new IncomingSidTable(32);
+   _incomingsidtable_size = 0;
  }
  
  DrawLink::~DrawLink () 
***************
*** 106,112 ****
      out << " :state " << _state+1;
      out << " :rid " << _local_linkid;
      out << " :lid " << _remote_linkid;
!     out << " :sid " << sid;
      if (sessionid) {
        out << " :pid " << sessionid->pid();
        out << " :user \"" << sessionid->username() << "\"";
--- 107,113 ----
      out << " :state " << _state+1;
      out << " :rid " << _local_linkid;
      out << " :lid " << _remote_linkid;
!     out << " :sid 0x" << std::hex << sid << std::dec;
      if (sessionid) {
        out << " :pid " << sessionid->pid();
        out << " :user \"" << sessionid->username() << "\"";
***************
*** 160,163 ****
--- 161,206 ----
  int DrawLink::handle() {
    if (_socket) return _socket->get_handle();
    else return -1;
+ }
+ 
+ unsigned DrawLink::sid_lookup(unsigned int sid) {
+   unsigned int local_sid = 0;
+   if (_incomingsidtable_size==0) return sid;
+   incomingsidtable()->find(local_sid, sid);
+   return local_sid ? local_sid : sid;
+ }
+ 
+ void DrawLink::sid_change(unsigned int& id) {
+   if (_incomingsidtable_size==0) return;
+   id = sid_lookup(id & DrawServ::SessionIdMask) | (id & DrawServ::GraphicIdMask);
+   return;
+ }
+ 
+ void DrawLink::sid_insert(unsigned int sid, unsigned int alt_sid) {
+   if (sid!=alt_sid) {
+     _incomingsidtable_size++;
+     _incomingsidtable->insert(sid, alt_sid);
+   }
+ }
+ 
+ void DrawLink::dump(FILE* fptr) {
+   fprintf(fptr, "Host                            Alt.                            Port    LID  RID  State\n");
+   fprintf(fptr, "------------------------------  ------------------------------  ------  ---  ---  -----\n");
+   fprintf(fptr, "%-30.30s  %-30.30s  %-6d  %-3d  %-3d  %-3d\n", 
+ 	  hostname(), althostname(), portnum(),
+ 	  local_linkid(), remote_linkid(), state());
+   dump_incomingsidtable(fptr);
+ }
+ 
+ void DrawLink::dump_incomingsidtable(FILE* fptr) {
+   IncomingSidTable* table = incomingsidtable();
+   IncomingSidTable_Iterator it(*table);
+   printf("sid         osid\n");
+   printf("----------  ----------\n");
+   while(it.more()) {
+     unsigned int osid = (unsigned int)it.cur_value();
+     unsigned int sid = (unsigned int)it.cur_key();
+     fprintf(fptr, "0x%08x  0x%08x\n", sid, osid);
+     it.next();
+   }
  }
Index: DrawServ/drawlink.h
diff -c DrawServ/drawlink.h:1.14 DrawServ/drawlink.h:1.15
*** DrawServ/drawlink.h:1.14	Tue May 25 12:12:08 2004
--- src/DrawServ/drawlink.h	Tue Jun  1 17:52:55 2004
***************
*** 118,123 ****
--- 118,138 ----
      ACE_SOCK_Stream* socket() { return _socket; }
      // return pointer to connected socket.
  
+     unsigned int sid_lookup(unsigned int sid);
+     // map incoming sid to local sid.
+ 
+     void sid_change(unsigned int& id);
+     // change sid portion of an id to use local sid.
+ 
+     void sid_insert(unsigned int sid, unsigned int alt_sid);
+     // insert new sid pair into table
+ 
+     void dump(FILE*);
+     // dump complete information on this DrawLink
+ 
+     void dump_incomingsidtable(FILE*);
+     // dump complete information on this DrawLink's IncomingSidTable
+ 
  protected:
      const char* _host;
      const char* _althost;
***************
*** 128,133 ****
--- 143,149 ----
      int _remote_linkid;
      int _state;
      IncomingSidTable* _incomingsidtable;
+     int _incomingsidtable_size;
  
  #ifdef HAVE_ACE
      ACE_INET_Addr* _addr;
Index: DrawServ/drawserv-handler.c
diff -c DrawServ/drawserv-handler.c:1.4 DrawServ/drawserv-handler.c:1.5
*** DrawServ/drawserv-handler.c:1.4	Tue May 25 12:12:08 2004
--- src/DrawServ/drawserv-handler.c	Tue Jun  1 17:52:55 2004
***************
*** 54,63 ****
--- 54,65 ----
  
  void DrawServHandler::destroy (void) {
    if (_sigpipe_handler) {
+ #if 0
      if (ComterpHandler::reactor_singleton()->remove_handler 
  	(SIGPIPE, (ACE_Sig_Action*)nil) == -1)
        ACE_DEBUG ((LM_ERROR, 
  		  "(%P|%t) can't remove signal handler from reactor\n"));
+ #endif
      _sigpipe_handler = _sigpipe_handler_initialized = 0;
    }
    ComterpHandler::destroy();
Index: DrawServ/drawserv.c
diff -c DrawServ/drawserv.c:1.50 DrawServ/drawserv.c:1.51
*** DrawServ/drawserv.c:1.50	Tue May 25 12:12:08 2004
--- src/DrawServ/drawserv.c	Tue Jun  1 17:52:55 2004
***************
*** 52,57 ****
--- 52,58 ----
  
  #include <ComTerp/comterpserv.h>
  
+ #include <Attribute/attribute.h>
  #include <Attribute/attrlist.h>
  #include <Attribute/attrvalue.h>
  
***************
*** 66,71 ****
--- 67,74 ----
  unsigned int DrawServ::GraphicIdMask = 0x000fffff;
  unsigned int DrawServ::SessionIdMask = 0xfff00000;
  
+ static int seed=0;
+ 
  /*****************************************************************************/
  
  DrawServ::DrawServ (Catalog* c, int& argc, char** argv, 
***************
*** 87,92 ****
--- 90,96 ----
    _compidtable = new CompIdTable(1024);
  
    _sessionid = unique_sessionid();
+   _sessionid = 0xfff00000;  // for testing purposes
    char hostbuf[HOST_NAME_MAX];
    gethostname(hostbuf, HOST_NAME_MAX);
    char* username = getlogin();
***************
*** 223,229 ****
  }
  
  void DrawServ::ExecuteCmd(Command* cmd) {
!   static int id_sym = symbol_add("id");
    static int sid_sym = symbol_add("sid");
    boolean original = false;
  
--- 227,233 ----
  }
  
  void DrawServ::ExecuteCmd(Command* cmd) {
!   static int grid_sym = symbol_add("grid");
    static int sid_sym = symbol_add("sid");
    boolean original = false;
  
***************
*** 248,275 ****
  	for (cb->First(it); !cb->Done(it); cb->Next(it)) {
  	  OverlayComp* comp = (OverlayComp*)cb->GetComp(it);
  	  AttributeList* al = comp->GetAttributeList();
! 	  AttributeValue* idv = al->find(id_sym);
  	  AttributeValue* sidv = al->find(sid_sym);
  	  
  	  /* unique id already remotely assigned */
  	  if (idv && idv->uint_val() !=0 && sidv && sidv->uint_val() !=0) {
! 	    GraphicId* grid = new GraphicId();
! 	    grid->grcomp(comp);
! 	    grid->id(idv->uint_val());
! 	    grid->selector(sidv->uint_val());
! 	    grid->selected(LinkSelection::RemotelySelected);
  	  } 
  	  
  	  /* generate unique id and add as attribute */
  	  /* also mark with selector id */
  	  else {
! 	    GraphicId* grid = new GraphicId(sessionid());
! 	    grid->grcomp(comp);
! 	    grid->selector(((DrawServ*)unidraw)->sessionid());
! 	    AttributeValue* idv = new AttributeValue(grid->id(), AttributeValue::UIntType);
! 	    idv->state(AttributeValue::HexState);
! 	    al->add_attr(id_sym, idv);
! 	    AttributeValue* sidv = new AttributeValue(grid->selector(), AttributeValue::UIntType);
  	    sidv->state(AttributeValue::HexState);
  	    al->add_attr(sid_sym, sidv);
  	    original = true;
--- 252,279 ----
  	for (cb->First(it); !cb->Done(it); cb->Next(it)) {
  	  OverlayComp* comp = (OverlayComp*)cb->GetComp(it);
  	  AttributeList* al = comp->GetAttributeList();
! 	  AttributeValue* idv = al->find(grid_sym);
  	  AttributeValue* sidv = al->find(sid_sym);
  	  
  	  /* unique id already remotely assigned */
  	  if (idv && idv->uint_val() !=0 && sidv && sidv->uint_val() !=0) {
! 	    GraphicId* graphicid = new GraphicId();
! 	    graphicid->grcomp(comp);
! 	    graphicid->id(idv->uint_val());
! 	    graphicid->selector(sidv->uint_val());
! 	    graphicid->selected(LinkSelection::RemotelySelected);
  	  } 
  	  
  	  /* generate unique id and add as attribute */
  	  /* also mark with selector id */
  	  else {
! 	    GraphicId* graphicid = new GraphicId(sessionid());
! 	    graphicid->grcomp(comp);
! 	    graphicid->selector(((DrawServ*)unidraw)->sessionid());
! 	    AttributeValue* gridv = new AttributeValue(graphicid->id(), AttributeValue::UIntType);
! 	    gridv->state(AttributeValue::HexState);
! 	    al->add_attr(grid_sym, gridv);
! 	    AttributeValue* sidv = new AttributeValue(graphicid->selector(), AttributeValue::UIntType);
  	    sidv->state(AttributeValue::HexState);
  	    al->add_attr(sid_sym, sidv);
  	    original = true;
***************
*** 398,404 ****
        alt_id = DrawServ::unique_sessionid();
      SessionId* session_id = new SessionId(alt_id, osid, pid, username, hostname, hostid, link);
      sidtable->insert(alt_id, session_id);
!     link->incomingsidtable()->insert(sid, alt_id);
  
      /* propagate */
      sessionid_register_propagate(link, alt_id, osid, pid, username,
--- 402,413 ----
        alt_id = DrawServ::unique_sessionid();
      SessionId* session_id = new SessionId(alt_id, osid, pid, username, hostname, hostid, link);
      sidtable->insert(alt_id, session_id);
!     link->sid_insert(sid, alt_id);
!     if (sid != alt_id) {
!       char buffer[BUFSIZ];
!       snprintf(buffer, BUFSIZ, "sid(0x%08x 0x%08x :remap)\n", sid, alt_id);
!       SendCmdString(link, buffer);
!     }
  
      /* propagate */
      sessionid_register_propagate(link, alt_id, osid, pid, username,
***************
*** 425,431 ****
  }
  
  unsigned int DrawServ::unique_grid() {
-   static int seed=0;
    if (!seed) {
      seed = time(nil) & (time(nil) << 16);
      srand(seed);
--- 434,439 ----
***************
*** 450,463 ****
  }
  
  unsigned int DrawServ::unique_sessionid() {
-   static int seed=0;
    if (!seed) {
      seed = time(nil) & (time(nil) << 16);
      srand(seed);
    }
    int retval;
    do {
-     static int flip=0;
      while ((retval=rand()&SessionIdMask)==0);
  
    } while (!test_sessionid(retval));
--- 458,469 ----
***************
*** 478,484 ****
    char buf[BUFSIZ];
    if (grid->selected()==LinkSelection::LocallySelected ||
        (grid->selector()==sessionid() && grid->selected()==LinkSelection::NotSelected)) {
!     snprintf(buf, BUFSIZ, "grid(0x%08x 0x%08x :state %d )%c", grid->id(), grid->selector(), 
  	     grid->selected()==LinkSelection::LocallySelected ? 
  	     LinkSelection::RemotelySelected : LinkSelection::NotSelected, '\0');
      DistributeCmdString(buf);
--- 484,490 ----
    char buf[BUFSIZ];
    if (grid->selected()==LinkSelection::LocallySelected ||
        (grid->selector()==sessionid() && grid->selected()==LinkSelection::NotSelected)) {
!     snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :state %d )%c", grid->id(), grid->selector(), 
  	     grid->selected()==LinkSelection::LocallySelected ? 
  	     LinkSelection::RemotelySelected : LinkSelection::NotSelected, '\0');
      DistributeCmdString(buf);
***************
*** 488,494 ****
      DrawLink* link = _linklist->find_drawlink(grid);
      
      if (link) {
!       snprintf(buf, BUFSIZ, "grid(0x%08x 0x%08x :request 0x%08x)%c", grid->id(), 
  	       grid->selector(), sessionid(), '\0');
        SendCmdString(link, buf);
      }
--- 494,500 ----
      DrawLink* link = _linklist->find_drawlink(grid);
      
      if (link) {
!       snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :request chgid(0x%08x))%c", grid->id(), 
  	       grid->selector(), sessionid(), '\0');
        SendCmdString(link, buf);
      }
***************
*** 510,516 ****
  	grid->selected(LinkSelection::NotSelected);
  	grid->selector(newselector);
  	char buf[BUFSIZ];
! 	snprintf(buf, BUFSIZ, "grid(0x%08x 0x%08x :grant 0x%08x)%c",
  		 grid->id(), newselector, sessionid(), '\0');
  	SendCmdString(link, buf);
        }
--- 516,522 ----
  	grid->selected(LinkSelection::NotSelected);
  	grid->selector(newselector);
  	char buf[BUFSIZ];
! 	snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :grant chgid(0x%08x))%c",
  		 grid->id(), newselector, sessionid(), '\0');
  	SendCmdString(link, buf);
        }
***************
*** 607,609 ****
--- 613,647 ----
    return found;
  }
  
+ boolean DrawServ::selftest(const char* host, unsigned int portnum) 
+ {
+   if (portnum==comdraw_port()) {
+     if (strcmp(host, "localhost")==0 ||
+ 	strcmp(host, "127.0.0.1")==0)
+       return 1;
+     else {
+       char hostbuf[HOST_NAME_MAX];
+       gethostname(hostbuf, HOST_NAME_MAX);
+       if (strcmp(host, hostbuf)==0)
+ 	return 1;
+     }
+   }
+   return 0;
+ }
+ 
+ boolean DrawServ::PrintAttributeList(ostream& out, AttributeList* attrlist) {
+   static int grid_sym = symbol_add("grid");
+   static int sid_sym = symbol_add("sid");
+ 
+   ALIterator i;
+   for (attrlist->First(i); !attrlist->Done(i); attrlist->Next(i)) {
+     Attribute* attr = attrlist->GetAttr(i);
+     out << " :" << attr->Name() << " ";
+     AttributeValue* attrval = attr->Value();
+     boolean special = attr->SymbolId()==grid_sym || attr->SymbolId()==sid_sym;
+     if (special) out << "chgid(";
+     out << *attrval;
+     if (special) out << ")";
+   }
+   return true;
+ }
Index: DrawServ/drawserv.h
diff -c DrawServ/drawserv.h:1.26 DrawServ/drawserv.h:1.27
*** DrawServ/drawserv.h:1.26	Tue May 25 12:12:08 2004
--- src/DrawServ/drawserv.h	Tue Jun  1 17:52:55 2004
***************
*** 156,161 ****
--- 156,169 ----
    // return port used for comdraw command interpreter
  
    boolean cycletest(unsigned int sid, const char* host, const char* user, int pid);
+   // test for new incoming link that would establish a cycle
+ 
+   boolean selftest(const char* host, unsigned int portnum);
+   // test if a new outgoing link is really to yourself
+ 
+   virtual boolean PrintAttributeList(ostream& out, AttributeList* list);
+   // alternate method for serializing an AttributeList
+   // returns false if really not there.
  
  protected:
      DrawLinkList* _linklist;
Index: DrawServ/linkselection.c
diff -c DrawServ/linkselection.c:1.20 DrawServ/linkselection.c:1.21
*** DrawServ/linkselection.c:1.20	Fri Apr  2 12:55:02 2004
--- src/DrawServ/linkselection.c	Tue Jun  1 17:52:55 2004
***************
*** 90,96 ****
        if (grid->selected()==LocallySelected || grid->selected()==WaitingToBeSelected) 
  	grid->selected(NotSelected);
        char buf[BUFSIZ];
!       snprintf(buf, BUFSIZ, "grid(0x%08x 0x%08x :state %d)%c",
  	       grid->id(), grid->selector(), grid->selected(), '\0');
        ((DrawServ*)unidraw)->DistributeCmdString(buf);
      }
--- 90,96 ----
        if (grid->selected()==LocallySelected || grid->selected()==WaitingToBeSelected) 
  	grid->selected(NotSelected);
        char buf[BUFSIZ];
!       snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :state %d)%c",
  	       grid->id(), grid->selector(), grid->selected(), '\0');
        ((DrawServ*)unidraw)->DistributeCmdString(buf);
      }
Index: DrawServ/rcdialog.c
diff -c DrawServ/rcdialog.c:1.6 DrawServ/rcdialog.c:1.7
*** DrawServ/rcdialog.c:1.6	Tue May 25 12:12:08 2004
--- src/DrawServ/rcdialog.c	Tue Jun  1 17:52:55 2004
***************
*** 223,234 ****
  void ConnectionsDialogImpl::connect() {
    const String* hoststr = hostfe_->text();
    const String* portstr = portfe_->text();
!   if (hoststr->length() > 0) {
      int portnum=20002;
!     if (portstr->length() > 0) portnum = atoi(portstr->string());
!     if(((DrawServ*)unidraw)->linkup(hoststr->string(), portnum, 0)==nil) {
        char buffer[BUFSIZ];
!       snprintf(buffer, BUFSIZ, "%s:%d", hoststr->string(), portnum);
        GAcknowledgeDialog::map(dialog_->GetEditor()->GetWindow(), "Connection refused", buffer, "Connection refused");
      }
    }
--- 223,256 ----
  void ConnectionsDialogImpl::connect() {
    const String* hoststr = hostfe_->text();
    const String* portstr = portfe_->text();
! 
!   /* remove terminating spaces */
!   int hostlen = strlen(hoststr->string())+1;
!   int portlen = strlen(portstr->string())+1;
!   char hostbuf[hostlen];
!   char portbuf[portlen];
!   strcpy(hostbuf, hoststr->string());
!   strcpy(portbuf, portstr->string());
!   char *ptr;
!   ptr = hostbuf + hostlen - 2;
!   while (*ptr == ' ' && ptr >= (char*)hostbuf) *ptr-- = '\0';
!   ptr = portbuf + portlen - 2;
!   while (*ptr == ' ' && ptr >= (char*)portbuf) *ptr-- = '\0';
! 
!   if (strlen(hostbuf) > 0) {
      int portnum=20002;
!     if (strlen(portbuf) > 0) portnum = atoi(portbuf);
! 
!     if(((DrawServ*)unidraw)->selftest(hostbuf, portnum)) {
!       char buffer[BUFSIZ];
!       snprintf(buffer, BUFSIZ, "%s:%d", hostbuf, portnum);
!       GAcknowledgeDialog::map(dialog_->GetEditor()->GetWindow(), "Can't connect to self", buffer, "Can't connect to self");
!       return;
!     }
! 
!     if(((DrawServ*)unidraw)->linkup(hostbuf, portnum, 0)==nil) {
        char buffer[BUFSIZ];
!       snprintf(buffer, BUFSIZ, "%s:%d", hostbuf, portnum);
        GAcknowledgeDialog::map(dialog_->GetEditor()->GetWindow(), "Connection refused", buffer, "Connection refused");
      }
    }
***************
*** 237,246 ****
  void ConnectionsDialogImpl::disconnect() {
    const String* hoststr = hostfe_->text();
    const String* portstr = portfe_->text();
!   if (hoststr->length() > 0) {
      int portnum=20002;
!     if (portstr->length() > 0) portnum = atoi(portstr->string());
!     DrawLink* link = ((DrawServ*)unidraw)->linkget(hoststr->string(), portnum);
      if (link) 
        ((DrawServ*)unidraw)->linkdown(link);
    }
--- 259,282 ----
  void ConnectionsDialogImpl::disconnect() {
    const String* hoststr = hostfe_->text();
    const String* portstr = portfe_->text();
! 
!   /* remove terminating spaces */
!   int hostlen = strlen(hoststr->string())+1;
!   int portlen = strlen(portstr->string())+1;
!   char hostbuf[hostlen];
!   char portbuf[portlen];
!   strcpy(hostbuf, hoststr->string());
!   strcpy(portbuf, portstr->string());
!   char *ptr;
!   ptr = hostbuf + hostlen - 2;
!   while (*ptr == ' ' && ptr >= (char*)hostbuf) *ptr-- = '\0';
!   ptr = portbuf + portlen - 2;
!   while (*ptr == ' ' && ptr >= (char*)portbuf) *ptr-- = '\0';
! 
!   if (strlen(hostbuf) > 0) {
      int portnum=20002;
!     if (strlen(portbuf) > 0) portnum = atoi(portbuf);
!     DrawLink* link = ((DrawServ*)unidraw)->linkget(hostbuf, portnum);
      if (link) 
        ((DrawServ*)unidraw)->linkdown(link);
    }
Index: OverlayUnidraw/ovunidraw.h
diff -c OverlayUnidraw/ovunidraw.h:1.1 OverlayUnidraw/ovunidraw.h:1.2
*** OverlayUnidraw/ovunidraw.h:1.1	Fri Jan  9 11:44:54 2004
--- src/OverlayUnidraw/ovunidraw.h	Tue Jun  1 17:52:49 2004
***************
*** 30,35 ****
--- 30,36 ----
  
  #include <Unidraw/unidraw.h>
  
+ class AttributeList;
  class Command;
  class ComTerpServ;
  class Event;
***************
*** 52,57 ****
--- 53,63 ----
      virtual void Log(Command*, boolean dirty);
  
      void Append(Command*);
+ 
+     virtual boolean PrintAttributeList(ostream& out, AttributeList* list) 
+       { return false; }
+     // alternate method for serializing an AttributeList
+     // returns false if really not there.
  
      static boolean unidraw_updated();
      static boolean npause_lessened();
Index: OverlayUnidraw/scriptview.c
diff -c OverlayUnidraw/scriptview.c:1.1 OverlayUnidraw/scriptview.c:1.2
*** OverlayUnidraw/scriptview.c:1.1	Fri Jan  9 11:44:55 2004
--- src/OverlayUnidraw/scriptview.c	Tue Jun  1 17:52:50 2004
***************
*** 28,33 ****
--- 28,34 ----
  #include <OverlayUnidraw/ovcatalog.h>
  #include <OverlayUnidraw/ovclasses.h>
  #include <OverlayUnidraw/ovexport.h>
+ #include <OverlayUnidraw/ovunidraw.h>
  
  #include <ComTerp/parser.h>
  
***************
*** 927,933 ****
  
  void OverlayScript::Attributes(ostream& out) {
      AttributeList* attrlist = GetOverlayComp()->GetAttributeList();
!     out << *attrlist;
  }
  
  Clipboard* OverlayScript::GetGSList() {
--- 928,935 ----
  
  void OverlayScript::Attributes(ostream& out) {
      AttributeList* attrlist = GetOverlayComp()->GetAttributeList();
!     if( !((OverlayUnidraw*)unidraw)->PrintAttributeList(out, attrlist))
!       out << *attrlist;
  }
  
  Clipboard* OverlayScript::GetGSList() {
*** /dev/null	 Tue Jun 1 17:53:08 PDT 2004
--- patches/ivtools-040601-johnston-083
*************** patches/ivtools-040601-johnston-083
*** 0 ****
--- 1 ----
+ ivtools-040601-johnston-083

--Apple-Mail-4-683457111
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="ivtools-040603-johnston-084"
Content-Disposition: attachment;
	filename=ivtools-040603-johnston-084

Patch:    ivtools-040603-johnston-084
For:      ivtools-1.1.3
Author:   [email protected]
Subject:  more drawserv work
Requires: 

This is an intermediate patch to ivtools-1.1.3.  To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:

	patch -p0 <ThisFile

Summary of Changes:

Index: ComUnidraw/grfunc.c
diff -c ComUnidraw/grfunc.c:1.7 ComUnidraw/grfunc.c:1.8
*** ComUnidraw/grfunc.c:1.7	Tue Mar 23 11:18:15 2004
--- src/ComUnidraw/grfunc.c	Thu Jun  3 09:52:13 2004
***************
*** 167,176 ****
  	ComValue compval(symbol_add("RectComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
      } else 
  	push_stack(ComValue::nullval());
  
-     execute_log(cmd);
      Unref(al);
  }
  
--- 167,176 ----
  	ComValue compval(symbol_add("RectComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
+ 	execute_log(cmd);
      } else 
  	push_stack(ComValue::nullval());
  
      Unref(al);
  }
  
***************
*** 233,242 ****
  	ComValue compval(symbol_add("ArrowLineComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
      } else 
  	push_stack(ComValue::nullval());
  
-     execute_log(cmd);
      Unref(al);
  }
  
--- 233,242 ----
  	ComValue compval(symbol_add("ArrowLineComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
+ 	execute_log(cmd);
      } else 
  	push_stack(ComValue::nullval());
  
      Unref(al);
  }
  
***************
*** 298,307 ****
  	ComValue compval(symbol_add("EllipseComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
      } else 
  	push_stack(ComValue::nullval());
  
-     execute_log(cmd);
      Unref(al);
  }
  
--- 298,307 ----
  	ComValue compval(symbol_add("EllipseComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
+ 	execute_log(cmd);
      } else 
  	push_stack(ComValue::nullval());
  
      Unref(al);
  }
  
***************
*** 365,374 ****
  	ComValue compval(symbol_add("TextComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
      } else
          push_stack(ComValue::nullval());
  
-     execute_log(cmd);
      Unref(al);
  }
  
--- 365,374 ----
  	ComValue compval(symbol_add("TextComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
+ 	execute_log(cmd);
      } else
          push_stack(ComValue::nullval());
  
      Unref(al);
  }
  
***************
*** 432,441 ****
  	ComValue compval(symbol_add("ArrowMultiLineComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
      } else 
  	push_stack(ComValue::nullval());
  
-     execute_log(cmd);
      Unref(al);
  }
  
--- 432,441 ----
  	ComValue compval(symbol_add("ArrowMultiLineComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
+ 	execute_log(cmd);
      } else 
  	push_stack(ComValue::nullval());
  
      Unref(al);
  }
  
***************
*** 499,508 ****
  	ComValue compval(symbol_add("ArrowSplineComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
      } else 
  	push_stack(ComValue::nullval());
  
-     execute_log(cmd);
      Unref(al);
  }
  
--- 499,508 ----
  	ComValue compval(symbol_add("ArrowSplineComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
+ 	execute_log(cmd);
      } else 
  	push_stack(ComValue::nullval());
  
      Unref(al);
  }
  
***************
*** 564,573 ****
  	ComValue compval(symbol_add("PolygonComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
      } else 
  	push_stack(ComValue::nullval());
  
-     execute_log(cmd);
      Unref(al);
  }
  
--- 564,573 ----
  	ComValue compval(symbol_add("PolygonComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
+ 	execute_log(cmd);
      } else 
  	push_stack(ComValue::nullval());
  
      Unref(al);
  }
  
***************
*** 630,639 ****
  	ComValue compval(symbol_add("ClosedSplineComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
      } else 
  	push_stack(ComValue::nullval());
  
-     execute_log(cmd);
      Unref(al);
  }
  
--- 630,639 ----
  	ComValue compval(symbol_add("ClosedSplineComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
+ 	execute_log(cmd);
      } else 
  	push_stack(ComValue::nullval());
  
      Unref(al);
  }
  
***************
*** 701,710 ****
  	ComValue compval(symbol_add("RasterComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
      } else 
  	push_stack(ComValue::nullval());
  
-     execute_log(cmd);
      Unref(al);
  }
  
--- 701,710 ----
  	ComValue compval(symbol_add("RasterComp"), new ComponentView(comp));
  	compval.object_compview(true);
  	push_stack(compval);
+ 	execute_log(cmd);
      } else 
  	push_stack(ComValue::nullval());
  
      Unref(al);
  }
  
***************
*** 725,733 ****
  
      if (font) {
  	cmd = new FontCmd(_ed, font);
      }
  
-     execute_log(cmd);
  }
  
  /*****************************************************************************/
--- 725,733 ----
  
      if (font) {
  	cmd = new FontCmd(_ed, font);
+ 	execute_log(cmd);
      }
  
  }
  
  /*****************************************************************************/
***************
*** 839,847 ****
    
    if (font) {
      cmd = new FontCmd(_ed, font);
    }
    
-   execute_log(cmd);
  }
  /*****************************************************************************/
  ColorRgbFunc::ColorRgbFunc(ComTerp* comterp, Editor* ed) : UnidrawFunc(comterp, ed) {
--- 839,847 ----
    
    if (font) {
      cmd = new FontCmd(_ed, font);
+     execute_log(cmd);
    }
    
  }
  /*****************************************************************************/
  ColorRgbFunc::ColorRgbFunc(ComTerp* comterp, Editor* ed) : UnidrawFunc(comterp, ed) {
***************
*** 882,890 ****
  
      if (brush) {
  	cmd = new BrushCmd(_ed, brush);
      }
  
-     execute_log(cmd);
  }
  
  /*****************************************************************************/
--- 882,890 ----
  
      if (brush) {
  	cmd = new BrushCmd(_ed, brush);
+ 	execute_log(cmd);
      }
  
  }
  
  /*****************************************************************************/
***************
*** 904,912 ****
  
      if (pattern) {
  	cmd = new PatternCmd(_ed, pattern);
      }
  
-     execute_log(cmd);
  }
  
  /*****************************************************************************/
--- 904,912 ----
  
      if (pattern) {
  	cmd = new PatternCmd(_ed, pattern);
+ 	execute_log(cmd);
      }
  
  }
  
  /*****************************************************************************/
***************
*** 1064,1072 ****
  
      if (delx != 0  || dely != 0) {
  	cmd = new MoveCmd(_ed, delx, dely);
      }
  
-     execute_log(cmd);
  }
  
  /*****************************************************************************/
--- 1064,1072 ----
  
      if (delx != 0  || dely != 0) {
  	cmd = new MoveCmd(_ed, delx, dely);
+ 	execute_log(cmd);
      }
  
  }
  
  /*****************************************************************************/
***************
*** 1085,1093 ****
  
      if (fx > 0.0  || fy > 0.0) {
  	cmd = new ScaleCmd(_ed, fx, fy);
      }
  
-     execute_log(cmd);
  }
  
  /*****************************************************************************/
--- 1085,1093 ----
  
      if (fx > 0.0  || fy > 0.0) {
  	cmd = new ScaleCmd(_ed, fx, fy);
+ 	execute_log(cmd);
      }
  
  }
  
  /*****************************************************************************/
***************
*** 1123,1131 ****
  
      if (delx != 0  || dely != 0) {
  	cmd = new PanCmd(_ed, delx, dely);
      }
  
-     execute_log(cmd);
  }
  
  /*****************************************************************************/
--- 1123,1131 ----
  
      if (delx != 0  || dely != 0) {
  	cmd = new PanCmd(_ed, delx, dely);
+ 	execute_log(cmd);
      }
  
  }
  
  /*****************************************************************************/
***************
*** 1231,1239 ****
      
      if (zoom > 0.0) {
  	cmd = new ZoomCmd(_ed, zoom);
      }
      
-     execute_log(cmd);
  }
  
  /*****************************************************************************/
--- 1231,1239 ----
      
      if (zoom > 0.0) {
  	cmd = new ZoomCmd(_ed, zoom);
+ 	execute_log(cmd);
      }
      
  }
  
  /*****************************************************************************/
Index: DrawServ/drawlink.c
diff -c DrawServ/drawlink.c:1.20 DrawServ/drawlink.c:1.21
*** DrawServ/drawlink.c:1.20	Tue Jun  1 17:52:55 2004
--- src/DrawServ/drawlink.c	Thu Jun  3 09:52:19 2004
***************
*** 38,43 ****
--- 38,45 ----
  
  implementTable(IncomingSidTable,unsigned int,unsigned int)
  
+ char* DrawLink::_state_strings[] =  { "new_link", "one_way", "two_way", "redundant" };
+ 
  /*****************************************************************************/
  
  DrawLink::DrawLink (const char* hostname, int portnum, int state)
Index: DrawServ/drawlink.h
diff -c DrawServ/drawlink.h:1.15 DrawServ/drawlink.h:1.16
*** DrawServ/drawlink.h:1.15	Tue Jun  1 17:52:55 2004
--- src/DrawServ/drawlink.h	Thu Jun  3 09:52:19 2004
***************
*** 53,58 ****
--- 53,61 ----
      virtual ~DrawLink();
  
      enum { new_link=0, one_way, two_way, redundant };
+     
+     static char* state_string(int state)
+       { return state>=0 && state<=redundant ?  _state_strings[state] : nil; }
  
      const char* hostname() { return _host; }
      // return name of remote host
***************
*** 153,158 ****
--- 156,163 ----
  
      DrawServHandler* _comhandler;
      AckBackHandler* _ackhandler;
+ 
+     static char* _state_strings[];
  };
  
  #endif
Index: DrawServ/drawserv.c
diff -c DrawServ/drawserv.c:1.51 DrawServ/drawserv.c:1.52
*** DrawServ/drawserv.c:1.51	Tue Jun  1 17:52:55 2004
--- src/DrawServ/drawserv.c	Thu Jun  3 09:52:19 2004
***************
*** 27,32 ****
--- 27,33 ----
  
  #include <DrawServ/ackback-handler.h>
  #include <DrawServ/draweditor.h>
+ #include <DrawServ/drawkit.h>
  #include <DrawServ/drawlink.h>
  #include <DrawServ/drawlinklist.h>
  #include <DrawServ/drawserv.h>
***************
*** 106,113 ****
  {
    Iterator it;
    _linklist->First(it);
!   while(_linklist->GetDrawLink(it) && !_linklist->Done(it))
!     linkdown(_linklist->GetDrawLink(it));
    delete _linklist;
    delete _gridtable;
    delete _sessionidtable;
--- 107,117 ----
  {
    Iterator it;
    _linklist->First(it);
!   while(_linklist->GetDrawLink(it) && !_linklist->Done(it)) {
!     DrawLink* link = _linklist->GetDrawLink(it);
!     _linklist->Next(it);
!     linkdown(link);
!   }
    delete _linklist;
    delete _gridtable;
    delete _sessionidtable;
***************
*** 210,215 ****
--- 214,225 ----
    return link;
  }
  
+ DrawLink* DrawServ::linkget(unsigned int sessionid) {
+   void* ptr = nil;
+   if (sessionid>0) sessionidtable()->find(ptr, sessionid);
+   return ptr ? ((SessionId*)ptr)->drawlink() : nil;
+ }
+ 
  void DrawServ::linkdump(FILE* fptr) {
    fprintf(fptr, "Host                            Alt.                            Port    LID  RID  State\n");
    fprintf(fptr, "------------------------------  ------------------------------  ------  ---  ---  -----\n");
***************
*** 230,235 ****
--- 240,246 ----
    static int grid_sym = symbol_add("grid");
    static int sid_sym = symbol_add("sid");
    boolean original = false;
+   unsigned int from_sid = 0;
  
    if(!_linklist || _linklist->Number()==0) 
  
***************
*** 254,259 ****
--- 265,271 ----
  	  AttributeList* al = comp->GetAttributeList();
  	  AttributeValue* idv = al->find(grid_sym);
  	  AttributeValue* sidv = al->find(sid_sym);
+ 	  from_sid = sidv ? sidv->uint_val() : 0;
  	  
  	  /* unique id already remotely assigned */
  	  if (idv && idv->uint_val() !=0 && sidv && sidv->uint_val() !=0) {
***************
*** 279,286 ****
  	    original = true;
  	  }
  	    
! 
! 	  if (comp&&original) {
  	    Creator* creator = unidraw->GetCatalog()->GetCreator();
  	    OverlayScript* scripter = (OverlayScript*)
  	      creator->Create(Combine(comp->GetClassId(), SCRIPT_VIEW));
--- 291,297 ----
  	    original = true;
  	  }
  	    
! 	  if (comp && (original || linklist()->Number()>1)) {
  	    Creator* creator = unidraw->GetCatalog()->GetCreator();
  	    OverlayScript* scripter = (OverlayScript*)
  	      creator->Create(Combine(comp->GetClassId(), SCRIPT_VIEW));
***************
*** 296,302 ****
  	  }
  	}
        }
!       if (original) {
  	if (!scripted)
  	  sbuf << "print(\"Failed attempt to generate script for a PASTE_CMD\\n\" :err)";
  	sbuf.put('\0');
--- 307,313 ----
  	  }
  	}
        }
!       if (original || linklist()->Number()>1) {
  	if (!scripted)
  	  sbuf << "print(\"Failed attempt to generate script for a PASTE_CMD\\n\" :err)";
  	sbuf.put('\0');
***************
*** 313,319 ****
  #endif
  
        /* then send everywhere else */
!       if (original) DistributeCmdString(sbuf.str());
        
        }
        break;
--- 324,331 ----
  #endif
  
        /* then send everywhere else */
!       if (original || linklist()->Number()>1) 
! 	DistributeCmdString(sbuf.str(), linkget(from_sid));
        
        }
        break;
***************
*** 333,345 ****
    }
  }
  
! void DrawServ::DistributeCmdString(const char* cmdstring) {
  
    Iterator i;
    _linklist->First(i);
    while (!_linklist->Done(i)) {
      DrawLink* link = _linklist->GetDrawLink(i);
!     if (link && link->state()==DrawLink::two_way) {
        int fd = link->handle();
        if (fd>=0) {
  	fileptr_filebuf fbuf(fd, ios_base::out, false, static_cast<size_t>(BUFSIZ));
--- 345,357 ----
    }
  }
  
! void DrawServ::DistributeCmdString(const char* cmdstring, DrawLink* orglink) {
  
    Iterator i;
    _linklist->First(i);
    while (!_linklist->Done(i)) {
      DrawLink* link = _linklist->GetDrawLink(i);
!     if (link && link != orglink && link->state()==DrawLink::two_way) {
        int fd = link->handle();
        if (fd>=0) {
  	fileptr_filebuf fbuf(fd, ios_base::out, false, static_cast<size_t>(BUFSIZ));
***************
*** 405,411 ****
      link->sid_insert(sid, alt_id);
      if (sid != alt_id) {
        char buffer[BUFSIZ];
!       snprintf(buffer, BUFSIZ, "sid(0x%08x 0x%08x :remap)\n", sid, alt_id);
        SendCmdString(link, buffer);
      }
  
--- 417,423 ----
      link->sid_insert(sid, alt_id);
      if (sid != alt_id) {
        char buffer[BUFSIZ];
!       snprintf(buffer, BUFSIZ, "sid(0x%08x 0x%08x :remap)%c", sid, alt_id, '\0');
        SendCmdString(link, buffer);
      }
  
***************
*** 509,529 ****
    gridtable()->find(ptr, id);
    if (ptr) {
      GraphicId* grid = (GraphicId*)ptr;
      if (selector==sessionid() && newselector!=0) {
!       if (grid->selector()==sessionid() && 
! 	  (grid->selected()==LinkSelection::NotSelected || 
! 	   grid->selected()==LinkSelection::WaitingToBeSelected)) {
! 	grid->selected(LinkSelection::NotSelected);
! 	grid->selector(newselector);
  	char buf[BUFSIZ];
! 	snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :grant chgid(0x%08x))%c",
! 		 grid->id(), newselector, sessionid(), '\0');
! 	SendCmdString(link, buf);
        }
-     } else {
-       grid->selector(selector);
-       grid->selected(state);
      }
    }
  }
  
--- 521,584 ----
    gridtable()->find(ptr, id);
    if (ptr) {
      GraphicId* grid = (GraphicId*)ptr;
+ 
+     /* if this request is aimed here */
      if (selector==sessionid() && newselector!=0) {
! 
!       /* if graphic is still locally owned */
!       if (grid->selector()==sessionid()) {
! 
! 	/* if graphic is not actually selected */
! 	if ((grid->selected()==LinkSelection::NotSelected || 
! 	     grid->selected()==LinkSelection::WaitingToBeSelected)) {
! 	  grid->selected(LinkSelection::NotSelected);
! 	  grid->selector(newselector);
! 	  char buf[BUFSIZ];
! 	  snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :grant chgid(0x%08x))%c",
! 		   grid->id(), newselector, sessionid(), '\0');
! 	  SendCmdString(link, buf);
! 	  fprintf(stderr, "grid: request granted\n");
! 	} 
! 
! 	/* else do nothing, because it is selected */
! 	else {
! 	  fprintf(stderr, "grid: request ignored, graphic locally selected\n");
! 	}
!       } 
!       
!       /* else reformulate this request and pass it along */
!       else {
! 	fprintf(stderr, "grid: request passed along to current selector\n");
  	char buf[BUFSIZ];
! 	snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :request chgid(0x%08x))%c",
! 		 grid->id(), grid->selector(), newselector, '\0');
! 	SendCmdString(linkget(grid->selector()), buf);
        }
      }
+ 
+     /* else this request and/or simple state update should be passed along */
+     else {
+       /* if simple state, set the values here, and pass it on to everyone else */
+       if (newselector==0) {
+ 	if (linklist()->Number()>1)
+ 	  fprintf(stderr, "grid: state change passed along to everyone else\n");
+ 	grid->selector(selector);
+ 	grid->selected(state);
+ 	char buf[BUFSIZ];
+ 	snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :state %d)%c",
+ 		 grid->id(), grid->selector(), grid->selected(), '\0');
+ 	DistributeCmdString(buf, link);
+       } 
+ 
+       /* else pass the request on to the target selector */
+       else {
+ 	fprintf(stderr, "grid:  request passed along to targeted selector");
+ 	char buf[BUFSIZ];
+ 	snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :request chgid(0x%08x))%c",
+ 		 grid->id(), selector, newselector, '\0');
+ 	SendCmdString(linkget(grid->selector()), buf);
+       }
+     }
    }
  }
  
***************
*** 535,552 ****
    gridtable()->find(ptr, id);
    if (ptr) {
      GraphicId* grid = (GraphicId*)ptr;
-     grid->selector(selector);
-   }
- }
  
! // handle reserve request from remote DrawLink.
! void DrawServ::grid_message_propagate(DrawLink* link, unsigned int id, unsigned int selector, 
! 				      int selected, unsigned int otherselector)
! {
!   void* ptr = nil;
!   gridtable()->find(ptr, id);
!   if (ptr) {
!     GraphicId* grid = (GraphicId*)ptr;
    }
  }
  
--- 590,613 ----
    gridtable()->find(ptr, id);
    if (ptr) {
      GraphicId* grid = (GraphicId*)ptr;
  
!     /* if request is granted, add to selection */
!     if (grid->selected()==LinkSelection::WaitingToBeSelected && selector==sessionid()) {
!       grid->selector(selector);
!       fprintf(stderr, "grid:  request granted, add to selection now\n");
!       OverlayComp* comp = (OverlayComp*)grid->grcomp();
!       LinkSelection* sel = (LinkSelection*)DrawKit::Instance()->GetEditor()->GetSelection();
!       sel->AddComp(comp);
!     }
! 
!     /* otherwise, pass the granting message along */
!     else {
!       fprintf(stderr, "grid:  pass grant request along\n");
!       char buf[BUFSIZ];
!       snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :grant chgid(0x%08x))%c",
! 	       grid->id(), selector, oldselector, '\0');
!       SendCmdString(linkget(selector), buf);
!     }
    }
  }
  
Index: DrawServ/drawserv.h
diff -c DrawServ/drawserv.h:1.27 DrawServ/drawserv.h:1.28
*** DrawServ/drawserv.h:1.27	Tue Jun  1 17:52:55 2004
--- src/DrawServ/drawserv.h	Thu Jun  3 09:52:19 2004
***************
*** 76,89 ****
    DrawLink* linkget(const char* hostname, int portnum);
    // return pointer to existing DrawLink
    
    void linkdump(FILE*);
    // dump text table of DrawLink's
    
    virtual void ExecuteCmd(Command*);
    // execute Command's locally, and on remote linked DrawServ's.
    
!   virtual void DistributeCmdString(const char* cmdstring);
!   // execute command string remote DrawServ's
    
    virtual void SendCmdString(DrawLink* link, const char* cmdstring);
    // execute command string on one remote DrawServ
--- 76,92 ----
    DrawLink* linkget(const char* hostname, int portnum);
    // return pointer to existing DrawLink
    
+   DrawLink* linkget(unsigned int sessionid);
+   // return pointer to existing DrawLink given a sessionid.
+   
    void linkdump(FILE*);
    // dump text table of DrawLink's
    
    virtual void ExecuteCmd(Command*);
    // execute Command's locally, and on remote linked DrawServ's.
    
!   virtual void DistributeCmdString(const char* cmdstring, DrawLink* orglink=nil);
!   // send command string to every remote DrawServ (except where it came from).
    
    virtual void SendCmdString(DrawLink* link, const char* cmdstring);
    // execute command string on one remote DrawServ
***************
*** 130,138 ****
--- 133,143 ----
  			     int state, unsigned int oldselector);
    // callback for graphic id selection message 
  
+ #if 0
    void grid_message_propagate(DrawLink* link, unsigned int id, unsigned int selector, 
  			      int state, unsigned int otherselector=0);
    // propagate graphic id selection message
+ #endif
  
    static unsigned int unique_grid();
    // generate unique graphic id.
Index: DrawServ/linkselection.c
diff -c DrawServ/linkselection.c:1.21 DrawServ/linkselection.c:1.22
*** DrawServ/linkselection.c:1.21	Tue Jun  1 17:52:55 2004
--- src/DrawServ/linkselection.c	Thu Jun  3 09:52:19 2004
***************
*** 177,179 ****
--- 177,185 ----
      Next(it);
    }
  }
+ 
+ void LinkSelection::AddComp(OverlayComp* comp) {
+   OverlayView* ov = comp->FindView(_editor->GetViewer());
+   Append(ov);
+   Update(_editor->GetViewer());
+ }
Index: DrawServ/linkselection.h
diff -c DrawServ/linkselection.h:1.7 DrawServ/linkselection.h:1.8
*** DrawServ/linkselection.h:1.7	Mon Mar 22 12:20:07 2004
--- src/DrawServ/linkselection.h	Thu Jun  3 09:52:19 2004
***************
*** 46,54 ****
      virtual void Reserve();
      // reserve newly created graphics in selection across the network
  
    enum { NotSelected, LocallySelected, RemotelySelected, WaitingToBeSelected };
  
!   static const char* selected_string(int state) { return _selected_strings[state]; }
  
  protected:
    DrawEditor* _editor;
--- 46,58 ----
      virtual void Reserve();
      // reserve newly created graphics in selection across the network
  
+     void AddComp(OverlayComp*);
+     // add this graphic to the Selection.
+ 
    enum { NotSelected, LocallySelected, RemotelySelected, WaitingToBeSelected };
  
!   static const char* selected_string(int state) 
!     { return state>=0 && state<=WaitingToBeSelected ?  _selected_strings[state] : nil; }
  
  protected:
    DrawEditor* _editor;
Index: DrawServ/rcdialog.c
diff -c DrawServ/rcdialog.c:1.7 DrawServ/rcdialog.c:1.8
*** DrawServ/rcdialog.c:1.7	Tue Jun  1 17:52:55 2004
--- src/DrawServ/rcdialog.c	Thu Jun  3 09:52:19 2004
***************
*** 376,383 ****
    for(int i=0; i<strlen(buf); i++) vbuf.push_back(buf[i]);
    for (list_->First(i); !list_->Done(i); list_->Next(i)) {
      DrawLink* link = list_->GetDrawLink(i);
!     snprintf(buf, BUFSIZ, "%-30.30s  %-6d  %-3d\n", 
! 	     link->hostname(), link->portnum(), link->state());
      for(int i=0; i<strlen(buf); i++) vbuf.push_back(buf[i]);
    }
    vbuf.push_back('\0');
--- 376,383 ----
    for(int i=0; i<strlen(buf); i++) vbuf.push_back(buf[i]);
    for (list_->First(i); !list_->Done(i); list_->Next(i)) {
      DrawLink* link = list_->GetDrawLink(i);
!     snprintf(buf, BUFSIZ, "%-30.30s  %-6d  %s\n", 
! 	     link->hostname(), link->portnum(), DrawLink::state_string(link->state()));
      for(int i=0; i<strlen(buf); i++) vbuf.push_back(buf[i]);
    }
    vbuf.push_back('\0');
*** /dev/null	 Thu Jun 3 09:52:36 PDT 2004
--- patches/ivtools-040603-johnston-084
*************** patches/ivtools-040603-johnston-084
*** 0 ****
--- 1 ----
+ ivtools-040603-johnston-084

--Apple-Mail-4-683457111
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="ivtools-040603-johnston-085"
Content-Disposition: attachment;
	filename=ivtools-040603-johnston-085

Patch:    ivtools-040603-johnston-085
For:      ivtools-1.1.3
Author:   [email protected]
Subject:  compile without ACE support
Requires: 

This is an intermediate patch to ivtools-1.1.3.  To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:

	patch -p0 <ThisFile

Summary of Changes:

Index: DrawServ/Imakefile
diff -c DrawServ/Imakefile:1.9 DrawServ/Imakefile:1.10
*** DrawServ/Imakefile:1.9	Tue May 25 12:12:08 2004
--- src/DrawServ/Imakefile	Thu Jun  3 11:17:14 2004
***************
*** 19,46 ****
--- 19,54 ----
  #define Obj26(file) MakeObjectFromSrcFlags(file,)
  #define Obj26A(file) MakeObjectFromSrcFlags(file, -D__ACE_INLINE__)
  
+ #ifdef HAVE_ACE
  Obj26A(ackback-handler)
+ #endif
  Obj26(drawcatalog)
  Obj26(drawcreator)
  Obj26(drawcomps)
  Obj26(draweditor)
+ #ifdef HAVE_ACE
  Obj26A(drawfunc)
  Obj26A(drawlink)
  Obj26(drawlinkcomp)
  Obj26(drawlinklist)
+ #endif
  Obj26(drawserv)
  Obj26A(drawserv-handler)
  Obj26(drawviews)
+ #ifdef HAVE_ACE
  Obj26(grid)
  Obj26(gridlist)
  Obj26(linkselection)
  Obj26(sid)
+ #endif
  
  
  #define Obj31(file) MakeObjectFromSrcFlags(file, -Div2_6_incompatible -I$(TOP)/src/include $(TOP_CCINCLUDES))
  
  Obj31(drawkit)
+ #ifdef HAVE_ACE
  Obj31(rcdialog)
+ #endif
  
  IncludeDependencies()
  
Index: DrawServ/draweditor.c
diff -c DrawServ/draweditor.c:1.8 DrawServ/draweditor.c:1.9
*** DrawServ/draweditor.c:1.8	Tue Jun  1 17:52:55 2004
--- src/DrawServ/draweditor.c	Thu Jun  3 11:17:14 2004
***************
*** 85,93 ****
--- 85,95 ----
  void DrawEditor::AddCommands(ComTerp* comterp) {
    FrameEditor::AddCommands(comterp);
  
+ #ifdef HAVE_ACE
    comterp->add_command("drawlink", new DrawLinkFunc(comterp, this));
    comterp->add_command("sid", new SessionIdFunc(comterp, this));
    comterp->add_command("grid", new GraphicIdFunc(comterp, this));
    comterp->add_command("chgid", new ChangeIdFunc(comterp, this));
+ #endif
  }
  
Index: DrawServ/drawkit.c
diff -c DrawServ/drawkit.c:1.6 DrawServ/drawkit.c:1.7
*** DrawServ/drawkit.c:1.6	Tue Mar 30 11:05:49 2004
--- src/DrawServ/drawkit.c	Thu Jun  3 11:17:14 2004
***************
*** 453,462 ****
--- 453,467 ----
  }
  
  OverlaySelection* DrawKit::MakeSelection(Selection* sel) {
+ #ifdef HAVE_ACE
    return new LinkSelection((DrawEditor*)GetEditor(), sel);
+ #else
+   return FrameKit::MakeSelection(sel);
+ #endif
  }
  
  MenuItem * DrawKit::MakeViewersMenu() {
+ #ifdef HAVE_ACE
      LayoutKit& lk = *LayoutKit::instance();
      WidgetKit& kit = *WidgetKit::instance();
  
***************
*** 468,473 ****
--- 473,481 ----
      mbi->menu()->append_item(menu_item);
  
      return mbi;
+ #else
+     return nil;
+ #endif
  }
  
  
Index: DrawServ/drawlink.h
diff -c DrawServ/drawlink.h:1.16 DrawServ/drawlink.h:1.17
*** DrawServ/drawlink.h:1.16	Thu Jun  3 09:52:19 2004
--- src/DrawServ/drawlink.h	Thu Jun  3 11:17:14 2004
***************
*** 45,50 ****
--- 45,51 ----
  class ACE_SOCK_Stream;
  class ACE_SOCK_Stream;
  #endif
+ #include <stdio.h>
  
  //: object to encapsulate 2-way link with remote drawserv
  class DrawLink : public Observable {
***************
*** 118,125 ****
--- 119,128 ----
      int state() { return _state; }
      // get state of DrawLink
  
+ #ifdef HAVE_ACE
      ACE_SOCK_Stream* socket() { return _socket; }
      // return pointer to connected socket.
+ #endif
  
      unsigned int sid_lookup(unsigned int sid);
      // map incoming sid to local sid.
Index: DrawServ/drawserv.c
diff -c DrawServ/drawserv.c:1.52 DrawServ/drawserv.c:1.53
*** DrawServ/drawserv.c:1.52	Thu Jun  3 09:52:19 2004
--- src/DrawServ/drawserv.c	Thu Jun  3 11:17:14 2004
***************
*** 61,66 ****
--- 61,67 ----
  #include <strstream>
  #include <unistd.h>
  
+ #ifdef HAVE_ACE
  implementTable(GraphicIdTable,int,void*)
  implementTable(SessionIdTable,int,void*)
  implementTable(CompIdTable,void*,void*)
***************
*** 69,74 ****
--- 70,76 ----
  unsigned int DrawServ::SessionIdMask = 0xfff00000;
  
  static int seed=0;
+ #endif /* HAVE_ACE */
  
  /*****************************************************************************/
  
***************
*** 84,89 ****
--- 86,92 ----
  }
  
  void DrawServ::Init() {
+ #ifdef HAVE_ACE
    _linklist = new DrawLinkList;
  
    _gridtable = new GraphicIdTable(1024);
***************
*** 91,97 ****
--- 94,102 ----
    _compidtable = new CompIdTable(1024);
  
    _sessionid = unique_sessionid();
+ #if 0
    _sessionid = 0xfff00000;  // for testing purposes
+ #endif
    char hostbuf[HOST_NAME_MAX];
    gethostname(hostbuf, HOST_NAME_MAX);
    char* username = getlogin();
***************
*** 101,110 ****
--- 106,117 ----
    _sessionidtable->insert(_sessionid, sid);
  
    _comdraw_port = atoi(unidraw->GetCatalog()->GetAttribute("comdraw"));
+ #endif /* HAVE_ACE */
  }
  
  DrawServ::~DrawServ () 
  {
+ #ifdef HAVE_ACE
    Iterator it;
    _linklist->First(it);
    while(_linklist->GetDrawLink(it) && !_linklist->Done(it)) {
***************
*** 116,123 ****
--- 123,133 ----
    delete _gridtable;
    delete _sessionidtable;
    delete _compidtable;
+ #endif /* HAVE_ACE */
  }
  
+ #ifdef HAVE_ACE
+ 
  DrawLink* DrawServ::linkup(const char* hostname, int portnum, 
  		     int state, int local_id, int remote_id,
  		     ComTerp* comterp) {
***************
*** 706,708 ****
--- 716,720 ----
    }
    return true;
  }
+ 
+ #endif /* HAVE_ACE */
Index: DrawServ/drawserv.h
diff -c DrawServ/drawserv.h:1.28 DrawServ/drawserv.h:1.29
*** DrawServ/drawserv.h:1.28	Thu Jun  3 09:52:19 2004
--- src/DrawServ/drawserv.h	Thu Jun  3 11:17:14 2004
***************
*** 47,52 ****
--- 47,56 ----
  class GraphicId;
  class GraphicIdList;
  
+ #if !defined (HOST_NAME_MAX)
+ #  define HOST_NAME_MAX 256
+ #endif /* !HOST_NAME_MAX */
+ 
  class DrawServ : public OverlayUnidraw {
  public:
    DrawServ(
***************
*** 58,63 ****
--- 62,68 ----
    
    void Init();
    
+ #ifdef HAVE_ACE
    DrawLink* linkup(const char* hostname, int portnum, 
  		   int state, int local_id=-1, int remote_id=-1,
  		   ComTerp* comterp=nil);
***************
*** 189,194 ****
--- 194,200 ----
      int _comdraw_port;
      // port used for comdraw command interpreter
  
+ #endif /* HAVE_ACE */
  };
  
  #endif
Index: DrawServ/linkselection.h
diff -c DrawServ/linkselection.h:1.8 DrawServ/linkselection.h:1.9
*** DrawServ/linkselection.h:1.8	Thu Jun  3 09:52:19 2004
--- src/DrawServ/linkselection.h	Thu Jun  3 11:17:14 2004
***************
*** 28,33 ****
--- 28,34 ----
  #ifndef link_selection_h
  #define link_selection_h
  
+ #ifdef HAVE_ACE
  #include <OverlayUnidraw/ovselection.h>
  
  class DrawLinkList;
***************
*** 62,66 ****
    static char* _selected_strings[];
  
  };
! 
  #endif
--- 63,67 ----
    static char* _selected_strings[];
  
  };
! #endif /* HAVE_ACE */
  #endif
Index: src_dispatch/dispatcher.c
diff -c src_dispatch/dispatcher.c:1.1 src_dispatch/dispatcher.c:1.2
*** src_dispatch/dispatcher.c:1.1	Fri Jan  9 11:42:57 2004
--- src/Dispatch/dispatcher.c	Thu Jun  3 11:16:52 2004
***************
*** 653,667 ****
  	sv.sa_flags = SV_INTERRUPT;
  	sigaction(SIGCLD, &sv, &osv);
  #else
- #ifdef __APPLE__
- 	sv.sv_handler = (void (*)()) fxSIGVECHANDLER(&Dispatcher::sigCLD);
- 	sv.sv_flags = SV_INTERRUPT;
- 	sigvec(SIGCLD, &sv, &osv);
- #else
  	sv.sv_handler = (void (*)(int)) fxSIGVECHANDLER(&Dispatcher::sigCLD);
  	sv.sv_flags = SV_INTERRUPT;
  	sigvec(SIGCLD, &sv, &osv);
- #endif
  #endif
  #else
  #ifdef SA_NOCLDSTOP                   /* POSIX */
--- 653,661 ----
*** /dev/null	 Thu Jun 3 11:17:28 PDT 2004
--- patches/ivtools-040603-johnston-085
*************** patches/ivtools-040603-johnston-085
*** 0 ****
--- 1 ----
+ ivtools-040603-johnston-085

--Apple-Mail-4-683457111--



-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504