mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
t/file: Remove hacky file handling functions
This commit is contained in:
parent
2063bc30b8
commit
231d39185e
1
doc/changes/aux/mr.266.4.md
Normal file
1
doc/changes/aux/mr.266.4.md
Normal file
|
@ -0,0 +1 @@
|
|||
tracking: Remove all path hardcoded calibration data loading and saving functions.
|
|
@ -19,9 +19,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
static int
|
||||
mkpath(char *path);
|
||||
|
||||
static bool
|
||||
read_cv_mat(FILE *f, cv::Mat *m, const char *name);
|
||||
|
||||
|
@ -313,105 +310,12 @@ t_stereo_camera_calibration_save_v1(FILE *calib_file,
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Hack functions.
|
||||
*
|
||||
*/
|
||||
|
||||
extern "C" bool
|
||||
t_stereo_camera_calibration_load_v1_hack(
|
||||
struct t_stereo_camera_calibration **out_data)
|
||||
{
|
||||
const char *configuration_filename = "PS4_EYE";
|
||||
|
||||
char path_string[256]; //! @todo 256 maybe not enough
|
||||
//! @todo Use multiple env vars?
|
||||
char *config_path = secure_getenv("HOME");
|
||||
snprintf(path_string, 256, "%s/.config/monado/%s.calibration",
|
||||
config_path, configuration_filename); //! @todo Hardcoded 256
|
||||
|
||||
FILE *calib_file = fopen(path_string, "rb");
|
||||
if (calib_file == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = t_stereo_camera_calibration_load_v1(calib_file, out_data);
|
||||
|
||||
fclose(calib_file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
t_stereo_camera_calibration_save_v1_hack(
|
||||
struct t_stereo_camera_calibration *data)
|
||||
{
|
||||
char path_string[PATH_MAX];
|
||||
char file_string[PATH_MAX];
|
||||
// TODO: centralise this - use multiple env vars?
|
||||
char *config_path = secure_getenv("HOME");
|
||||
snprintf(path_string, PATH_MAX, "%s/.config/monado", config_path);
|
||||
snprintf(file_string, PATH_MAX, "%s/.config/monado/%s.calibration",
|
||||
config_path, "PS4_EYE");
|
||||
FILE *calib_file = fopen(file_string, "wb");
|
||||
if (!calib_file) {
|
||||
// try creating it
|
||||
mkpath(path_string);
|
||||
}
|
||||
calib_file = fopen(file_string, "wb");
|
||||
if (!calib_file) {
|
||||
printf(
|
||||
"ERROR. could not create calibration file "
|
||||
"%s\n",
|
||||
file_string);
|
||||
return false;
|
||||
}
|
||||
|
||||
t_stereo_camera_calibration_save_v1(calib_file, data);
|
||||
|
||||
fclose(calib_file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Helpers
|
||||
*
|
||||
*/
|
||||
|
||||
//! @todo Move this as it is a generic helper
|
||||
static int
|
||||
mkpath(char *path)
|
||||
{
|
||||
char tmp[PATH_MAX]; //!< @todo PATH_MAX probably not strictly correct
|
||||
char *p = nullptr;
|
||||
size_t len;
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s", path);
|
||||
len = strlen(tmp) - 1;
|
||||
if (tmp[len] == '/') {
|
||||
tmp[len] = 0;
|
||||
}
|
||||
|
||||
for (p = tmp + 1; *p; p++) {
|
||||
if (*p == '/') {
|
||||
*p = 0;
|
||||
if (mkdir(tmp, S_IRWXU) < 0 && errno != EEXIST)
|
||||
return -1;
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
|
||||
if (mkdir(tmp, S_IRWXU) < 0 && errno != EEXIST) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
write_cv_mat(FILE *f, cv::Mat *m)
|
||||
{
|
||||
|
|
|
@ -178,13 +178,6 @@ bool
|
|||
t_stereo_camera_calibration_load_v1(
|
||||
FILE *calib_file, struct t_stereo_camera_calibration **out_data);
|
||||
|
||||
/*!
|
||||
* Load a stereo calibration struct from a hardcoded place.
|
||||
*/
|
||||
bool
|
||||
t_stereo_camera_calibration_load_v1_hack(
|
||||
struct t_stereo_camera_calibration **out_data);
|
||||
|
||||
/*!
|
||||
* Save the given stereo calibration data to the given file.
|
||||
*/
|
||||
|
@ -192,14 +185,6 @@ bool
|
|||
t_stereo_camera_calibration_save_v1(FILE *calib_file,
|
||||
struct t_stereo_camera_calibration *data);
|
||||
|
||||
/*!
|
||||
* Save raw calibration data to file, hack until prober has storage for such
|
||||
* things.
|
||||
*/
|
||||
bool
|
||||
t_stereo_camera_calibration_save_v1_hack(
|
||||
struct t_stereo_camera_calibration *data);
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue