|
|
@ -1,4 +1,4 @@ |
|
|
|
use ::Result; |
|
|
|
use core::marker::PhantomData; |
|
|
|
|
|
|
|
|
|
|
|
use ::raw::services::apt; |
|
|
|
use ::raw::services::apt; |
|
|
|
|
|
|
|
|
|
|
@ -14,10 +14,10 @@ pub enum AppStatus { |
|
|
|
AppletClosed |
|
|
|
AppletClosed |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<AppStatus> for apt::APP_STATUS { |
|
|
|
fn to_raw_appstatus(status: AppStatus) -> apt::APP_STATUS { |
|
|
|
fn from(a: AppStatus) -> apt::APP_STATUS { |
|
|
|
use self::AppStatus::*; |
|
|
|
use self::AppStatus::*; |
|
|
|
match status { |
|
|
|
match a { |
|
|
|
NotInitialized => apt::APP_STATUS::APP_NOTINITIALIZED, |
|
|
|
NotInitialized => apt::APP_STATUS::APP_NOTINITIALIZED, |
|
|
|
Running => apt::APP_STATUS::APP_RUNNING, |
|
|
|
Running => apt::APP_STATUS::APP_RUNNING, |
|
|
|
Suspended => apt::APP_STATUS::APP_SUSPENDED, |
|
|
|
Suspended => apt::APP_STATUS::APP_SUSPENDED, |
|
|
@ -28,11 +28,13 @@ fn to_raw_appstatus(status: AppStatus) -> apt::APP_STATUS { |
|
|
|
AppletStarted => apt::APP_STATUS::APP_APPLETSTARTED, |
|
|
|
AppletStarted => apt::APP_STATUS::APP_APPLETSTARTED, |
|
|
|
AppletClosed => apt::APP_STATUS::APP_APPLETCLOSED, |
|
|
|
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::*; |
|
|
|
use self::AppStatus::*; |
|
|
|
match status { |
|
|
|
match a { |
|
|
|
apt::APP_STATUS::APP_NOTINITIALIZED => NotInitialized, |
|
|
|
apt::APP_STATUS::APP_NOTINITIALIZED => NotInitialized, |
|
|
|
apt::APP_STATUS::APP_RUNNING => Running, |
|
|
|
apt::APP_STATUS::APP_RUNNING => Running, |
|
|
|
apt::APP_STATUS::APP_SUSPENDED => Suspended, |
|
|
|
apt::APP_STATUS::APP_SUSPENDED => Suspended, |
|
|
@ -43,67 +45,66 @@ fn from_raw_appstatus(status: apt::APP_STATUS) -> AppStatus { |
|
|
|
apt::APP_STATUS::APP_APPLETSTARTED => AppletStarted, |
|
|
|
apt::APP_STATUS::APP_APPLETSTARTED => AppletStarted, |
|
|
|
apt::APP_STATUS::APP_APPLETCLOSED => AppletClosed |
|
|
|
apt::APP_STATUS::APP_APPLETCLOSED => AppletClosed |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn init() -> Result { |
|
|
|
pub struct Apt { |
|
|
|
unsafe { |
|
|
|
pd: PhantomData<()> |
|
|
|
return apt::aptInit(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn exit() -> () { |
|
|
|
impl Apt { |
|
|
|
|
|
|
|
pub fn new() -> Result<Apt, i32> { |
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
apt::aptExit(); |
|
|
|
let r = apt::aptInit(); |
|
|
|
|
|
|
|
if r < 0 { |
|
|
|
|
|
|
|
Err(r) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Ok(Apt { pd: PhantomData }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_status() -> AppStatus { |
|
|
|
pub fn get_status(&self) -> AppStatus { |
|
|
|
unsafe { |
|
|
|
unsafe { apt::aptGetStatus().into() } |
|
|
|
return from_raw_appstatus(apt::aptGetStatus()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_status(status: AppStatus) -> () { |
|
|
|
pub fn set_status(&mut self, status: AppStatus) { |
|
|
|
unsafe { |
|
|
|
unsafe { apt::aptSetStatus(status.into()) }; |
|
|
|
apt::aptSetStatus(to_raw_appstatus(status)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Return to the home menu.
|
|
|
|
/// Return to the home menu.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// When `get_status` returns `AppStatus::Suspending`, you should call this,
|
|
|
|
/// When `get_status` returns `AppStatus::Suspending`, you should call this,
|
|
|
|
/// otherwise the app will be left stuck in that state.
|
|
|
|
/// otherwise the app will be left stuck in that state.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// The program will not return from this function until the system returns
|
|
|
|
/// The program will not return from this function until the system returns
|
|
|
|
/// to the application, or when the status changes to `AppStatus::Exiting`.
|
|
|
|
/// to the application, or when the status changes to `AppStatus::Exiting`.
|
|
|
|
///
|
|
|
|
pub fn return_to_menu(&mut self) { |
|
|
|
/// # Examples
|
|
|
|
unsafe { apt::aptReturnToMenu() }; |
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// if get_status() == Suspending {
|
|
|
|
|
|
|
|
/// return_to_menu();
|
|
|
|
|
|
|
|
/// }
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn return_to_menu() -> () { |
|
|
|
|
|
|
|
unsafe { |
|
|
|
|
|
|
|
apt::aptReturnToMenu(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Execute a function repeatedly until the apt main loop is over.
|
|
|
|
pub fn main_loop(&mut self, app: &mut Application) { |
|
|
|
///
|
|
|
|
|
|
|
|
/// # Examples
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```rust
|
|
|
|
|
|
|
|
/// main_loop(|| {
|
|
|
|
|
|
|
|
/// // do things here
|
|
|
|
|
|
|
|
/// false
|
|
|
|
|
|
|
|
/// });
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn main_loop<F>(mut f: F) -> () where F : FnMut() -> bool { |
|
|
|
|
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
while apt::aptMainLoop() != 0 { |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|