1 /* 2 Copyright (C) 2015-2021, Dirk Krause 3 SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 /* 7 WARNING: This file was generated by the dkct program (see 8 http://dktools.sourceforge.net/ for details). 9 Changes you make here will be lost if dkct is run again! 10 You should modify the original source and run dkct on it. 11 Original source: Dk4WxAutostartController.cpt 12 */ 13 14 #ifndef DK4WXAUTOSTARTCONTROLLER_H_INCLUDED 15 /** Avoid multiple inclusions. */ 16 #define DK4WXAUTOSTARTCONTROLLER_H_INCLUDED 1 17 18 19 /** @file Dk4WxAutostartController.h Autostart controller. 20 */ 21 22 #ifndef DK4CONF_H_INCLUDED 23 #if DK4_BUILDING_DKTOOLS4 24 #include "dk4conf.h" 25 #else 26 #include <dktools-4/dk4conf.h> 27 #endif 28 #endif 29 30 #ifndef DK4TYPES_H_INCLUDED 31 #if DK4_BUILDING_DKTOOLS4 32 #include <libdk4base/dk4types.h> 33 #else 34 #include <dktools-4/dk4types.h> 35 #endif 36 #endif 37 38 #ifndef DK4CONST_H_INCLUDED 39 #if DK4_BUILDING_DKTOOLS4 40 #include <libdk4base/dk4const.h> 41 #else 42 #include <dktools-4/dk4const.h> 43 #endif 44 #endif 45 46 #ifndef DK4ERROR_H_INCLUDED 47 #if DK4_BUILDING_DKTOOLS4 48 #include <libdk4base/dk4error.h> 49 #else 50 #include <dktools-4/dk4error.h> 51 #endif 52 #endif 53 54 #ifndef DK4TIME_H_INCLUDED 55 #if DK4_BUILDING_DKTOOLS4 56 #include <libdk4c/dk4time.h> 57 #else 58 #include <dktools-4/dk4time.h> 59 #endif 60 #endif 61 62 #ifndef WX_WXPREC_H_INCLUDED 63 #include <wx/wxprec.h> 64 #define WX_WXPREC_H_INCLUDED 1 65 #endif 66 67 #ifdef __BORLANDC__ 68 #pragma hdrstop 69 #endif 70 71 #ifndef WX_PRECOMP 72 #ifndef WX_WX_H_INCLUDED 73 #include <wx/wx.h> 74 #define WX_WX_H_INCLUDED 1 75 #endif 76 #endif 77 78 #ifndef WX_THREAD_H_INCLUDED 79 #include <wx/thread.h> 80 #define WX_THREAD_H_INCLUDED 1 81 #endif 82 83 84 85 /** Controller to check whether or not to start an autostart run 86 on idle events. 87 */ 88 class Dk4WxAutostartController 89 { 90 protected: 91 92 /** Internal controller state. 93 */ 94 enum { 95 /** No idle event received yet. 96 */ 97 STATE_NONE = 0 , 98 99 /** Expecting start processing. 100 */ 101 STATE_EXPECT_START , 102 103 /** In processing. 104 */ 105 STATE_PROCESSING , 106 107 /** Processing finished, 108 expecting application end. 109 */ 110 STATE_EXPECT_EXIT , 111 112 /** Processing finished. 113 */ 114 STATE_FINISHED 115 }; 116 117 /** Synchronize access from multiple threads or events. 118 */ 119 wxCriticalSection csProtect; 120 121 /** Time for automatic exit. 122 */ 123 dk4_time_t iExitTime; 124 125 /** Current controller state. 126 */ 127 int iState; 128 129 /** Flag: Start automatically. 130 */ 131 bool bAutostart; 132 133 /** Flag: Exit after successfull processing via autostart. 134 */ 135 bool bAutoexit; 136 137 public: 138 139 /** Reactions on idle events. 140 */ 141 enum { 142 /** Ignore the event, we are done. 143 */ 144 REACTION_IGNORE = 0 , 145 146 /** Start autorun. 147 */ 148 REACTION_START , 149 150 /** Request more idle events. 151 */ 152 REACTION_MORE , 153 154 /** Exit the application. 155 */ 156 REACTION_EXIT 157 }; 158 159 160 /** Default controller. 161 */ 162 Dk4WxAutostartController(); 163 164 /** Enable auto start. 165 Call this function from the frames constructor. 166 @param fl Flag to enable/disable auto start. 167 */ 168 void 169 SetAutoStart(bool fl = true); 170 171 /** Enable auto exit. 172 An application can exit automatically if no feedback is required 173 after an automatic one-time processing resulting in success. 174 Example: A program to schedule a file to a print queue invoked 175 via the file managers context menu. The program should immediately 176 transfer the file to the print queue, so you enable auto start. 177 After completing successfully you want the program to exit immediately. 178 Call this function from the frames constructor. 179 @param fl Flag to enable/disable auto exit. 180 */ 181 void 182 SetAutoExit(bool fl = true); 183 184 /** Get reaction for one idle event. 185 This function is typically called from the frames idle event 186 handler to decide what to do. 187 @return One from: 188 - REACTION_IGNORE<br> 189 to ignore the idle event, 190 - REACTION_START<br> 191 to start an automatic run, 192 - REACTION_MORE<br> 193 to request more idle events, or 194 - REACTION_EXIT<br> 195 to exit the application. 196 */ 197 int 198 GetReaction(void); 199 200 /** Indicate to the controller that processing was started. 201 Call this function to indicate start of processing. 202 Should be called for both auto start runs and manually started runs. 203 */ 204 void 205 StartProcessing(void); 206 207 /** Indicate end of processing. 208 Should be called for both auto start runs and manually started runs. 209 @param success Result from processing. 210 */ 211 void 212 EndProcessing(bool success = true); 213 214 }; 215 216 217 218 219 220 #endif 221