plptools
Loading...
Searching...
No Matches
psion.cpp
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 2002 Daniel Brahneborg <basic@chello.se>
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 "psion.h"
23
24#include <cliutils.h>
25#include <memory>
26#include <plpintl.h>
27#include <rfsv.h>
28#include <rpcs.h>
29#include <rfsvfactory.h>
30#include <rpcsfactory.h>
31#include <bufferarray.h>
32#include <bufferstore.h>
33#include <tcpsocket.h>
34
35#include <dirent.h>
36#include <netdb.h>
37
38#include <stdio.h>
39
41 disconnect();
42}
43
45 int sockNum = cli_utils::lookup_default_port();
46 std::string host = "127.0.0.1";
47 auto rfsvFactory = std::make_unique<RFSVFactory>(host, sockNum);
48 auto rpcsFactory = std::make_unique<RPCSFactory>(host, sockNum);
49 rfsv_ = rfsvFactory->create(true);
50 rpcs_ = rpcsFactory->create(true);
51 if ((rfsv_ != NULL) && (rpcs_ != NULL)) {
52 return true;
53 }
54 return false;
55}
56
57Enum<RFSV::errs> Psion::copyFromPsion(const char * const from, int fd, cpCallback_t func) {
58 return rfsv_->copyFromPsion(from, fd, func);
59}
60
61Enum<RFSV::errs> Psion::copyToPsion(const char * const from, const char * const to, void *, cpCallback_t func) {
62 return rfsv_->copyToPsion(from, to, NULL, func);
63}
64
65Enum<RFSV::errs> Psion::devinfo(const char drive, Drive& plpDrive) {
66 return rfsv_->devinfo(drive, plpDrive);
67}
68
69Enum<RFSV::errs> Psion::devlist(uint32_t& devbits) {
71 res = rfsv_->devlist(devbits);
72 return res;
73}
74
75Enum<RFSV::errs> Psion::dir(const char* dir, PlpDir& files) {
76 return rfsv_->dir(dir, files);
77}
78
79bool Psion::dirExists(const char* name) {
80 RFSVDirHandle handle;
82 bool exists = false;
83 res = rfsv_->opendir(RFSV::PSI_A_ARCHIVE, name, handle);
84 if (res == RFSV::E_PSI_GEN_NONE) {
85 exists = true;
86 }
87 res = rfsv_->closedir(handle);
88 return exists;
89}
90
92 if (rfsv_) {
93 delete rfsv_;
94 rfsv_ = nullptr;
95 }
96 if (rpcs_) {
97 delete rpcs_;
98 rpcs_ = nullptr;
99 }
100}
101
103 return rfsv_->mkdir(dir);
104}
105
106void Psion::remove(const char* name) {
107 rfsv_->remove(name);
108}
A class representing information about a Disk drive on the psion.
Definition: drive.h:51
Wrapper class featuring range-checking and string representation of enumerated values.
Definition: Enum.h:135
virtual Enum< RFSV::errs > copyToPsion(const char *const from, const char *const to, void *, cpCallback_t func)
Definition: psion.cpp:61
virtual Enum< RFSV::errs > dir(const char *dir, PlpDir &files)
Definition: psion.cpp:75
virtual Enum< RFSV::errs > copyFromPsion(const char *const from, int fd, cpCallback_t func)
Definition: psion.cpp:57
virtual Enum< RFSV::errs > devlist(uint32_t &devbits)
Definition: psion.cpp:69
virtual Enum< RFSV::errs > devinfo(const char drive, Drive &plpDrive)
Definition: psion.cpp:65
RFSV * rfsv_
Definition: psion.h:64
virtual void disconnect()
Definition: psion.cpp:91
virtual bool dirExists(const char *name)
Definition: psion.cpp:79
virtual void remove(const char *name)
Definition: psion.cpp:106
virtual ~Psion()
Definition: psion.cpp:40
RPCS * rpcs_
Definition: psion.h:63
virtual Enum< RFSV::errs > mkdir(const char *dir)
Definition: psion.cpp:102
virtual bool connect()
Definition: psion.cpp:44
A helper class for storing intermediate internal information in RFSV16 and RFSV32 .
Definition: rfsv.h:56
virtual Enum< errs > remove(const char *const name)=0
Removes a file on the Psion.
virtual Enum< errs > opendir(const uint32_t attr, const char *const name, RFSVDirHandle &handle)=0
Open a directory for reading with readdir.
virtual Enum< errs > copyToPsion(const char *const from, const char *const to, void *, cpCallback_t func)=0
Copies a file from local machine to the Psion.
virtual Enum< errs > mkdir(const char *const name)=0
Creates a directory on the Psion.
virtual Enum< errs > dir(const char *const name, PlpDir &ret)=0
Reads a directory on the Psion.
virtual Enum< errs > devlist(uint32_t &devbits)=0
Retrieves available drives on the Psion.
virtual Enum< errs > devinfo(const char drive, Drive &dinfo)=0
Retrieves details about a drive.
virtual Enum< errs > closedir(RFSVDirHandle &handle)=0
Close a directory, previously opened with opendir.
@ E_PSI_GEN_NONE
Definition: rfsv.h:114
virtual Enum< errs > copyFromPsion(const char *from, const char *to, void *context, cpCallback_t func)=0
Copies a file from the Psion to the local machine.
@ PSI_A_ARCHIVE
Definition: rfsv.h:203
int lookup_default_port()
Definition: cliutils.cc:44
int(* cpCallback_t)(void *, uint32_t)
Defines the callback procedure for progress indication of copy operations.
Definition: rfsv.h:45
std::deque< class PlpDirent > PlpDir
Definition: rfsv.h:34