Fix camera start bs issue
[profile/ivi/camera.git] / src / cam.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.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
18 #include <stdio.h>
19 #include <pthread.h>
20 #include <X11/Xlib.h>
21 #include <utilX.h>
22 #include <power.h>
23 #include "cam.h"
24 #include "cam_app.h"
25 #include "camera_utils.h"
26 #include "cam_ta.h"
27 #include "cam_mm.h"
28 #include "cam_debug.h"
29 #include "cam_toolbar_edc_callback.h"
30 #include "cam_zoom_edc_callback.h"
31 #include "cam_indicator_edc_callback.h"
32 #include "cam_common_edc_callback.h"
33 #include "cam_rec.h"
34 #include "cam_file.h"
35 #include "cam_menu_composer.h"
36 #include "cam_device_capacity.h"
37
38
39 static int __is_idle_lock(void);
40
41 static int _is_running(void)
42 {
43 #ifdef CHECK_RUNNING_PROC
44         GDir *dir = NULL;
45         GError *error = NULL;
46         const gchar *dir_name;
47         char path[255] = { 0, };
48         char proc_name[255] = { 0, };
49         int fd = 0, count = 0;
50         dir = g_dir_open("/proc", 0, &error);
51
52         if (dir) {
53                 while ((dir_name = g_dir_read_name(dir)) != NULL) {
54                         if (!isdigit(dir_name[0]))
55                                 continue;
56
57                         snprintf(path, sizeof(path), "/proc/%s/cmdline",
58                                  dir_name);
59                         fd = open(path, O_RDONLY);
60                         read(fd, proc_name, sizeof(proc_name) - 1);
61                         close(fd);
62                         if (strstr(proc_name, "camera")) {
63                                 static int pid = 0;
64                                 count++;
65                                 if (count > 1) {
66                                         g_dir_close(dir);
67                                         printf
68                                             ("camera application[PID: %d] is already running !!!!\n\n",
69                                              pid);
70                                         return 1;
71                                 }
72                                 pid = atoi(dir_name);
73                         }
74                 }
75                 g_dir_close(dir);
76         } else {
77                 printf("cannot open proc directory [%s]", error->message);
78         }
79
80         if (error)
81                 g_error_free(error);
82
83         return 0;
84 #else
85         return 0;
86 #endif
87 }
88
89 static int __convert_orientation_to_angle(app_device_orientation_e orientation)
90 {
91         switch (orientation) {
92         case APP_DEVICE_ORIENTATION_0:
93                 return 0;
94                 break;
95         case APP_DEVICE_ORIENTATION_180:
96                 return 180;
97                 break;
98         case APP_DEVICE_ORIENTATION_270:
99                 return 270;
100                 break;
101         case APP_DEVICE_ORIENTATION_90:
102                 return 90;
103                 break;
104         default:
105                 return 0;
106         }
107 }
108
109 static bool cam_create(void *data)
110 {
111         CAM_TA_ACUM_ITEM_BEGIN("==cam_create==", 0);
112         cam_debug(LOG_UI, "************** cam_create START **************");
113
114         if (__is_idle_lock()) {
115                 return FALSE;/*fix crash*/
116         }
117
118         struct appdata *ad = data;
119         Ecore_X_Display *dpy = NULL;
120         debug_fenter(LOG_CAM);
121
122         /* create main window */
123         ad->win_main = cam_app_create_win(PACKAGE);
124         cam_retvm_if(ad->win_main == NULL, FALSE, "cam_app_create_win failed");
125 #ifdef EFL_TEMP_CODE
126         cam_win_transparent_set(ad);
127 #endif
128         /* remove effect */
129         dpy = ecore_x_display_get();
130         if (dpy) {
131                 Ecore_X_Window win;
132                 win = elm_win_xwindow_get(ad->win_main);
133
134                 printf("dpy is not null .. set no effect to display = %d\n",
135                        win);
136                 utilx_set_window_effect_style(dpy, win,
137                                               UTILX_EFFECT_TYPE_ROTATION,
138                                               UTILX_EFFECT_STYLE_NONE);
139         }
140
141         /* set indicator. */
142 #ifndef CAMERA_MACHINE_I686
143         elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_HIDE);
144 #endif
145
146
147         ad->evas = evas_object_evas_get(ad->win_main);
148         ad->ee = ecore_evas_ecore_evas_get(ad->evas);
149         ad->main_xid = elm_win_xwindow_get(ad->win_main);
150         ad->launch_type = CAM_LAUNCH_FIRST;
151
152         /* camera application initialization */
153         CAM_TA_ACUM_ITEM_BEGIN("  cam_app_init", 0);
154         if (!cam_app_init(ad))
155                 return FALSE;
156         CAM_TA_ACUM_ITEM_END("  cam_app_init", 0);
157
158         /*add camera exteral engine lib load*/
159         open_cam_ext_handle();
160
161         ad->rot_current = app_get_device_orientation();
162         ad->rot_previous = ad->rot_current;
163         int win_angle = elm_win_rotation_get(ad->win_main);
164         ad->angle = __convert_orientation_to_angle(ad->rot_current);
165
166         if(win_angle != ad->angle) {
167                 cam_critical(LOG_UI, "win_angle:%d device_angle:%d ", win_angle, ad->angle);
168                 elm_win_rotation_with_resize_set(ad->win_main, ad->angle);
169         }
170
171         evas_object_show(ad->win_main);
172
173         cam_debug(LOG_UI, "******** cam_create END**********");
174         CAM_TA_ACUM_ITEM_END("==cam_create==", 0);
175
176         return true;
177 }
178
179
180
181 static void cam_terminate(void *data)
182 {
183         cam_debug(LOG_UI, "############## cam_terminate ##############");
184
185         struct appdata *ad = (struct appdata *)data;
186         if (!ad) return;
187         ad->appcore_state = CAM_APPCORE_TERMINATE_STATE;
188
189
190         debug_fenter(LOG_CAM);
191
192         CAM_TA_ACUM_ITEM_BEGIN("cam_terminate", 0);
193
194         cam_key_grab_deinit(ad);
195
196 #ifdef USE_FIFO_THREAD
197         cam_app_FIFO_thread_exit();
198 #endif
199
200 #ifdef USE_FILE_REG_THREAD
201         cam_app_file_register_thread_exit(ad);
202 #endif
203
204         CAM_TA_ACUM_ITEM_BEGIN("  cam_app_quit", 0);
205         cam_app_quit(ad);
206         CAM_TA_ACUM_ITEM_END("  cam_app_quit", 0);
207
208 #ifdef ENABLE_CAM_POWER_CONTROL
209         power_unlock_state(POWER_STATE_NORMAL);
210 #endif
211
212         CAM_TA_ACUM_ITEM_END("app_terminate", 0);
213
214         CAM_TA_ACUM_ITEM_SHOW_RESULT_TO(CAM_TA_SHOW_FILE);
215         CAM_TA_RELEASE();
216
217         close_cam_ext_handle();
218 }
219
220 static void cam_pause(void *data)
221 {
222         cam_debug(LOG_UI, "############## cam_pause ##############");
223
224         struct appdata *ad = (struct appdata *)data;
225         cam_ret_if(ad == NULL);
226         CamAppData *camapp = ad->camapp_handle;
227         cam_ret_if(camapp == NULL);
228         debug_fenter(LOG_CAM);
229         ad->appcore_state = CAM_APPCORE_PAUSE_STATE;
230
231         if ( ad->launching_mode == CAM_LAUNCHING_MODE_EXTERNAL) {
232                 int mm_state = 0;
233                 mm_state = cam_mm_get_state();
234                 ad->appcore_state = CAM_APPCORE_PAUSE_STATE;
235
236                 if (mm_state < CAMERA_STATE_CAPTURING) { /* MM_CAMCORDER_STATE_CAPTURING < MM_CAMCORDER_STATE_RECORDING */
237                         if (ad->imageviewer_ug) { /*Is this paused by Video player ? */
238                                 DEBUG_TRACE("###### ug_pause() ######");
239                                 ug_pause();
240                                 return;
241                         } else {
242                                 cam_app_exit(ad);
243                                 return;
244                         }
245                 } else if (mm_state == RECORDER_STATE_RECORDING && camapp->camera_mode == CAM_CAMCORDER_MODE) {
246                         if (!cam_video_record_stop(ad)) {
247                                 DEBUG_TRACE("record stop fail");
248                                 return;
249                         }
250                 }
251         }
252
253         if (ad->imageviewer_ug) {
254                 DEBUG_TRACE("###### ug_pause() ######");
255                 ug_pause();
256         }
257
258         if (ad->foucs_out_from_quickview == TRUE) {
259                 DEBUG_TRACE("image viewer UG->image editor");
260                 ad->foucs_out_from_quickview = FALSE;
261
262 #ifdef ENABLE_CAM_POWER_CONTROL
263                 return;
264 #endif
265
266         }
267         CAM_TA_ACUM_ITEM_BEGIN("app_stop", 0);
268         DEBUG_TRACE(" ");
269         ad->foucs_out_from_quickview = FALSE;
270         ad->launch_type = CAM_LAUNCH_RELAUNCH;  /* set launch type */
271         cam_app_pause(ad);
272
273 #ifdef ENABLE_CAM_POWER_CONTROL
274         power_unlock_state(POWER_STATE_NORMAL);
275 #endif
276
277         CAM_TA_ACUM_ITEM_END("app_stop", 0);
278
279 }
280
281 static void cam_resume(void *data)
282 {
283         cam_debug(LOG_UI, "############## cam_resume ##############");
284
285         struct appdata *ad = (struct appdata *)data;
286         cam_ret_if(ad == NULL);
287         debug_fenter(LOG_CAM);
288         DEBUG_TRACE(" ");
289         CamAppData *camapp = ad->camapp_handle;
290         cam_ret_if(camapp == NULL);
291
292         ad->appcore_state = CAM_APPCORE_RESUME_STATE;
293
294         if (!cam_check_dir()) {
295                 cam_app_notice_popup(data, "Cannot make default path",
296                          cam_app_timeout_notice_response_cb);
297                 return;
298         }
299         if (!cam_utils_check_torchlight_status(ad)) {
300                 DEBUG_TRACE("Can not get torchlight status");
301         }
302
303         if (ad->imageviewer_ug) {       /* bug fix camera app overlab with imageviewer_ug */
304                 DEBUG_TRACE("####### ug_resume() ######");
305                 ug_resume();
306                 return;
307         }
308
309 #ifdef ENABLE_CAM_POWER_CONTROL
310         else
311                 power_lock_state(POWER_STATE_NORMAL, 0);
312 #endif
313
314         CAM_TA_INIT();
315
316         if (ad) {
317                 CAM_TA_ACUM_ITEM_BEGIN("  cam_app_resume", 0);
318                 if (!cam_app_resume(ad))
319                         return;
320                 CAM_TA_ACUM_ITEM_END("  cam_app_resume", 0);
321         }
322
323 }
324
325 static void cam_service(service_h service, void *user_data)
326 {
327         CAM_TA_ACUM_ITEM_BEGIN("==cam_service==", 0);
328         cam_debug(LOG_UI, "############## cam_service START##############");
329         struct appdata *ad = (struct appdata *)user_data;
330         cam_ret_if(ad == NULL);
331         CamAppData *camapp = ad->camapp_handle;
332         cam_ret_if(camapp == NULL);
333
334         DEBUG_TRACE("ad->launch_type = %d ", ad->launch_type);
335         gint latest_mode = 0;
336         ad->appcore_state = CAM_APPCORE_RESET_STATE;
337
338         if (!cam_check_dir()) {
339                 cam_app_notice_popup(ad, "Cannot make default path",
340                          cam_app_timeout_notice_response_cb);
341                 return;
342         }
343         if (!cam_utils_check_torchlight_status(ad)) {
344                 DEBUG_TRACE("Can not get torchlight status");
345         }
346         if (ad->launch_type == CAM_LAUNCH_IS_ALREADY_RUNNING) {
347                 cam_app_notice_popup(ad, "Camera is alreay running.",
348                                      cam_app_popup_response_cb);
349                 return;
350         }
351         /* remove exe args */
352         if (ad->exe_args) {
353                 if (ad->exe_args->caller) {
354                         free(ad->exe_args->caller);
355                         ad->exe_args->caller = NULL;
356                 }
357                 free(ad->exe_args);
358                 ad->exe_args = NULL;
359         }
360
361         char *operation = NULL;
362
363         int ret = service_get_operation(service, &operation);
364         if (ret != SERVICE_ERROR_NONE)
365         {
366                 cam_debug(LOG_UI, "service_get_operation failed");
367                 return;
368         }
369
370         if ( operation == NULL )
371         {
372                 cam_debug(LOG_UI, "operation is null");
373                 return;
374         }
375
376         ret = service_clone(&ad->service_handle, service);
377         if (ret != SERVICE_ERROR_NONE)
378         {
379                 cam_debug(LOG_UI, "service_clone failed");
380                 return;
381         }
382
383         CamExeArgs *args = (CamExeArgs *)malloc(sizeof(CamExeArgs));
384         if (args == NULL) {
385                 return;
386         }
387         memset(args,0,sizeof(CamExeArgs));
388
389         if (!cam_app_parse_args(args, service)) {
390                 return;
391         }
392         ad->exe_args = args;
393
394         if( strcmp(operation, SERVICE_OPERATION_CREATE_CONTENT ) == 0){
395                 cam_debug(LOG_UI, "Operation is SERVICE_OPERATION_CREATE_CONTENT");
396
397                 ad->launching_mode = CAM_LAUNCHING_MODE_EXTERNAL;
398
399
400                 CAM_TA_ACUM_ITEM_BEGIN("    cam_handle_init", 0);
401                 if (!cam_handle_init(ad, ad->exe_args->cam_mode)) {
402                         cam_critical(LOG_CAM, "cam_handle_init failed");
403                         return;
404                 }
405                 CAM_TA_ACUM_ITEM_END("    cam_handle_init", 0);
406
407                 cam_app_init_with_args(ad);
408         } else {
409                 ad->launching_mode = CAM_LAUNCHING_MODE_NORMAL;
410
411                 latest_mode = cam_app_get_latest_mode();
412
413                 CAM_TA_ACUM_ITEM_BEGIN("    cam_handle_init", 0);
414                 if (!cam_handle_init(ad, latest_mode)) {
415                         cam_critical(LOG_CAM, "cam_handle_init failed");
416                         return;
417                 }
418                 CAM_TA_ACUM_ITEM_END("    cam_handle_init", 0);
419         }
420
421         if (ad->launch_type == CAM_LAUNCH_FIRST) {
422                 debug_fenter(LOG_CAM);
423
424                 if (!open_cam_handle((void*)ad)) {
425                         cam_critical(LOG_CAM, "open_cam_handle failed");
426                         return;
427                 }
428
429 #ifdef ENABLE_CAM_POWER_CONTROL
430                 power_lock_state(POWER_STATE_NORMAL, 0);
431 #endif
432
433                 /*elm_win_alpha_set(ad->win_main, EINA_TRUE);*/
434
435                 ad->setting_menu_composer = NULL;
436
437                 if( ad->setting_menu_composer == NULL){
438                         ad->setting_menu_composer = malloc(sizeof(ad->setting_menu_composer));
439                         cam_compose_setting_menu(ad->setting_menu_composer);
440                 }
441
442                 CAM_TA_ACUM_ITEM_BEGIN("    cam_layout_init", 0);
443                 if (!cam_layout_init(ad)) {
444                         cam_critical(LOG_UI, "cam_layout_init failed");
445                         return;
446                 }
447                 CAM_TA_ACUM_ITEM_END("    cam_layout_init", 0);
448
449                 ecore_idler_add(cam_app_start, ad);
450         } else {
451                 /* RELUNCHING!! //in paused -> Camera process is called by External process  */
452
453                 cam_debug(LOG_SYS, "RELUNCHING !!!");
454
455                 /*remove GUI*/
456                 if (ad->imageviewer_ug) {
457                         DEBUG_TRACE("destory imageviewer");
458                         ug_destroy(ad->imageviewer_ug);
459                         ad->imageviewer_ug = NULL;
460                 }
461
462                 cam_layout_del_all(ad);
463
464 #ifdef ENABLE_CAM_POWER_CONTROL
465                 power_lock_state(POWER_STATE_NORMAL, 0);
466 #endif
467
468                 if (ad->exe_args == NULL)
469                         return;
470
471                 ResetCaps();
472
473                 CAM_TA_ACUM_ITEM_BEGIN("    cam_layout_init", 0);
474                 if (!cam_layout_init(ad)) {
475                         cam_critical(LOG_UI, "cam_layout_init failed");
476                         return;
477                 }
478                 CAM_TA_ACUM_ITEM_END("    cam_layout_init", 0);
479
480                 evas_object_raise(ad->win_main);
481                 ecore_idler_add(cam_app_start, ad);
482         }
483
484         cam_debug(LOG_UI, "############## cam_service END##############");
485         CAM_TA_ACUM_ITEM_END("==cam_service==", 0);
486 }
487
488 static int __is_idle_lock(void)
489 {
490
491         int vconf_val = 0;
492         int vconf_ret = 0;
493
494         vconf_ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &vconf_val);
495         if(vconf_ret == 0){
496                 if (vconf_val == VCONFKEY_IDLE_LOCK) {
497                         DEBUG_TRACE("  IDLE IN LOCK STATE  ");
498                         return 1;
499                 }
500         }
501
502         return 0;
503
504 }
505
506 #define CAM_EXT_LIB_PATH "/usr/lib/libcamera-external-engine.so"
507
508 void *handle = NULL;
509 gboolean open_cam_ext_handle()
510 {
511
512         if (!handle) {
513                 handle = dlopen(CAM_EXT_LIB_PATH, RTLD_NOW);
514                 if ( !handle ) {
515                         return FALSE;
516                 }
517         }
518         return TRUE;
519 }
520
521 void close_cam_ext_handle()
522 {
523
524         if (handle) {
525                 dlclose(handle);
526                 handle = NULL;
527         }
528 }
529
530 gboolean open_cam_handle(void* data)
531 {
532         struct appdata *ad = (struct appdata *)data;
533         CamAppData *camapp = NULL;
534         int session_type;
535         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
536         camapp = ad->camapp_handle;
537         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
538
539         if (camapp->camera_mode == CAM_CAMERA_MODE) {
540                 DEBUG_TRACE("session_type : SOUND_SESSION_TYPE_SHARE");
541                 session_type = SOUND_SESSION_TYPE_SHARE;
542         } else {
543                 DEBUG_TRACE("session_type : SOUND_SESSION_TYPE_EXCLUSIVE");
544                 session_type = SOUND_SESSION_TYPE_EXCLUSIVE;
545         }
546         if (!cam_mm_session_init(session_type)) {
547                 cam_critical(LOG_MM, "cam_mm_session_init faild");
548                 return FALSE;
549         }
550
551 /*open camera handle*/
552         if (!cam_mm_create(CAM_DEVICE_MEGA, camapp->camera_mode)) {
553                 cam_critical(LOG_MM, "cam_mm_create failed");
554                 cam_app_notice_popup(ad, "UNABLE TO LAUNCH CAMERA", cam_app_timeout_notice_response_cb);
555
556                 return FALSE;
557         }
558         return TRUE;
559
560 }
561
562 static void cam_low_power_cb(void *data)
563 {
564         struct appdata *ad = (struct appdata *)data;
565
566         cam_info(LOG_SYS, "Low battery !!");
567
568         cam_retm_if(ad == NULL, "appdata is NULL");
569         CamAppData *camapp = ad->camapp_handle;
570         cam_retm_if(camapp == NULL, "camapp_handle is NULL");
571         if (evas_object_visible_get(ad->win_main)) {
572                 int state = cam_mm_get_state();
573                 if ((state == RECORDER_STATE_RECORDING
574                     || state == RECORDER_STATE_PAUSED)
575                     &&camapp->camera_mode == CAM_CAMCORDER_MODE) {
576                         camapp->rec_stop_type = CAM_REC_STOP_LOW_BATTERY;
577                         ad->recording_commit =
578                             ecore_idler_add(cam_video_idler_record_stop, ad);
579                 } else {
580                         cam_app_exit(ad);
581                 }
582         }
583
584 }
585
586 static void cam_update_ts_cb(void *data)
587 {
588         struct appdata *ad = (struct appdata *)data;
589
590         cam_info(LOG_SYS, "#################Update String !!");
591
592         cam_retm_if(ad == NULL, "appdata is NULL");
593         char *path = NULL;
594
595         elm_win_indicator_mode_set(ad->win_main, 0);
596
597         path = vconf_get_str(VCONFKEY_LANGSET);
598         if (!path) {
599                 return;
600         }
601
602
603         /* update main */
604         update_ts_main(data);
605
606         enum ug_event ev = UG_EVENT_LANG_CHANGE;
607         ug_send_event(ev);
608 }
609
610 static void cam_device_orientation_cb(app_device_orientation_e mode, void *data)
611 {
612         struct appdata *ad = (struct appdata *)data;
613         cam_retm_if(ad == NULL, "appdata is NULL");
614         if (ad->appcore_state == CAM_APPCORE_TERMINATE_STATE
615                 || ad->appcore_state == CAM_APPCORE_PAUSE_STATE) {/*NOTE: in pause state, and terminate state, not cb*/
616                 return;
617         }
618         cam_retm_if(ad->camapp_handle == NULL, "ad->camapp_handle is NULL");
619
620         cam_debug(LOG_UI, "rotated : %d", mode);
621
622         /*TODO: now just return, if the last rotated is not finished*/
623         if (ad->is_rotating) {
624                 return;
625         }
626
627         int angle = 0;
628         ui_gadget_h ug = NULL;
629
630         enum ug_event ev = UG_EVENT_ROTATE_LANDSCAPE;
631         ad->rot_previous = ad->rot_current;
632         ad->rot_current = mode;
633
634         if (ad->toolbar_edj_file)
635                 free(ad->toolbar_edj_file);
636         ad->toolbar_edj_file = NULL;
637
638         switch (mode) {
639         case APP_DEVICE_ORIENTATION_0:
640                 angle = 0;
641                 ad->target_direction = CAM_TARGET_DIRECTION_PORTRAIT;
642                 ev = UG_EVENT_ROTATE_PORTRAIT;
643                 ad->camcorder_rotate = CAMERA_ROTATION_90;
644                 ad->toolbar_edj_file = strdup(CAM_TOOLBAR_LAYOUT_VERTICAL_EDJ_NAME);
645                 break;
646         case APP_DEVICE_ORIENTATION_270:
647                 angle = 270;
648                 ad->target_direction = CAM_TARGET_DIRECTION_LANDSCAPE;
649                 ev = UG_EVENT_ROTATE_LANDSCAPE;
650                 ad->camcorder_rotate = CAMERA_ROTATION_NONE;
651                 ad->toolbar_edj_file = strdup(CAM_TOOLBAR_LAYOUT_EDJ_NAME);
652                 break;
653         case APP_DEVICE_ORIENTATION_180:
654                 angle = 180;
655                 ad->target_direction = CAM_TARGET_DIRECTION_PORTRAIT_INVERSE;
656                 ev = UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN;
657                 ad->camcorder_rotate = CAMERA_ROTATION_270;
658                 ad->toolbar_edj_file = strdup(CAM_TOOLBAR_LAYOUT_VERTICAL_INVERSE_EDJ_NAME);
659                 break;
660         case APP_DEVICE_ORIENTATION_90:
661                 angle = 90;
662                 ad->target_direction = CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE;
663                 ev = UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN;
664                 ad->camcorder_rotate = CAMERA_ROTATION_180;
665                 ad->toolbar_edj_file = strdup(CAM_TOOLBAR_LAYOUT_INVERSE_EDJ_NAME);
666                 break;
667
668         default:
669                 break;
670         }
671         ad->angle = angle;
672
673         if (ad->imageviewer_ug) {
674                 ug = ad->imageviewer_ug;
675         }
676         if (ug) {
677                 enum ug_mode md = ug_get_mode(ug);
678                 if (md == UG_MODE_FULLVIEW) {
679                         if(ev == UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN)
680                                 return;
681                         elm_win_rotation_with_resize_set(ad->win_main, angle);
682                         /* send event to ug      */
683                         ug_send_event(ev);
684                 }
685         } else {
686
687
688                 unsigned int *main_pipe_op_type = NULL;
689                 main_pipe_op_type = (unsigned int *)calloc(1, sizeof(unsigned int));
690                 if (main_pipe_op_type)
691                         *main_pipe_op_type = CAM_MAIN_PIPE_OP_TYPE_ROTATE_ANIMATOR;
692                 ecore_pipe_write(ad->main_pipe, (void *)main_pipe_op_type, sizeof(unsigned int));
693         }
694 }
695
696 int main(int argc, char *argv[])
697 {
698         DEBUG_TRACE(" ");
699
700         int i = 0;
701         struct appdata ad;
702         if (_is_running())
703                 return 0;
704
705         /*set appdata init variable*/
706         memset(&ad, 0x0, sizeof(struct appdata));
707
708         g_type_init();
709
710         CAM_TA_INIT();
711         DEBUG_TRACE("argc = %d", argc, argv);
712         for (i = 0; i < argc; i++) {
713                 DEBUG_TRACE("argv[%d] = %s", i, argv[i]);
714         }
715
716         app_event_callback_s event_callbacks;
717
718         event_callbacks.create = cam_create;
719         event_callbacks.terminate = cam_terminate;
720         event_callbacks.pause = cam_pause;
721         event_callbacks.resume = cam_resume;
722         event_callbacks.service = cam_service;
723
724         event_callbacks.language_changed = cam_update_ts_cb;
725         event_callbacks.low_battery = cam_low_power_cb;
726         event_callbacks.device_orientation = cam_device_orientation_cb;
727
728         event_callbacks.low_memory = NULL;
729         event_callbacks.region_format_changed = NULL;
730
731         setenv("ELM_ENGINE", "gl", 1); /*add open gl support for 3D slide_show of image viewer*/
732         ecore_evas_app_comp_sync_set(EINA_FALSE);
733
734         return app_efl_main(&argc, &argv, &event_callbacks, &ad);
735
736 }
737
738 int update_ts_main(void *data)
739 {
740         DEBUG_TRACE(" ");
741
742         struct appdata *ad = (struct appdata *)data;
743
744         if (ad && ad->layout_main)
745                 edje_object_part_text_set(_EDJ(ad->layout_main), "txt_title", dgettext("sys_string", "IDS_COM_BODY_CAMERA"));
746
747         return TRUE;
748 }
749 //end file