1 // This file is part of BOINC. 2 // http://boinc.berkeley.edu 3 // Copyright (C) 2008 University of California 4 // 5 // BOINC is free software; you can redistribute it and/or modify it 6 // under the terms of the GNU Lesser General Public License 7 // as published by the Free Software Foundation, 8 // either version 3 of the License, or (at your option) any later version. 9 // 10 // BOINC is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 // See the GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with BOINC. If not, see <http://www.gnu.org/licenses/>. 17 18 #ifndef BOINC_MAINDOCUMENT_H 19 #define BOINC_MAINDOCUMENT_H 20 21 #if defined(__GNUG__) && !defined(__APPLE__) 22 #pragma interface "MainDocument.cpp" 23 #endif 24 25 #include <vector> 26 #include "common_defs.h" 27 #include "gui_rpc_client.h" 28 #include "AsyncRPC.h" 29 30 typedef struct { 31 int slot; 32 std::string project_url; 33 std::string name; 34 #ifdef _WIN32 35 HANDLE pid; 36 #else 37 int pid; 38 #endif 39 } RUNNING_GFX_APP; 40 41 42 /// 43 /// Bitmask values for GetCurrentViewPage() 44 /// Used by CMainDocument::RunPeriodicRPCs() and Mac Accessibility 45 /// 46 #define VW_PROJ 1 47 #define VW_TASK 2 48 #define VW_XFER 4 49 #define VW_STAT 8 50 #define VW_DISK 16 51 #define VW_NOTIF 128 52 #define VW_SGUI 256 53 #define VW_SMSG 2048 54 #define VW_SNOTIF 4096 55 56 57 extern bool g_use_sandbox; 58 59 class CMainDocument; 60 class CBOINCClientManager; 61 62 class CNetworkConnection : public wxObject { 63 public: 64 CNetworkConnection(CMainDocument* pDocument); 65 ~CNetworkConnection(); 66 67 void Poll(); FireReconnectEvent()68 void FireReconnectEvent() { m_bConnectEvent = true; }; ForceDisconnect()69 void ForceDisconnect() { m_bForceReconnect = false; m_bReconnectOnError = false; m_bConnectEvent = false; SetStateDisconnected(); }; ForceReconnect()70 void ForceReconnect() { m_bForceReconnect = true; SetStateDisconnected(); }; 71 int FrameShutdownDetected(); 72 int GetConnectedComputerName(wxString& strMachine); 73 int GetConnectedComputerVersion(wxString& strVersion); 74 int GetConnectingComputerName(wxString& strMachine); 75 bool IsComputerNameLocal(const wxString& strMachine); 76 int GetLocalPassword(wxString& strPassword); 77 int SetComputer( 78 const wxString& szComputer, const int iPort, const wxString& szPassword, const bool bUseDefaultPassword 79 ); 80 void SetStateError(); 81 void SetStateErrorAuthentication(); 82 void SetStateReconnecting(); 83 void SetStateSuccess(wxString& strComputer, wxString& strComputerPassword); 84 void SetStateDisconnected(); IsConnectEventSignaled()85 bool IsConnectEventSignaled() { return m_bConnectEvent; }; IsConnected()86 bool IsConnected() { return m_bConnected; }; IsReconnecting()87 bool IsReconnecting() { return m_bReconnecting; }; 88 89 private: 90 CMainDocument* m_pDocument; 91 bool m_bFrameShutdownDetected; 92 bool m_bConnectEvent; 93 bool m_bForceReconnect; 94 bool m_bReconnectOnError; 95 bool m_bConnected; 96 bool m_bReconnecting; 97 bool m_bUseDefaultPassword; 98 bool m_bUsedDefaultPassword; 99 int m_iReadGUIRPCAuthFailure; 100 bool m_bNewConnection; 101 wxString m_strNewComputerName; 102 wxString m_strNewComputerPassword; 103 wxString m_strConnectedComputerName; 104 wxString m_strConnectedComputerPassword; 105 wxString m_strConnectedComputerVersion; 106 int m_iPort; 107 }; 108 109 110 class CMainDocument : public wxObject { 111 DECLARE_DYNAMIC_CLASS(CMainDocument) 112 113 public: 114 CMainDocument(); 115 ~CMainDocument(); 116 117 // 118 // Global 119 // 120 private: 121 char m_szLanguage[256]; 122 wxDateTime m_dtCachedCCStatusTimestamp; 123 bool m_bClientStartCheckCompleted; 124 125 126 public: 127 int OnInit(); 128 int OnExit(); 129 int OnPoll(); 130 131 int OnRefreshState(); 132 int CachedStateUpdate(); 133 int ResetState(); 134 135 int Connect( 136 const wxString& szComputer, 137 const int iPort, 138 const wxString& szComputerPassword = wxEmptyString, 139 const bool bDisconnect = FALSE, 140 const bool bUseDefaultPassword = FALSE 141 ); 142 int Reconnect(); 143 144 int CachedStateLock(); 145 int CachedStateUnlock(); 146 147 void ForceDisconnect(); 148 int FrameShutdownDetected(); 149 int CoreClientQuit(); 150 151 int GetConnectedComputerName(wxString& strMachine); 152 int GetConnectedComputerVersion(wxString& strVersion); 153 int GetConnectingComputerName(wxString& strMachine); 154 bool IsComputerNameLocal(const wxString& strMachine); 155 bool IsConnected(); 156 bool IsReconnecting(); 157 158 int GetCoreClientStatus(CC_STATUS&, bool bForce = false); 159 int SetActivityRunMode(int iMode, int iTimeout); 160 int SetGPURunMode(int iMode, int iTimeout); 161 int SetNetworkRunMode(int iMode, int iTimeout); 162 163 void RefreshRPCs(bool fullReset = false); 164 void RunPeriodicRPCs(int frameRefreshRate); 165 int ForceCacheUpdate(bool immediate = true); 166 int RunBenchmarks(); 167 168 bool IsUserAuthorized(); 169 170 void CheckForVersionUpdate(bool showMessage = false); 171 172 CNetworkConnection* m_pNetworkConnection; 173 CBOINCClientManager* m_pClientManager; 174 AsyncRPC rpc; 175 RPC_CLIENT rpcClient; 176 PROJECTS async_projects_update_buf; 177 178 CC_STATE state; 179 CC_STATE async_state_buf; 180 int m_iGet_state_rpc_result; 181 182 CC_STATUS status; 183 CC_STATUS async_status_buf; 184 int m_iGet_status_rpc_result; 185 wxDateTime m_dtCachedStateTimestamp; 186 187 // 188 // Async RPC support 189 // 190 public: 191 int RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority = false); 192 void OnRPCComplete(CRPCFinishedEvent& event); GetCurrentRPCRequest()193 ASYNC_RPC_REQUEST* GetCurrentRPCRequest() { return ¤t_rpc_request; } WaitingForRPC()194 bool WaitingForRPC() { return m_bWaitingForRPC; } GetRPCWaitDialog()195 wxDialog* GetRPCWaitDialog() { return m_RPCWaitDlg; } 196 // void TestAsyncRPC(); // For testing Async RPCs 197 RPCThread* m_RPCThread; 198 bool m_bRPCThreadIsReady; 199 bool m_bShutDownRPCThread; 200 201 private: 202 void HandleCompletedRPC(); 203 void KillRPCThread(); 204 int CopyProjectsToStateBuffer(PROJECTS& p, CC_STATE& state); 205 ASYNC_RPC_REQUEST current_rpc_request; 206 AsyncRPCDlg* m_RPCWaitDlg; 207 std::vector<ASYNC_RPC_REQUEST> RPC_requests; 208 bool m_bWaitingForRPC; 209 bool m_bNeedRefresh; 210 bool m_bNeedTaskBarRefresh; 211 BOINC_Mutex* m_pRPC_Thread_Mutex; 212 BOINC_Condition* m_pRPC_Thread_Condition; 213 BOINC_Mutex* m_pRPC_Request_Mutex; 214 BOINC_Condition* m_pRPC_Request_Condition; 215 wxDateTime m_dtLasAsyncRPCDlgTime; 216 wxDateTime m_dtLastFrameViewRefreshRPCTime; 217 218 // 219 // Projects Tab 220 // 221 private: 222 int m_iGet_project_status1_rpc_result; 223 wxDateTime m_dtProjectsStatusTimestamp; 224 225 public: 226 int CachedProjectStatusUpdate(bool bForce = false); 227 PROJECT* project(unsigned int); 228 PROJECT* project(char* url); 229 double m_fProjectTotalResourceShare; 230 231 int GetProjectCount(); 232 233 int ProjectNoMoreWork(int iIndex); 234 int ProjectAllowMoreWork(int iIndex); 235 int ProjectAttach(const wxString& strURL, const wxString& strAccountKey); 236 int ProjectDetach(int iIndex); 237 int ProjectUpdate(int iIndex); 238 int ProjectReset(int iIndex); 239 int ProjectSuspend(int iIndex); 240 int ProjectResume(int iIndex); 241 242 // 243 // Work Tab 244 // 245 private: 246 int CachedResultsStatusUpdate(); 247 wxDateTime m_dtResultsTimestamp; 248 double m_fResultsRPCExecutionTime; 249 wxDateTime m_dtKillInactiveGfxTimestamp; 250 std::vector<RUNNING_GFX_APP> m_running_gfx_apps; 251 RUNNING_GFX_APP* GetRunningGraphicsApp(RESULT* result, int slot); 252 void KillAllRunningGraphicsApps(); 253 void KillInactiveGraphicsApps(); 254 #ifdef _WIN32 255 void KillGraphicsApp(HANDLE pid); 256 #else 257 void KillGraphicsApp(int tpid); 258 #endif 259 260 public: 261 RESULTS results; 262 RESULTS async_results_buf; 263 int m_iGet_results_rpc_result; 264 bool m_ActiveTasksOnly; 265 266 RESULT* result(unsigned int); 267 RESULT* result(const wxString& name, const wxString& project_url); 268 269 int GetWorkCount(); 270 271 int WorkSuspend(char* url, char* name); 272 int WorkResume(char* url, char* name); 273 int WorkShowGraphics(RESULT* result); 274 int WorkShowVMConsole(RESULT* result); 275 int WorkAbort(char* url, char* name); GetState()276 CC_STATE* GetState() { return &state; }; 277 278 279 // 280 // Notices Tab 281 // 282 private: 283 wxDateTime m_dtNoticesTimeStamp; 284 285 int m_iNoticeSequenceNumber; 286 int m_iLastReadNoticeSequenceNumber; 287 double m_dLastReadNoticeArrivalTime; 288 bool m_bWaitingForGetNoticesRPC; 289 290 public: 291 NOTICES notices; 292 int m_iGet_notices_rpc_result; 293 294 NOTICE* notice(unsigned int); 295 int CachedNoticeUpdate(); 296 297 int GetNoticeCount(); 298 int GetUnreadNoticeCount(); 299 300 void SaveUnreadNoticeInfo(); 301 void RestoreUnreadNoticeInfo(); 302 303 void UpdateUnreadNoticeState(); 304 int ResetNoticeState(); 305 306 307 // 308 // Messages Tab 309 // 310 private: 311 312 313 public: 314 MESSAGES messages; 315 int m_iGet_messages_rpc_result; 316 317 MESSAGE* message(unsigned int); 318 int CachedMessageUpdate(); 319 320 int GetMessageCount(); 321 322 int ResetMessageState(); 323 324 int m_iFirstMessageSequenceNumber; 325 int m_iLastMessageSequenceNumber; 326 GetFirstMsgSeqNum()327 int GetFirstMsgSeqNum() { return m_iFirstMessageSequenceNumber; } GetLastMsgSeqNum()328 int GetLastMsgSeqNum() { return m_iLastMessageSequenceNumber; } 329 330 // 331 // Transfers Tab 332 // 333 private: 334 int CachedFileTransfersUpdate(); 335 wxDateTime m_dtFileTransfersTimestamp; 336 337 public: 338 FILE_TRANSFERS ft; 339 FILE_TRANSFERS async_ft_buf; 340 int m_iGet_file_transfers_rpc_result; 341 342 FILE_TRANSFER* file_transfer(unsigned int); 343 FILE_TRANSFER* file_transfer(const wxString& fileName, const wxString& project_url); 344 345 int GetTransferCount(); 346 347 int TransferRetryNow(int iIndex); 348 int TransferRetryNow(const wxString& fileName, const wxString& project_url); 349 int TransferAbort(int iIndex); 350 int TransferAbort(const wxString& fileName, const wxString& project_url); 351 352 353 // 354 // Disk Tab 355 // 356 private: 357 wxDateTime m_dtDiskUsageTimestamp; 358 359 public: 360 DISK_USAGE disk_usage; 361 DISK_USAGE async_disk_usage_buf; 362 int m_iGet_dsk_usage_rpc_result; 363 364 PROJECT* DiskUsageProject(unsigned int); 365 int CachedDiskUsageUpdate(); 366 367 // 368 // Statistics Tab 369 // 370 private: 371 int CachedStatisticsStatusUpdate(); 372 wxDateTime m_dtStatisticsStatusTimestamp; 373 374 public: 375 PROJECTS statistics_status; 376 PROJECTS async_statistics_status_buf; 377 PROJECT* statistic(unsigned int); 378 int m_iGet_statistics_rpc_result; 379 380 int GetStatisticsCount(); 381 382 383 // 384 // Proxy Configuration 385 // 386 private: 387 388 public: 389 GR_PROXY_INFO proxy_info; 390 int GetProxyConfiguration(); 391 int SetProxyConfiguration(); 392 393 394 // 395 // Simple GUI Updates 396 // 397 int m_iGet_simple_gui2_rpc_result; 398 int m_iAcct_mgr_info_rpc_result; 399 int CachedSimpleGUIUpdate(bool bForce = false); 400 private: 401 wxDateTime m_dtCachedSimpleGUITimestamp; 402 wxDateTime m_dtCachedAcctMgrInfoTimestamp; 403 404 public: 405 ACCT_MGR_INFO ami; 406 ACCT_MGR_INFO async_ami_buf; 407 int GetSimpleProjectCount(); 408 int GetSimpleGUIWorkCount(); 409 410 }; 411 412 extern wxString suspend_reason_wxstring(int reason); 413 extern wxString result_description(RESULT*, bool show_resources=true); 414 extern wxString process_client_message(const char*); 415 extern void localize(wxString& strMessage); 416 extern void eol_to_br(wxString& strMessage); 417 extern void remove_eols(wxString& strMessage); 418 extern void https_to_http(wxString& strMessage); 419 extern void color_cycle(int i, int n, wxColour& color); 420 extern wxString FormatTime(double secs); 421 422 #ifdef __WXMSW__ 423 #define ADJUSTFORXDPI(x) (int)(x * GetXDPIScaling()) 424 #define ADJUSTFORYDPI(y) (int)(y * GetYDPIScaling()) 425 extern double GetXDPIScaling(); 426 extern double GetYDPIScaling(); 427 #else 428 #define ADJUSTFORXDPI(x) x 429 #define ADJUSTFORYDPI(y) y 430 #endif 431 432 wxBitmap GetScaledBitmapFromXPMData(const char** XPMData); 433 wxString format_number(double x, int nprec); 434 435 #ifdef SANDBOX 436 #define BOINC_MASTER_GROUP_NAME "boinc_master" 437 #endif 438 439 #endif 440