"Fossies" - the Fresh Open Source Software Archive

Member "ivtools-ivtools-2.0.4/src/OverlayUnidraw/aceimport.c" (9 Oct 2020, 3983 Bytes) of package /linux/misc/ivtools-ivtools-2.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "aceimport.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 1996 Vectaport Inc.
    3  *
    4  * Permission to use, copy, modify, distribute, and sell this software and
    5  * its documentation for any purpose is hereby granted without fee, provided
    6  * that the above copyright notice appear in all copies and that both that
    7  * copyright notice and this permission notice appear in supporting
    8  * documentation, and that the names of the copyright holders not be used in
    9  * advertising or publicity pertaining to distribution of the software
   10  * without specific, written prior permission.  The copyright holders make
   11  * no representations about the suitability of this software for any purpose.
   12  * It is provided "as is" without express or implied warranty.
   13  *
   14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
   15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
   16  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
   17  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
   18  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
   19  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
   20  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   21  * 
   22  */
   23 
   24 #ifdef HAVE_ACE
   25 
   26 #ifdef __llvm__
   27 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   28 #endif
   29 
   30 #include <OverlayUnidraw/aceimport.h>
   31 
   32 #include <OverlayUnidraw/oved.h>
   33 #include <OverlayUnidraw/ovcomps.h>
   34 #include <OverlayUnidraw/ovimport.h>
   35 #include <IVGlyph/importchooser.h>
   36 #include <Unidraw/iterator.h>
   37 #include <Unidraw/unidraw.h>
   38 #include <ComTerp/comhandler.h>
   39 #include <fstream.h>
   40 #include <stdio.h>
   41 
   42 #include <iostream>
   43 using std::cout;
   44 using std::cerr;
   45 
   46 /*****************************************************************************/
   47 
   48 UnidrawImportHandler::UnidrawImportHandler ()
   49 {
   50     Iterator i;
   51     unidraw->First(i);
   52     OverlayEditor* ed = (OverlayEditor*)unidraw->GetEditor(i);
   53     OverlayIdrawComp* topcomp = (OverlayIdrawComp*) ed->GetComponent();
   54     topcomp->ResetIndexedGS();
   55     _import_cmd = new OvImportCmd(unidraw->GetEditor(i), &ImportChooser::instance());
   56     _inptr = nil;
   57     _filebuf = nil;
   58     _infptr = nil;
   59 }
   60 
   61 void
   62 UnidrawImportHandler::destroy (void)
   63 {
   64     cerr << this->peer_name_ << " disconnected from import port\n";
   65 #if 0
   66     ComterpHandler::reactor_singleton()->cancel_timer (this);
   67 #endif
   68     this->peer ().close ();
   69     if (_infptr) {
   70       fclose(_infptr);
   71       _infptr = nil;
   72     }
   73 }
   74 
   75 int
   76 UnidrawImportHandler::handle_timeout (const ACE_Time_Value &,
   77                  const void *arg)
   78 {
   79     ACE_ASSERT (arg == this);
   80     ACE_DEBUG ((LM_DEBUG, "(%P|%t) handling timeout from this = %u\n", this));
   81     return 0;
   82 }
   83 
   84 int
   85 UnidrawImportHandler::handle_input (ACE_HANDLE fd)
   86 {
   87     if (!_infptr) _infptr = fdopen(fd, "r");
   88     FILEBUF(fbuf, _infptr, ios_base::in);
   89     istream in(&fbuf);
   90     int ch = in.get();
   91     if (ch != EOF && in.good()) {
   92       in.unget();
   93       _import_cmd->instream(&in);
   94       _import_cmd->Execute();
   95     }
   96     return -1;  /* only return -1, which indicates input handling is fini */
   97 }
   98 
   99 int
  100 UnidrawImportHandler::open (void *)
  101 {
  102   ACE_INET_Addr addr;
  103   
  104   if (this->peer ().get_remote_addr (addr) == -1)
  105     return -1;
  106   else
  107     {
  108       ACE_OS::strncpy (this->peer_name_, 
  109                addr.get_host_name (), 
  110                MAXHOSTNAMELEN + 1);
  111 
  112       if (ComterpHandler::reactor_singleton()->register_handler 
  113       (this, ACE_Event_Handler::READ_MASK) == -1)
  114     ACE_ERROR_RETURN ((LM_ERROR, 
  115                "(%P|%t) can't register with reactor\n"), -1);
  116 #if 0
  117       else if (ComterpHandler::reactor_singleton()->schedule_timer
  118       (this, 
  119       (const void *) this, 
  120        ACE_Time_Value (10), 
  121        ACE_Time_Value (10)) == -1)
  122     ACE_ERROR_RETURN ((LM_ERROR, 
  123                "can'(%P|%t) t register with reactor\n"), -1);
  124 #endif
  125       else
  126         cerr << this->peer_name_ << " connected to import port\n";
  127       return 0;
  128     }
  129 }
  130 
  131 int
  132 UnidrawImportHandler::close (u_long)
  133 {
  134   delete _filebuf;
  135   delete _inptr;
  136   this->destroy ();
  137   return 0;
  138 }
  139 
  140 #endif /* HAVE_ACE */