plptools
Loading...
Searching...
No Matches
rpcsfactory.cc
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 2000-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 "rpcs16.h"
23#include "rpcs32.h"
24#include "rpcsfactory.h"
25#include "bufferstore.h"
26#include "tcpsocket.h"
27#include "Enum.h"
28
29#include <stdlib.h>
30#include <time.h>
31
33 stringRep.add(rpcsfactory::FACERR_NONE, N_("no error"));
34 stringRep.add(rpcsfactory::FACERR_COULD_NOT_SEND, N_("could not send version request"));
35 stringRep.add(rpcsfactory::FACERR_AGAIN, N_("try again"));
36 stringRep.add(rpcsfactory::FACERR_NOPSION, N_("no EPOC device connected"));
37 stringRep.add(rpcsfactory::FACERR_PROTVERSION, N_("wrong protocol version"));
38 stringRep.add(rpcsfactory::FACERR_NORESPONSE, N_("no response from ncpd"));
40
42{
43 err = FACERR_NONE;
44 skt = _skt;
45}
46
47rpcs * rpcsfactory::create(bool reconnect)
48{
49 // skt is connected to the ncp daemon, which will have (hopefully) seen
50 // an INFO exchange, where the protocol version of the remote Psion was
51 // sent, and noted. We have to ask the ncp daemon which protocol it saw,
52 // so we can instantiate the correct rpcs protocol handler for the
53 // caller. We announce ourselves to the NCP daemon, and the relevant
54 // rpcs module will also announce itself.
55
57
59 a.addStringT("NCP$INFO");
60 if (!skt->sendBufferStore(a)) {
61 if (!reconnect)
63 else {
65 skt->reconnect();
67 }
68 return NULL;
69 }
70 if (skt->getBufferStore(a) == 1) {
71 if (a.getLen() > 8 && !strncmp(a.getString(), "Series 3", 8)) {
72 return new rpcs16(skt);
73 }
74 else if (a.getLen() > 8 && !strncmp(a.getString(), "Series 5", 8)) {
75 return new rpcs32(skt);
76 }
77 if ((a.getLen() > 8) && !strncmp(a.getString(), "No Psion", 8)) {
79 skt->reconnect();
81 return NULL;
82 }
83 // Invalid protocol version
85 } else
87
88 // No message returned.
89 return NULL;
90}
#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 rpcs protocol for Psion series 3 (SIBO) variant.
Definition: rpcs16.h:37
This is the implementation of the rpcs protocol for Psion series 5 (EPOC) variant.
Definition: rpcs32.h:36
Remote procedure call services via PLP.
Definition: rpcs.h:51
A factory for automatically instantiating the correct protocol variant depending on the connected Psi...
Definition: rpcsfactory.h:32
virtual rpcs * create(bool reconnect)
Creates a new rpcs instance.
Definition: rpcsfactory.cc:47
errs
The known errors which can happen during create .
Definition: rpcsfactory.h:38
@ FACERR_PROTVERSION
Definition: rpcsfactory.h:43
@ FACERR_NORESPONSE
Definition: rpcsfactory.h:44
@ FACERR_COULD_NOT_SEND
Definition: rpcsfactory.h:40
TCPSocket * skt
The socket to be used for connecting to the ncpd daemon.
Definition: rpcsfactory.h:79
Enum< errs > err
Definition: rpcsfactory.h:80
static rfsv * a
Definition: main.cc:53
#define N_(String)
Definition: plpintl.h:36
stringRep add(rpcsfactory::FACERR_NONE, N_("no error"))
static void error(int line)
Definition: sismain.cpp:43
Description of a Psion-Device.
Definition: plpfuse.h:34