plptools
Loading...
Searching...
No Matches
wprt.cc
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20#include "config.h"
21
22#include "wprt.h"
23#include "bufferstore.h"
24#include "tcpsocket.h"
25#include "bufferarray.h"
26#include "Enum.h"
27
28#include <iostream>
29
30#include <stdlib.h>
31#include <time.h>
32
33using namespace std;
34
36{
37 skt = _skt;
38 reset();
39}
40
42{
44}
45
46//
47// public common API
48//
50reconnect(void)
51{
52 //skt->closeSocket();
53 skt->reconnect();
54 reset();
55}
56
58reset(void)
59{
62 a.addStringT(getConnectName());
63 if (skt->sendBufferStore(a)) {
64 if (skt->getBufferStore(a) == 1) {
65 if (!strcmp(a.getString(0), "Ok"))
67 }
68 }
69}
70
72getStatus(void)
73{
74 return status;
75}
76
77const char *wprt::
79{
80 return "SYS$WPRT";
81}
82
83//
84// protected internals
85//
87sendCommand(enum commands cc, bufferStore & data)
88{
90 reconnect();
92 return false;
93 }
94 bool result;
96 a.addByte(cc);
97 a.addBuff(data);
98 result = skt->sendBufferStore(a);
99 if (!result) {
100 reconnect();
101 result = skt->sendBufferStore(a);
102 if (!result)
104 }
105 return result;
106}
107
109initPrinter() {
111
113 a.addByte(2); // Major printer version
114 a.addByte(0); // Minor printer version
116 if ((ret = getResponse(a)) != rfsv::E_PSI_GEN_NONE)
117 cerr << "WPRT ERR:" << a << endl;
118 else {
119 if (a.getLen() != 3)
121 if ((a.getByte(0) != 0) || (a.getWord(1) != 2))
123 }
124 return ret;
125}
126
128getData(bufferStore &buf) {
130
131 sendCommand(WPRT_GET, buf);
132 if ((ret = getResponse(buf)) != rfsv::E_PSI_GEN_NONE)
133 cerr << "WPRT ERR:" << buf << endl;
134 return ret;
135}
136
138cancelJob() {
141
143 if ((ret = getResponse(a)) != rfsv::E_PSI_GEN_NONE)
144 cerr << "WPRT ERR:" << a << endl;
145 return ret;
146}
147
149stop() {
151 return sendCommand(WPRT_STOP, a);
152}
153
156{
158 if (skt->getBufferStore(data) == 1)
159 return ret;
160 else
162 return status;
163}
Wrapper class featuring range-checking and string representation of enumerated values.
Definition: Enum.h:136
A class for dealing with sockets.
Definition: tcpsocket.h:38
bool closeSocket(void)
Closes the connection.
Definition: tcpsocket.cc:374
virtual bool reconnect()
Reopens the connection after closing it.
Definition: tcpsocket.cc:100
int getBufferStore(bufferStore &a, bool wait=true)
Receive data into a bufferStore .
Definition: tcpsocket.cc:289
bool sendBufferStore(const bufferStore &a)
Sends data from a bufferStore .
Definition: tcpsocket.cc:325
A generic container for an array of bytes.
Definition: bufferstore.h:37
@ E_PSI_GEN_NONE
Definition: rfsv.h:110
@ E_PSI_GEN_FAIL
Definition: rfsv.h:111
@ E_PSI_FILE_DISC
Definition: rfsv.h:152
bool sendCommand(enum commands cc, bufferStore &data)
Sends a command to the remote side.
Definition: wprt.cc:87
Enum< rfsv::errs > cancelJob()
Cancels a running job.
Definition: wprt.cc:138
Enum< rfsv::errs > getResponse(bufferStore &data)
Definition: wprt.cc:155
Enum< rfsv::errs > status
The current status of the connection.
Definition: wprt.h:105
void reset()
Initializes a connection to the remote machine.
Definition: wprt.cc:58
TCPSocket * skt
The socket, used for communication with ncpd.
Definition: wprt.h:100
void reconnect()
Attempts to re-establish a remote connection by first closing the socket, then connecting again to th...
Definition: wprt.cc:50
commands
The possible commands.
Definition: wprt.h:89
@ WPRT_CANCEL
Definition: wprt.h:92
@ WPRT_STOP
Definition: wprt.h:93
@ WPRT_INIT
Definition: wprt.h:90
@ WPRT_GET
Definition: wprt.h:91
Enum< rfsv::errs > initPrinter()
Init Printer.
Definition: wprt.cc:109
bool stop()
Stops the WPRT server.
Definition: wprt.cc:149
~wprt()
Virtual destructor.
Definition: wprt.cc:41
Enum< rfsv::errs > getStatus()
Retrieves the current status of the connection.
Definition: wprt.cc:72
wprt(TCPSocket *)
Definition: wprt.cc:35
const char * getConnectName()
Definition: wprt.cc:78
Enum< rfsv::errs > getData(bufferStore &buf)
Get Print Data.
Definition: wprt.cc:128
Definition: doctest.h:522
static rfsv * a
Definition: main.cc:53