-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkiofuseapp.h
158 lines (141 loc) · 8.19 KB
/
kiofuseapp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/****************************************************************************
* Copyright (c) 2003-2004 by Alexander Neundorf & Kevin 'ervin' Ottens *
* Copyright (c) 2007-2008 Vlad Codrea *
* Copyright (c) 2015 Thomas Fischer *
* *
* 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 3 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. *
* *
****************************************************************************/
#ifndef KIO_FUSE_APP_H
#define KIO_FUSE_APP_H
#include <errno.h>
extern "C" {
#include <stdint.h>
}
#include "cache.h"
#include "jobhelpers.h"
#include <KApplication>
#include <ktemporaryfile.h>
#define VERIFY(expression) if(expression) {} else { kioFuseApp->quitGracefully(#expression, __FILE__, __LINE__, __FUNCTION__); }
//#desdfdsfine VERIFY(expression) if(!expression) { kioFuseApp->quitGracefully(#expression, __FILE__, __LINE__, __FUNCTION__); }
class ListJobHelper;
class StatJobHelper;
class OpenJobHelper;
class ReadJobHelper;
class WriteJobHelper;
class MkNodHelper;
class SymLinkHelper;
class ReNameHelper;
class ChModHelper;
class ReleaseJobHelper;
class MkDirHelper;
class UnLinkHelper;
class ChTimeHelper;
class LockHelper;
class KioFuseApp : public KApplication
{
Q_OBJECT
public:
KioFuseApp(const KUrl &url, const KUrl &mountPoint);
~KioFuseApp();
const KUrl& baseUrl(); // Getter method for the remote base URL
const KUrl& mountPoint(); // Getter method for the mountpoint URL
KUrl buildRemoteUrl(const QString& path); // Create a full URL containing both the remote base and the relative path
KUrl buildLocalUrl(const QString& path); // Create a full URL containing both the local mountpoint and the relative path
void storeOpenHandle(KIO::FileJob* fileJob, OpenJobHelper* openJobHelper);
//void lockJob(const uint64_t& fileHandleId);
//void unLockJob(const uint64_t& fileHandleId);
KIO::FileJob* checkOutJob(/*const KUrl& url,*/ const uint64_t& fileHandleId); // Find the job using its ID,
// and prevent other threads from using it.
// void checkInJob(const KUrl& url, const uint64_t& fileHandleId); // Allow other threads to use the
// FileJob specified by this fileHandleId.
void removeJob(const uint64_t& fileHandleId, FileJobData* fileJobData,
const bool& jobIsAnnulled);
void setUpTypes();
//void setUpErrorTranslator();
int sysErrFromKioErr(const int& kioErr);
void addAnnulledFh(const uint64_t& fh);
void removeAnnulledFh(const uint64_t& fh);
bool isAnnulled(const uint64_t& fh);
void quitGracefully(const char* expression, const char* file,
const int& line, const char* function);
QMutex fhIdtoFileJobDataMutex;
public slots:
void listJobMainThread(const KUrl& url, ListJobHelper* listJobHelper);
void slotResult(KJob* job);
void statJobMainThread(const KUrl& url, StatJobHelper* statJobHelper);
void slotStatJobResult(KJob* job);
void openJobMainThread(const KUrl& url, const QIODevice::OpenMode& qtMode, OpenJobHelper* openJobHelper);
void fileJobOpened(KIO::Job* job);
//void jobErrorOpen(KJob* job);
void jobErrorReadWrite(KJob* job);
void slotMimetype(KIO::Job* job, const QString& type);
void findMutexMainThread(const uint64_t& fileHandleId, LockHelper* lockHelper);
void seekReadMainThread(const uint64_t& fileHandleId, const off_t& offset, ReadJobHelper* readJobHelper);
void slotReadPosition(KIO::Job* job, KIO::filesize_t pos);
void readMainThread(KIO::FileJob* fileJob, const size_t& size, ReadJobHelper* readJobHelper);
void slotData(KIO::Job* job, const QByteArray& data);
void seekWriteMainThread(const uint64_t& fileHandleId, const off_t& offset, WriteJobHelper* writeJobHelper);
void slotWritePosition(KIO::Job* job, KIO::filesize_t pos);
void writeMainThread(KIO::FileJob* fileJob, const QByteArray& data, WriteJobHelper* writeJobHelper);
void slotWritten(KIO::Job* job, const KIO::filesize_t& written);
void mkDirMainThread(const KUrl& url, const mode_t& mode, MkDirHelper* mkDirHelper);
void mkNodMainThread(const KUrl& url, const mode_t& mode, MkNodHelper* mkNodHelper);
void slotMkNodResult(KJob* job);
void chModMainThread(const KUrl& url, const mode_t& mode,
ChModHelper* chModHelper);
void symLinkMainThread(const KUrl& source, const KUrl& dest,
SymLinkHelper* symLinkHelper);
void reNameMainThread(const KUrl& source, const KUrl& dest,
ReNameHelper* reNameHelper);
void unLinkMainThread(const KUrl& url, UnLinkHelper* unLinkHelper);
void releaseJobMainThread(/*const KUrl& url,*/ const uint64_t& fileHandleId,
const bool& jobIsAnnulled,
ReleaseJobHelper* releaseJobHelper);
void chTimeMainThread(const KUrl& url, const QDateTime& dt,
ChTimeHelper* chTimeHelper);
/*
signals:
void sendJobDone(const int&);
void sendJobMutex(QMutex*, const int&);
void sendEntry(const KIO::UDSEntry&);
void sendFileHandleId(const uint64_t&);
void sendPosition(const off_t&, const int&, KIO::FileJob*);
void sendData(const QByteArray&, const int&);
void sendWritten(const size_t&, const int&);
*/
private:
KUrl m_baseUrl; // Remote base URL
KUrl m_mountPoint; // Local mountpoint
QMutex m_baseUrlMutex; // Allows only one thread to access the remote
// base URL at a time.
QMutex m_mountPointMutex; // Allows only one thread to access the
// local mountpoint URL at a time.
QMutex m_terminatedFhListMutex; // Allows only one thread to access
// the list of terminated jobs at a
// time.
//QMutex m_errorTransMutex; // Controls error translator
//Cache* m_cacheRoot; // Root node of cache
//int m_numCached; // Number of files cached
//int m_numLeafStubsCached; // Leaf stubs are for opened files that have no stat data
//QMutex m_cacheMutex; // Allows only one thread to access the cache at a time
QMap<KJob *, BaseJobHelper *> m_jobToJobHelper; // Correlate listJob with the ListJobHelper that needs it
QMap<KJob *, KTemporaryFile *> m_jobToTempFile; // Correlate FileCopyJob with the MkNodHelper that needs it
QMap<uint64_t, FileJobData*> fhIdtoFileJobData; // Correlate opened file
// handles with the FileJob
//QMap<int, int> KIOErrToSysError; // Translates between KIO:Error and
// // the errors defined in errno.h
QList<uint64_t> m_terminatedFhList;
};
extern KioFuseApp *kioFuseApp; // Make the kioFuseApp variable known to everyone who includes this file
#endif /* FUSE_KIO_FUSE_APP_H */