[niepce] npc-fwk: use cxx for Exempi, misc function
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] npc-fwk: use cxx for Exempi, misc function
- Date: Sun, 16 Oct 2022 02:25:37 +0000 (UTC)
commit 4c63e3f59598e036a12bc1961170ea93005cc3d8
Author: Hubert Figuière <hub figuiere net>
Date: Sat Oct 15 12:20:34 2022 -0400
npc-fwk: use cxx for Exempi, misc function
- Also remove some unused Date bindings
crates/npc-fwk/src/base/date.rs | 9 -----
crates/npc-fwk/src/lib.rs | 58 ++++++++++++++----------------
crates/npc-fwk/src/utils/exempi.rs | 14 --------
src/fwk/base/date.cpp | 7 +---
src/fwk/base/date.hpp | 3 +-
src/fwk/toolkit/metadatawidget.cpp | 2 +-
src/fwk/toolkit/t/testconfigdatabinder.cpp | 2 +-
src/fwk/utils/exempi.cpp | 9 -----
src/fwk/utils/exempi.hpp | 5 +--
src/niepce/main.cpp | 4 +--
src/niepce/modules/map/mapmodule.cpp | 10 +++---
src/rust_bindings.hpp | 1 -
12 files changed, 38 insertions(+), 86 deletions(-)
---
diff --git a/crates/npc-fwk/src/base/date.rs b/crates/npc-fwk/src/base/date.rs
index d7b5ad71..080e1423 100644
--- a/crates/npc-fwk/src/base/date.rs
+++ b/crates/npc-fwk/src/base/date.rs
@@ -33,15 +33,6 @@ pub fn xmp_date_from(d: &chrono::DateTime<chrono::Utc>) -> exempi::DateTime {
xmp_date
}
-/// Delete a %Date object
-///
-/// # Safety
-/// Dereference the raw pointer.
-#[no_mangle]
-pub unsafe extern "C" fn fwk_date_delete(date: *mut Date) {
- drop(Box::from_raw(date));
-}
-
#[no_mangle]
pub extern "C" fn fwk_date_to_string(date: &Date) -> *mut libc::c_char {
CString::new(date.to_string().as_bytes())
diff --git a/crates/npc-fwk/src/lib.rs b/crates/npc-fwk/src/lib.rs
index 236f04a2..ac5057f9 100644
--- a/crates/npc-fwk/src/lib.rs
+++ b/crates/npc-fwk/src/lib.rs
@@ -33,39 +33,7 @@ pub use self::base::date::*;
pub use self::toolkit::mimetype::MimeType;
-use libc::c_char;
use std::f64;
-use std::ffi::CStr;
-
-/// Convert a gps coord (in string format) to a decimal (floating point)
-///
-/// # Safety
-/// Dereference the pointer.
-#[no_mangle]
-pub unsafe extern "C" fn fwk_gps_coord_from_xmp(cvalue: *const c_char) -> f64 {
- let value = CStr::from_ptr(cvalue);
- if let Ok(svalue) = value.to_str() {
- if let Some(coord) = gps_coord_from_xmp(svalue) {
- return coord;
- }
- }
- f64::NAN
-}
-
-/// Convert a fraction (in string format) to a decimal (floating point)
-///
-/// # Safety
-/// Dereference the pointer.
-#[no_mangle]
-pub unsafe extern "C" fn fwk_fraction_to_decimal(cvalue: *const c_char) -> f64 {
- let value = CStr::from_ptr(cvalue);
- if let Ok(svalue) = value.to_str() {
- if let Some(dec) = fraction_to_decimal(svalue) {
- return dec;
- }
- }
- f64::NAN
-}
///
/// Init funtion because rexiv2 need one.
@@ -90,6 +58,18 @@ fn configuration_new(file: &str) -> cxx::SharedPtr<ffi::SharedConfiguration> {
})
}
+fn exempi_manager_new() -> Box<ExempiManager> {
+ Box::new(ExempiManager::new(None))
+}
+
+pub fn gps_coord_from_xmp_(value: &str) -> f64 {
+ gps_coord_from_xmp(value).unwrap_or(f64::NAN)
+}
+
+pub fn fraction_to_decimal_(value: &str) -> f64 {
+ fraction_to_decimal(value).unwrap_or(f64::NAN)
+}
+
#[cxx::bridge(namespace = "fwk")]
mod ffi {
struct SharedConfiguration {
@@ -110,4 +90,18 @@ mod ffi {
#[cxx_name = "setValue"]
fn set_value(&self, key: &str, value: &str);
}
+
+ extern "Rust" {
+ type ExempiManager;
+
+ #[cxx_name = "ExempiManager_new"]
+ fn exempi_manager_new() -> Box<ExempiManager>;
+ }
+
+ extern "Rust" {
+ #[cxx_name = "gps_coord_from_xmp"]
+ fn gps_coord_from_xmp_(value: &str) -> f64;
+ #[cxx_name = "fraction_to_decimal"]
+ fn fraction_to_decimal_(value: &str) -> f64;
+ }
}
diff --git a/crates/npc-fwk/src/utils/exempi.rs b/crates/npc-fwk/src/utils/exempi.rs
index c9d7debf..95b39a50 100644
--- a/crates/npc-fwk/src/utils/exempi.rs
+++ b/crates/npc-fwk/src/utils/exempi.rs
@@ -512,20 +512,6 @@ pub fn xmp_date_from_exif(d: &str) -> Option<exempi::DateTime> {
Some(xmp_date)
}
-#[no_mangle]
-pub extern "C" fn fwk_exempi_manager_new() -> *mut ExempiManager {
- Box::into_raw(Box::new(ExempiManager::new(None)))
-}
-
-/// Delete the ExempiManager
-///
-/// # Safety
-/// Dereference the pointer.
-#[no_mangle]
-pub unsafe extern "C" fn fwk_exempi_manager_delete(em: *mut ExempiManager) {
- drop(Box::from_raw(em));
-}
-
#[cfg(test)]
mod tests {
use super::xmp_date_from_exif;
diff --git a/src/fwk/base/date.cpp b/src/fwk/base/date.cpp
index 2a61bb40..119be8bf 100644
--- a/src/fwk/base/date.cpp
+++ b/src/fwk/base/date.cpp
@@ -1,7 +1,7 @@
/*
* niepce - fwk/base/date.cpp
*
- * Copyright (C) 2012-2020 Hubert Figuière
+ * Copyright (C) 2012-2022 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -34,11 +34,6 @@ extern "C" char* fwk_date_to_string(const fwk::Date*);
namespace fwk {
-DatePtr date_wrap(fwk::Date* date)
-{
- return DatePtr(date, ffi::fwk_date_delete);
-}
-
std::string date_to_string(const Date* d)
{
DBG_ASSERT(d, "d is nullptr");
diff --git a/src/fwk/base/date.hpp b/src/fwk/base/date.hpp
index a5442619..56ac9938 100644
--- a/src/fwk/base/date.hpp
+++ b/src/fwk/base/date.hpp
@@ -1,7 +1,7 @@
/*
* niepce - fwk/base/date.hpp
*
- * Copyright (C) 2012-2017 Hubert Figuiere
+ * Copyright (C) 2012-2022 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,7 +38,6 @@ bool make_xmp_date_time(time_t t, XmpDateTime& xmp_dt);
typedef std::shared_ptr<Date> DatePtr;
-DatePtr date_wrap(Date*);
std::string date_to_string(const Date*);
}
diff --git a/src/fwk/toolkit/metadatawidget.cpp b/src/fwk/toolkit/metadatawidget.cpp
index 2c9df534..785f9b85 100644
--- a/src/fwk/toolkit/metadatawidget.cpp
+++ b/src/fwk/toolkit/metadatawidget.cpp
@@ -276,7 +276,7 @@ bool MetaDataWidget::set_fraction_dec_data(Gtk::Widget* w,
const std::string str_value = fwk::property_value_get_string(*value);
DBG_OUT("set fraction dec %s", str_value.c_str());
std::string frac = str(boost::format("%.1f")
- % ffi::fwk_fraction_to_decimal(str_value.c_str()));
+ % fwk::fraction_to_decimal(str_value));
AutoFlag flag(m_update);
static_cast<Gtk::Label*>(w)->set_text(frac);
}
diff --git a/src/fwk/toolkit/t/testconfigdatabinder.cpp b/src/fwk/toolkit/t/testconfigdatabinder.cpp
index e80a5c76..c69d8373 100644
--- a/src/fwk/toolkit/t/testconfigdatabinder.cpp
+++ b/src/fwk/toolkit/t/testconfigdatabinder.cpp
@@ -1,7 +1,7 @@
/*
* niepce - fwk/toolkit/testdatabinder.cpp
*
- * Copyright (C) 2013-2018 Hubert Figuiere
+ * Copyright (C) 2013-2022 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/src/fwk/utils/exempi.cpp b/src/fwk/utils/exempi.cpp
index 5ec23c70..aa9fd76d 100644
--- a/src/fwk/utils/exempi.cpp
+++ b/src/fwk/utils/exempi.cpp
@@ -29,15 +29,6 @@ const char* UFRAW_INTEROP_NAMESPACE =
const char* UFRAW_INTEROP_NS_PREFIX = "ufrint";
}
-namespace fwk {
-
-ExempiManagerPtr exempi_manager_new()
-{
- return ExempiManagerPtr(ffi::fwk_exempi_manager_new(),
- &ffi::fwk_exempi_manager_delete);
-}
-}
-
/*
Local Variables:
mode:c++
diff --git a/src/fwk/utils/exempi.hpp b/src/fwk/utils/exempi.hpp
index 5f84ee98..35607c0f 100644
--- a/src/fwk/utils/exempi.hpp
+++ b/src/fwk/utils/exempi.hpp
@@ -1,7 +1,7 @@
/*
* niepce - utils/exempi.h
*
- * Copyright (C) 2007-2013 Hubert Figuiere
+ * Copyright (C) 2007-2022 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -87,9 +87,6 @@ extern const char * UFRAW_INTEROP_NS_PREFIX;
namespace fwk {
class XmpMeta;
-typedef std::shared_ptr<ExempiManager> ExempiManagerPtr;
-
-ExempiManagerPtr exempi_manager_new();
}
diff --git a/src/niepce/main.cpp b/src/niepce/main.cpp
index d119fb84..0e3eeea3 100644
--- a/src/niepce/main.cpp
+++ b/src/niepce/main.cpp
@@ -1,7 +1,7 @@
/*
* niepce - main/main.cpp
*
- * Copyright (C) 2007-2020 Hubert Figuière
+ * Copyright (C) 2007-2022 Hubert Figuière
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -36,7 +36,7 @@ int main(int argc, char ** argv)
fwk::utils::init();
- fwk::ExempiManagerPtr manager = fwk::exempi_manager_new();
+ auto manager = fwk::ExempiManager_new();
fwk::Application::Ptr app = ui::NiepceApplication::create(argc, argv);
return fwk::Application::main(app, argc, argv);
diff --git a/src/niepce/modules/map/mapmodule.cpp b/src/niepce/modules/map/mapmodule.cpp
index 98b68f18..7a32fab0 100644
--- a/src/niepce/modules/map/mapmodule.cpp
+++ b/src/niepce/modules/map/mapmodule.cpp
@@ -1,7 +1,7 @@
/*
* niepce - modules/map/mapmodule.cpp
*
- * Copyright (C) 2014-2017 Hubert Figuiere
+ * Copyright (C) 2014-2022 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,8 @@
#include "engine/db/libmetadata.hpp"
#include "mapmodule.hpp"
+#include "rust_bindings.hpp"
+
namespace mapm {
MapModule::MapModule(const ui::IModuleShell & shell)
@@ -90,8 +92,7 @@ MapModule::on_lib_notification(const eng::LibNotification &ln)
fwk::PropertyValuePtr val = result.unwrap();
// it is a string
if (fwk_property_value_is_string(val.get())) {
- longitude = ffi::fwk_gps_coord_from_xmp(
- fwk::property_value_get_string(*val).c_str());
+ longitude = fwk::gps_coord_from_xmp(fwk::property_value_get_string(*val));
}
}
result = fwk::get_value_for_property(*properties, ffi::NiepcePropertyIdx::NpExifGpsLatProp);
@@ -99,8 +100,7 @@ MapModule::on_lib_notification(const eng::LibNotification &ln)
fwk::PropertyValuePtr val = result.unwrap();
// it is a string
if (fwk_property_value_is_string(val.get())) {
- latitude = ffi::fwk_gps_coord_from_xmp(
- fwk::property_value_get_string(*val).c_str());
+ latitude = fwk::gps_coord_from_xmp(fwk::property_value_get_string(*val));
}
}
diff --git a/src/rust_bindings.hpp b/src/rust_bindings.hpp
index 15052fc7..86a72c72 100644
--- a/src/rust_bindings.hpp
+++ b/src/rust_bindings.hpp
@@ -40,7 +40,6 @@ struct NiepcePropertySet;
namespace fwk {
typedef std::shared_ptr<SharedConfiguration> ConfigurationPtr;
-typedef ffi::ExempiManager ExempiManager;
typedef ffi::PropertyValue PropertyValue;
typedef ffi::NiepcePropertyBag PropertyBag;
typedef ffi::NiepcePropertySet PropertySet;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]