lottieplayer: handling error code. 75/187175/2
authorHermet Park <hermetpark@gmail.com>
Mon, 20 Aug 2018 11:10:32 +0000 (20:10 +0900)
committerSubhransu Mohanty <sub.mohanty@samsung.com>
Tue, 21 Aug 2018 02:24:10 +0000 (02:24 +0000)
Change-Id: I24c88fad24b821e18e7071e6bd82a828b8fd358e

inc/lotcommon.h
inc/lotplayer.h
src/binding/c/lottieplayer.cpp

index d07369f..8223df1 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _LOTCOMMON_H_
-#define _LOTCOMMON_H_
+#ifndef _LOT_COMMON_H_
+#define _LOT_COMMON_H_
 
 #ifdef _WIN32
 #ifdef LOT_BUILD
 #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_
index f1554b1..4fa589f 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _LOTPLAYER_H_
-#define _LOTPLAYER_H_
+#ifndef _LOT_PLAYER_H_
+#define _LOT_PLAYER_H_
 
 #include <future>
 #include <vector>
@@ -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_
index 9db88d7..b3ee6a8 100644 (file)
@@ -1,4 +1,5 @@
 #include <lotplayer.h>
+#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;
    }