reviewd & updated exceptional handling cases all over the code.
Below Exception classes were introduced newly.
UiIfaceException
UiBaseException
UiException
Change-Id: I8c3fbc2f934f6efae522c0d1b7fa032b147b5299
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.
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;
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;
}
#define UI_BASE_VIEWMGR dynamic_cast<efl_viewmanager::UiBaseViewmgr *>(ui_viewmanager::UiIfaceViewmgr::getInstance())
+typedef class ui_viewmanager::UiIfaceException UiBaseException;
+
#endif /* UI_BASE_VIEWMANAGER_H */
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.
#define UI_VIEWMGR (efl_viewmanager::UiApp::getInstance()->getViewmgr())
+typedef class ui_viewmanager::UiIfaceException UiException;
+
+
#endif /* UI_MOBILE_VIEWMANAGER_H */
* @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.
* 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:
/**
--- /dev/null
+/*
+ * 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_ */
#endif
#include "UiIfaceTypes.h"
+#include "UiIfaceException.h"
#include "UiIfaceRotatable.h"
#include "UiIfaceOverlay.h"
#include "UiIfaceView.h"
interface/UiIfaceView.cpp
interface/UiIfaceViewmgr.cpp
interface/UiIfaceApp.cpp
+ interface/UiIfaceException.cpp
efl/UiBaseView.cpp
efl/UiBaseViewmgr.cpp
efl/UiBaseKeyListener.cpp
interface/UiIfaceView.cpp
interface/UiIfaceViewmgr.cpp
interface/UiIfaceApp.cpp
+ interface/UiIfaceException.cpp
efl/UiBaseView.cpp
efl/UiBaseViewmgr.cpp
efl/UiBaseKeyListener.cpp
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;
//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.
//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);
}
{
}
- 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)
{
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);
}
{
ui_app_capi *app = g_app;
if (app) delete (app);
- else return false;
-
g_app = NULL;
-
return true;
}
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();
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, };
if (ret != APP_ERROR_NONE) {
LOGE("ui_app_main() is failed. err = %d", ret);
+ return false;
}
- return ret;
+ return true;
}
UiIfaceAppImpl::~UiIfaceAppImpl()
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;
}
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;
}
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);
}
--- /dev/null
+/*
+ * 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();
+}
this->_rotations = new int[count];
if (!this->_rotations) {
- LOGE("Allocation failed");
+ LOGE("Memory Allocation failed");
return false;
}