Title & Indicator policy has been changed.
[platform/framework/web/wrt.git] / src / wrt-client / wrt-client.cpp
1 /*
2  * Copyright (c) 2011 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 #include "wrt-client.h"
17 #include <cstdlib>
18 #include <cstdio>
19 #include <string>
20 #include <dpl/log/log.h>
21 #include <dpl/optional_typedefs.h>
22 #include <common/application_data.h>
23 #include <core_module.h>
24 #include <global_logic.h>
25 #include <widget_localize_model.h>
26 #include <localization_setting.h>
27 #include <widget_deserialize_model.h>
28 #include <launch_user_data.h>
29 #include <EWebKit2.h>
30 #include <dpl/localization/w3c_file_localization.h>
31 #include <dpl/localization/LanguageTagsProvider.h>
32
33 //W3C PACKAGING enviroment variable name
34 #define W3C_DEBUG_ENV_VARIABLE "DEBUG_LOAD_FINISH"
35
36 // window signal callback
37 const std::string VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
38 const std::string VIEWMODE_TYPE_MAXIMIZED = "maximized";
39 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
40
41 WrtClient::WrtClient(int argc, char **argv) :
42     Application(argc, argv, "wrt-client", false),
43     DPL::TaskDecl<WrtClient>(this),
44     m_launched(false),
45     m_initializing(false),
46     m_initialized(false),
47     m_sdkLauncherPid(0),
48     m_debugMode(false),
49     m_debuggerPort(0),
50     m_returnStatus(ReturnStatus::Succeeded),
51     m_widgetState(WidgetState::WidgetState_Stopped)
52 {
53     Touch();
54     LogDebug("App Created");
55 }
56
57 WrtClient::~WrtClient()
58 {
59     LogDebug("App Finished");
60 }
61
62 WrtClient::ReturnStatus::Type WrtClient::getReturnStatus() const
63 {
64     return m_returnStatus;
65 }
66
67 void WrtClient::OnStop()
68 {
69     LogInfo("Stopping Dummy Client");
70 }
71
72
73 void WrtClient::OnCreate()
74 {
75     LogInfo("On Create");
76 }
77
78
79 void WrtClient::OnResume()
80 {
81     if (m_widgetState != WidgetState_Suspended) {
82         LogWarning("Widget is not suspended, resuming was skipped");
83         return;
84     }
85     m_widget->Resume();
86     evas_object_focus_set(m_widget->GetCurrentWebview(), EINA_TRUE);
87     m_widgetState = WidgetState_Running;
88 }
89
90
91 void WrtClient::OnPause()
92 {
93     if (m_widgetState != WidgetState_Running) {
94         LogWarning("Widget is not running to be suspended");
95         return;
96     }
97     m_widget->Suspend();
98     evas_object_focus_set(m_widget->GetCurrentWebview(), EINA_FALSE);
99     m_widgetState = WidgetState_Suspended;
100 }
101
102 void WrtClient::OnReset(bundle *b)
103 {
104     LogDebug("OnReset");
105     // bundle argument is freed after OnReset() is returned
106     // So bundle duplication is needed
107     ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
108
109     if (true == m_initializing) {
110         LogDebug("can not handle reset event");
111         return;
112     }
113     if (true == m_launched) {
114         if (m_widgetState == WidgetState_Stopped) {
115             LogError("Widget is not running to be reset");
116             return;
117         }
118         m_widget->Reset();
119         elm_win_raise(m_windowData->m_win);
120         evas_object_focus_set(m_widget->GetCurrentWebview(), EINA_TRUE);
121         m_widgetState = WidgetState_Running;
122     } else {
123         if (true == checkArgument())
124         {
125             setStep();
126         }
127         else
128         {
129             showHelpAndQuit();
130         }
131     }
132 }
133
134 void WrtClient::OnTerminate()
135 {
136     LogDebug("Wrt Shutdown now");
137     shutdownStep();
138 }
139
140 void WrtClient::showHelpAndQuit()
141 {
142     printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
143            "launch widgets.\n"
144            "Mandatory arguments to long options are mandatory for short "
145            "options too.\n"
146            "  -h,    --help                                 show this help\n"
147            "  -l,    --launch                               "
148            "launch widget with given tizen ID\n"
149            "  -t,    --tizen                                "
150            "launch widget with given tizen ID\n"
151            "\n");
152
153     Quit();
154 }
155
156 bool WrtClient::checkArgument()
157 {
158     LogInfo("checkArgument");
159
160     std::string arg = m_argv[0];
161
162     if (arg.empty()) {
163         return false;
164     }
165
166     if (arg.find("wrt-client") != std::string::npos)
167     {
168         if (m_argc <= 1) {
169             return false;
170         }
171
172         arg = m_argv[1];
173
174         if (arg == "-h" || arg == "--help") {
175             // Just show help
176             return false;
177         } else if (arg == "-l" || arg == "--launch" ||
178                 arg == "-t" || arg == "--tizen") {
179             if (m_argc != 3) {
180                 return false;
181             }
182             m_tizenId = std::string(m_argv[2]);
183         } else {
184             return false;
185         }
186     } else {
187         size_t pos = arg.find_last_of('/');
188
189         if (pos != std::string::npos) {
190             arg = arg.erase(0, pos + 1);
191         }
192
193         // Launch widget based on application basename
194         m_tizenId = arg;
195         LogDebug("Tizen id: " << m_tizenId);
196     }
197
198     return true;
199 }
200
201 void WrtClient::setStep()
202 {
203     LogInfo("setStep");
204
205     AddStep(&WrtClient::initStep);
206
207     setSdkLauncherDebugData();
208
209     AddStep(&WrtClient::launchStep);
210     AddStep(&WrtClient::shutdownStep);
211
212     m_initializing = true;
213
214     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
215 }
216
217 void WrtClient::setSdkLauncherDebugData()
218 {
219     LogDebug("setSdkLauncherDebugData");
220
221     /* check bundle from sdk launcher */
222     bundle *bundleFromSdkLauncher;
223     bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
224     const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
225     const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
226     if (bundle_debug != NULL && bundle_pid != NULL) {
227         if (strcmp(bundle_debug, "true") == 0) {
228             m_debugMode = true;
229             m_sdkLauncherPid = atoi(bundle_pid);
230         } else {
231             m_debugMode = false;
232         }
233     }
234 }
235
236 bool WrtClient::checkDebugMode(SDKDebugData* debugData)
237 {
238     LogError("Checking for debug mode");
239     Assert(m_dao);
240
241     bool debugMode = debugData->debugMode;
242
243     LogInfo("[DEBUG_MODE] Widget is launched in " <<
244             (debugMode ? "DEBUG" : "RETAIL") <<
245             " mode.");
246
247     if (debugMode == true) {
248         // In WAC widget, only test widgets can use web inspector.
249         // In TIZEN widget,
250         // every launched widgets as debug mode can use it.
251         if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_WAC20)
252         {
253             bool developerMode =
254                 GlobalLogicSingleton::Instance().GetGlobalModel()
255                 ->DeveloperMode.Get();
256             //This code will be activated
257             //after WAC test certificate is used by SDK
258             //bool isTestWidget = view->m_widgetModel->IsTestWidget.Get();
259             //if(!isTestWidget)
260             //{
261             //    LogInfo("This is not WAC Test Widget");
262             //    break;
263             //}
264             if (!developerMode) {
265                 LogInfo("This is not WAC Developer Mode");
266                 debugMode = false;
267             }
268         }
269     }
270     return debugMode;
271 }
272
273 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
274 {
275     LogDebug("Executing next step");
276     NextStep();
277 }
278
279 void WrtClient::initStep()
280 {
281     LogDebug("");
282     if (WRT::CoreModuleSingleton::Instance().Init()) {
283         m_initialized = true;
284     } else {
285         m_returnStatus = ReturnStatus::Failed;
286         SwitchToStep(&WrtClient::shutdownStep);
287     }
288
289     // ecore_event_jobs are processed sequentially without concession to
290     // other type events. To give a chance of execute to other events,
291     // ecore_timer_add was used.
292     DPL::Event::ControllerEventHandler<NextStepEvent>::PostTimedEvent(
293             NextStepEvent(),0.001);
294 }
295
296 bool WrtClient::checkWACTestCertififedWidget()
297 {
298     // WAC Waikiki Beta Release Core Specification: Widget Runtime
299     // 10 Dec 2010
300     //
301     // WR-4710 The WRT MUST enable debug functions only for WAC test widgets
302     // i.e. the functions must not be usable for normal WAC widgets, even when
303     // a WAC test widget is executing.
304     ADD_PROFILING_POINT("DeveloperModeCheck", "start");
305     Assert(!!m_dao);
306     // WAC test widget
307     // A widget signed with a WAC-issued test certificate as described in
308     // Developer Mode.
309
310     bool developerWidget = m_dao->isTestWidget();
311     bool developerMode =
312         GlobalLogicSingleton::Instance().GetGlobalModel()->DeveloperMode.Get();
313
314     LogDebug("Is WAC test widget: " << developerWidget);
315     LogDebug("Is developer Mode: " << developerMode);
316
317     if (developerWidget) {
318         if(!developerMode)
319         {
320             LogError("WAC test certified developer widget is needed for " <<
321                     "developer mode");
322             return false;
323         }else{
324             //TODO: WR-4660 (show popup about developer widget
325             //      during launch
326             LogInfo("POPUP: THIS IS TEST WIDGET!");
327         }
328     }
329     ADD_PROFILING_POINT("DeveloperModeCheck", "stop");
330     return true;
331 }
332
333 void WrtClient::loadFinishCallback(bool success)
334 {
335     ADD_PROFILING_POINT("loadFinishCallback", "start");
336     SDKDebugData* debug = new SDKDebugData;
337     debug->debugMode = m_debugMode;
338     debug->pid = new unsigned long(getpid());
339
340     LogInfo("Post result of launch");
341
342     // Start inspector server, if current mode is debugger mode.
343     // In the WK2 case, ewk_view_inspector_server_start should
344     // be called after WebProcess is created.
345     if (checkDebugMode(debug))
346     {
347         debug->portnum =
348             ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
349         if (debug->portnum == 0) {
350             LogWarning("Failed to get portnum");
351         } else {
352             LogInfo("Assigned port number for inspector : "
353                     << debug->portnum);
354         }
355     } else {
356         LogDebug("Debug mode is disabled");
357     }
358
359     //w3c packaging test debug (message on 4>)
360     const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
361     if(makeScreen != NULL && strcmp(makeScreen, "1") == 0)
362     {
363         FILE* doutput = fdopen(4, "w");
364         fprintf(doutput,"didFinishLoadForFrameCallback: ready\n");
365         fclose(doutput);
366     }
367
368     if (success) {
369         LogDebug("Launch succesfull");
370
371         m_launched = true;
372         m_initializing = false;
373         setlinebuf(stdout);
374         ADD_PROFILING_POINT("loadFinishCallback", "stop");
375         printf("launched\n");
376         fflush(stdout);
377     } else {
378         printf("failed\n");
379
380         m_returnStatus = ReturnStatus::Failed;
381         //shutdownStep
382         DPL::Event::ControllerEventHandler<NextStepEvent>::
383                 PostEvent(NextStepEvent());
384     }
385
386     if(debug->debugMode)
387     {
388         LogDebug("Send RT signal to wrt-launcher(pid: "
389                 << m_sdkLauncherPid << ", status: " << success);
390         union sigval sv;
391         /* send real time signal with result to wrt-launcher */
392         if(success)
393         {
394             LogDebug("userData->portnum : " << debug->portnum);
395             sv.sival_int = debug->portnum;
396         }
397         else
398         {
399            sv.sival_int = -1;
400         }
401         sigqueue(m_sdkLauncherPid, SIGRTMIN, sv);
402     }
403
404     ApplicationDataSingleton::Instance().freeBundle();
405
406     LogDebug("Cleaning wrtClient launch resources...");
407     delete debug->pid;
408     delete debug;
409 }
410
411 void WrtClient::progressFinishCallback()
412 {
413     m_splashScreen->stopSplashScreen();
414 }
415
416 void WrtClient::windowCloseCallback()
417 {
418     LogDebug("window close called, terminating app");
419     SwitchToStep(&WrtClient::shutdownStep);
420     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
421             NextStepEvent());
422 }
423
424 void WrtClient::webCrashCallback()
425 {
426     LogDebug("webProcess crashed");
427     SwitchToStep(&WrtClient::shutdownStep);
428     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
429             NextStepEvent());
430 }
431
432
433 void WrtClient::launchStep()
434 {
435     ADD_PROFILING_POINT("launchStep", "start");
436     LogDebug("Launching widget ...");
437
438     m_widget = WRT::CoreModuleSingleton::Instance()
439                     .getRunnableWidgetObject(m_tizenId);
440     if (!m_widget) {
441         LogError("RunnableWidgetObject is NULL, stop launchStep");
442         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
443                     NextStepEvent());
444         return;
445     }
446
447     if (m_widgetState == WidgetState_Running) {
448         LogWarning("Widget already running, stop launchStep");
449         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
450                     NextStepEvent());
451         return;
452     }
453
454     if (m_widgetState == WidgetState_Authorizing) {
455         LogWarning("Widget already authorizing, stop launchStep");
456         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
457                     NextStepEvent());
458         return;
459     }
460
461     m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
462     Domain::localizeWidgetModel(m_dao->getDefaultlocale());
463     LocalizationSetting::SetLanguageChangedCallback(
464             languageChangedCallback, this);
465
466     ADD_PROFILING_POINT("CreateWindow", "start");
467     m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid())));
468     ADD_PROFILING_POINT("CreateWindow", "stop");
469
470     WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
471     m_splashScreen.reset(
472             new SplashScreenSupport(m_windowData->m_win));
473     if (m_splashScreen->createSplashScreen(m_dao->getSplashImgSrc())) {
474         m_splashScreen->startSplashScreen();
475         cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
476     }
477     DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
478     m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
479             m_windowData->m_win);
480     //you can't show window with splash screen before PrepareView
481     //ewk_view_add_with_context() in viewLogic breaks window
482     evas_object_show(m_windowData->m_win);
483     initializeWindowModes();
484     connectElmCallback();
485
486     if (!checkWACTestCertififedWidget())
487     {
488         LogWarning("WAC Certificate failed, stop launchStep");
489         return;
490     }
491
492     m_widgetState = WidgetState_Authorizing;
493     if (!m_widget->CheckBeforeLaunch()) {
494         LogError("CheckBeforeLaunch failed, stop launchStep");
495         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
496                     NextStepEvent());
497         return;
498     }
499     LogInfo("Widget launch accepted. Entering running state");
500     m_widgetState = WidgetState_Running;
501
502     cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
503     cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
504     cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
505     cbs->windowClose = DPL::MakeDelegate(this, &WrtClient::windowCloseCallback);
506     cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
507     cbs->toggleFullscreen = DPL::MakeDelegate(m_windowData.get(), &WindowData::toggleFullscreen);
508
509     m_widget->SetUserDelegates(cbs);
510     m_widget->Show();
511     ADD_PROFILING_POINT("launchStep", "stop");
512 }
513
514 void WrtClient::initializeWindowModes()
515 {
516     Assert(m_windowData);
517     Assert(m_dao);
518     auto windowModes = m_dao->getWindowModes();
519     bool fullscreen = false;
520     FOREACH(it, windowModes)
521     {
522         std::string viewMode = DPL::ToUTF8String(*it);
523         if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
524             fullscreen = true;
525             break;
526         } else if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
527             break;
528         }
529     }
530     bool indicator = true;
531     if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
532         WidgetSettings widgetSettings;
533         m_dao->getWidgetSettings(widgetSettings);
534         WidgetSettingList settings(widgetSettings);
535         indicator = (settings.getIndicatorPresence()
536                 == Indicator_Enable);
537     }
538
539     WrtDB::WidgetLocalizedInfo localizedInfo =
540             W3CFileLocalization::getLocalizedInfo(m_dao);
541     std::string name = "";
542     if (!(localizedInfo.name.IsNull())) {
543         name = DPL::ToUTF8String(*(localizedInfo.name));
544     }
545     LogInfo("initializeWindowModes " << m_debugMode);
546
547     SDKDebugData* debug = new SDKDebugData;
548     if(m_debugMode) {
549         m_windowData->m_debugMode = TRUE;
550     }
551     else {
552         m_windowData->m_debugMode = FALSE;
553     }
554
555     WindowData::CtxMenuItems ctxMenuItems;
556
557     WindowData::CtxMenuItem ctxMenuBackword;
558     ctxMenuBackword.label = WRT_OPTION_LABEL_BACKWARD;
559     ctxMenuBackword.icon = WRT_OPTION_ICON_BACKWARD;
560     ctxMenuBackword.callback = backwardCallback;
561     ctxMenuBackword.data = this;
562     ctxMenuItems.push_back(ctxMenuBackword);
563
564     WindowData::CtxMenuItem ctxMenuReload;
565     ctxMenuReload.label = WRT_OPTION_LABEL_RELOAD;
566     ctxMenuReload.icon = WRT_OPTION_ICON_RELOAD;
567     ctxMenuReload.callback = reloadCallback;
568     ctxMenuReload.data = this;
569     ctxMenuItems.push_back(ctxMenuReload);
570
571     WindowData::CtxMenuItem ctxMenuForward;
572     ctxMenuForward.label = WRT_OPTION_LABEL_FORWARD;
573     ctxMenuForward.icon = WRT_OPTION_ICON_FORWARD;
574     ctxMenuForward.callback = forwardCallback;
575     ctxMenuForward.data = this;
576     ctxMenuItems.push_back(ctxMenuForward);
577
578     m_windowData->setViewMode(fullscreen,
579                               ctxMenuItems);
580 }
581
582 void WrtClient::backButtonCallback(void* data,
583                                      Evas_Object * /*obj*/,
584                                      void * /*event_info*/)
585 {
586     LogInfo("BackButtonCallback");
587     Assert(data);
588
589     WrtClient* This = static_cast<WrtClient*>(data);
590
591     This->m_widget->Backward();
592 }
593
594 void WrtClient::backwardCallback(void *data,
595         Evas_Object */*obj*/,
596         void */*event_info*/)
597 {
598     LogInfo("BackButtonCallback");
599     Assert(data);
600
601     WrtClient* This = static_cast<WrtClient*>(data);
602
603     This->m_widget->Backward();
604     This->m_windowData->initFullViewMode();
605 }
606
607 void WrtClient::reloadCallback(void *data,
608         Evas_Object */*obj*/,
609         void */*event_info*/)
610 {
611     LogInfo("reloadCallback");
612
613     WrtClient* This = static_cast<WrtClient*>(data);
614
615     This->m_widget->Reload();
616     This->m_windowData->initFullViewMode();
617 }
618
619 void WrtClient::forwardCallback(void *data,
620         Evas_Object */*obj*/,
621         void */*event_info*/)
622 {
623     LogInfo("forwardCallback");
624
625     WrtClient* This = static_cast<WrtClient*>(data);
626
627     This->m_widget->Forward();
628     This->m_windowData->initFullViewMode();
629 }
630
631
632 void WrtClient::connectElmCallback()
633 {
634     Assert(m_windowData);
635     Assert(m_dao);
636     if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
637         WidgetSettings widgetSettings;
638         m_dao->getWidgetSettings(widgetSettings);
639         WidgetSettingList settings(widgetSettings);
640         WidgetSettingScreenLock rotationValue = settings.getRotationValue();
641         if (rotationValue == Screen_Portrait) {
642             elm_win_rotation_with_resize_set(m_windowData->m_win, 0);
643         } else if (rotationValue == Screen_Landscape) {
644             elm_win_rotation_with_resize_set(m_windowData->m_win, 270);
645         } else {
646             elm_win_rotation_with_resize_set(m_windowData->m_win, 0);
647         }
648     }
649 }
650
651 void WrtClient::setLayout(Evas_Object* newBuffer) {
652     LogDebug("add new webkit buffer to window");
653     Assert(newBuffer);
654
655     elm_object_part_content_set(m_windowData->m_user_layout, ELM_SWALLOW_CONTENT, newBuffer);
656
657     evas_object_show(newBuffer);
658     evas_object_focus_set(newBuffer, EINA_TRUE);
659 }
660
661 void WrtClient::unsetLayout(Evas_Object* currentBuffer) {
662     LogDebug("remove current webkit buffer from window");
663     Assert(currentBuffer);
664     evas_object_hide(currentBuffer);
665
666     elm_object_part_content_unset(m_windowData->m_user_layout, ELM_SWALLOW_CONTENT);
667
668 }
669
670 void WrtClient::shutdownStep()
671 {
672     LogDebug("Closing Wrt connection ...");
673     if (m_initialized && m_widget) {
674         m_widgetState = WidgetState_Stopped;
675         m_widget->Hide();
676         m_widget.reset();
677         m_windowData.reset();
678         WRT::CoreModuleSingleton::Instance().Terminate();
679         m_initialized = false;
680     }
681     Quit();
682 }
683
684 int WrtClient::languageChangedCallback(void *data)
685 {
686     LogDebug("Language Changed");
687     WrtClient* wrtClient = static_cast<WrtClient*>(data);
688
689     LanguageTags oldtags = LanguageTagsProviderSingleton::Instance().getLanguageTags();
690     // reset function fetches system locales and recreates language tags
691     LanguageTagsProviderSingleton::Instance().resetLanguageTags();
692     LanguageTags newtags = LanguageTagsProviderSingleton::Instance().getLanguageTags();
693
694     // check whether LanguageTags changed or not
695     if (oldtags != newtags) {
696         // update localized data
697         Domain::localizeWidgetModel(wrtClient->m_dao->getDefaultlocale());
698
699         if (true == wrtClient->m_launched &&
700                 wrtClient->m_widgetState != WidgetState_Stopped) {
701             wrtClient->m_widget->ReloadStartPage();
702         }
703     }
704     return 0;
705 }
706
707 int main(int argc,
708          char *argv[])
709 {
710     ADD_PROFILING_POINT("main-entered", "point");
711
712     // Output on stdout will be flushed after every newline character,
713     // even if it is redirected to a pipe. This is useful for running
714     // from a script and parsing output.
715     // (Standard behavior of stdlib is to use full buffering when
716     // redirected to a pipe, which means even after an end of line
717     // the output may not be flushed).
718     setlinebuf(stdout);
719
720     // set evas backend type
721     if (!getenv("ELM_ENGINE")) {
722         if (setenv("ELM_ENGINE", "gl", 1)) {
723                 LogDebug("Enable backend");
724         }
725     }
726 #ifndef TIZEN_PUBLIC
727     setenv("COREGL_FASTPATH", "1", 1);
728 #endif
729     setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
730     setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
731     setenv("ELM_IMAGE_CACHE", "0", 1);
732
733     // Set log tagging
734     DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-CLIENT");
735
736     WrtClient app(argc, argv);
737     int ret = app.Exec();
738     LogDebug("App returned: " << ret);
739     ret = app.getReturnStatus();
740     LogDebug("WrtClient returned: " << ret);
741     return ret;
742 }