#![cfg_attr(feature = "nightly", feature(external_doc) )] #![cfg_attr(feature = "nightly", doc(include = "../Readme.md"))]
#![allow(non_snake_case)]
use jni_sys::{jint, jlong};
use std::convert::TryFrom;
use std::ffi::c_void;
use std::io;
use std::os::raw::*;
use std::path::*;
pub struct JImageFile { _private: [u8; 0] }
pub type JImageLocationRef = jlong;
#[doc = "Error code"] pub const JIMAGE_NOT_FOUND : jint = 0;
#[doc = "Error code"] pub const JIMAGE_BAD_MAGIC : jint = -1;
#[doc = "Error code"] pub const JIMAGE_BAD_VERSION : jint = -2;
#[doc = "Error code"] pub const JIMAGE_CORRUPTED : jint = -3;
pub type JImageResourceVisitor = unsafe extern "C" fn (image: *mut JImageFile, module_name: *const c_char, version: *const c_char, package: *const c_char, name: *const c_char, extension: *const c_char, arg: *mut c_void) -> bool;
pub struct Library {
pub JIMAGE_Open: unsafe extern "C" fn (name: *const c_char, error: *mut jint) -> *mut JImageFile,
pub JIMAGE_Close: unsafe extern "C" fn (image: *mut JImageFile) -> (),
pub JIMAGE_PackageToModule: unsafe extern "C" fn (image: *mut JImageFile, package_name: *const c_char) -> *const c_char,
pub JIMAGE_FindResource: unsafe extern "C" fn (image: *mut JImageFile, module_name: *const c_char, version: *const c_char, name: *const c_char, size: *mut jlong) -> JImageLocationRef,
pub JIMAGE_GetResource: unsafe extern "C" fn (image: *mut JImageFile, location: JImageLocationRef, buffer: *mut c_char, size: jlong) -> jlong,
pub JIMAGE_ResourceIterator: unsafe extern "C" fn (image: *mut JImageFile, visitor: JImageResourceVisitor, arg: *mut c_void) -> (),
}
impl Library {
pub fn load(path: &Path) -> io::Result<Self> {
Self::from(minidl::Library::load(path)?)
}
pub fn from(lib: minidl::Library) -> io::Result<Self> {
unsafe{Ok(Self{
JIMAGE_Open: lib.sym("JIMAGE_Open\0")?,
JIMAGE_Close: lib.sym("JIMAGE_Close\0")?,
JIMAGE_PackageToModule: lib.sym("JIMAGE_PackageToModule\0")?,
JIMAGE_FindResource: lib.sym("JIMAGE_FindResource\0")?,
JIMAGE_GetResource: lib.sym("JIMAGE_GetResource\0")?,
JIMAGE_ResourceIterator: lib.sym("JIMAGE_ResourceIterator\0")?,
})}
}
}
impl TryFrom<minidl::Library> for Library {
type Error = io::Error;
fn try_from(lib: minidl::Library) -> io::Result<Self> {
Library::from(lib)
}
}