Geofence3 / src /

main.c

  1. /*
  2. * Copyright (c) 2016 Samsung Electronics Co., Ltd
  3. *
  4. * Licensed under the Flora License, Version 1.1 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://floralicense.org/license/
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. #include <app.h>
  18. #include <Elementary.h>
  19. #include <system_settings.h>
  20. #include <efl_extension.h>
  21. #include <dlog.h>
  22.  
  23. #include "$(appName).h"
  24. #include "view.h"
  25. #include "data.h"
  26.  
  27. /**
  28. * @brief Hook to take necessary actions before main event loop starts.
  29. * Initialize UI resources and application's data.
  30. * If this function returns true, the main loop of application starts.
  31. * If this function returns false, the application is terminated.
  32. */
  33. static bool app_create(void *user_data)
  34. {
  35. appdata_s *ad = (appdata_s *)user_data;
  36.  
  37. /* Initialize all resources. */
  38. data_initialize(ad);
  39.  
  40. /* create view */
  41. if (view_create(ad) == EINA_FALSE) {
  42. dlog_print(DLOG_ERROR, LOG_TAG, "view_create fail.");
  43.  
  44. /* destroy view */
  45. view_destroy();
  46. return false;
  47. }
  48.  
  49. return true;
  50. }
  51.  
  52. /**
  53. * @brief This callback function is called when another application
  54. * sends a launch request to the application.
  55. */
  56. static void app_control(app_control_h app_control, void *user_data)
  57. {
  58. /* Handle the launch request. */
  59. }
  60.  
  61. /**
  62. * @brief This callback function is called each time
  63. * the application is completely obscured by another application
  64. * and becomes invisible to the user.
  65. */
  66. static void app_pause(void *user_data)
  67. {
  68. /* Take necessary actions when application becomes invisible. */
  69. }
  70.  
  71. /**
  72. * @brief This callback function is called each time
  73. * the application becomes visible to the user.
  74. */
  75. static void app_resume(void *user_data)
  76. {
  77. /* Take necessary actions when application becomes visible. */
  78. }
  79.  
  80. /**
  81. * @brief This callback function is called once after the main loop of the application exits.
  82. */
  83. static void app_terminate(void *user_data)
  84. {
  85. appdata_s *ad = (appdata_s *)user_data;
  86.  
  87. /* Release all resources. */
  88. data_finalize(ad);
  89. }
  90.  
  91. /**
  92. * @brief This function will be called when the language is changed.
  93. */
  94. static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
  95. {
  96. /* APP_EVENT_LANGUAGE_CHANGED */
  97. char *locale = NULL;
  98.  
  99. system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
  100.  
  101. if (locale != NULL) {
  102. elm_language_set(locale);
  103. free(locale);
  104. }
  105. return;
  106. }
  107.  
  108. /**
  109. * @brief Main function of the application.
  110. */
  111. int main(int argc, char *argv[])
  112. {
  113. /* Application data. */
  114. appdata_s ad = {{0}, };
  115. int ret;
  116.  
  117. ui_app_lifecycle_callback_s event_callback = {0, };
  118. app_event_handler_h handlers[5] = {NULL, };
  119.  
  120. event_callback.create = app_create;
  121. event_callback.terminate = app_terminate;
  122. event_callback.pause = app_pause;
  123. event_callback.resume = app_resume;
  124. event_callback.app_control = app_control;
  125.  
  126. /*
  127. * If you want to handle more events,
  128. * please check the application lifecycle guide.
  129. */
  130. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
  131.  
  132. ret = ui_app_main(argc, argv, &event_callback, &ad);
  133. if (ret != APP_ERROR_NONE)
  134. dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() failed. err = %d", ret);
  135.  
  136. return ret;
  137. }