1 #ifndef FILEZILLA_INTERFACE_ASYNCREQUESTQUEUE_HEADER 2 #define FILEZILLA_INTERFACE_ASYNCREQUESTQUEUE_HEADER 3 4 #include "context_control.h" 5 6 #include <wx/timer.h> 7 8 #include <list> 9 #include <memory> 10 11 class cert_store; 12 class CQueueView; 13 14 class CAsyncRequestQueue final : public wxEvtHandler, protected CGlobalStateEventHandler 15 { 16 public: 17 CAsyncRequestQueue(wxTopLevelWindow * parent, cert_store & certStore); 18 ~CAsyncRequestQueue(); 19 20 bool AddRequest(CFileZillaEngine *pEngine, std::unique_ptr<CAsyncRequestNotification> && pNotification); 21 void ClearPending(CFileZillaEngine const* const pEngine); 22 void RecheckDefaults(); 23 24 void SetQueue(CQueueView *pQueue); 25 26 void TriggerProcessing(); 27 28 protected: 29 virtual void OnStateChange(CState* pState, t_statechange_notifications notification, std::wstring const&, const void*) override; 30 31 // Returns false if main window doesn't have focus or is minimized. 32 // Request attention if needed 33 bool CheckWindowState(); 34 35 wxTopLevelWindow *parent_{}; 36 CQueueView *m_pQueueView{}; 37 cert_store & certStore_; 38 39 bool ProcessNextRequest(); 40 bool ProcessDefaults(CFileZillaEngine *pEngine, std::unique_ptr<CAsyncRequestNotification> & pNotification); 41 42 struct t_queueEntry 43 { t_queueEntryt_queueEntry44 t_queueEntry(CFileZillaEngine *e, std::unique_ptr<CAsyncRequestNotification>&& n) 45 : pEngine(e) 46 , pNotification(std::move(n)) 47 { 48 } 49 50 CFileZillaEngine *pEngine{}; 51 std::unique_ptr<CAsyncRequestNotification> pNotification; 52 }; 53 std::list<t_queueEntry> m_requestList; 54 55 bool ProcessFileExistsNotification(t_queueEntry &entry); 56 57 bool SendReply(t_queueEntry & entry); 58 59 DECLARE_EVENT_TABLE() 60 void OnProcessQueue(wxCommandEvent &event); 61 void OnTimer(wxTimerEvent& event); 62 63 // Reentrancy guard 64 bool m_inside_request{}; 65 66 wxTimer m_timer; 67 }; 68 69 #endif 70