link.rs 933 B

123456789101112131415161718192021222324252627282930313233343536
  1. use metadata::SpMetadata;
  2. use session::SpSession;
  3. use track::sp_track;
  4. use types::sp_error;
  5. use types::sp_error::*;
  6. use std::ffi::CStr;
  7. use std::rc::Rc;
  8. use libc::c_char;
  9. use librespot::link::Link;
  10. #[allow(non_camel_case_types)]
  11. pub type sp_link = Rc<Link>;
  12. #[no_mangle]
  13. pub unsafe extern "C" fn sp_link_create_from_string(uri: *const c_char) -> *mut sp_link {
  14. let uri = CStr::from_ptr(uri).to_string_lossy();
  15. let link = Link::from_str(&uri).unwrap();
  16. Box::into_raw(Box::new(Rc::new(link)))
  17. }
  18. #[no_mangle]
  19. pub unsafe extern "C" fn sp_link_release(c_link: *mut sp_link) -> sp_error {
  20. drop(Box::from_raw(c_link));
  21. SP_ERROR_OK
  22. }
  23. #[no_mangle]
  24. pub unsafe extern "C" fn sp_link_as_track(c_link: *mut sp_link) -> *mut sp_track {
  25. let link = &*c_link;
  26. let session = SpSession::global();
  27. let track = SpMetadata::from_future(link.as_track(&session.session).unwrap());
  28. Box::into_raw(Box::new(track))
  29. }