plptools
Loading...
Searching...
No Matches
rclip.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 "rclip.h"
23#include "bufferstore.h"
24#include "tcpsocket.h"
25#include "bufferarray.h"
26#include "Enum.h"
27
28#include <stdlib.h>
29#include <time.h>
30
32{
33 skt = _skt;
34 reset();
35}
36
38{
40}
41
42//
43// public common API
44//
46reconnect(void)
47{
48 //skt->closeSocket();
49 skt->reconnect();
50 reset();
51}
52
54reset(void)
55{
58 a.addStringT(getConnectName());
59 if (skt->sendBufferStore(a)) {
60 if (skt->getBufferStore(a) == 1) {
61 if (!strcmp(a.getString(0), "NAK"))
63 if (!strcmp(a.getString(0), "Ok"))
65 }
66 }
67}
68
70getStatus(void)
71{
72 return status;
73}
74
75const char *rclip::
77{
78 return "CLIPSVR.RSY";
79}
80
81//
82// protected internals
83//
85sendCommand(enum commands cc)
86{
88 reconnect();
90 return false;
91 }
93 return false;
94
95 bool result;
97 a.addByte(cc);
98 switch (cc) {
99 case RCLIP_INIT:
100 a.addWord(0x100);
101 break;
102 case RCLIP_NOTIFY:
103 a.addByte(0);
104 }
105 result = skt->sendBufferStore(a);
106 if (!result) {
107 reconnect();
108 result = skt->sendBufferStore(a);
109 if (!result)
111 }
112 return result;
113}
114
116sendListen() {
119 else
120 return status;
121}
122
124checkNotify() {
127
128 int r = skt->getBufferStore(a, false);
129 if (r < 0) {
131 } else {
132 if (r == 0)
134 else {
135 if ((a.getLen() != 1) || (a.getByte(0) != 0))
137 }
138 }
139 return ret;
140}
141
143waitNotify() {
145
148 if ((ret = getResponse(a)) == rfsv::E_PSI_GEN_NONE) {
149 if ((a.getLen() != 1) || (a.getByte(0) != 0))
151 }
152 return ret;
153}
154
156notify() {
159
161 if ((ret = getResponse(a)) == rfsv::E_PSI_GEN_NONE) {
162 if ((a.getLen() != 1) || (a.getByte(0) != RCLIP_NOTIFY))
164 }
165 return ret;
166}
167
169initClipbd() {
172
174 return status;
175
177 if ((ret = getResponse(a)) == rfsv::E_PSI_GEN_NONE) {
178 if ((a.getLen() != 3) || (a.getByte(0) != RCLIP_INIT) ||
179 (a.getWord(1) != 0x100))
181 }
182 return ret;
183}
184
187{
189
191 return status;
192
193 if (skt->getBufferStore(data) == 1)
194 return ret;
195 else
197 return status;
198}
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
Enum< rfsv::errs > status
The current status of the connection.
Definition: rclip.h:155
Enum< rfsv::errs > getResponse(bufferStore &data)
Definition: rclip.cc:186
Enum< rfsv::errs > waitNotify()
Send listen request and wait for notification.
Definition: rclip.cc:143
bool sendCommand(enum commands cc)
Sends a command to the remote side.
Definition: rclip.cc:85
const char * getConnectName()
Definition: rclip.cc:76
void reconnect()
Attempts to re-establish a remote connection by first closing the socket, then connecting again to th...
Definition: rclip.cc:46
~rclip()
Destructor.
Definition: rclip.cc:37
Enum< rfsv::errs > sendListen()
Send listen request.
Definition: rclip.cc:116
rclip(TCPSocket *skt)
Constructs a new rclip object.
Definition: rclip.cc:31
commands
The possible commands.
Definition: rclip.h:140
@ RCLIP_LISTEN
Definition: rclip.h:143
@ RCLIP_INIT
Definition: rclip.h:141
@ RCLIP_NOTIFY
Definition: rclip.h:142
Enum< rfsv::errs > checkNotify()
Check for clipboard notification.
Definition: rclip.cc:124
Enum< rfsv::errs > getStatus()
Retrieves the current status of the connection.
Definition: rclip.cc:70
void reset()
Initializes a connection to the remote machine.
Definition: rclip.cc:54
TCPSocket * skt
The socket, used for communication with ncpd.
Definition: rclip.h:150
Enum< rfsv::errs > notify()
Send a notification to the Psion.
Definition: rclip.cc:156
Enum< rfsv::errs > initClipbd()
Send initialization frame.
Definition: rclip.cc:169
@ E_PSI_GEN_NSUP
Definition: rfsv.h:114
@ E_PSI_GEN_NONE
Definition: rfsv.h:110
@ E_PSI_FILE_EOF
Definition: rfsv.h:138
@ E_PSI_GEN_FAIL
Definition: rfsv.h:111
@ E_PSI_FILE_DISC
Definition: rfsv.h:152
static rpcs * r
Definition: main.cc:56
static rfsv * a
Definition: main.cc:53