From 8bba2bc8d413b0aff7bc065f2a6e6b36274c209f Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 20 Aug 2018 20:10:32 +0900 Subject: [PATCH] lottieplayer: handling error code. Change-Id: I24c88fad24b821e18e7071e6bd82a828b8fd358e --- inc/lotcommon.h | 22 +++++++++++++++++++--- inc/lotplayer.h | 10 +++++----- src/binding/c/lottieplayer.cpp | 37 ++++++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/inc/lotcommon.h b/inc/lotcommon.h index d07369f..8223df1 100644 --- a/inc/lotcommon.h +++ b/inc/lotcommon.h @@ -1,5 +1,5 @@ -#ifndef _LOTCOMMON_H_ -#define _LOTCOMMON_H_ +#ifndef _LOT_COMMON_H_ +#define _LOT_COMMON_H_ #ifdef _WIN32 #ifdef LOT_BUILD @@ -23,6 +23,22 @@ #endif #endif + +/** + * @brief Enumeration for Lottie Player error code. + */ +typedef enum +{ + LOT_PLAYER_ERROR_NONE = 0, + LOT_PLAYER_ERROR_NOT_PERMITTED, + LOT_PLAYER_ERROR_OUT_OF_MEMORY, + LOT_PLAYER_ERROR_INVALID_PARAMETER, + LOT_PLAYER_ERROR_RESULT_OUT_OF_RANGE, + LOT_PLAYER_ERROR_ALREADY_IN_PROGRESS, + LOT_PLAYER_ERROR_UNKNOWN +} lotplayer_error_e; + + typedef struct LOTNode { #define ChangeFlagNone 0x0000 @@ -83,4 +99,4 @@ typedef struct LOTBuffer { bool clear; } lotbuf; -#endif // _LOTCOMMON_H_ +#endif // _LOT_COMMON_H_ diff --git a/inc/lotplayer.h b/inc/lotplayer.h index f1554b1..4fa589f 100644 --- a/inc/lotplayer.h +++ b/inc/lotplayer.h @@ -1,5 +1,5 @@ -#ifndef _LOTPLAYER_H_ -#define _LOTPLAYER_H_ +#ifndef _LOT_PLAYER_H_ +#define _LOT_PLAYER_H_ #include #include @@ -8,7 +8,7 @@ //TODO: Hide this. class LOTPlayerPrivate; -#define _LOTPLAYER_DECLARE_PRIVATE(A) \ +#define _LOT_PLAYER_DECLARE_PRIVATE(A) \ class A##Private *d; namespace lottieplayer { @@ -33,9 +33,9 @@ public: bool renderSync(float pos, LOTBuffer buffer, bool forceRender = false); private: - _LOTPLAYER_DECLARE_PRIVATE(LOTPlayer); + _LOT_PLAYER_DECLARE_PRIVATE(LOTPlayer); }; } // namespace lotplayer -#endif // _LOTPLAYER_H_ +#endif // _LOT_PLAYER_H_ diff --git a/src/binding/c/lottieplayer.cpp b/src/binding/c/lottieplayer.cpp index 9db88d7..b3ee6a8 100644 --- a/src/binding/c/lottieplayer.cpp +++ b/src/binding/c/lottieplayer.cpp @@ -1,4 +1,5 @@ #include +#include "vdebug.h" extern "C" { @@ -10,73 +11,83 @@ LOT_EXPORT lotplayer *lotplayer_create(void) { lotplayer* p = new LOTPlayer(); if (!p) { - //TODO: Print Error + vCritical << "Failed to initialize lotplayer"; } return p; } LOT_EXPORT int lotplayer_destroy(lotplayer *player) { - if (!player) return -1; + if (!player) return LOT_PLAYER_ERROR_INVALID_PARAMETER; delete(player); - return 0; + return LOT_PLAYER_ERROR_NONE; } LOT_EXPORT int lotplayer_set_file(lotplayer *player, const char *file) { - if (!player) return -1; + if (!player) return LOT_PLAYER_ERROR_INVALID_PARAMETER; bool ret = player->setFilePath(file); if (!ret) return -1; - return 0; + return LOT_PLAYER_ERROR_NONE; } LOT_EXPORT int lotplayer_set_size(lotplayer *player, int w, int h) { - if (!player) return -1; + if (!player) return LOT_PLAYER_ERROR_INVALID_PARAMETER; player->setSize(w, h); - return 0; + return LOT_PLAYER_ERROR_NONE; } LOT_EXPORT int lotplayer_get_size(const lotplayer *player, int* w, int* h) { - if (!player) return -1; + if (!player) return LOT_PLAYER_ERROR_INVALID_PARAMETER; player->size(*w, *h); - return 0; + return LOT_PLAYER_ERROR_NONE; } LOT_EXPORT float lotplayer_get_pos(const lotplayer *player) { - if (!player) return -1.0f; + if (!player) { + vWarning << "Invalid parameter player = nullptr"; + return -1.0f; + } return player->pos(); } LOT_EXPORT size_t lotplayer_get_node_count(const lotplayer *player, float pos) { - if (!player) return 0; + if (!player) return LOT_PLAYER_ERROR_NONE; return player->renderList(pos).size(); } LOT_EXPORT float lotplayer_get_playtime(const lotplayer *player) { - if (!player) return 0.0f; + if (!player) { + vWarning << "Invalid parameter player = nullptr"; + return 0.0f; + } return player->playTime(); } LOT_EXPORT const lotnode* lotplayer_get_node(lotplayer *player, float pos, size_t idx) { - if (!player) return nullptr; + if (!player) { + vWarning << "Invalid parameter player = nullptr"; + return nullptr; + } if (idx >= player->renderList(pos).size()) { + vWarning << "Invalid parameter idx? (0 ~ " << player->renderList(pos).size() << "), given idx = " << idx; return nullptr; } -- 2.7.4