From: Hermet Park Date: Fri, 9 Sep 2016 05:02:12 +0000 (+0900) Subject: c++: concreted exceptional handlings. X-Git-Tag: submit/tizen/20160928.045111^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ee419c66be505e188bffb75359b86a957da8935f;p=platform%2Fcore%2Fuifw%2Fui-viewmgr.git c++: concreted exceptional handlings. reviewd & updated exceptional handling cases all over the code. Below Exception classes were introduced newly. UiIfaceException UiBaseException UiException Change-Id: I8c3fbc2f934f6efae522c0d1b7fa032b147b5299 --- diff --git a/src/examples/efl/c/main.cpp b/src/examples/efl/c/main.cpp index 0de5b65..fe37edd 100644 --- a/src/examples/efl/c/main.cpp +++ b/src/examples/efl/c/main.cpp @@ -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; diff --git a/src/examples/efl/cpp/main.cpp b/src/examples/efl/cpp/main.cpp index 7f01d87..c84b0bd 100644 --- a/src/examples/efl/cpp/main.cpp +++ b/src/examples/efl/cpp/main.cpp @@ -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; } diff --git a/src/include/efl/UiBaseViewManager.h b/src/include/efl/UiBaseViewManager.h index cc28255..4adbf21 100644 --- a/src/include/efl/UiBaseViewManager.h +++ b/src/include/efl/UiBaseViewManager.h @@ -30,4 +30,6 @@ #define UI_BASE_VIEWMGR dynamic_cast(ui_viewmanager::UiIfaceViewmgr::getInstance()) +typedef class ui_viewmanager::UiIfaceException UiBaseException; + #endif /* UI_BASE_VIEWMANAGER_H */ diff --git a/src/include/efl/mobile/UiApp.h b/src/include/efl/mobile/UiApp.h index 99cfc3e..8791f38 100644 --- a/src/include/efl/mobile/UiApp.h +++ b/src/include/efl/mobile/UiApp.h @@ -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. diff --git a/src/include/efl/mobile/UiMobileViewManager.h b/src/include/efl/mobile/UiMobileViewManager.h index a4e895c..4088fd5 100644 --- a/src/include/efl/mobile/UiMobileViewManager.h +++ b/src/include/efl/mobile/UiMobileViewManager.h @@ -28,4 +28,7 @@ #define UI_VIEWMGR (efl_viewmanager::UiApp::getInstance()->getViewmgr()) +typedef class ui_viewmanager::UiIfaceException UiException; + + #endif /* UI_MOBILE_VIEWMANAGER_H */ diff --git a/src/include/efl/mobile/c/ui_application.h b/src/include/efl/mobile/c/ui_application.h index 6f5073c..a524c10 100644 --- a/src/include/efl/mobile/c/ui_application.h +++ b/src/include/efl/mobile/c/ui_application.h @@ -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. diff --git a/src/include/interface/UiIfaceApp.h b/src/include/interface/UiIfaceApp.h index d0e6275..5b13aca 100644 --- a/src/include/interface/UiIfaceApp.h +++ b/src/include/interface/UiIfaceApp.h @@ -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 index 0000000..f259906 --- /dev/null +++ b/src/include/interface/UiIfaceException.h @@ -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_ */ diff --git a/src/include/interface/UiIfaceViewManager.h b/src/include/interface/UiIfaceViewManager.h index bdff91c..43afd98 100644 --- a/src/include/interface/UiIfaceViewManager.h +++ b/src/include/interface/UiIfaceViewManager.h @@ -57,6 +57,7 @@ #endif #include "UiIfaceTypes.h" +#include "UiIfaceException.h" #include "UiIfaceRotatable.h" #include "UiIfaceOverlay.h" #include "UiIfaceView.h" diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 21d0506..d74f09a 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -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 diff --git a/src/lib/efl/UiBaseViewmgr.cpp b/src/lib/efl/UiBaseViewmgr.cpp index d3b1e02..b1fb4c8 100644 --- a/src/lib/efl/UiBaseViewmgr.cpp +++ b/src/lib/efl/UiBaseViewmgr.cpp @@ -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); } diff --git a/src/lib/efl/mobile/c/ui_application.cpp b/src/lib/efl/mobile/c/ui_application.cpp index 3e4ee63..8a59512 100644 --- a/src/lib/efl/mobile/c/ui_application.cpp +++ b/src/lib/efl/mobile/c/ui_application.cpp @@ -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; } diff --git a/src/lib/interface/UiIfaceApp.cpp b/src/lib/interface/UiIfaceApp.cpp index 5a2b322..db0b08d 100644 --- a/src/lib/interface/UiIfaceApp.cpp +++ b/src/lib/interface/UiIfaceApp.cpp @@ -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, ®ion); 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 index 0000000..9fc5053 --- /dev/null +++ b/src/lib/interface/UiIfaceException.cpp @@ -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 +#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(); +} diff --git a/src/lib/interface/UiIfaceView.cpp b/src/lib/interface/UiIfaceView.cpp index 0be30e9..58bed2b 100644 --- a/src/lib/interface/UiIfaceView.cpp +++ b/src/lib/interface/UiIfaceView.cpp @@ -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; }