diff options
| -rw-r--r-- | lib/Makefile.am | 4 | ||||
| -rw-r--r-- | lib/rclip.cc | 157 | ||||
| -rw-r--r-- | lib/rclip.h | 124 | ||||
| -rw-r--r-- | lib/wprt.cc | 157 | ||||
| -rw-r--r-- | lib/wprt.h | 124 | 
5 files changed, 564 insertions, 2 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 505b19d..49c9e46 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -8,10 +8,10 @@ libplp_la_LDFLAGS = $(LIBDEBUG) -version-info $(LIBVERSION)  libplp_la_SOURCES = bufferarray.cc  bufferstore.cc iowatch.cc ppsocket.cc \  	rfsv16.cc rfsv32.cc rfsvfactory.cc log.cc rfsv.cc rpcs32.cc rpcs16.cc \ -	rpcs.cc rpcsfactory.cc psitime.cc Enum.cc plpdirent.cc +	rpcs.cc rpcsfactory.cc psitime.cc Enum.cc plpdirent.cc wprt.cc rclip.cc  pkginclude_HEADERS = bufferarray.h bufferstore.h iowatch.h ppsocket.h \  	rfsv.h rfsv16.h rfsv32.h rfsvfactory.h log.h rpcs32.h rpcs16.h rpcs.h \ -	rpcsfactory.h psitime.h Enum.h plpdirent.h +	rpcsfactory.h psitime.h Enum.h plpdirent.h wprt.h plpintl.h rclip.h  maintainer-clean-local:  	rm -f Makefile.in diff --git a/lib/rclip.cc b/lib/rclip.cc new file mode 100644 index 0000000..b8df5fe --- /dev/null +++ b/lib/rclip.cc @@ -0,0 +1,157 @@ +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + *  Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com> + * + *  This program is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  This program is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stream.h> +#include <stdlib.h> +#include <fstream.h> +#include <iomanip.h> +#include <time.h> +#include <string.h> + +#include <rclip.h> +#include <bufferstore.h> +#include <ppsocket.h> +#include <bufferarray.h> +#include <Enum.h> + +rclip::rclip(ppsocket * _skt) +{ +    skt = _skt; +    reset(); +} + +rclip::~rclip() +{ +    skt->closeSocket(); +} + +// +// public common API +// +void rclip:: +reconnect(void) +{ +    //skt->closeSocket(); +    skt->reconnect(); +    reset(); +} + +void rclip:: +reset(void) +{ +    bufferStore a; +    status = rfsv::E_PSI_FILE_DISC; +    a.addStringT(getConnectName()); +    if (skt->sendBufferStore(a)) { +	if (skt->getBufferStore(a) == 1) { +	    if (!strcmp(a.getString(0), "Ok")) +		status = rfsv::E_PSI_GEN_NONE; +	} +    } +} + +Enum<rfsv::errs> rclip:: +getStatus(void) +{ +    return status; +} + +const char *rclip:: +getConnectName(void) +{ +    return "SYS$RCLIP"; +} + +// +// protected internals +// +bool rclip:: +sendCommand(enum commands cc, bufferStore & data) +{ +    if (status == rfsv::E_PSI_FILE_DISC) { +	reconnect(); +	if (status == rfsv::E_PSI_FILE_DISC) +	    return false; +    } +    bool result; +    bufferStore a; +    a.addByte(cc); +    a.addBuff(data); +    result = skt->sendBufferStore(a); +    if (!result) { +	reconnect(); +	result = skt->sendBufferStore(a); +	if (!result) +	    status = rfsv::E_PSI_FILE_DISC; +    } +    return result; +} + +Enum<rfsv::errs> rclip:: +putData(bufferStore &) { +    Enum<rfsv::errs> ret; + +    bufferStore a; +    a.addWord(0); +    sendCommand(RCLIP_INIT, a); +    if ((ret = getResponse(a)) != rfsv::E_PSI_GEN_NONE) +	cerr << "RCLIP ERR:" << a << endl; +    else { +	if (a.getLen() != 3) +	    ret = rfsv::E_PSI_GEN_FAIL; +	if ((a.getByte(0) != 0) || (a.getWord(1) != 2)) +	    ret = rfsv::E_PSI_GEN_FAIL; +    } +    return ret; +} + +Enum<rfsv::errs> rclip:: +getData(bufferStore &buf) { +    Enum<rfsv::errs> ret; +    bufferStore a; + +    sendCommand(RCLIP_GET, buf); +    if ((ret = getResponse(buf)) != rfsv::E_PSI_GEN_NONE) +	cerr << "RCLIP ERR:" << a << endl; +    return ret; +} + +Enum<rfsv::errs> rclip:: +getResponse(bufferStore & data) +{ +    Enum<rfsv::errs> ret = rfsv::E_PSI_GEN_NONE; +    if (skt->getBufferStore(data) == 1) +	return ret; +    else +	status = rfsv::E_PSI_FILE_DISC; +    return status; +} + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ diff --git a/lib/rclip.h b/lib/rclip.h new file mode 100644 index 0000000..617f31b --- /dev/null +++ b/lib/rclip.h @@ -0,0 +1,124 @@ +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + *  Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com> + * + *  This program is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  This program is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + */ +#ifndef _RCLIP_H_ +#define _RCLIP_H_ + +#include <rfsv.h> +#include <Enum.h> + +class ppsocket; +class bufferStore; +class bufferArray; + +/** + * Remote ClipBoard services via PLP + * + */ +class rclip { +public: +    rclip(ppsocket *); + +    /** +    * Virtual destructor. +    */ +    ~rclip(); + +    /** +    * Initializes a connection to the remote +    * machine. +    */ +    void reset(); + +    /** +    * Attempts to re-establish a remote +    * connection by first closing the socket, +    * then connecting again to the ncpd daemon +    * and finally calling @ref reset. +    */ +    void reconnect(); + +    /** +    * Retrieves the current status of the +    * connection. +    * +    * @returns The connection status. +    */ +    Enum<rfsv::errs> getStatus(); + +    /** +    * Get Remote ClipBoard Data +    */ +    Enum<rfsv::errs> getData(bufferStore &buf); + +    /** +    * Put Data to Remote ClipBoard +    */ +    Enum<rfsv::errs> putData(bufferStore &buf); + +protected: +    /** +    * The possible commands. +    */ +    enum commands { +	RCLIP_INIT = 0x0100, +	RCLIP_GET  = 0xf0f0, +    }; + +    /** +    * The socket, used for communication +    * with ncpd. +    */ +    ppsocket *skt; + +    /** +    * The current status of the connection. +    */ +    Enum<rfsv::errs> status; + +   /** +    * Sends a command to the remote side. +    * +    * If communication fails, a reconnect is triggered +    * and a second attempt to transmit the request +    * is attempted. If that second attempt fails, +    * the function returns an error an sets rpcs::status +    * to E_PSI_FILE_DISC. +    * +    * @param cc The command to execute on the remote side. +    * @param data Additional data for this command. +    * +    * @returns true on success, false on failure. +    */ +    bool sendCommand(enum commands cc, bufferStore &data); +    Enum<rfsv::errs> getResponse(bufferStore &data); +    const char *getConnectName(); + +}; + +#endif + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ diff --git a/lib/wprt.cc b/lib/wprt.cc new file mode 100644 index 0000000..89d037f --- /dev/null +++ b/lib/wprt.cc @@ -0,0 +1,157 @@ +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + *  Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com> + * + *  This program is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  This program is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stream.h> +#include <stdlib.h> +#include <fstream.h> +#include <iomanip.h> +#include <time.h> +#include <string.h> + +#include "wprt.h" +#include "bufferstore.h" +#include "ppsocket.h" +#include "bufferarray.h" +#include "Enum.h" + +wprt::wprt(ppsocket * _skt) +{ +    skt = _skt; +    reset(); +} + +wprt::~wprt() +{ +    skt->closeSocket(); +} + +// +// public common API +// +void wprt:: +reconnect(void) +{ +    //skt->closeSocket(); +    skt->reconnect(); +    reset(); +} + +void wprt:: +reset(void) +{ +    bufferStore a; +    status = rfsv::E_PSI_FILE_DISC; +    a.addStringT(getConnectName()); +    if (skt->sendBufferStore(a)) { +	if (skt->getBufferStore(a) == 1) { +	    if (!strcmp(a.getString(0), "Ok")) +		status = rfsv::E_PSI_GEN_NONE; +	} +    } +} + +Enum<rfsv::errs> wprt:: +getStatus(void) +{ +    return status; +} + +const char *wprt:: +getConnectName(void) +{ +    return "SYS$WPRT"; +} + +// +// protected internals +// +bool wprt:: +sendCommand(enum commands cc, bufferStore & data) +{ +    if (status == rfsv::E_PSI_FILE_DISC) { +	reconnect(); +	if (status == rfsv::E_PSI_FILE_DISC) +	    return false; +    } +    bool result; +    bufferStore a; +    a.addByte(cc); +    a.addBuff(data); +    result = skt->sendBufferStore(a); +    if (!result) { +	reconnect(); +	result = skt->sendBufferStore(a); +	if (!result) +	    status = rfsv::E_PSI_FILE_DISC; +    } +    return result; +} + +Enum<rfsv::errs> wprt:: +initPrinter() { +    Enum<rfsv::errs> ret; + +    bufferStore a; +    a.addWord(0); +    sendCommand(WPRT_INIT, a); +    if ((ret = getResponse(a)) != rfsv::E_PSI_GEN_NONE) +	cerr << "WPRT ERR:" << a << endl; +    else { +	if (a.getLen() != 3) +	    ret = rfsv::E_PSI_GEN_FAIL; +	if ((a.getByte(0) != 0) || (a.getWord(1) != 2)) +	    ret = rfsv::E_PSI_GEN_FAIL; +    } +    return ret; +} + +Enum<rfsv::errs> wprt:: +getData(bufferStore &buf) { +    Enum<rfsv::errs> ret; +    bufferStore a; + +    sendCommand(WPRT_GET, buf); +    if ((ret = getResponse(buf)) != rfsv::E_PSI_GEN_NONE) +	cerr << "WPRT ERR:" << a << endl; +    return ret; +} + +Enum<rfsv::errs> wprt:: +getResponse(bufferStore & data) +{ +    Enum<rfsv::errs> ret = rfsv::E_PSI_GEN_NONE; +    if (skt->getBufferStore(data) == 1) +	return ret; +    else +	status = rfsv::E_PSI_FILE_DISC; +    return status; +} + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ diff --git a/lib/wprt.h b/lib/wprt.h new file mode 100644 index 0000000..54ca84b --- /dev/null +++ b/lib/wprt.h @@ -0,0 +1,124 @@ +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + *  Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com> + * + *  This program is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  This program is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + */ +#ifndef _WPRT_H_ +#define _WPRT_H_ + +#include <rfsv.h> +#include <Enum.h> + +class ppsocket; +class bufferStore; +class bufferArray; + +/** + * Remote Print services via PLP + * + */ +class wprt { +public: +    wprt(ppsocket *); + +    /** +    * Virtual destructor. +    */ +    ~wprt(); + +    /** +    * Initializes a connection to the remote +    * machine. +    */ +    void reset(); + +    /** +    * Attempts to re-establish a remote +    * connection by first closing the socket, +    * then connecting again to the ncpd daemon +    * and finally calling @ref reset. +    */ +    void reconnect(); + +    /** +    * Retrieves the current status of the +    * connection. +    * +    * @returns The connection status. +    */ +    Enum<rfsv::errs> getStatus(); + +    /** +    * Get Print Data +    */ +    Enum<rfsv::errs> getData(bufferStore &buf); + +    /** +    * Init Printer +    */ +    Enum<rfsv::errs> initPrinter(); + +protected: +    /** +    * The possible commands. +    */ +    enum commands { +	WPRT_INIT = 0x0100, +	WPRT_GET  = 0xf0f0, +    }; + +    /** +    * The socket, used for communication +    * with ncpd. +    */ +    ppsocket *skt; + +    /** +    * The current status of the connection. +    */ +    Enum<rfsv::errs> status; + +   /** +    * Sends a command to the remote side. +    * +    * If communication fails, a reconnect is triggered +    * and a second attempt to transmit the request +    * is attempted. If that second attempt fails, +    * the function returns an error an sets rpcs::status +    * to E_PSI_FILE_DISC. +    * +    * @param cc The command to execute on the remote side. +    * @param data Additional data for this command. +    * +    * @returns true on success, false on failure. +    */ +    bool sendCommand(enum commands cc, bufferStore &data); +    Enum<rfsv::errs> getResponse(bufferStore &data); +    const char *getConnectName(); + +}; + +#endif + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */  | 
