Add API to access battery power state

Done:
- X11, server (tested)
- Windows (developed, would be nice to retest)
- OSX (not tested)
Prepared (not developed):
- Android (code is here, but may not compile)
- iphone
- winrt
- bb10
- haiku
- javascript
This commit is contained in:
Julian Murgia
2016-07-23 13:15:55 +02:00
committed by Rémi Verschelde
parent e6272fe76e
commit 1d08349ce9
4 changed files with 131 additions and 0 deletions

View File

@@ -143,6 +143,8 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
ERR_PRINT("Initializing audio failed.");
}
power_manager = memnew( PowerHaiku );
}
void OS_Haiku::finalize() {

View File

@@ -40,6 +40,7 @@
#include "context_gl_haiku.h"
#include "haiku_application.h"
#include "haiku_direct_window.h"
#include "power_haiku.h"
class OS_Haiku : public OS_Unix {
@@ -53,6 +54,7 @@ private:
VideoMode current_video_mode;
PhysicsServer* physics_server;
Physics2DServer* physics_2d_server;
PowerHaiku* power_manager;
#ifdef MEDIA_KIT_ENABLED
AudioDriverMediaKit driver_media_kit;
@@ -114,6 +116,10 @@ public:
virtual VideoMode get_video_mode(int p_screen=0) const;
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen=0) const;
virtual String get_executable_path() const;
virtual PowerState get_power_state();
virtual int get_power_seconds_left();
virtual int get_power_percent_left();
};
#endif

74
power_haiku.cpp Normal file
View File

@@ -0,0 +1,74 @@
/*************************************************************************/
/* power_haiku.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "core/error_macros.h"
#include "power_haiku.h"
bool PowerHaiku::UpdatePowerInfo() {
return false;
}
PowerState PowerHaiku::get_power_state() {
if (UpdatePowerInfo()) {
return power_state;
}
else {
WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN");
return POWERSTATE_UNKNOWN;
}
}
int PowerX11::get_power_seconds_left() {
if (UpdatePowerInfo()) {
return nsecs_left;
}
else {
WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
return -1;
}
}
int PowerX11::get_power_percent_left() {
if (UpdatePowerInfo()) {
return percent_left;
}
else {
WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
return -1;
}
}
PowerHaiku::PowerHaiku() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) {
}
PowerHaiku::~PowerHaiku() {
}

49
power_haiku.h Normal file
View File

@@ -0,0 +1,49 @@
/*************************************************************************/
/* power_haiku.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef PLATFORM_HAIKU_POWER_HAIKU_H_
#define PLATFORM_HAIKU_POWER_HAIKU_H_
class PowerHaiku {
private:
int nsecs_left;
int percent_left;
PowerState power_state;
bool UpdatePowerInfo();
public:
PowerHaiku();
virtual ~PowerHaiku();
PowerState get_power_state();
int get_power_seconds_left();
int get_power_percent_left();
};
#endif /* PLATFORM_HAIKU_POWER_HAIKU_H_ */