*/
#include <string.h>
+#include <glib.h>
#include "nnstreamer.h"
#include "ml-api-internal.h"
}
/**
+ * @brief error reporting infra
+ */
+#define _ML_ERRORMSG_LENGTH (4096)
+static char errormsg[_ML_ERRORMSG_LENGTH] = { 0 }; /* one page limit */
+
+static int reported = 0;
+G_LOCK_DEFINE_STATIC (errlock);
+
+/**
* @brief public API function of error reporting.
*/
const char *
ml_error (void)
{
- /** @todo NYI **/
- return NULL;
+ G_LOCK (errlock);
+ if (reported != 0) {
+ errormsg[0] = '\0';
+ reported = 0;
+ }
+ if (errormsg[0] == '\0') {
+ G_UNLOCK (errlock);
+ return NULL;
+ }
+
+ reported = 1;
+
+ G_UNLOCK (errlock);
+ return errormsg;
}
/**
+ * @brief Internal interface to write messages for ml_error()
+ */
+void
+_ml_error_report (const char *message)
+{
+ G_LOCK (errlock);
+ strncpy (errormsg, message, _ML_ERRORMSG_LENGTH);
+ errormsg[_ML_ERRORMSG_LENGTH - 1] = '\0';
+ reported = 0;
+ G_UNLOCK (errlock);
+}
+
+static const char *strerrors[] = {
+ [0] = "Not an error",
+ [EINVAL] =
+ "Invalid parameters are given to a function. Check parameter values. (EINVAL)",
+};
+
+/**
* @brief public API function of error code descriptions
*/
const char *
ml_strerror (int errnum)
{
- /** @todo NYI **/
- return NULL;
+ int size = sizeof (strerrors) / sizeof (strerrors[0]);
+ if (errnum < 0 || errnum >= size)
+ return NULL;
+ return strerrors[errnum];
}
int ml_tizen_set_feature_state (int state);
/****** TIZEN CHECK FEATURE ENDS *****/
#endif /* __TIZEN__ */
+
+
+/***** Begin: Error reporting internal interfaces ****
+ * ml-api-* implementation needs to use these interfaces to provide
+ * proper error messages for ml_error();
+ */
+
+/**
+ * @brief Call when an error occurs during API execution.
+ * @param[in] message The error description
+ */
+void _ml_error_report (const char *message);
+
+#define _ml_error_report_return (errno, message) do { \
+ _ml_error_report (message); \
+ return errno; \
+} while(0)
+
+/***** End: Error reporting internal interfaces *****/
+
+
#ifdef __cplusplus
}
#endif /* __cplusplus */