fix: include glue module

Co-authored-by: alemi <me@alemi.dev>
This commit is contained in:
zaaarf 2023-09-07 00:52:05 +02:00
parent 1b92d0052e
commit 4ed7704ff0
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C
2 changed files with 30 additions and 24 deletions

View file

@ -4,15 +4,16 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.4.5", features = ["global"] } codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.4.5", features = ["global", "sync"] }
jni = { version = "0.21.1", features = ["invocation"] } jni = { version = "0.21.1", features = ["invocation"] }
jni-sys = "0.3.0"
log = "0.4.20"
rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7"} rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7"}
[build-dependencies] [build-dependencies]
flapigen = "0.6.0" flapigen = "0.6.0"
rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7"} rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7"}
[lib] [lib]
crate_type = ["cdylib"] crate_type = ["cdylib"]
path = "src/main/rust/lib.rs" path = "src/main/rust/lib.rs"

View file

@ -5,58 +5,62 @@ use codemp::prelude::*;
use rifgen::rifgen_attr::generate_interface; use rifgen::rifgen_attr::generate_interface;
use crate::error::ErrorWrapper; use crate::error::ErrorWrapper;
pub mod glue {
include!(concat!(env!("OUT_DIR"), "/glue.rs"));
}
// #[generate_interface_doc] //TODO // #[generate_interface_doc] //TODO
struct CodeMPHandler {} struct CodeMPHandler {}
impl CodeMPHandler { impl CodeMPHandler {
#[generate_interface(constructor)] #[generate_interface(constructor)]
async fn new() -> CodeMPHandler { fn new() -> CodeMPHandler {
CodeMPHandler {} CodeMPHandler {}
} }
#[generate_interface] #[generate_interface]
async fn connect(addr: String) -> Result<(), String> { fn connect(addr: String) -> Result<(), String> {
convert(CODEMP_INSTANCE.connect(&addr).await) convert(CODEMP_INSTANCE.connect(&addr))
} }
#[generate_interface] #[generate_interface]
async fn join(session: String) -> Result<CursorHandler, String> { fn join(session: String) -> Result<CursorHandler, String> {
convert_cursor(CODEMP_INSTANCE.join(&session).await) convert_cursor(CODEMP_INSTANCE.join(&session))
} }
#[generate_interface] #[generate_interface]
async fn create(path: String) -> Result<(), String> { fn create(path: String) -> Result<(), String> {
convert(CODEMP_INSTANCE.create(&path, None).await) convert(CODEMP_INSTANCE.create(&path, None))
} }
#[generate_interface] #[generate_interface]
async fn create_with_content(path: String, content: String) -> Result<(), String> { fn create_with_content(path: String, content: String) -> Result<(), String> {
convert(CODEMP_INSTANCE.create(&path, Some(&content)).await) convert(CODEMP_INSTANCE.create(&path, Some(&content)))
} }
#[generate_interface] #[generate_interface]
async fn attach(path: String) -> Result<BufferHandler, String> { fn attach(path: String) -> Result<BufferHandler, String> {
convert_buffer(CODEMP_INSTANCE.attach(&path).await) convert_buffer(CODEMP_INSTANCE.attach(&path))
} }
#[generate_interface] #[generate_interface]
async fn get_cursor() -> Result<CursorHandler, String> { fn get_cursor() -> Result<CursorHandler, String> {
convert_cursor(CODEMP_INSTANCE.get_cursor().await) convert_cursor(CODEMP_INSTANCE.get_cursor())
} }
#[generate_interface] #[generate_interface]
async fn get_buffer(path: String) -> Result<BufferHandler, String> { fn get_buffer(path: String) -> Result<BufferHandler, String> {
convert_buffer(CODEMP_INSTANCE.get_buffer(&path).await) convert_buffer(CODEMP_INSTANCE.get_buffer(&path))
} }
#[generate_interface] #[generate_interface]
async fn leave_workspace() -> Result<(), String> { fn leave_workspace() -> Result<(), String> {
convert(CODEMP_INSTANCE.leave_workspace().await) convert(CODEMP_INSTANCE.leave_workspace())
} }
#[generate_interface] #[generate_interface]
async fn disconnect_buffer(path: String) -> Result<bool, String> { fn disconnect_buffer(path: String) -> Result<bool, String> {
convert(CODEMP_INSTANCE.disconnect_buffer(&path).await) convert(CODEMP_INSTANCE.disconnect_buffer(&path))
} }
} }
@ -73,24 +77,25 @@ fn convert<T>(result: Result<T, CodempError>) -> Result<T, String> {
} }
struct CursorHandler { struct CursorHandler {
#[allow(unused)]
cursor: Option<Arc<CodempCursorController>> cursor: Option<Arc<CodempCursorController>>
} }
impl CursorHandler { impl CursorHandler {
#[generate_interface(constructor)] #[generate_interface(constructor)]
async fn new() -> CursorHandler { //TODO: this sucks but whatever fn new() -> CursorHandler { //TODO: this sucks but whatever
panic!("Default constructor for CursrorHandler should never be called!") panic!("Default constructor for CursrorHandler should never be called!")
} }
} }
struct BufferHandler { struct BufferHandler {
#[allow(unused)]
buffer: Option<Arc<CodempBufferController>> buffer: Option<Arc<CodempBufferController>>
} }
impl BufferHandler { impl BufferHandler {
#[generate_interface(constructor)] #[generate_interface(constructor)]
async fn new() -> BufferHandler { //TODO: this sucks but whatever fn new() -> BufferHandler { //TODO: this sucks but whatever
panic!("Default constructor for BufferHandler should never be called!") panic!("Default constructor for BufferHandler should never be called!")
} }
} }