|
|
|
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
|
|
|
|
use ::Result; |
|
|
|
|
use core::marker::PhantomData; |
|
|
|
|
|
|
|
|
|
use ::raw::services::apt; |
|
|
|
|
|
|
|
|
@ -14,10 +14,10 @@ pub enum AppStatus {
@@ -14,10 +14,10 @@ pub enum AppStatus {
|
|
|
|
|
AppletClosed |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn to_raw_appstatus(status: AppStatus) -> apt::APP_STATUS { |
|
|
|
|
impl From<AppStatus> for apt::APP_STATUS { |
|
|
|
|
fn from(a: AppStatus) -> apt::APP_STATUS { |
|
|
|
|
use self::AppStatus::*; |
|
|
|
|
match status { |
|
|
|
|
match a { |
|
|
|
|
NotInitialized => apt::APP_STATUS::APP_NOTINITIALIZED, |
|
|
|
|
Running => apt::APP_STATUS::APP_RUNNING, |
|
|
|
|
Suspended => apt::APP_STATUS::APP_SUSPENDED, |
|
|
|
@ -29,10 +29,12 @@ fn to_raw_appstatus(status: AppStatus) -> apt::APP_STATUS {
@@ -29,10 +29,12 @@ fn to_raw_appstatus(status: AppStatus) -> apt::APP_STATUS {
|
|
|
|
|
AppletClosed => apt::APP_STATUS::APP_APPLETCLOSED, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn from_raw_appstatus(status: apt::APP_STATUS) -> AppStatus { |
|
|
|
|
impl From<apt::APP_STATUS> for AppStatus { |
|
|
|
|
fn from(a: apt::APP_STATUS) -> AppStatus { |
|
|
|
|
use self::AppStatus::*; |
|
|
|
|
match status { |
|
|
|
|
match a { |
|
|
|
|
apt::APP_STATUS::APP_NOTINITIALIZED => NotInitialized, |
|
|
|
|
apt::APP_STATUS::APP_RUNNING => Running, |
|
|
|
|
apt::APP_STATUS::APP_SUSPENDED => Suspended, |
|
|
|
@ -44,29 +46,30 @@ fn from_raw_appstatus(status: apt::APP_STATUS) -> AppStatus {
@@ -44,29 +46,30 @@ fn from_raw_appstatus(status: apt::APP_STATUS) -> AppStatus {
|
|
|
|
|
apt::APP_STATUS::APP_APPLETCLOSED => AppletClosed |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn init() -> Result { |
|
|
|
|
unsafe { |
|
|
|
|
return apt::aptInit(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn exit() -> () { |
|
|
|
|
unsafe { |
|
|
|
|
apt::aptExit(); |
|
|
|
|
} |
|
|
|
|
pub struct Apt { |
|
|
|
|
pd: PhantomData<()> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn get_status() -> AppStatus { |
|
|
|
|
impl Apt { |
|
|
|
|
pub fn new() -> Result<Apt, i32> { |
|
|
|
|
unsafe { |
|
|
|
|
return from_raw_appstatus(apt::aptGetStatus()); |
|
|
|
|
let r = apt::aptInit(); |
|
|
|
|
if r < 0 { |
|
|
|
|
Err(r) |
|
|
|
|
} else { |
|
|
|
|
Ok(Apt { pd: PhantomData }) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn set_status(status: AppStatus) -> () { |
|
|
|
|
unsafe { |
|
|
|
|
apt::aptSetStatus(to_raw_appstatus(status)); |
|
|
|
|
pub fn get_status(&self) -> AppStatus { |
|
|
|
|
unsafe { apt::aptGetStatus().into() } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn set_status(&mut self, status: AppStatus) { |
|
|
|
|
unsafe { apt::aptSetStatus(status.into()) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Return to the home menu.
|
|
|
|
@ -76,34 +79,32 @@ pub fn set_status(status: AppStatus) -> () {
@@ -76,34 +79,32 @@ pub fn set_status(status: AppStatus) -> () {
|
|
|
|
|
///
|
|
|
|
|
/// The program will not return from this function until the system returns
|
|
|
|
|
/// to the application, or when the status changes to `AppStatus::Exiting`.
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// if get_status() == Suspending {
|
|
|
|
|
/// return_to_menu();
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn return_to_menu() -> () { |
|
|
|
|
unsafe { |
|
|
|
|
apt::aptReturnToMenu(); |
|
|
|
|
} |
|
|
|
|
pub fn return_to_menu(&mut self) { |
|
|
|
|
unsafe { apt::aptReturnToMenu() }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Execute a function repeatedly until the apt main loop is over.
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// main_loop(|| {
|
|
|
|
|
/// // do things here
|
|
|
|
|
/// false
|
|
|
|
|
/// });
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn main_loop<F>(mut f: F) -> () where F : FnMut() -> bool { |
|
|
|
|
pub fn main_loop(&mut self, app: &mut Application) { |
|
|
|
|
unsafe { |
|
|
|
|
while apt::aptMainLoop() != 0 { |
|
|
|
|
if !f() { break; } |
|
|
|
|
app.main_loop(self); |
|
|
|
|
if app.ready_to_quit() { |
|
|
|
|
self.set_status(AppStatus::Exiting) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Drop for Apt { |
|
|
|
|
fn drop(&mut self) { |
|
|
|
|
unsafe { apt::aptExit() }; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub trait Application { |
|
|
|
|
/// Program app loop body.
|
|
|
|
|
fn main_loop(&mut self, apt: &mut Apt); |
|
|
|
|
|
|
|
|
|
/// True if the application is ready to quit.
|
|
|
|
|
fn ready_to_quit(&self) -> bool; |
|
|
|
|
} |
|
|
|
|