c++: concreted exceptional handlings. 69/87669/1
authorHermet Park <hermet@hermet.pe.kr>
Fri, 9 Sep 2016 05:02:12 +0000 (14:02 +0900)
committerHermet Park <hermet@hermet.pe.kr>
Fri, 9 Sep 2016 05:10:58 +0000 (14:10 +0900)
reviewd & updated exceptional handling cases all over the code.

Below Exception classes were introduced newly.

UiIfaceException
UiBaseException
UiException

Change-Id: I8c3fbc2f934f6efae522c0d1b7fa032b147b5299

15 files changed:
src/examples/efl/c/main.cpp
src/examples/efl/cpp/main.cpp
src/include/efl/UiBaseViewManager.h
src/include/efl/mobile/UiApp.h
src/include/efl/mobile/UiMobileViewManager.h
src/include/efl/mobile/c/ui_application.h
src/include/interface/UiIfaceApp.h
src/include/interface/UiIfaceException.h [new file with mode: 0644]
src/include/interface/UiIfaceViewManager.h
src/lib/CMakeLists.txt
src/lib/efl/UiBaseViewmgr.cpp
src/lib/efl/mobile/c/ui_application.cpp
src/lib/interface/UiIfaceApp.cpp
src/lib/interface/UiIfaceException.cpp [new file with mode: 0644]
src/lib/interface/UiIfaceView.cpp

index 0de5b656bd2aea392eb66459a3757304da418b94..fe37edd35171caaed3bf7f1d71eba7c4287b8a88 100644 (file)
@@ -26,10 +26,10 @@ main(int argc, char *argv[])
        ui_app_lifecycle_callback_s lifecycle_callback = {0, };
 
        //Initialize ui_app. ui_app initializes basic resources including ui_viewmgr internally.
-       if (!(ret = ui_application_init(PACKAGE, LOCALE_DIR)))
+       if (!ui_application_init(PACKAGE, LOCALE_DIR))
        {
-               dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_init() is failed. err = %d", ret);
-               return ret;
+               dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_init() is failed");
+               return 1;
        }
 
        //Register life cycle callback functions.
@@ -37,17 +37,17 @@ main(int argc, char *argv[])
        lifecycle_callback.app_control = app_control;
 
        //Run ui_app. Now it requests to run an application mainloop.
-       if ((ret = ui_application_run(argc, argv, &lifecycle_callback, NULL)))
+       if (!ui_application_run(argc, argv, &lifecycle_callback, NULL))
        {
-               dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_run() is failed. err = %d", ret);
-               return ret;
+               dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_run() is failed");
+               return 1;
        }
 
        //Terminate ui_app. Remove all ui_app resources.
-       if (!(ret = ui_application_term()))
+       if (!ui_application_term())
        {
-               dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_term() is failed. err = %d", ret);
-               return ret;
+               dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_term() is failed");
+               return 1;
        }
 
        return 0;
index 7f01d874ea25b97e93b29959a15b52a5a63082ac..c84b0bd25d273d8396a5596d3258a4f49f1059bd 100644 (file)
@@ -60,6 +60,12 @@ protected:
 
 int main(int argc, char *argv[])
 {
-       SampleApp app;
-       return app.run(argc, argv);
+       try {
+               SampleApp app = SampleApp();
+               app.run(argc, argv);
+       } catch (UiException& ex)
+       {
+               dlog_print(DLOG_ERROR, LOG_TAG, ex.getMessage());
+       }
+       return 0;
 }
index cc28255d2b0da2047d6756cb8417e45df5ebd05b..4adbf21587067efab81e5c0a61b1381c6ccd909d 100644 (file)
@@ -30,4 +30,6 @@
 
 #define UI_BASE_VIEWMGR dynamic_cast<efl_viewmanager::UiBaseViewmgr *>(ui_viewmanager::UiIfaceViewmgr::getInstance())
 
+typedef class ui_viewmanager::UiIfaceException UiBaseException;
+
 #endif /* UI_BASE_VIEWMANAGER_H */
index 99cfc3e3648577b280310a711db5d9faaeb3d0b9..8791f38bc0b99fd241ca5c3bdc5fa3f2929fe716 100644 (file)
@@ -23,21 +23,21 @@ namespace efl_viewmanager
 class UiViewmgr;
 
 /*
- *  @class UiIfaceApp
+ *  @class UiApp
  *
  *  @ingroup ui_viewmanager
  *
- *  @brief UiIfaceApp is designed for wrapping the application instance. This class hides unnecessary application settings but expose only basic functions
+ *  @brief UiApp is designed for wrapping the application instance. This class hides unnecessary application settings but expose only basic functions
  *         such as initialization and run. Basically, it works on the application life-cycle. It has application life-cycle event interfaces such as create(),
  *         pause(), resume(), terminate(), etc so that users can handle those events for the their application concept. Also, It provides system event
- *         interfaces such as low_baterry(), low_meomory(), lang_changed(), region_changed() and so on. UiIfaceApp create an unique UiViewmgr instance
+ *         interfaces such as low_baterry(), low_meomory(), lang_changed(), region_changed() and so on. UiApp create an unique UiViewmgr instance
  *         internally, and manage its life.
 */
 class UiApp : public ui_viewmanager::UiIfaceApp
 {
 public:
        /**
-        *  @brief This is a constructor for initializing UiPopup.
+        *  @brief This is a constructor for initializing UiApp.
         *
         *  @param pkg The name of package.
         *  @param loale_dir The path of locale directory.
index a4e895cc97cb61ed34080fbdc1bc7059f80a4c8d..4088fd5990f56239999afeb7d06e2c7f61a60f85 100644 (file)
@@ -28,4 +28,7 @@
 
 #define UI_VIEWMGR (efl_viewmanager::UiApp::getInstance()->getViewmgr())
 
+typedef class ui_viewmanager::UiIfaceException UiException;
+
+
 #endif /* UI_MOBILE_VIEWMANAGER_H */
index 6f5073cc3e0a3e7b828b6b88a3d96b3a2a3e254f..a524c10add583cf9e328004c26ed1100c77ee990 100644 (file)
@@ -38,9 +38,9 @@ EAPI bool ui_application_init(const char *pkg, const char *locale_dir);
  *  @param lifecycle_callback The set of callback functions to handle application lifecycle events.
  *  @param user_data The user data to be passed to the gieven @p life_cycle_callback functions.
  *
- *  @return 0 on success, otherwise a negative error value
+ *  @return @c true if it succeeds, @c false otherwise.
  */
-EAPI int ui_application_run(int argc, char **argv, ui_app_lifecycle_callback_s *lifecycle_callback, void *user_data);
+EAPI bool ui_application_run(int argc, char **argv, ui_app_lifecycle_callback_s *lifecycle_callback, void *user_data);
 
 /**
  *  @brief This is ui_application destructor.
index d0e6275983407d90b986cad397b6a8b4ec0aad11..5b13acacd05a65b2cf256f737cf88cfb939a785c 100644 (file)
@@ -69,8 +69,10 @@ public:
         *        create, terminate, pause, resume, app_control, APP_EVENT_LOW_BATTERY, APP_EVENT_LOW_MEMORY
         *        APP_EVENT_DEVICE_ORIENTATION_CHANGED, APP_EVENT_LANGUAGE_CHANGED, APP_EVENT_REGION_FORMAT_CHANGED.
         *        Application can add those events using wrapping functions by viewmgr supported.
+        *
+        *  @return @c true if it succeeds, @c false otherwise.
         */
-       virtual int run(int argc, char **argv);
+       virtual bool run(int argc, char **argv);
 
 protected:
        /**
diff --git a/src/include/interface/UiIfaceException.h b/src/include/interface/UiIfaceException.h
new file mode 100644 (file)
index 0000000..f259906
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+#ifndef _UI_IFACE_EXCEPTION_H_
+#define _UI_IFACE_EXCEPTION_H_
+
+namespace ui_viewmanager {
+
+class UiIfaceException
+{
+public:
+       UiIfaceException(const char *msg);
+       virtual ~UiIfaceException();
+       const char *getMessage();
+
+private:
+       _UI_DECLARE_PRIVATE_IMPL(UiIfaceException);
+};
+
+}
+
+#endif /* _UI_IFACE_EXCEPTION_H_ */
index bdff91ce25ef41e0100de8d4b43398c3853c09a6..43afd9839016614bb5e5295d2ca5b3150fb5d426 100644 (file)
@@ -57,6 +57,7 @@
 #endif
 
 #include "UiIfaceTypes.h"
+#include "UiIfaceException.h"
 #include "UiIfaceRotatable.h"
 #include "UiIfaceOverlay.h"
 #include "UiIfaceView.h"
index 21d050689aeda364939ace267d062c1364274331..d74f09a3fbe2b09b385b5ac3e0f8fe8011a9fcbb 100644 (file)
@@ -4,6 +4,7 @@ SET(SRCS
      interface/UiIfaceView.cpp
      interface/UiIfaceViewmgr.cpp
      interface/UiIfaceApp.cpp
+     interface/UiIfaceException.cpp
      efl/UiBaseView.cpp
      efl/UiBaseViewmgr.cpp
      efl/UiBaseKeyListener.cpp
@@ -22,6 +23,7 @@ SET(SRCS
      interface/UiIfaceView.cpp
      interface/UiIfaceViewmgr.cpp
      interface/UiIfaceApp.cpp
+     interface/UiIfaceException.cpp
      efl/UiBaseView.cpp
      efl/UiBaseViewmgr.cpp
      efl/UiBaseKeyListener.cpp
index d3b1e025a088c2f5bcfb4771719fb2e91d9643b2..b1fb4c8f94d3308a57cdcf7ce0dbbf07ebdce46a 100644 (file)
@@ -62,8 +62,6 @@ public:
        bool deactivate();
        UiBaseView *pushView(UiBaseView *view);
        bool popView();
-       bool insertViewBefore(UiBaseView *view, UiBaseView *before);
-       bool insertViewAfter(UiBaseView *view, UiBaseView *after);
 
        Evas_Object *getBase() {
                return this->_layout;
@@ -264,9 +262,11 @@ UiBaseViewmgrImpl::UiBaseViewmgrImpl(UiBaseViewmgr *viewmgr, const char *pkg, Ui
        //Window
        this->_win = elm_win_util_standard_add(pkg, pkg);
 
+       char buf[256];
+
        if (!this->_win) {
-               LOGE("Failed to create a window (%s)", pkg);
-               return;
+               snprintf(buf, sizeof(buf), "Failed to create a window (%s)", pkg);
+               throw UiBaseException(buf);
        }
 
        //FIXME: Make a method? to set available rotation degree.
@@ -301,24 +301,23 @@ UiBaseViewmgrImpl::UiBaseViewmgrImpl(UiBaseViewmgr *viewmgr, const char *pkg, Ui
 
        //FIXME: Make conformant configurable?
        if (!this->_createConformant(this->_win)) {
-               LOGE("Failed to create a conformant (%s)", pkg);
-               return;
+               snprintf(buf, sizeof(buf), "Failed to create a conformant (%s)", pkg);
+               throw UiBaseException(buf);
        }
 
        if (!this->_createScroller(this->_conform)) {
-               LOGE("Failed to create a scroller (%s)", pkg);
-               return;
+               snprintf(buf, sizeof(buf), "Failed to create a scroller (%s)", pkg);
+               throw UiBaseException(buf);
        }
 
        if (!this->_createBaseLayout(this->_scroller, "default")) {
-               LOGE("Failed to create a base layout (%s)", pkg);
-               return;
+               snprintf(buf, sizeof(buf), "Failed to create a base layout (%s)", pkg);
+               throw UiBaseException(buf);
        }
 
        //Set Indicator properties
        elm_win_indicator_mode_set(this->_win, ELM_WIN_INDICATOR_SHOW);
        elm_win_indicator_opacity_set(this->_win, ELM_WIN_INDICATOR_OPAQUE);
-
        elm_win_autodel_set(this->_win, EINA_TRUE);
 }
 
index 3e4ee63d3bea19768eaa583d0d62c9708ec85e82..8a59512b3ed1fe6b218cdec51b1ff2949d08c9a0 100644 (file)
@@ -56,7 +56,7 @@ public:
        {
        }
 
-       int run(int argc, char **argv, ui_app_lifecycle_callback_s *lifecycle_callback, void *user_data)
+       bool run(int argc, char **argv, ui_app_lifecycle_callback_s *lifecycle_callback, void *user_data)
        {
                if (lifecycle_callback)
                {
@@ -88,10 +88,14 @@ EAPI bool ui_application_init(const char *pkg, const char *locale_dir)
        return true;
 }
 
-EAPI int ui_application_run(int argc, char **argv, ui_app_lifecycle_callback_s *lifecycle_callback, void *user_data)
+EAPI bool ui_application_run(int argc, char **argv, ui_app_lifecycle_callback_s *lifecycle_callback, void *user_data)
 {
        ui_app_capi *app = g_app;
-       if (!app) return -1;
+       if (!app)
+       {
+               LOGE("ui_application is not initialized yet.");
+               return false;
+       }
 
        return app->run(argc, argv, lifecycle_callback, user_data);
 }
@@ -100,9 +104,6 @@ EAPI bool ui_application_term(void)
 {
        ui_app_capi *app = g_app;
        if (app) delete (app);
-       else return false;
-
        g_app = NULL;
-
        return true;
 }
index 5a2b3226b8c3e12c786bae89589153c521284f38..db0b08d93815427042e28d47fca34832097b0561 100644 (file)
@@ -38,7 +38,7 @@ public:
        UiIfaceAppImpl(UiIfaceApp *app, const char *pkg, const char *locale_dir, UiIfaceViewmgr* viewmgr);
        ~UiIfaceAppImpl();
 
-       int run(int argc, char **argv);
+       bool run(int argc, char **argv);
 
        bool init();
        bool onCreate();
@@ -132,7 +132,7 @@ UiIfaceAppImpl::UiIfaceAppImpl(UiIfaceApp *app, const char *pkg, const char *loc
        this->locale_dir = eina_stringshare_add(locale_dir);
 }
 
-int UiIfaceAppImpl::run(int argc, char **argv)
+bool UiIfaceAppImpl::run(int argc, char **argv)
 {
        ui_app_lifecycle_callback_s event_callback = { 0, };
        app_event_handler_h handlers[5] = { NULL, };
@@ -153,9 +153,10 @@ int UiIfaceAppImpl::run(int argc, char **argv)
 
        if (ret != APP_ERROR_NONE) {
                LOGE("ui_app_main() is failed. err = %d", ret);
+               return false;
        }
 
-       return ret;
+       return true;
 }
 
 UiIfaceAppImpl::~UiIfaceAppImpl()
@@ -226,7 +227,7 @@ void UiIfaceApp::onLangChanged(app_event_info_h event_info)
        char *language = NULL;
        int ret = app_event_get_language(event_info, &language);
        if (ret != APP_ERROR_NONE) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "app_event_get_language() failed. Err = %d.", ret);
+               LOGE("app_event_get_language() failed. Err = %d", ret);
                return;
        }
 
@@ -255,7 +256,7 @@ void UiIfaceApp::onRegionChanged(app_event_info_h event_info)
        char *region = NULL;
        int ret = app_event_get_region_format(event_info, &region);
        if (ret != APP_ERROR_NONE) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "model_app_event_get_region_format() failed. Err = %d", ret);
+               LOGE("app_event_get_region_format() failed. Err = %d", ret);
                return;
        }
 
@@ -295,14 +296,14 @@ void UiIfaceApp::onTerminate()
 UiIfaceApp::UiIfaceApp(const char *pkg, const char *locale_dir, UiIfaceViewmgr *viewmgr)
 {
        if (_inst) {
-               LOGE("You created UiIfaceApp multiple times!!");
+               throw UiIfaceException("Requested to create UiIfaceApp instance multiple times!!");
        }
        _inst = this;
 
        this->_impl = new UiIfaceAppImpl(this, pkg, locale_dir, viewmgr);
 }
 
-int UiIfaceApp::run(int argc, char **argv)
+bool UiIfaceApp::run(int argc, char **argv)
 {
        return this->_impl->run(argc, argv);
 }
diff --git a/src/lib/interface/UiIfaceException.cpp b/src/lib/interface/UiIfaceException.cpp
new file mode 100644 (file)
index 0000000..9fc5053
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+#include <string>
+#include "../../include/interface/UiIfaceViewManager.h"
+
+using namespace ui_viewmanager;
+using namespace std;
+
+/***********************************************************************************************/
+/* Internal class Implementation                                                               */
+/***********************************************************************************************/
+namespace ui_viewmanager
+{
+
+class UiIfaceExceptionImpl
+{
+public:
+       string msg;
+
+       UiIfaceExceptionImpl(const char *msg)
+       {
+               this->msg = string(msg);
+       }
+};
+
+}
+
+/***********************************************************************************************/
+/* External class Implementation                                                               */
+/***********************************************************************************************/
+
+UiIfaceException ::UiIfaceException(const char *msg)
+{
+       LOGE("%s", msg);
+       this->_impl = new UiIfaceExceptionImpl(msg);
+}
+
+UiIfaceException::~UiIfaceException()
+{
+       delete(this->_impl);
+}
+
+const char *UiIfaceException::getMessage()
+{
+       return this->_impl->msg.c_str();
+}
index 0be30e9ce8ced5cb75164a9b931214170d7bc55b..58bed2b48e34fff2c19fad573892d6557470f0f4 100644 (file)
@@ -180,7 +180,7 @@ bool UiIfaceViewImpl::setAvailableRotations(const int *rotations, unsigned int c
 
        this->_rotations = new int[count];
        if (!this->_rotations) {
-               LOGE("Allocation failed");
+               LOGE("Memory Allocation failed");
                return false;
        }