upload tizen1.0 source
[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 <string>
19 #include <fstream>
20 #include <iostream>
21 #include <sys/stat.h>
22 #include <sys/utsname.h>
23 #include <unistd.h>
24 #include <vconf.h>
25 #include <dpl/optional.h>
26 #include <dpl/scoped_free.h>
27 #include <dpl/wrt-dao-ro/global_config.h>
28 #include <dpl/localization/localization_utils.h>
29 #include <dpl/optional_typedefs.h>
30 #include <dpl/semaphore.h>
31 #include <dpl/exception.h>
32 #include <signal.h>
33 #include <application_data.h>
34 #include <window_data.h>
35
36 using namespace WrtDB;
37
38 namespace { // anonymous
39 const char* PLUGIN_INSTALL_SEMAPHORE = "/.wrt_plugin_install_lock";
40 const char* MACHINE_NAME_EMUL = "emulated"; // "arch_emulated"
41
42 template<typename Predicate>
43 DPL::OptionalInt findWidgetHandleForPredicate(const Predicate &predicate)
44 {
45     int count;
46     int *handles;
47
48     if (wrt_has_succeded(wrt_get_widget_list(&count, &handles))) {
49         for (int i = 0; i < count; ++i) {
50             wrt_widget_info *info;
51
52             // Get widget infor for handle
53             if (wrt_has_succeded(wrt_get_widget_info(handles[i], &info))) {
54                 if (predicate(info)) {
55                     // Free widget name
56                     wrt_free_widget_info(info);
57
58                     // Done
59                     return DPL::OptionalInt(handles[i]);
60                 }
61
62                 // Free widget info
63                 wrt_free_widget_info(info);
64             } else {
65                 LogWarning("ReturnStatus::Faileded to get widget name");
66             }
67         }
68
69         // Free list
70         wrt_free_widget_list(handles);
71     } else {
72         LogWarning("ReturnStatus::Faileded to get widget handle list");
73     }
74
75     return DPL::OptionalInt::Null;
76 }
77
78 struct WidgetNamePredicate
79 {
80   private:
81     std::string m_name;
82
83   public:
84     WidgetNamePredicate(const std::string &name) : m_name(name) {}
85
86     bool operator()(wrt_widget_info *info) const
87     {
88         return info->name && m_name == info->name;
89     }
90 };
91
92 struct WidgetGUIDPredicate
93 {
94   private:
95     std::string m_guid;
96
97   public:
98     WidgetGUIDPredicate(const std::string &guid) : m_guid(guid) {}
99
100     bool operator()(wrt_widget_info *info) const
101     {
102         return info->id && m_guid == info->id;
103     }
104 };
105
106 DPL::OptionalInt findWidgetHandleForName(const std::string &widgetName)
107 {
108     return findWidgetHandleForPredicate(WidgetNamePredicate(widgetName));
109 }
110
111 DPL::OptionalInt findWidgetHandleForGUID(const std::string &widgetName)
112 {
113     return findWidgetHandleForPredicate(WidgetGUIDPredicate(widgetName));
114 }
115
116 struct PluginInstallerData
117 {
118     void* wrtClient;
119     std::string pluginPath;
120 };
121
122 struct PluginUtils
123 {
124     struct FileState
125     {
126         enum Type
127         {
128             FILE_EXISTS,
129             FILE_EXISTS_NOT_REGULAR,
130             FILE_NOT_EXISTS,
131             FILE_READ_DATA_ERROR
132         };
133     };
134
135     static bool lockPluginInstallation()
136     {
137         Try {
138             DPL::Semaphore lock(PLUGIN_INSTALL_SEMAPHORE);
139             return true;
140         }
141         Catch(DPL::Semaphore::Exception::CreateFailed){
142             LogError("create");
143             return false;
144         }
145         Catch(DPL::Semaphore::Exception::Base){
146             return false;
147         }
148     }
149
150     static bool unlockPluginInstallation()
151     {
152         Try {
153             DPL::Semaphore::Remove(PLUGIN_INSTALL_SEMAPHORE);
154             return true;
155         }
156         Catch(DPL::Semaphore::Exception::Base){
157             return false;
158         }
159     }
160
161     static bool checkPluginInstallationRequired()
162     {
163         std::string installRequest =
164             std::string(GlobalConfig::GetPluginInstallInitializerName());
165
166         FileState::Type installationRequest = checkFile(installRequest);
167
168         switch (installationRequest) {
169         case FileState::FILE_EXISTS:
170             return true;
171         case FileState::FILE_NOT_EXISTS:
172             return false;
173         default:
174             LogWarning("Opening installation request file failed");
175             return false;
176         }
177     }
178
179     static bool removeInstallationRequiredFlag()
180     {
181         std::string installRequest =
182             std::string(GlobalConfig::GetPluginInstallInitializerName());
183
184         return removeFile(installRequest);
185     }
186
187     //checks if file exists and is regular file
188     static FileState::Type checkFile(const std::string& filename)
189     {
190         struct stat tmp;
191
192         if (-1 == stat(filename.c_str(), &tmp)) {
193             if (ENOENT == errno) {
194                 return FileState::FILE_NOT_EXISTS;
195             }
196             return FileState::FILE_READ_DATA_ERROR;
197         } else if (!S_ISREG(tmp.st_mode)) {
198             return FileState::FILE_EXISTS_NOT_REGULAR;
199         }
200         return FileState::FILE_EXISTS;
201     }
202
203     static bool removeFile(const std::string& filename)
204     {
205         if (0 != unlink(filename.c_str())) {
206             return false;
207         }
208
209         return true;
210     }
211 };
212 } // namespace anonymous
213
214 WrtClient::WrtClient(int argc, char **argv) :
215     Application(argc, argv, "wrt-client", false),
216     DPL::TaskDecl<WrtClient>(this),
217     m_packagePath(),
218     m_handle(-1),
219     m_launched(false),
220     m_initialized(false),
221     m_sdkLauncherPid(0),
222     m_debugMode(false),
223     m_debuggerPort(0),
224     m_developerMode(false),
225     m_complianceMode(false),
226     m_numPluginsToInstall(0),
227     m_returnStatus(ReturnStatus::Succeeded),
228     m_startupPluginInstallation(false)
229 {
230     Touch();
231     LogDebug("App Created");
232 }
233
234 WrtClient::~WrtClient()
235 {
236     LogDebug("App Finished");
237 }
238
239 WrtClient::ReturnStatus::Type WrtClient::getReturnStatus() const
240 {
241     return m_returnStatus;
242 }
243
244 void WrtClient::OnStop()
245 {
246     LogInfo("Stopping Dummy Client");
247 }
248
249
250 void WrtClient::OnCreate()
251 {
252     LogInfo("On Create");
253 }
254
255
256 void WrtClient::OnResume()
257 {
258     wrt_resume_widget(m_handle, NULL, staticWrtResumeStatusCallback);
259 }
260
261
262 void WrtClient::OnPause()
263 {
264     wrt_suspend_widget(m_handle, NULL, staticWrtSuspendStatusCallback);
265 }
266
267 void WrtClient::OnReset(bundle *b)
268 {
269     LogDebug("OnReset");
270     // bundle argument is freed after OnReset() is returned
271     // So bundle duplication is needed
272     ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
273
274     if (m_launched == true) {
275         wrt_reset_widget(m_handle, NULL, staticWrtResetStatusCallback);
276     } else {
277         setStep();
278     }
279 }
280
281 void WrtClient::OnTerminate()
282 {
283     LogDebug("Wrt Shutdown now");
284     wrt_shutdown();
285 }
286
287 void WrtClient::showHelpAndQuit()
288 {
289     printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
290            "launch widgets.\n"
291            "Mandatory arguments to long options are mandatory for short "
292            "options too.\n"
293            "  -h,    --help                                 show this help\n"
294            "  -l,    --launch                               "
295            "launch widget with given ID\n"
296            "\n");
297
298     Quit();
299 }
300
301 void WrtClient::setStep()
302 {
303     LogInfo("setStep");
304
305     AddStep(&WrtClient::initStep);
306
307     std::string arg = m_argv[0];
308
309     if (arg.empty()) {
310         return showHelpAndQuit();
311     }
312
313     installNewPlugins();
314
315     setSdkLauncherDebugData();
316
317     if (arg.find("wrt-dummy-client") != std::string::npos ||
318         arg.find("wrt-client") != std::string::npos)
319     {
320         if (m_argc <= 1) {
321             return showHelpAndQuit();
322         }
323
324         arg = m_argv[1];
325
326         if (arg == "-h" || arg == "--help") {
327             if (m_argc != 2) {
328                 return showHelpAndQuit();
329             }
330
331             // Just show help
332             showHelpAndQuit();
333         } else if (arg == "-l" || arg == "--launch") {
334             if (m_argc != 3) {
335                 return showHelpAndQuit();
336             }
337
338             m_handle = atoi(m_argv[2]);
339             AddStep(&WrtClient::launchStep);
340             AddStep(&WrtClient::finalizeLaunchStep);
341             AddStep(&WrtClient::killWidgetStep);
342         } else {
343             return showHelpAndQuit();
344         }
345     } else {
346         // Launch widget based on application basename
347         size_t pos = arg.find_last_of('/');
348
349         if (pos != std::string::npos) {
350             arg = arg.erase(0, pos + 1);
351         }
352
353         if (sscanf(arg.c_str(), "%i", &m_handle) != 1) {
354             printf("failed: invalid widget handle\n");
355             return showHelpAndQuit();
356         }
357
358         LogDebug("Widget Id: " << m_handle << " (" << arg << ")");
359
360         AddStep(&WrtClient::launchStep);
361         AddStep(&WrtClient::finalizeLaunchStep);
362         AddStep(&WrtClient::killWidgetStep);
363     }
364
365     AddStep(&WrtClient::shutdownStep);
366
367     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
368 }
369
370 void WrtClient::setSdkLauncherDebugData()
371 {
372     LogDebug("setSdkLauncherDebugData");
373
374     /* check bundle from sdk launcher */
375     bundle *bundleFromSdkLauncher;
376     bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
377     const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
378     const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
379     if (bundle_debug != NULL && bundle_pid != NULL) {
380         if (strcmp(bundle_debug, "true") == 0) {
381             m_debugMode = true;
382             m_sdkLauncherPid = atoi(bundle_pid);
383         } else {
384             m_debugMode = false;
385         }
386     }
387 }
388
389 void WrtClient::OnEventReceived(const QuitEvent &/* event */)
390 {
391     LogDebug("Quiting");
392
393     if (m_launched) {
394         LogDebug("Killing widgets first");
395         SwitchToStep(&WrtClient::killWidgetStep);
396         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
397     } else if (m_initialized) {
398         LogDebug("Wrt Shutdown now");
399         SwitchToStep(&WrtClient::shutdownStep);
400         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
401     } else {
402         LogDebug("Quiting application");
403         return Quit();
404     }
405 }
406
407 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
408 {
409     LogDebug("Executing next step");
410     NextStep();
411 }
412
413 void WrtClient::initStep()
414 {
415     wrt_init(this, staticWrtInitCallback);
416 }
417
418 void WrtClient::launchStep()
419 {
420     LogDebug("Launching widget ...");
421
422     WrtClientUserData *userData = new WrtClientUserData;
423     userData->This = this;
424     userData->pid = new unsigned long(getpid());
425     userData->debugMode = this->m_debugMode;
426
427     wrt_launch_widget(m_handle,
428                       userData->pid,
429                       NULL,
430                       userData,
431                       &staticWrtLaunchWidgetCallback);
432 }
433
434 void WrtClient::launchNameStep()
435 {
436     LogDebug("Launching name widget ...");
437
438     DPL::OptionalInt handle = findWidgetHandleForName(m_name);
439
440     if (!handle) {
441         printf("failed: widget name not found\n");
442
443         m_returnStatus = ReturnStatus::Failed;
444         DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
445         return;
446     }
447
448     WrtClientUserData *userData = new WrtClientUserData;
449     userData->This = this;
450     userData->pid = new unsigned long(getpid());
451     userData->debugMode = this->m_debugMode;
452
453     wrt_launch_widget(*handle,
454                       userData->pid,
455                       NULL,
456                       userData,
457                       &staticWrtLaunchWidgetCallback);
458 }
459
460 void WrtClient::launchGUIDStep()
461 {
462     LogDebug("Launching GUID widget ...");
463
464     DPL::OptionalInt handle = findWidgetHandleForGUID(m_name);
465
466     if (!handle) {
467         printf("failed: widget GUID not found\n");
468
469         m_returnStatus = ReturnStatus::Failed;
470         DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
471         return;
472     }
473
474     WrtClientUserData *userData = new WrtClientUserData;
475     userData->This = this;
476     userData->pid = new unsigned long(getpid());
477     userData->debugMode = this->m_debugMode;
478
479     wrt_launch_widget(*handle,
480                       userData->pid,
481                       NULL,
482                       userData,
483                       &staticWrtLaunchWidgetCallback);
484 }
485
486 void WrtClient::killWidgetStep()
487 {
488     LogDebug("Killing widget ...");
489     wrt_kill_widget(m_handle, this, &staticWrtStatusCallback);
490 }
491
492 void WrtClient::finalizeLaunchStep()
493 {
494     LogDebug("Finalizing Launching widget ...");
495     m_launched = true;
496 }
497
498 void WrtClient::shutdownStep()
499 {
500     LogDebug("Closing Wrt connection ...");
501     wrt_shutdown();
502     m_initialized = false;
503     DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
504 }
505
506 void WrtClient::setDeveloperModeStep()
507 {
508     LogDebug("Set developer mode...");
509     wrt_set_developer_mode(m_developerMode,
510                            &staticSetDeveloperModeCallback,
511                            this);
512 }
513
514 void WrtClient::setComplianceModeStep()
515 {
516     LogDebug("Set compliance mode...");
517     wrt_set_compliance_mode(m_complianceMode,
518                             &staticSetComplianceModeCallback,
519                             this);
520 }
521
522 void WrtClient::setComplianceImeiStep()
523 {
524     LogDebug("Set compliance fake IMEI...");
525     wrt_set_compliance_fake_imei(m_complianceIMEI.c_str(),
526                                  &staticSetComplianceImeiCallback,
527                                  this);
528 }
529
530 void WrtClient::setComplianceMeidStep()
531 {
532     LogDebug("Set compliance fake MEID...");
533     wrt_set_compliance_fake_meid(m_complianceMEID.c_str(),
534                                  &staticSetComplianceMeidCallback,
535                                  this);
536 }
537
538 void WrtClient::queryListStep()
539 {
540     LogDebug("Query list...");
541
542     int count;
543     int *handles;
544
545     printf("%3s%12s%32s%16s%64s%32s\n",
546             "No", "ID", "Name", "Version", "GUID", "Package Name");
547     printf("%3s%12s%32s%16s%64s%32s\n",
548             "--", "--", "----", "-------", "----", "------------");
549
550     if (wrt_has_succeded(wrt_get_widget_list(&count, &handles))) {
551         for (int i = 0; i < count; ++i) {
552             wrt_widget_info *info;
553
554             // Get widget infor for handle
555             WrtErrStatus status = wrt_get_widget_info(handles[i], &info);
556             LogInfo("Status: " << status);
557             if (wrt_has_succeded(status)) {
558                 printf("%3i%12i%32s%16s%64s%32s\n",
559                        i + 1,
560                        handles[i],
561                        !info->name ? "[NULL]" : info->name,
562                        !info->version ? "[NULL]" : info->version,
563                        !info->id ? "[NULL]" : info->id,
564                        !info->pkg_name ? "[NULL]" : info->pkg_name);
565
566                 // Free widget info
567                 wrt_free_widget_info(info);
568             } else {
569                 LogWarning("ReturnStatus::Failed to get widget name");
570             }
571         }
572
573         // Free list
574         wrt_free_widget_list(handles);
575     } else {
576         LogWarning("ReturnStatus::Failed to get widget handle list");
577     }
578
579     DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
580 }
581
582 void WrtClient::staticWrtInitCallback(WrtErrStatus status,
583                                       void* userdata)
584 {
585     WrtClient *This = static_cast<WrtClient*>(userdata);
586
587     if (status == WRT_SUCCESS) {
588         LogDebug("Init succesfull");
589         This->m_initialized = true;
590         This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
591                 NextStepEvent());
592     } else {
593         LogError("Init unsuccesfull");
594         This->m_returnStatus = ReturnStatus::Failed;
595         This->DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
596     }
597 }
598
599 void WrtClient::staticWrtLaunchWidgetCallback(void* /*canvas*/,
600                                               int handle,
601                                               WrtErrStatus status,
602                                               const char* errorMsg,
603                                               void* userdata)
604 {
605     WrtClientUserData *userData = static_cast<WrtClientUserData*>(userdata);
606
607     if (status == WRT_SUCCESS) {
608         LogDebug("Launch succesfull");
609
610         userData->This->m_handle = handle;
611         userData->This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
612                 NextStepEvent());
613
614         setlinebuf(stdout);
615         printf("launched\n");
616         fflush(stdout);
617     } else {
618         LogError("Launch unsuccesfull: " << errorMsg);
619
620         printf("failed\n");
621
622         userData->This->m_returnStatus = ReturnStatus::Failed;
623         userData->This->DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(
624                 QuitEvent());
625     }
626
627     if(userData->debugMode == EINA_TRUE)
628     {
629         LogDebug("Send RT signal to wrt-launcher(pid: "
630                 << userData->This->m_sdkLauncherPid << ", status: " << status);
631         union sigval sv;
632         /* send real time signal with result to wrt-launcher */
633         if(status == WRT_SUCCESS)
634         {
635             LogDebug("userData->portnum : " << userData->portnum);
636             sv.sival_int = userData->portnum;
637         }
638         else
639         {
640            sv.sival_int = -1;
641         }
642         sigqueue(userData->This->m_sdkLauncherPid, SIGRTMIN, sv);
643     }
644
645     ApplicationDataSingleton::Instance().freeBundle();
646
647     delete userData->pid;
648     delete userData;
649 }
650
651 void WrtClient::staticWrtStatusCallback(int handle,
652                                         WrtErrStatus status,
653                                         void* userdata)
654 {
655     WrtClient *This = static_cast<WrtClient*>(userdata);
656
657     if (status == WRT_SUCCESS) {
658         LogDebug("Status succesfull");
659         This->m_handle = handle;
660         This->m_launched = false;
661
662         This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
663                 NextStepEvent());
664
665         return;
666     }
667
668     // Failure
669     LogWarning("Install failed!");
670
671     This->m_returnStatus = ReturnStatus::Failed;
672     This->DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
673 }
674
675 void WrtClient::staticCloseWidgetCallback(int /*widgetHandle*/,
676                                           void *data)
677 {
678     WrtClient *This = static_cast<WrtClient*>(data);
679
680     This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
681             NextStepEvent());
682 }
683
684 void WrtClient::staticSetDeveloperModeCallback(void *userParam)
685 {
686     WrtClient *This = static_cast<WrtClient *>(userParam);
687
688     This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
689             NextStepEvent());
690 }
691
692 void WrtClient::staticSetComplianceModeCallback(void *userParam)
693 {
694     Assert(userParam);
695     WrtClient *This = static_cast<WrtClient *>(userParam);
696
697     LogInfo("Compliance mode is " <<
698             (This->m_complianceMode ? "enabled" : "disabled"));
699
700     This->DPL::Event::ControllerEventHandler<NextStepEvent>::
701         PostEvent(NextStepEvent());
702 }
703
704 void WrtClient::staticSetComplianceImeiCallback(void *userParam)
705 {
706     Assert(userParam);
707     WrtClient *This = static_cast<WrtClient *>(userParam);
708
709     LogInfo("Compliance fake IMEI is " << This->m_complianceIMEI);
710
711     This->DPL::Event::ControllerEventHandler<NextStepEvent>::
712         PostEvent(NextStepEvent());
713 }
714
715 void WrtClient::staticSetComplianceMeidCallback(void *userParam)
716 {
717     Assert(userParam);
718     WrtClient *This = static_cast<WrtClient *>(userParam);
719
720     LogInfo("Compliance fake MEID is " << This->m_complianceMEID);
721
722     This->DPL::Event::ControllerEventHandler<NextStepEvent>::
723         PostEvent(NextStepEvent());
724 }
725
726 void WrtClient::staticWrtResumeStatusCallback(int /*handle*/,
727                                               WrtErrStatus status,
728                                               void* /*userdata*/)
729 {
730     if (WRT_SUCCESS == status) {
731         LogDebug("Resume succesfull");
732         return;
733     }
734 }
735
736 void WrtClient::staticWrtSuspendStatusCallback(int /*handle*/,
737                                                WrtErrStatus status,
738                                                void* /*userdata*/)
739 {
740     if (WRT_SUCCESS == status) {
741         LogDebug("Suspend succesfull");
742         return;
743     }
744 }
745
746 void WrtClient::staticWrtResetStatusCallback(int /*handle*/,
747                                              WrtErrStatus status,
748                                              void* /*userdata*/)
749 {
750     if (WRT_SUCCESS == status) {
751         LogDebug("Reset succesfull");
752         return;
753     }
754 }
755
756 void WrtClient::installNewPlugins()
757 {
758     LogDebug("Install new plugins");
759
760     if (!PluginUtils::checkPluginInstallationRequired()) {
761         LogDebug("Plugin installation not required");
762         return;
763     }
764
765     m_startupPluginInstallation = true;
766     system("wrt-installer -p");
767 }
768
769 int main(int argc,
770          char *argv[])
771 {
772     ADD_PROFILING_POINT("main-entered", "point");
773
774     // Output on stdout will be flushed after every newline character,
775     // even if it is redirected to a pipe. This is useful for running
776     // from a script and parsing output.
777     // (Standard behavior of stdlib is to use full buffering when
778     // redirected to a pipe, which means even after an end of line
779     // the output may not be flushed).
780     setlinebuf(stdout);
781
782     // set evas backend type
783     // check current machine is target or emul
784     struct utsname u;
785     std::string backend = "gl";
786     if (0 == uname(&u)) {
787         if ((!u.machine) || (0 == strlen(u.machine))) {
788             LogError("Fail to get machine name");
789         } else {
790             // If current machine is emul,
791             // machine name include "<arch>_emulated"
792             std::string machine = u.machine;
793             LogDebug("machine name is [" << machine << "]");
794             // find "emulated" string in the u.machine
795             if (std::string::npos != machine.find(MACHINE_NAME_EMUL)) {
796                 LogDebug("Current machine is emul");
797                 backend = "x11";
798             } else {
799                 //webkit accel needs to evas backend
800                 LogDebug("Set backend to gl");
801                 backend = "gl";
802             }
803         }
804     } else {
805         perror("Fail to get machine name");
806     }
807
808     if (!getenv("ELM_ENGINE")) {
809         if (setenv("ELM_ENGINE", backend.c_str(), 1)) {
810                 LogDebug("Enable backend");
811         }
812     }
813     DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-CLIENT");
814     WrtClient app(argc, argv);
815     int ret = app.Exec();
816     LogDebug("App returned: " << ret);
817     ret = app.getReturnStatus();
818     LogDebug("WrtClient returned: " << ret);
819     return ret;
820 }