1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/tizen/appcore_context.h"
7 #include <appcore-common.h>
11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h"
14 // AppcoreContextImpl uses private Tizen appcore API to reuse Tizen 2.0
16 // This private implementation of appcore is a bit huge. We will decide later
17 // whether to maintain the code similar to appcore private implementation
18 // in Crosswalk or not after investigating appcore in Tizen 3.0.
21 int app_get_id(char** id);
23 // define in app_private.h
24 int app_get_package_app_name(const char* package, char** name);
25 void app_finalizer_execute(void);
28 int aul_status_update(int status);
30 // define in appcore-internal.h
45 void (*cb_app)(enum app_event evnt, void* data, bundle*);
51 // FIXME: this implementation is not compatible with shared process mode,
52 // because Tizen task switcher cannot recognize multiple tasks per process.
53 // Shared process mode requires one Crosswalk process to include multiple tasks
54 // (= web applications). It is not supported by current task switcher.
55 class AppcoreContextImpl
56 : public AppcoreContext {
59 virtual ~AppcoreContextImpl();
64 static void HandleAppcoreEvents(enum app_event, void*, bundle*);
65 void HandleAppcoreEventsInternal(enum app_event, bundle*);
68 char* application_name_;
70 struct ui_ops appcore_operations_;
72 DISALLOW_COPY_AND_ASSIGN(AppcoreContextImpl);
75 scoped_ptr<AppcoreContext> AppcoreContext::Create() {
76 scoped_ptr<AppcoreContextImpl> context(new AppcoreContextImpl());
77 if (context->Initialize())
78 return context.PassAs<AppcoreContext>();
79 return scoped_ptr<AppcoreContext>();
82 AppcoreContextImpl::AppcoreContextImpl()
84 application_name_(NULL),
86 appcore_operations_.data = this;
87 appcore_operations_.cb_app = HandleAppcoreEvents;
90 AppcoreContextImpl::~AppcoreContextImpl() {
92 app_finalizer_execute();
93 aul_status_update(STATUS_DYING);
95 DCHECK(package_ && application_name_);
98 // app_get_id() and app_get_package_app_name() allocated them using malloc.
100 free(application_name_);
103 bool AppcoreContextImpl::Initialize() {
104 if (app_get_id(&package_) != TIZEN_ERROR_NONE) {
105 LOG(ERROR) << "Failed to get the package: " << package_;
109 if (app_get_package_app_name(package_, &application_name_) !=
111 LOG(ERROR) << "Failed to get the package's application name: "
112 << application_name_;
116 DCHECK(application_name_ && application_name_[0] != '\0');
117 char* argv[2] = {'\0', };
118 int r = appcore_init(application_name_, &appcore_operations_, 1, argv);
120 LOG(ERROR) << "Failed to initialize appcore. application name: "
121 << application_name_;
130 void AppcoreContextImpl::HandleAppcoreEvents(enum app_event event,
133 static_cast<AppcoreContextImpl*>(data)->
134 HandleAppcoreEventsInternal(event, b);
137 void AppcoreContextImpl::HandleAppcoreEventsInternal(enum app_event event,
139 DCHECK(initialized_);
145 LOG(INFO) << "[XWalk " << getpid() <<"] TERMINATE";
146 base::MessageLoop::current()->QuitNow();