2023-07-14 16:52:12 +03:00
|
|
|
#ifndef NIX_API_UTIL_INTERNAL_H
|
|
|
|
#define NIX_API_UTIL_INTERNAL_H
|
|
|
|
|
|
|
|
#include <string>
|
2023-08-11 12:49:10 +03:00
|
|
|
#include <optional>
|
2023-07-14 16:52:12 +03:00
|
|
|
|
2023-08-11 12:49:10 +03:00
|
|
|
#include "error.hh"
|
|
|
|
#include "nix_api_util.h"
|
2023-07-14 16:52:12 +03:00
|
|
|
|
2023-08-28 17:45:02 +03:00
|
|
|
struct nix_c_context
|
|
|
|
{
|
|
|
|
nix_err last_err_code = NIX_OK;
|
|
|
|
std::optional<std::string> last_err = {};
|
|
|
|
std::optional<nix::ErrorInfo> info = {};
|
|
|
|
std::string name = "";
|
2023-07-14 16:52:12 +03:00
|
|
|
};
|
|
|
|
|
2023-08-28 17:45:02 +03:00
|
|
|
nix_err nix_context_error(nix_c_context * context);
|
2023-07-14 16:52:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal use only.
|
|
|
|
*
|
2024-03-29 11:01:16 +02:00
|
|
|
* Helper to invoke nix_get_string_callback
|
2023-07-14 16:52:12 +03:00
|
|
|
* @param context optional, the context to store errors in if this function
|
|
|
|
* fails
|
2024-03-27 18:50:36 +02:00
|
|
|
* @param str The string to observe
|
|
|
|
* @param callback Called with the observed string.
|
|
|
|
* @param user_data optional, arbitrary data, passed to the callback when it's called.
|
|
|
|
* @return NIX_OK if there were no errors.
|
2024-03-29 11:01:16 +02:00
|
|
|
* @see nix_get_string_callback
|
2023-07-14 16:52:12 +03:00
|
|
|
*/
|
2024-04-15 13:05:57 +03:00
|
|
|
nix_err call_nix_get_string_callback(const std::string str, nix_get_string_callback callback, void * user_data);
|
2023-08-28 17:45:02 +03:00
|
|
|
|
|
|
|
#define NIXC_CATCH_ERRS \
|
|
|
|
catch (...) \
|
|
|
|
{ \
|
|
|
|
return nix_context_error(context); \
|
|
|
|
} \
|
|
|
|
return NIX_OK;
|
|
|
|
|
|
|
|
#define NIXC_CATCH_ERRS_RES(def) \
|
|
|
|
catch (...) \
|
|
|
|
{ \
|
|
|
|
nix_context_error(context); \
|
|
|
|
return def; \
|
|
|
|
}
|
2023-07-14 16:52:12 +03:00
|
|
|
#define NIXC_CATCH_ERRS_NULL NIXC_CATCH_ERRS_RES(nullptr)
|
|
|
|
|
|
|
|
#endif // NIX_API_UTIL_INTERNAL_H
|