Add some logging

This commit is contained in:
Caelan Sayler
2024-11-15 20:24:22 +00:00
committed by Caelan
parent b9c08b92d8
commit d644444511
7 changed files with 16 additions and 4 deletions

View File

@@ -2,7 +2,7 @@
#include <optional>
#include <string>
#include <thread>
#include "Velopack.h"
#include "Velopack.hpp"
using namespace Velopack;

View File

@@ -8,7 +8,7 @@ fn main() {
.with_crate(crate_dir)
.with_documentation(true)
.with_language(cbindgen::Language::C)
.with_autogen_warning("// === THIS FILE IS AUTO-GENERATED - DO NOT EDIT ===")
.with_autogen_warning("/* THIS FILE IS AUTO-GENERATED - DO NOT EDIT */")
.with_include_guard("VELOPACK_H")
.with_cpp_compat(true)
.with_include_version(true)

View File

@@ -3,7 +3,7 @@
/* Generated with cbindgen:0.27.0 */
// === THIS FILE IS AUTO-GENERATED - DO NOT EDIT ===
/* THIS FILE IS AUTO-GENERATED - DO NOT EDIT */
#include <stdarg.h>
#include <stdbool.h>

View File

@@ -200,6 +200,7 @@ static inline char** to_cstring_array(const std::vector<std::string>& vec) {
#else
strcpy(result[i], vec[i].c_str()); // Copy string content
#endif
result[i][vec[i].size()] = '\0'; // Null-terminate the string
}
return result;
}
@@ -207,6 +208,7 @@ static inline char** to_cstring_array(const std::vector<std::string>& vec) {
static inline void free_cstring_array(char** arr, size_t size) {
for (size_t i = 0; i < size; ++i) {
delete[] arr[i];
arr[i] = nullptr;
}
delete[] arr;
}

View File

@@ -356,6 +356,6 @@ impl UpdateManagerOpaque {
impl Drop for UpdateManagerOpaque {
fn drop(&mut self) {
log::debug!("UpdateManagerOpaque dropped");
log::debug!("UpdateManagerOpaque freed");
}
}

View File

@@ -142,6 +142,7 @@ pub fn c_to_velopacklocatorconfig_opt(obj: *mut vpkc_locator_config_t) -> Option
#[rustfmt::skip]
pub unsafe fn allocate_velopacklocatorconfig(dto: VelopackLocatorConfig, obj: *mut vpkc_locator_config_t) {
if obj.is_null() { return; }
log::debug!("vpkc_locator_config_t allocated");
allocate_pathbuf(dto.RootAppDir, &mut (*obj).RootAppDir);
allocate_pathbuf(dto.UpdateExePath, &mut (*obj).UpdateExePath);
allocate_pathbuf(dto.PackagesDir, &mut (*obj).PackagesDir);
@@ -153,6 +154,7 @@ pub unsafe fn allocate_velopacklocatorconfig(dto: VelopackLocatorConfig, obj: *m
#[rustfmt::skip]
pub unsafe fn free_velopacklocatorconfig(obj: *mut vpkc_locator_config_t) {
if obj.is_null() { return; }
log::debug!("vpkc_locator_config_t freed");
free_pathbuf(&mut (*obj).RootAppDir);
free_pathbuf(&mut (*obj).UpdateExePath);
free_pathbuf(&mut (*obj).PackagesDir);
@@ -208,6 +210,7 @@ pub fn c_to_velopackasset_opt(obj: *mut vpkc_asset_t) -> Option<VelopackAsset> {
#[rustfmt::skip]
pub unsafe fn allocate_velopackasset(dto: VelopackAsset, obj: *mut vpkc_asset_t) {
if obj.is_null() { return; }
log::debug!("vpkc_asset_t allocated");
allocate_string(dto.PackageId, &mut (*obj).PackageId);
allocate_string(dto.Version, &mut (*obj).Version);
allocate_string(dto.Type, &mut (*obj).Type);
@@ -222,6 +225,7 @@ pub unsafe fn allocate_velopackasset(dto: VelopackAsset, obj: *mut vpkc_asset_t)
#[rustfmt::skip]
pub unsafe fn free_velopackasset(obj: *mut vpkc_asset_t) {
if obj.is_null() { return; }
log::debug!("vpkc_asset_t freed");
free_string(&mut (*obj).PackageId);
free_string(&mut (*obj).Version);
free_string(&mut (*obj).Type);
@@ -261,6 +265,7 @@ pub fn c_to_updateinfo_opt(obj: *mut vpkc_update_info_t) -> Option<UpdateInfo> {
#[rustfmt::skip]
pub unsafe fn allocate_updateinfo(dto: UpdateInfo, obj: *mut vpkc_update_info_t) {
if obj.is_null() { return; }
log::debug!("vpkc_update_info_t allocated");
allocate_velopackasset(dto.TargetFullRelease, &mut (*obj).TargetFullRelease);
(*obj).IsDowngrade = dto.IsDowngrade;
}
@@ -268,6 +273,7 @@ pub unsafe fn allocate_updateinfo(dto: UpdateInfo, obj: *mut vpkc_update_info_t)
#[rustfmt::skip]
pub unsafe fn free_updateinfo(obj: *mut vpkc_update_info_t) {
if obj.is_null() { return; }
log::debug!("vpkc_update_info_t freed");
free_velopackasset(&mut (*obj).TargetFullRelease);
}
@@ -307,6 +313,7 @@ pub fn c_to_updateoptions_opt(obj: *mut vpkc_update_options_t) -> Option<UpdateO
#[rustfmt::skip]
pub unsafe fn allocate_updateoptions(dto: UpdateOptions, obj: *mut vpkc_update_options_t) {
if obj.is_null() { return; }
log::debug!("vpkc_update_options_t allocated");
(*obj).AllowVersionDowngrade = dto.AllowVersionDowngrade;
allocate_string_opt(dto.ExplicitChannel, &mut (*obj).ExplicitChannel);
}
@@ -314,6 +321,7 @@ pub unsafe fn allocate_updateoptions(dto: UpdateOptions, obj: *mut vpkc_update_o
#[rustfmt::skip]
pub unsafe fn free_updateoptions(obj: *mut vpkc_update_options_t) {
if obj.is_null() { return; }
log::debug!("vpkc_update_options_t freed");
free_string(&mut (*obj).ExplicitChannel);
}
// !! AUTO-GENERATED-END RUST_TYPES

View File

@@ -99,6 +99,7 @@
sb.AppendLine($"pub unsafe fn allocate_{rs.Name.ToLower()}(dto: {rs.Name}, obj: *mut {cName}) {{");
using (sb.Indent()) {
sb.AppendLine("if obj.is_null() { return; }");
sb.AppendLine($"log::debug!(\"{cName} allocated\");");
foreach (var field in rs.Fields) {
if (field.Optional || field.Type == "PathBuf" || field.Type == "String" || nameMap.ContainsKey(field.Type)) {
sb.AppendLine($"allocate_{field.Type.ToLower()}{(field.Optional ? "_opt": "")}(dto.{field.Name}, &mut (*obj).{field.Name});");
@@ -114,6 +115,7 @@
sb.AppendLine($"pub unsafe fn free_{rs.Name.ToLower()}(obj: *mut {cName}) {{");
using (sb.Indent()) {
sb.AppendLine("if obj.is_null() { return; }");
sb.AppendLine($"log::debug!(\"{cName} freed\");");
foreach (var field in rs.Fields) {
if (field.Optional || field.Type == "PathBuf" || field.Type == "String" || nameMap.ContainsKey(field.Type)) {
sb.AppendLine($"free_{field.Type.ToLower()}(&mut (*obj).{field.Name});");