Piano / src /

main-app.c

  1. /*
  2. * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
  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 "main-app.h"
  18. #include "player/piano-player.h"
  19. #include "logger.h"
  20. #include "view/piano-impl-view.h"
  21. #include <stdlib.h>
  22. #include <Elementary.h>
  23. #include <app.h>
  24.  
  25. /* app event callbacks */
  26. static bool _on_create_cb(void *user_data);
  27. static void _on_terminate_cb(void *user_data);
  28. static void _on_pause_cb(void *user_data);
  29. static void _on_resume_cb(void *user_data);
  30. static void _on_app_control_cb(app_control_h app_control, void *user_data);
  31.  
  32. app_data *app_create()
  33. {
  34. app_data *app = calloc(1, sizeof(app_data));
  35.  
  36. return app;
  37. }
  38.  
  39. void app_destroy(app_data *app)
  40. {
  41. free(app);
  42. }
  43.  
  44. int app_run(app_data *app, int argc, char **argv)
  45. {
  46. if (!app) {
  47. return -1;
  48. }
  49.  
  50. ui_app_lifecycle_callback_s cbs = {
  51. .create = _on_create_cb,
  52. .terminate = _on_terminate_cb,
  53. .pause = _on_pause_cb,
  54. .resume = _on_resume_cb,
  55. .app_control = _on_app_control_cb
  56. };
  57.  
  58. return ui_app_main(argc, argv, &cbs, app);
  59. }
  60.  
  61. static bool _on_create_cb(void *user_data)
  62. {
  63. app_data *ad = user_data;
  64.  
  65. if (!ad) {
  66. return false;
  67. }
  68.  
  69. ad->win = win_create();
  70. if (!ad->win) {
  71. return false;
  72. }
  73.  
  74. piano_createview(ad);
  75. return true;
  76. }
  77.  
  78. static void _on_terminate_cb(void *user_data)
  79. {
  80. app_data *app = user_data;
  81.  
  82. if (!app) {
  83. return;
  84. }
  85.  
  86. piano_players_destroy(app);
  87. piano_clear_win(app);
  88. win_destroy(app->win);
  89. app->win = NULL;
  90. }
  91.  
  92. static void _on_pause_cb(void *user_data)
  93. {
  94. }
  95.  
  96. static void _on_resume_cb(void *user_data)
  97. {
  98. }
  99.  
  100. static void _on_app_control_cb(app_control_h app_control, void *user_data)
  101. {
  102. }