source: filezilla/trunk/fuentes/src/engine/engineprivate.h @ 3185

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 3 years ago

Update new version: 3.15.02

File size: 6.3 KB
RevLine 
[130]1#ifndef __FILEZILLAENGINEPRIVATE_H__
2#define __FILEZILLAENGINEPRIVATE_H__
3
[3185]4#include <libfilezilla/event.hpp>
5#include <libfilezilla/event_handler.hpp>
6#include <libfilezilla/mutex.hpp>
7#include <libfilezilla/time.hpp>
[130]8
9#include "engine_context.h"
10#include "FileZillaEngine.h"
11#include "option_change_event_handler.h"
12
13#include <atomic>
14
15class CControlSocket;
16class CLogging;
17class CRateLimiter;
18
19enum EngineNotificationType
20{
21        engineCancel,
22        engineTransferEnd
23};
24
25struct filezilla_engine_event_type;
[3185]26typedef fz::simple_event<filezilla_engine_event_type, EngineNotificationType> CFileZillaEngineEvent;
[130]27
28class CTransferStatusManager final
29{
30public:
31        CTransferStatusManager(CFileZillaEnginePrivate& engine);
32
33        CTransferStatusManager(CTransferStatusManager const&) = delete;
34        CTransferStatusManager& operator=(CTransferStatusManager const&) = delete;
35
36        bool empty();
37
38        void Init(wxFileOffset totalSize, wxFileOffset startOffset, bool list);
39        void Reset();
40        void SetStartTime();
41        void SetMadeProgress();
42        void Update(wxFileOffset transferredBytes);
43
44        CTransferStatus Get(bool &changed);
45
46protected:
[3185]47        fz::mutex mutex_;
[130]48
49        CTransferStatus status_;
50        std::atomic<int64_t> currentOffset_{};
51        int send_state_{};
52
53        CFileZillaEnginePrivate& engine_;
54};
55
[3185]56class CFileZillaEnginePrivate final : public fz::event_handler, COptionChangeEventHandler
[130]57{
58public:
59        CFileZillaEnginePrivate(CFileZillaEngineContext& engine_context, CFileZillaEngine& parent);
60        virtual ~CFileZillaEnginePrivate();
61
62        int Init(wxEvtHandler *pEventHandler);
63
64        int Execute(CCommand const& command);
65        int Cancel();
66        int ResetOperation(int nErrorCode);
67
68        const CCommand *GetCurrentCommand() const;
69        Command GetCurrentCommandId() const;
70
71        bool IsBusy() const;
72        bool IsConnected() const;
73
74        bool IsPendingAsyncRequestReply(std::unique_ptr<CAsyncRequestNotification> const& pNotification);
75        bool SetAsyncRequestReply(std::unique_ptr<CAsyncRequestNotification> && pNotification);
76        unsigned int GetNextAsyncRequestNumber();
77
78        CTransferStatus GetTransferStatus(bool &changed);
79
80        int CacheLookup(CServerPath const& path, CDirectoryListing& listing);
81
82        static bool IsActive(CFileZillaEngine::_direction direction);
83        void SetActive(int direction);
84
85        // Add new pending notification
86        void AddNotification(CNotification *pNotification);
87        void AddLogNotification(CLogmsgNotification *pNotification);
88        std::unique_ptr<CNotification> GetNextNotification();
89
90        COptionsBase& GetOptions() { return m_options; }
91        CRateLimiter& GetRateLimiter() { return m_rateLimiter; }
92        CDirectoryCache& GetDirectoryCache() { return directory_cache_; }
93        CPathCache& GetPathCache() { return path_cache_; }
94
95        void SendDirectoryListingNotification(const CServerPath& path, bool onList, bool modified, bool failed);
96
97        // If deleting or renaming a directory, it could be possible that another
98        // engine's CControlSocket instance still has that directory as
99        // current working directory (m_CurrentPath)
100        // Since this would cause problems, this function interate over all engines
101        // connected ot the same server and invalidates the current working
102        // directories if they match or if it is a subdirectory of the changed
103        // directory.
104        void InvalidateCurrentWorkingDirs(const CServerPath& path);
105
106        int GetEngineId() const {return m_engine_id; }
107
108        CTransferStatusManager transfer_status_;
109protected:
110        virtual void OnOptionsChanged(changed_options_t const& options);
111
112        void SendQueuedLogs(bool reset_flag = false);
113        void ClearQueuedLogs(bool reset_flag);
114        bool ShouldQueueLogsFromOptions() const;
115
116        int CheckCommandPreconditions(CCommand const& command, bool checkBusy);
117
118
119        bool CheckAsyncRequestReplyPreconditions(std::unique_ptr<CAsyncRequestNotification> const& reply);
120        void OnSetAsyncRequestReplyEvent(std::unique_ptr<CAsyncRequestNotification> const& reply);
121
122        // Command handlers, only called by CFileZillaEngine::Command
123        int Connect(const CConnectCommand &command);
124        int Disconnect(const CDisconnectCommand &command);
125        int List(const CListCommand &command);
126        int FileTransfer(const CFileTransferCommand &command);
127        int RawCommand(const CRawCommand& command);
128        int Delete(CDeleteCommand& command);
129        int RemoveDir(const CRemoveDirCommand& command);
130        int Mkdir(const CMkdirCommand& command);
131        int Rename(const CRenameCommand& command);
132        int Chmod(const CChmodCommand& command);
133
134        void DoCancel();
135
136        int ContinueConnect();
137
[3185]138        void operator()(fz::event_base const& ev);
[130]139        void OnEngineEvent(EngineNotificationType type);
140        void OnTimer(int timer_id);
141        void OnCommandEvent();
142
143        // General mutex for operations on the engine
144        // Todo: More fine-grained locking, a global mutex isn't nice
[3185]145        static fz::mutex mutex_;
[130]146
147        // Used to synchronize access to the notification list
[3185]148        fz::mutex notification_mutex_;
[130]149
150        wxEvtHandler *m_pEventHandler{};
151
152        int m_engine_id;
153
154        static std::vector<CFileZillaEnginePrivate*> m_engineList;
155
156        // Indicicates if data has been received/sent and whether to send any notifications
157        static std::atomic_int m_activeStatus[2];
158
159        // Remember last path used in a dirlisting.
160        CServerPath m_lastListDir;
[3185]161        fz::monotonic_clock m_lastListTime;
[130]162
163        std::unique_ptr<CControlSocket> m_pControlSocket;
164
165        std::unique_ptr<CCommand> m_pCurrentCommand;
166
167        // Protect access to these three with notification_mutex_
168        std::list<CNotification*> m_NotificationList;
169        bool m_maySendNotificationEvent{true};
170        unsigned int m_asyncRequestCounter{};
171
172        bool m_bIsInCommand{}; //true if Command is on the callstack
173        int m_nControlSocketError{};
174
175        COptionsBase& m_options;
176
177        CLogging* m_pLogging;
178
179        // Everything related to the retry code
180        // ------------------------------------
181
182        void RegisterFailedLoginAttempt(const CServer& server, bool critical);
183
184        // Get the amount of time to wait till next reconnection attempt in milliseconds
185        unsigned int GetRemainingReconnectDelay(const CServer& server);
186
187        struct t_failedLogins final
188        {
189                CServer server;
[3185]190                fz::datetime time;
[130]191                bool critical{};
192        };
193        static std::list<t_failedLogins> m_failedLogins;
194        int m_retryCount{};
[3185]195        fz::timer_id m_retryTimer{};
[130]196
197        CRateLimiter& m_rateLimiter;
198        CDirectoryCache& directory_cache_;
199        CPathCache& path_cache_;
200
201        CFileZillaEngine& parent_;
202
203        bool queue_logs_{true};
204        std::deque<CLogmsgNotification*> queued_logs_;
205};
206
207struct command_event_type{};
[3185]208typedef fz::simple_event<command_event_type> CCommandEvent;
[130]209
210struct async_request_reply_event_type{};
[3185]211typedef fz::simple_event<async_request_reply_event_type, std::unique_ptr<CAsyncRequestNotification>> CAsyncRequestReplyEvent;
[130]212
213#endif //__FILEZILLAENGINEPRIVATE_H__
Note: See TracBrowser for help on using the repository browser.