plptools
Loading...
Searching...
No Matches
rfsvfactory.cc
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Matt J. Gumbley <matt@gumbley.demon.co.uk>
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 "rfsv.h"
23#include "rfsv16.h"
24#include "rfsv32.h"
25#include "rfsvfactory.h"
26#include "bufferstore.h"
27#include "tcpsocket.h"
28#include "Enum.h"
29
30#include <stdlib.h>
31#include <time.h>
32
33using namespace std;
34
36 stringRep.add(rfsvfactory::FACERR_NONE, N_("no error"));
37 stringRep.add(rfsvfactory::FACERR_COULD_NOT_SEND, N_("could not send version request"));
38 stringRep.add(rfsvfactory::FACERR_AGAIN, N_("try again"));
39 stringRep.add(rfsvfactory::FACERR_NOPSION, N_("no EPOC device connected"));
40 stringRep.add(rfsvfactory::FACERR_PROTVERSION, N_("wrong protocol version"));
41 stringRep.add(rfsvfactory::FACERR_NORESPONSE, N_("no response from ncpd"));
43
45{
46 err = FACERR_NONE;
47 skt = _skt;
48}
49
51{
52}
53
54rfsv * rfsvfactory::create(bool reconnect)
55{
56 // skt is connected to the ncp daemon, which will have (hopefully) seen
57 // an INFO exchange, where the protocol version of the remote Psion was
58 // sent, and noted. We have to ask the ncp daemon which protocol it saw,
59 // so we can instantiate the correct RFSV protocol handler for the
60 // caller. We announce ourselves to the NCP daemon, and the relevant
61 // RFSV module will also announce itself.
62
64
66 a.addStringT("NCP$INFO");
67 if (!skt->sendBufferStore(a)) {
68 if (!reconnect)
70 else {
72 serNum = 0;
73 skt->reconnect();
75 }
76 return NULL;
77 }
78 if (skt->getBufferStore(a) == 1) {
79 if (a.getLen() > 8 && !strncmp(a.getString(), "Series 3", 8)) {
80 return new rfsv16(skt);
81 }
82 else if (a.getLen() > 8 && !strncmp(a.getString(), "Series 5", 8)) {
83 return new rfsv32(skt);
84 }
85 if ((a.getLen() > 8) && !strncmp(a.getString(), "No Psion", 8)) {
87 serNum = 0;
88 skt->reconnect();
90 return NULL;
91 }
92 // Invalid protocol version
94 } else
96
97 return NULL;
98}
#define ENUM_DEFINITION_END(EnumName)
Definition: Enum.h:304
#define ENUM_DEFINITION_BEGIN(EnumName, initWith)
Helper macro to construct an enumeration wrapper Enum<E> for a specific enum type.
Definition: Enum.h:299
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
This is the implementation of the rfsv protocol for Psion series 3 (SIBO) variant.
Definition: rfsv16.h:35
This is the implementation of the rfsv protocol for Psion series 5 (EPOC) variant.
Definition: rfsv32.h:37
Access remote file services of a Psion.
Definition: rfsv.h:75
A factory for automatically instantiating the correct rfsv protocol variant depending on the connecte...
Definition: rfsvfactory.h:33
virtual ~rfsvfactory()
Delete the rfsvfactory, cleaning up any resources.
Definition: rfsvfactory.cc:50
errs
The known errors which can happen during create .
Definition: rfsvfactory.h:39
@ FACERR_NORESPONSE
Definition: rfsvfactory.h:45
@ FACERR_PROTVERSION
Definition: rfsvfactory.h:44
@ FACERR_COULD_NOT_SEND
Definition: rfsvfactory.h:41
TCPSocket * skt
The socket to be used for connecting to the ncpd daemon.
Definition: rfsvfactory.h:87
Enum< errs > err
Definition: rfsvfactory.h:89
virtual rfsv * create(bool)
Creates a new rfsv instance.
Definition: rfsvfactory.cc:54
Definition: doctest.h:522
static rfsv * a
Definition: main.cc:53
#define N_(String)
Definition: plpintl.h:36
stringRep add(rfsvfactory::FACERR_NONE, N_("no error"))
static void error(int line)
Definition: sismain.cpp:43
Description of a Psion-Device.
Definition: plpfuse.h:34