"Fossies" - the Fresh Open Source Software Archive

Member "plptools-1.0.15/lib/wprt.cc" (31 Oct 2019, 3477 Bytes) of package /linux/privat/plptools-1.0.15.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 "wprt.cc" see the Fossies "Dox" file reference documentation.

    1 /*-*-c++-*-
    2  * $Id$
    3  *
    4  * This file is part of plptools.
    5  *
    6  *  Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
    7  *
    8  *  This program is free software; you can redistribute it and/or modify
    9  *  it under the terms of the GNU General Public License as published by
   10  *  the Free Software Foundation; either version 2 of the License, or
   11  *  (at your option) any later version.
   12  *
   13  *  This program is distributed in the hope that it will be useful,
   14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16  *  GNU General Public License for more details.
   17  *
   18  *  You should have received a copy of the GNU General Public License
   19  *  along with this program; if not, write to the Free Software
   20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21  *
   22  */
   23 #ifdef HAVE_CONFIG_H
   24 #include "config.h"
   25 #endif
   26 
   27 #include "wprt.h"
   28 #include "bufferstore.h"
   29 #include "ppsocket.h"
   30 #include "bufferarray.h"
   31 #include "Enum.h"
   32 
   33 #include <iostream>
   34 
   35 #include <stdlib.h>
   36 #include <time.h>
   37 
   38 using namespace std;
   39 
   40 wprt::wprt(ppsocket * _skt)
   41 {
   42     skt = _skt;
   43     reset();
   44 }
   45 
   46 wprt::~wprt()
   47 {
   48     skt->closeSocket();
   49 }
   50 
   51 //
   52 // public common API
   53 //
   54 void wprt::
   55 reconnect(void)
   56 {
   57     //skt->closeSocket();
   58     skt->reconnect();
   59     reset();
   60 }
   61 
   62 void wprt::
   63 reset(void)
   64 {
   65     bufferStore a;
   66     status = rfsv::E_PSI_FILE_DISC;
   67     a.addStringT(getConnectName());
   68     if (skt->sendBufferStore(a)) {
   69     if (skt->getBufferStore(a) == 1) {
   70         if (!strcmp(a.getString(0), "Ok"))
   71         status = rfsv::E_PSI_GEN_NONE;
   72     }
   73     }
   74 }
   75 
   76 Enum<rfsv::errs> wprt::
   77 getStatus(void)
   78 {
   79     return status;
   80 }
   81 
   82 const char *wprt::
   83 getConnectName(void)
   84 {
   85     return "SYS$WPRT";
   86 }
   87 
   88 //
   89 // protected internals
   90 //
   91 bool wprt::
   92 sendCommand(enum commands cc, bufferStore & data)
   93 {
   94     if (status == rfsv::E_PSI_FILE_DISC) {
   95     reconnect();
   96     if (status == rfsv::E_PSI_FILE_DISC)
   97         return false;
   98     }
   99     bool result;
  100     bufferStore a;
  101     a.addByte(cc);
  102     a.addBuff(data);
  103     result = skt->sendBufferStore(a);
  104     if (!result) {
  105     reconnect();
  106     result = skt->sendBufferStore(a);
  107     if (!result)
  108         status = rfsv::E_PSI_FILE_DISC;
  109     }
  110     return result;
  111 }
  112 
  113 Enum<rfsv::errs> wprt::
  114 initPrinter() {
  115     Enum<rfsv::errs> ret;
  116 
  117     bufferStore a;
  118     a.addByte(2); // Major printer version
  119     a.addByte(0); // Minor printer version
  120     sendCommand(WPRT_INIT, a);
  121     if ((ret = getResponse(a)) != rfsv::E_PSI_GEN_NONE)
  122     cerr << "WPRT ERR:" << a << endl;
  123     else {
  124     if (a.getLen() != 3)
  125         ret = rfsv::E_PSI_GEN_FAIL;
  126     if ((a.getByte(0) != 0) || (a.getWord(1) != 2))
  127         ret = rfsv::E_PSI_GEN_FAIL;
  128     }
  129     return ret;
  130 }
  131 
  132 Enum<rfsv::errs> wprt::
  133 getData(bufferStore &buf) {
  134     Enum<rfsv::errs> ret;
  135 
  136     sendCommand(WPRT_GET, buf);
  137     if ((ret = getResponse(buf)) != rfsv::E_PSI_GEN_NONE)
  138     cerr << "WPRT ERR:" << buf << endl;
  139     return ret;
  140 }
  141 
  142 Enum<rfsv::errs> wprt::
  143 cancelJob() {
  144     Enum<rfsv::errs> ret;
  145     bufferStore a;
  146 
  147     sendCommand(WPRT_CANCEL, a);
  148     if ((ret = getResponse(a)) != rfsv::E_PSI_GEN_NONE)
  149     cerr << "WPRT ERR:" << a << endl;
  150     return ret;
  151 }
  152 
  153 bool wprt::
  154 stop() {
  155     bufferStore a;
  156     return sendCommand(WPRT_STOP, a);
  157 }
  158 
  159 Enum<rfsv::errs> wprt::
  160 getResponse(bufferStore & data)
  161 {
  162     Enum<rfsv::errs> ret = rfsv::E_PSI_GEN_NONE;
  163     if (skt->getBufferStore(data) == 1)
  164     return ret;
  165     else
  166     status = rfsv::E_PSI_FILE_DISC;
  167     return status;
  168 }
  169 
  170 /*
  171  * Local variables:
  172  * c-basic-offset: 4
  173  * End:
  174  */