1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2017 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 //  Mac_Saver_Module.h
19 //  BOINC_Saver_Module
20 //
21 
22 #ifndef _SCREENSAVER_MAC_H
23 #define _SCREENSAVER_MAC_H
24 
25 #include <Carbon/Carbon.h>
26 
27 // The declarations below must be kept in sync with
28 // the corresponding ones in Mac_Saver_ModuleView.h
29 #ifdef _DEBUG
30     #define _T(x) x
31 #endif
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 void            initBOINCSaver(void);
38 int             startBOINCSaver(void);
39 int             getSSMessage(char **theMessage, int* coveredFreq);
40 void            windowIsCovered();
41 void            drawPreview(CGContextRef myContext);
42 void            closeBOINCSaver(void);
43 void            setDefaultDisplayPeriods(void);
44 bool            getShow_default_ss_first();
45 double          getGFXDefaultPeriod();
46 double          getGFXSciencePeriod();
47 double          getGGFXChangePeriod();
48 void            incompatibleGfxApp(char * appPath, pid_t pid, int slot);
49 void            setShow_default_ss_first(bool value);
50 void            setGFXDefaultPeriod(double value);
51 void            setGFXSciencePeriod(double value);
52 void            setGGFXChangePeriod(double value);
53 double          getDTime();
54 void            doBoinc_Sleep(double seconds);
55 void            launchedGfxApp(char * appPath, pid_t thePID, int slot);
56 void            print_to_log_file(const char *format, ...);
57 void            strip_cr(char *buf);
58 void            PrintBacktrace(void);
59 
60 #ifdef __cplusplus
61 }	// extern "C"
62 #endif
63 
64 // The declarations above must be kept in sync with
65 // the corresponding ones in Mac_Saver_ModuleView.h
66 
67 struct ss_periods
68 {
69     double          GFXDefaultPeriod;
70     double          GFXSciencePeriod;
71     double          GFXChangePeriod;
72     bool            Show_default_ss_first;
73 };
74 
75 //-----------------------------------------------------------------------------
76 // Name: class CScreensaver
77 // Desc: Screensaver class
78 //-----------------------------------------------------------------------------
79 class CScreensaver
80 {
81 public:
82     CScreensaver();
83 
84     int             Create();
85     int             Run();
86 
87 
88     //
89     // Infrastructure layer
90     //
91 protected:
92     OSStatus        initBOINCApp(void);
93     int             GetBrandID(void);
94     char*           PersistentFGets(char *buf, size_t buflen, FILE *f);
95     pid_t           FindProcessPID(char* name, pid_t thePID);
96     void            updateSSMessageText(char *msg);
97     void            strip_cr(char *buf);
98     char            m_gfx_Switcher_Path[PATH_MAX];
99     void            SetDiscreteGPU(bool setDiscrete);
100     void            CheckDualGPUStatus();
101     bool            Host_is_running_on_batteries();
102 
103     bool            m_bErrorMode;        // Whether to draw moving logo and possibly display an error
104     unsigned int    m_hrError;           // Error code to display
105 
106     bool            m_wasAlreadyRunning;
107     pid_t           m_CoreClientPID;
108     int             m_dwBlankScreen;
109     time_t          m_dwBlankTime;
110     int             m_iGraphicsStartingMsgCounter;
111     bool            m_bDefault_ss_exists;
112     bool            m_bScience_gfx_running;
113     bool            m_bDefault_gfx_running;
114     bool            m_bConnected;
115     std::vector<char*>   m_vIncompatibleGfxApps;
116     //
117     // Data management layer
118     //
119 protected:
120     bool            CreateDataManagementThread();
121     bool            DestroyDataManagementThread();
122 
123     void*           DataManagementProc();
124     static void*    DataManagementProcStub( void* param );
125     int             terminate_v6_screensaver(int& graphics_application);
126     int             terminate_default_screensaver(int& graphics_application);
127     int             launch_screensaver(RESULT* rp, int& graphics_application);
128     int             launch_default_screensaver(char *dir_path, int& graphics_application);
129     void            HandleRPCError(void);
130     int             KillScreenSaver(void);
131     void            GetDefaultDisplayPeriods(struct ss_periods &periods);
132     pthread_t       m_hDataManagementThread;
133 
134 // Determine if two RESULT pointers refer to the same task
135     bool            is_same_task(RESULT* taska, RESULT* taskb);
136 
137 // Count the number of active graphics-capable apps
138     int             count_active_graphic_apps(RESULTS& results, RESULT* exclude = NULL);
139 
140 // Choose a random graphics application from the vector that
141 //   was passed in.
142 
143     RESULT*         get_random_graphics_app(RESULTS& results, RESULT* exclude = NULL);
144 
145     bool            m_bResetCoreState;
146     bool            m_bQuitDataManagementProc;
147     bool            m_bDataManagementProcStopped;
148     bool            m_bV5_GFX_app_is_running;
149 
150 
151     //
152     // Presentation layer
153     //
154 protected:
155     char            m_MessageText[2048];
156     char*           m_CurrentBannerMessage;
157     char*           m_BrandText;
158 public:
159     int             getSSMessage(char **theMessage, int* coveredFreq);
160     void            windowIsCovered(void);
161     void            drawPreview(CGContextRef myContext);
162     void            ShutdownSaver();
163     void            markAsIncompatible(char *gfxAppName);
164     bool            isIncompatible(char *appName);
165     bool            SetError( bool bErrorMode, unsigned int hrError );
166     void            setSSMessageText(const char *msg);
167 
168     int             terminate_screensaver(int& graphics_application, RESULT *worker_app);
169     bool            HasProcessExited(pid_t pid, int &exitCode);
170 
171     CC_STATE        state;
172     RESULTS         results;
173     RPC_CLIENT      *rpc;
174 
175     double          m_fGFXDefaultPeriod;
176     double          m_fGFXSciencePeriod;
177     double          m_fGFXChangePeriod;
178     bool            m_bShow_default_ss_first;
179 
180     pid_t           m_hGraphicsApplication;
181 
182 protected:
183 };
184 
185 #endif
186