diff --git a/src/framework/AbstractGraphicsEngine.cpp b/src/framework/AbstractGraphicsEngine.cpp index 1f4577e4a2de67115917f17a5e25ef6d721a21ce..2f56439a19afd1415d3e080001ad50337692373e 100644 --- a/src/framework/AbstractGraphicsEngine.cpp +++ b/src/framework/AbstractGraphicsEngine.cpp @@ -20,7 +20,8 @@ #include "AbstractGraphicsEngine.h" -AbstractGraphicsEngine::AbstractGraphicsEngine() : m_BoincAdapter() +AbstractGraphicsEngine::AbstractGraphicsEngine(string sharedMemoryIdentifier) : + m_BoincAdapter(sharedMemoryIdentifier) { } diff --git a/src/framework/AbstractGraphicsEngine.h b/src/framework/AbstractGraphicsEngine.h index 6d12b68d8d8896b1befded9c4f8b49d20d9fb837..e36ee58e5fac4ddd2b62b9e007e04ba8b7dea891 100644 --- a/src/framework/AbstractGraphicsEngine.h +++ b/src/framework/AbstractGraphicsEngine.h @@ -21,9 +21,13 @@ #ifndef ABSTRACTGRAPHICSENGINE_H_ #define ABSTRACTGRAPHICSENGINE_H_ +#include <string> + #include "BOINCClientAdapter.h" #include "Resource.h" +using namespace std; + /** * \addtogroup framework Framework * @{ @@ -169,11 +173,17 @@ public: protected: /** - * \brief Default constructor + * \brief Constructor + * + * The constructor is protected since this is an abstract class. It takes + * as an argument the name of the shared memory area which is propagated + * to the BOINC client adapter instance (during construction). + * + * \param sharedMemoryIdentifier The identifier of the shared memory area * - * The constructor is protected since this is an abstract class. + * \see BOINCClientAdapter::BOINCClientAdapter() */ - AbstractGraphicsEngine(); + AbstractGraphicsEngine(string sharedMemoryIdentifier); /** * \brief This method has to be called in order to update the BOINC client information diff --git a/src/framework/BOINCClientAdapter.cpp b/src/framework/BOINCClientAdapter.cpp index c9b8a7145c5aedfdbe8ead16032bb17358da0aa2..cfde209e48948bab31b79a2f4717c1f86183f40f 100644 --- a/src/framework/BOINCClientAdapter.cpp +++ b/src/framework/BOINCClientAdapter.cpp @@ -20,9 +20,10 @@ #include "BOINCClientAdapter.h" -BOINCClientAdapter::BOINCClientAdapter() +BOINCClientAdapter::BOINCClientAdapter(string sharedMemoryIdentifier) { m_Initialized = false; + m_SharedMemoryAreaIdentifier = sharedMemoryIdentifier; m_SharedMemoryAreaAvailable = false; } @@ -30,13 +31,11 @@ BOINCClientAdapter::~BOINCClientAdapter() { } -void BOINCClientAdapter::initialize(string sharedMemoryIdentifier) +void BOINCClientAdapter::initialize() { - m_SharedMemoryAreaIdentifier = sharedMemoryIdentifier; - readUserInfo(); readSharedMemoryArea(); - + m_Initialized = true; } @@ -45,8 +44,8 @@ void BOINCClientAdapter::refresh() if(m_Initialized) { readUserInfo(); readSharedMemoryArea(); - - /// \todo Check that we're still watching our own WU (or science app)! + + /// \todo Check that we're still watching our own WU (or science app)! } else { cerr << "The BOINC Client Adapter has not yet been initialized!"; @@ -69,11 +68,11 @@ void BOINCClientAdapter::readSharedMemoryArea() // the shared memory area's not available, try to get a pointer to it else { m_SharedMemoryArea = (char*) boinc_graphics_get_shmem((char*)m_SharedMemoryAreaIdentifier.c_str()); - + if(m_SharedMemoryArea) { // fine, get the contents recursively m_SharedMemoryAreaAvailable = true; - readSharedMemoryArea(); + readSharedMemoryArea(); } else { // bad luck @@ -121,12 +120,12 @@ int BOINCClientAdapter::graphicsWindowHeight() const string BOINCClientAdapter::coreVersion() const { stringstream buffer; - + // build common version string buffer << m_UserData.major_version << "." << m_UserData.minor_version << "." << m_UserData.release; - + return string(buffer.str()); } @@ -139,8 +138,8 @@ string BOINCClientAdapter::applicationVersion() const { stringstream buffer; buffer << m_UserData.app_version; - - return string(buffer.str()); + + return string(buffer.str()); } string BOINCClientAdapter::userName() const @@ -170,17 +169,17 @@ double BOINCClientAdapter::hostCredit() const double BOINCClientAdapter::hostRACredit() const { - return m_UserData.host_expavg_credit; + return m_UserData.host_expavg_credit; } string BOINCClientAdapter::wuName() const { - return string(m_UserData.wu_name); + return string(m_UserData.wu_name); } double BOINCClientAdapter::wuFPOpsEstimated() const { - return m_UserData.rsc_fpops_est; + return m_UserData.rsc_fpops_est; } diff --git a/src/framework/BOINCClientAdapter.h b/src/framework/BOINCClientAdapter.h index d459a5da80297ab35279f900258be08fbbec3c8a..072b6bb8e01ab474bb035f3063e76972eabcde5b 100644 --- a/src/framework/BOINCClientAdapter.h +++ b/src/framework/BOINCClientAdapter.h @@ -37,10 +37,10 @@ using namespace std; /** * \brief Adapter class which facilitates communications with the BOINC client - * + * * This adapter class can be used to query the BOINC core client for information * about the user and the running science application instance. - * + * * \author Oliver Bock\n * Max-Planck-Institute for Gravitational Physics\n * Hannover, Germany @@ -48,18 +48,25 @@ using namespace std; class BOINCClientAdapter { public: - /// Default constructor - BOINCClientAdapter(); - + /** + * \brief Constructor + * + * It takes as an argument the name of the shared memory area to be used + * for inter-process communication. + * + * \param sharedMemoryIdentifier The identifier of the shared memory area + */ + BOINCClientAdapter(string sharedMemoryAreaIdentifier); + /// Destructor virtual ~BOINCClientAdapter(); - + /** * \brief Defined quality settings for graphics applications - * + * * \see graphicsQualitySetting * \see graphicsFrameRate - */ + */ enum GraphicsQualitySetting { LowGraphicsQualitySetting = 1, MediumGraphicsQualitySetting = 2, @@ -68,93 +75,93 @@ public: /** * \brief Initializes the BOINC client adapter instance - * + * * This method has to be called first, otherwise no data will be returned when requested! */ - void initialize(string sharedMemoryIdentifier); - + void initialize(); + /** * \brief Refreshes dynamic data (e.g. search information) - * + * * You want to call this method periodically to refresh any volatile client information. * Please make sure that you call initialize() first! - * + * * \see AbstractGraphicsEngine::refreshBOINCInformation * \see initialize */ void refresh(); - + /** * \brief Retrieves the BOINC core client version of the currently active client - * + * * \return The BOINC core client version */ string coreVersion() const; - + /** * \brief Retrieves the \b Einstein\@Home application name of the currently active work unit - * + * * \return The \b Einstein\@Home application name */ string applicationName() const; - + /** * \brief Retrieves the \b Einstein\@Home application version of the currently active work unit - * + * * \return The \b Einstein\@Home application version */ string applicationVersion() const; - + /** * \brief Retrieves the BOINC user name currently logged in - * + * * \return The BOINC user name */ string userName() const; - + /** * \brief Retrieves the BOINC team name of the currently logged in user - * + * * \return The BOINC team name */ string teamName() const; - + /** * \brief Retrieves the total project credit of the currently logged in user - * + * * \return The total project credit - */ + */ double userCredit() const; - + /** * \brief Retrieves the recent average project credit (RAC) of the currently logged in user - * + * * \return The recent average project credit - */ + */ double userRACredit() const; - + /** * \brief Retrieves the total project credit of this host - * + * * \return The total project credit - */ + */ double hostCredit() const; - + /** * \brief Retrieves the recent average project credit (RAC) of this host - * + * * \return The recent average project credit - */ + */ double hostRACredit() const; /** * \brief Retrieves the name of the currently active work unit - * + * * \return The work unit name */ string wuName() const; - + double wuFPOpsEstimated() const; double wuFPOpsBound() const; double wuMemoryBound() const; @@ -162,23 +169,23 @@ public: /** * \brief Retrieves the accumulated time spent on the currently active work unit - * + * * \return The time spent on the work unit */ double wuCPUTimeSpent() const; - + /** * \brief Retrieves information provided by the running science application - * + * * \return The application specific information string (i.e. XML) found in APP_INIT_DATA - * + * * \see m_UserData */ string applicationInformation() const; - + /** * \brief Retrieves specific information provided by the currently active project - * + * * All projects using this framework are highly recommended to adhere to the following XML schema * (not yet literally a XML schema, will be provided later) with respect to graphics settings: * @@ -191,10 +198,10 @@ public: <waverider> <feature id="sound" enabled="false" /> </waverider> - </graphics> - </project_specific> + </graphics> + </project_specific> \endverbatim - * + * * The \c graphics tag and its four attributes \b must be provided as shown above where * the \c fps attribute contains the frame rate as integer value and \c quality contains * a lowercase string value describing the quality setting to be used (supported values: \c low, @@ -204,62 +211,62 @@ public: * stored per implementation. * * \return The project specific information string (i.e. XML) found in \c APP_INIT_DATA - * + * * \see m_UserData * \see GraphicsQualitySetting * \see graphicsFrameRate * \see graphicsQualitySetting */ string projectInformation() const; - + /** * \brief Retrieves the frame rate at which the project's graphics application should be rendered - * + * * This setting is given by the \c fps attribute of the \c graphics tag that's - * part of the \c project_specific XML tag. - * + * part of the \c project_specific XML tag. + * * \return The frame rate to be used for rendering - * + * * \see projectInformation * \see m_UserData */ int graphicsFrameRate() const; - + /** * \brief Retrieves the quality setting at which the project's graphics application should be rendered - * + * * This setting is given by the \c quality attribute of the \c graphics tag that's * part of the \c project_specific XML tag. - * + * * \return The quality setting to be used for rendering * - * \see GraphicsQualitySetting + * \see GraphicsQualitySetting * \see projectInformation * \see m_UserData */ GraphicsQualitySetting graphicsQualitySetting() const; - + /** * \brief Retrieves the initial window width when running in windowed mode - * + * * This setting is given by the \c width attribute of the \c graphics tag that's * part of the \c project_specific XML tag. It's ignored when the application * is started in fullscreen/screensaver mode. - * + * * \return The initial window width to be used * * \see projectInformation * \see m_UserData */ int graphicsWindowWidth() const; - + /** * \brief Retrieves the initial window height when running in windowed mode - * + * * This setting is given by the \c height attribute of the \c graphics tag that's * part of the \c project_specific XML tag. It's ignored when the application * is started in fullscreen/screensaver mode. - * + * * \return The initial window height to be used * * \see projectInformation @@ -270,43 +277,43 @@ public: private: /** * \brief Fetch the contents of \c init_data.xml - * + * * This method uses the BOINC API in order to fill the \c APP_INIT_DATA structure m_UserData * with initial information about the current work unit computation session (slot). The data * in \c init_data.xml is refreshed only at the beginning of a session, hence this method doesn't * need to be called periodically. */ void readUserInfo(); - + /** * \brief Fetch the contents of the shared memory area provided by the \b Einstein\@Home application - * + * * The shared memory area contains various informational bits and pieces about the running application * and work unit computation. The contents have to be considered as volatile, hence should be refreshed * periodically. - * + * * \see refresh() */ void readSharedMemoryArea(); - + /// State flag which indicates whether the adapter instance is ready to be used bool m_Initialized; - + /// Name tag used to identify the shared memory area provided by the \b Einstein\@Home application string m_SharedMemoryAreaIdentifier; - + /// Pointer to the shared memory area char *m_SharedMemoryArea; - + /// The contents of the shared memory area after the last refresh string m_SharedMemoryAreaContents; - + /// Flag to indicate whether the shared memory area is available or not bool m_SharedMemoryAreaAvailable; - + /** * \brief Information structure returned by the BOINC client API. - * + * * It contains information about the currently active project, science application, * user account, work unit and computation session. */ diff --git a/src/framework/WindowManager.cpp b/src/framework/WindowManager.cpp index 9a3492edd026d8f5c763a5df78b33e6cefffaaeb..3e9bce04323d643dbf74b2c946f7af55a6db0b83 100644 --- a/src/framework/WindowManager.cpp +++ b/src/framework/WindowManager.cpp @@ -23,7 +23,7 @@ WindowManager::WindowManager() { m_ScreensaverMode = false; - m_BoincAdapter = new BOINCClientAdapter(); + m_BoincAdapter = new BOINCClientAdapter(""); } WindowManager::~WindowManager() @@ -56,7 +56,7 @@ bool WindowManager::initialize(const int width, const int height, const int fram } // get initial non-fullscreen resolution and frame rate from project preferences - m_BoincAdapter->initialize(""); + m_BoincAdapter->initialize(); int preferredWidth = m_BoincAdapter->graphicsWindowWidth(); int preferredHeight = m_BoincAdapter->graphicsWindowHeight(); int preferredFrameRate = m_BoincAdapter->graphicsFrameRate(); diff --git a/src/starsphere/Starsphere.cpp b/src/starsphere/Starsphere.cpp index 81b09e5467badd27fc6f7cfed26c2fab2b2fe87a..222271f2fd846eea2e13acf12df17731ab71a1e4 100644 --- a/src/starsphere/Starsphere.cpp +++ b/src/starsphere/Starsphere.cpp @@ -23,7 +23,8 @@ #include "Starsphere.h" -Starsphere::Starsphere() : AbstractGraphicsEngine() +Starsphere::Starsphere(string sharedMemoryAreaIdentifier) : + AbstractGraphicsEngine(sharedMemoryAreaIdentifier) { m_FontResource = 0; m_FontLogo1 = 0; @@ -621,7 +622,7 @@ void Starsphere::initialize(const int width, const int height, const Resource *f if(font) m_FontResource = font; // initialize the BOINC client adapter - m_BoincAdapter.initialize(EinsteinS5R3Adapter::SharedMemoryIdentifier); + m_BoincAdapter.initialize(); // inital HUD offset setup m_XStartPosLeft = 5; diff --git a/src/starsphere/Starsphere.h b/src/starsphere/Starsphere.h index 7822da5eb19f6eca049efd794886dd6b39524cb2..bd3ea4cc053ab354cb2142ab557d0d9049b5dfcb 100644 --- a/src/starsphere/Starsphere.h +++ b/src/starsphere/Starsphere.h @@ -119,11 +119,18 @@ public: protected: /** - * \brief Default contructor + * \brief Constructor * - * The constructor is protected since this an abstract class. + * The constructor is protected since this is an abstract class. It takes + * as an argument the name of the shared memory area which is propagated + * to the BOINC client adapter instance (during construction). + * + * \param sharedMemoryIdentifier The identifier of the shared memory area + * + * \see AbstractGraphicsEngine::AbstractGraphicsEngine() + * \see BOINCClientAdapter::BOINCClientAdapter() */ - Starsphere(); + Starsphere(string sharedMemoryIdentifier); /** * \brief Render science run specific search information diff --git a/src/starsphere/StarsphereS5R3.cpp b/src/starsphere/StarsphereS5R3.cpp index ee48e4437a04ebf25590e975de75e0923a9aa24f..b9b4b6d41bd80549413bf661f8c9f6a9f5239ee7 100644 --- a/src/starsphere/StarsphereS5R3.cpp +++ b/src/starsphere/StarsphereS5R3.cpp @@ -20,7 +20,9 @@ #include "StarsphereS5R3.h" -StarsphereS5R3::StarsphereS5R3() : Starsphere(), m_EinsteinAdapter(&m_BoincAdapter) +StarsphereS5R3::StarsphereS5R3() : + Starsphere(EinsteinS5R3Adapter::SharedMemoryIdentifier), + m_EinsteinAdapter(&m_BoincAdapter) { } @@ -31,14 +33,14 @@ StarsphereS5R3::~StarsphereS5R3() void StarsphereS5R3::initialize(const int width, const int height, const Resource *font, const bool recycle) { Starsphere::initialize(width, height, font, recycle); - + // check whether we initialize the first time or have to recycle (required for windoze) if(!recycle) { - + // adjust HUD config m_YOffsetMedium = 15; m_XStartPosRight = width - 125; - m_YStartPosBottom = 70; + m_YStartPosBottom = 70; m_Y1StartPosBottom = m_YStartPosBottom - m_YOffsetMedium; m_Y2StartPosBottom = m_Y1StartPosBottom - m_YOffsetMedium; m_Y3StartPosBottom = m_Y2StartPosBottom - m_YOffsetMedium; @@ -49,7 +51,7 @@ void StarsphereS5R3::initialize(const int width, const int height, const Resourc void StarsphereS5R3::resize(const int width, const int height) { Starsphere::resize(width, height); - + // adjust HUD config m_XStartPosRight = width - 125; } @@ -58,17 +60,17 @@ void StarsphereS5R3::refreshBOINCInformation() { // call base class implementation Starsphere::refreshLocalBOINCInformation(); - + // update local/specific content m_EinsteinAdapter.refresh(); - + // prepare conversion buffer stringstream buffer; buffer.precision(2); buffer.setf(ios::fixed, ios::floatfield); buffer.fill('0'); buffer.setf(ios::right, ios::adjustfield); - + // store content required for our HUD (search info) if(m_CurrentRightAscension != m_EinsteinAdapter.wuSkyPosRightAscension()) { // we've got a new position, update search marker and HUD @@ -78,7 +80,7 @@ void StarsphereS5R3::refreshBOINCInformation() m_WUSkyPosRightAscension = buffer.str(); buffer.str(""); } - + if(m_CurrentDeclination != m_EinsteinAdapter.wuSkyPosDeclination()) { // we've got a new position, update search marker and HUD m_CurrentDeclination = m_EinsteinAdapter.wuSkyPosDeclination(); @@ -87,33 +89,33 @@ void StarsphereS5R3::refreshBOINCInformation() m_WUSkyPosDeclination = buffer.str(); buffer.str(""); } - + buffer << "Completed: " << fixed << m_EinsteinAdapter.wuFractionDone() * 100 << " %" << ends; m_WUPercentDone = buffer.str(); buffer.str(""); - - // show WU's total CPU time (previously accumulated + current session) + + // show WU's total CPU time (previously accumulated + current session) const double cputime = m_BoincAdapter.wuCPUTimeSpent() + m_EinsteinAdapter.wuCPUTime(); const int hrs = cputime / 3600; const int min = (cputime - hrs*3600) / 60; - const int sec = cputime - (hrs*3600 + min*60); + const int sec = cputime - (hrs*3600 + min*60); buffer << "CPU Time: " << right << setw(2) << hrs << ":" << right << setw(2) << min << ":" << right << setw(2) << sec << ends; - - m_WUCPUTime = buffer.str(); + + m_WUCPUTime = buffer.str(); } void StarsphereS5R3::renderSearchInformation() { - // left info block + // left info block m_FontHeader->draw(m_XStartPosLeft, m_YStartPosBottom, "BOINC Statistics"); m_FontText->draw(m_XStartPosLeft, m_Y1StartPosBottom, m_UserName.c_str()); m_FontText->draw(m_XStartPosLeft, m_Y2StartPosBottom, m_TeamName.c_str()); m_FontText->draw(m_XStartPosLeft, m_Y3StartPosBottom, m_UserCredit.c_str()); m_FontText->draw(m_XStartPosLeft, m_Y4StartPosBottom, m_UserRACredit.c_str()); - + // right info block m_FontHeader->draw(m_XStartPosRight, m_YStartPosBottom, "Search Information"); m_FontText->draw(m_XStartPosRight, m_Y1StartPosBottom, m_WUSkyPosRightAscension.c_str());