| 1 | /** |
| 2 | * Copyright (c) 2006-2023 LOVE Development Team |
| 3 | * |
| 4 | * This software is provided 'as-is', without any express or implied |
| 5 | * warranty. In no event will the authors be held liable for any damages |
| 6 | * arising from the use of this software. |
| 7 | * |
| 8 | * Permission is granted to anyone to use this software for any purpose, |
| 9 | * including commercial applications, and to alter it and redistribute it |
| 10 | * freely, subject to the following restrictions: |
| 11 | * |
| 12 | * 1. The origin of this software must not be misrepresented; you must not |
| 13 | * claim that you wrote the original software. If you use this software |
| 14 | * in a product, an acknowledgment in the product documentation would be |
| 15 | * appreciated but is not required. |
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
| 17 | * misrepresented as being the original software. |
| 18 | * 3. This notice may not be removed or altered from any source distribution. |
| 19 | **/ |
| 20 | |
| 21 | #ifndef LOVE_SYSTEM_H |
| 22 | #define LOVE_SYSTEM_H |
| 23 | |
| 24 | // LOVE |
| 25 | #include "common/config.h" |
| 26 | #include "common/Module.h" |
| 27 | #include "common/StringMap.h" |
| 28 | |
| 29 | // stdlib |
| 30 | #include <string> |
| 31 | |
| 32 | namespace love |
| 33 | { |
| 34 | namespace system |
| 35 | { |
| 36 | |
| 37 | class System : public Module |
| 38 | { |
| 39 | public: |
| 40 | |
| 41 | enum PowerState |
| 42 | { |
| 43 | POWER_UNKNOWN, |
| 44 | POWER_BATTERY, |
| 45 | POWER_NO_BATTERY, |
| 46 | POWER_CHARGING, |
| 47 | POWER_CHARGED, |
| 48 | POWER_MAX_ENUM |
| 49 | }; |
| 50 | |
| 51 | System(); |
| 52 | virtual ~System() {} |
| 53 | |
| 54 | // Implements Module. |
| 55 | virtual ModuleType getModuleType() const { return M_SYSTEM; } |
| 56 | |
| 57 | /** |
| 58 | * Gets the current operating system. |
| 59 | **/ |
| 60 | std::string getOS() const; |
| 61 | |
| 62 | /** |
| 63 | * Gets the number of reported CPU cores on the current system. |
| 64 | * Does not account for technologies such as Hyperthreading: a 4-core |
| 65 | * Hyperthreading-enabled Intel CPU will report 8, instead of 4. |
| 66 | **/ |
| 67 | virtual int getProcessorCount() const = 0; |
| 68 | |
| 69 | /** |
| 70 | * Replaces the contents of the system's text clipboard with a string. |
| 71 | * @param text The clipboard text to set. |
| 72 | **/ |
| 73 | virtual void setClipboardText(const std::string &text) const = 0; |
| 74 | |
| 75 | /** |
| 76 | * Gets the contents of the system's text clipboard. |
| 77 | **/ |
| 78 | virtual std::string getClipboardText() const = 0; |
| 79 | |
| 80 | /** |
| 81 | * Gets information about the system's power supply. |
| 82 | * |
| 83 | * @param[out] seconds Time in seconds of battery life left. |
| 84 | * -1 if a value can't be determined. |
| 85 | * @param[out] percent The percentage of battery life left (0-100.) |
| 86 | * -1 if a value can't be determined. |
| 87 | * |
| 88 | * @return The current state of the battery. |
| 89 | **/ |
| 90 | virtual PowerState getPowerInfo(int &seconds, int &percent) const = 0; |
| 91 | |
| 92 | /** |
| 93 | * Opens the specified URL with the user's default program to handle that |
| 94 | * particular URL type. |
| 95 | * |
| 96 | * @param url The URL to open. |
| 97 | * |
| 98 | * @return Whether the URL was opened successfully. |
| 99 | **/ |
| 100 | virtual bool openURL(const std::string &url) const; |
| 101 | |
| 102 | /** |
| 103 | * Vibrates for the specified amount of seconds. |
| 104 | * |
| 105 | * @param number of seconds to vibrate. |
| 106 | */ |
| 107 | virtual void vibrate(double seconds) const; |
| 108 | |
| 109 | /** |
| 110 | * Gets if the user is playing music on background. |
| 111 | * Throws an exception on unsupported platforms. |
| 112 | * |
| 113 | * @return Whether a music is playing on background. |
| 114 | **/ |
| 115 | bool hasBackgroundMusic() const; |
| 116 | |
| 117 | static bool getConstant(const char *in, PowerState &out); |
| 118 | static bool getConstant(PowerState in, const char *&out); |
| 119 | |
| 120 | private: |
| 121 | |
| 122 | static StringMap<PowerState, POWER_MAX_ENUM>::Entry powerEntries[]; |
| 123 | static StringMap<PowerState, POWER_MAX_ENUM> powerStates; |
| 124 | |
| 125 | }; // System |
| 126 | |
| 127 | } // system |
| 128 | } // love |
| 129 | |
| 130 | #endif // LOVE_SYSTEM_H |
| 131 | |