user_data_(user_data) {
}
+ AppEventStub(aul_app_event_launched_cb launched_cb,
+ aul_app_event_terminated_cb terminated_cb,
+ void* user_data)
+ : AppEvent(this),
+ launched_cb_(launched_cb),
+ terminated_cb_(terminated_cb),
+ user_data_(user_data) {
+ }
+
void OnAppLaunched(const AppContext* context) override {
AppContext* ctx = const_cast<AppContext*>(context);
launched_cb_(static_cast<aul_app_context_h>(ctx), user_data_);
} // namespace
-extern "C" API int aul_app_event_create(const char *app_id,
+extern "C" API int aul_app_event_create_with_appid(const char* app_id,
aul_app_event_launched_cb launched_cb,
aul_app_event_terminated_cb terminated_cb,
- void *user_data,
- aul_app_event_h *app_event) {
+ void* user_data,
+ aul_app_event_h* app_event) {
if (!app_id || !launched_cb || !terminated_cb || !app_event) {
_E("Invalid parameter");
return AUL_R_EINVAL;
return AUL_R_OK;
}
+extern "C" API int aul_app_event_create(aul_app_event_launched_cb launched_cb,
+ aul_app_event_terminated_cb terminated_cb,
+ void* user_data,
+ aul_app_event_h* app_event) {
+ if (!launched_cb || !terminated_cb || !app_event) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ AppEventStub* handle = nullptr;
+ try {
+ handle = new AppEventStub(launched_cb, terminated_cb, user_data);
+ } catch (Exception& e) {
+ return e.GetErrorCode();
+ }
+
+ *app_event = static_cast<aul_app_event_h>(handle);
+
+ return AUL_R_OK;
+}
+
extern "C" API int aul_app_event_destroy(aul_app_event_h app_event) {
if (!app_event) {
_E("Invalid parameter");
typedef void (*aul_app_event_terminated_cb)(aul_app_context_h app_context,
void *user_data);
-int aul_app_event_create(const char *app_id,
+int aul_app_event_create_with_appid(const char *app_id,
aul_app_event_launched_cb launched_cb,
aul_app_event_terminated_cb terminated_cb,
void *user_data,
aul_app_event_h *app_event);
+int aul_app_event_create(aul_app_event_launched_cb launched_cb,
+ aul_app_event_terminated_cb terminated_cb,
+ void *user_data,
+ aul_app_event_h *app_event);
+
int aul_app_event_destroy(aul_app_event_h app_event);
#ifdef __cplusplus
* limitations under the License.
*/
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <bundle_cpp.h>
+
#include "aul/app_manager/app_event.hh"
+#include "aul/common/common.hh"
#include "aul/common/exception.hh"
#include "aul/common/log_private.hh"
AppEvent::AppEvent(std::string app_id, AppEvent::IEvent* ev)
: app_id_(std::move(app_id)), ev_(ev) {
- int ret = aul_listen_app_status(app_id_.c_str(), OnAppStatusCb,
+ std::string endpoint = "app_status_event:" + app_id;
+ if (getuid() >= REGULAR_UID_MIN)
+ endpoint += ":" + std::to_string(getuid());
+
+ int ret = aul_app_com_create(endpoint.c_str(), nullptr, OnAppStatusCb,
+ this, &handle_);
+ if (ret != AUL_R_OK) {
+ _E("aul_app_com_create(%s) is failed. error(%d)", endpoint.c_str(), ret);
+ THROW(ret);
+ }
+}
+
+AppEvent::AppEvent(AppEvent::IEvent* ev) : ev_(ev) {
+ std::string endpoint = "app_status_event";
+ if (getuid() >= REGULAR_UID_MIN)
+ endpoint += ":" + std::to_string(getuid());
+
+ int ret = aul_app_com_create(endpoint.c_str(), nullptr, OnAppStatusCb,
this, &handle_);
if (ret != AUL_R_OK) {
- _E("Failed to listen app status event. error(%d)", ret);
+ _E("aul_app_com_create(%s) is failed. error(%d)", endpoint.c_str(), ret);
THROW(ret);
}
}
AppEvent::~AppEvent() {
if (handle_)
- aul_ignore_app_status(handle_);
+ aul_app_com_leave(handle_);
}
-int AppEvent::OnAppStatusCb(aul_app_info* info, int ctx_status, void* data) {
+int AppEvent::OnAppStatusCb(const char* endpoint, aul_app_com_result_e res,
+ bundle* envelope, void* user_data) {
+ tizen_base::Bundle b(envelope);
AppContext::Builder builder;
- builder.SetAppId(info->appid);
- builder.SetPkgId(info->pkgid);
- builder.SetInstId(info->instance_id);
- builder.SetExec(info->app_path);
- builder.SetPid(info->pid);
- builder.SetStatus(info->status);
- builder.SetIsSubApp(static_cast<bool>(info->is_sub_app));
+ builder.SetAppId(b.GetString(AUL_K_APPID));
+ builder.SetPkgId(b.GetString(AUL_K_PKGID));
+ builder.SetInstId(b.GetString(AUL_K_INSTANCE_ID));
+ builder.SetExec(b.GetString(AUL_K_EXEC));
+ builder.SetPid(std::stoi(b.GetString(AUL_K_PID)));
+ builder.SetStatus(std::stoi(b.GetString(AUL_K_STATUS)));
+ builder.SetIsSubApp(static_cast<bool>(
+ std::stoi(b.GetString(AUL_K_IS_SUBAPP))));
AppContext app_context = builder.Build();
- auto* handle = static_cast<AppEvent*>(data);
+ auto* handle = static_cast<AppEvent*>(user_data);
IEvent* ev = handle->ev_;
- if (ctx_status == STATUS_TERMINATE)
+ int context_status = std::stoi(b.GetString("__CONTEXT_STATUS__"));
+ if (context_status == STATUS_TERMINATE)
ev->OnAppTerminated(&app_context);
else
ev->OnAppLaunched(&app_context);
* limitations under the License.
*/
-#ifndef AUL_APP_MANAGER__APP_EVENT_HH_
+#ifndef AUL_APP_MANAGER_APP_EVENT_HH_
#define AUL_APP_MANAGER_APP_EVENT_HH_
#include <string>
#include "aul/app_manager/app_context.hh"
#include "include/aul.h"
+#include "include/aul_app_com.h"
namespace aul {
};
AppEvent(std::string app_id, IEvent* ev);
+ AppEvent(IEvent* ev);
virtual ~AppEvent();
private:
- static int OnAppStatusCb(aul_app_info* info, int ctx_status, void* data);
+ static int OnAppStatusCb(const char* endpoint, aul_app_com_result_e res,
+ bundle* envelope, void* user_data);
private:
std::string app_id_;
IEvent* ev_;
- status_listen_h handle_ = nullptr;
+ aul_app_com_connection_h handle_ = nullptr;
};
} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AUL_COMMON_COMMON_HH_
+#define AUL_COMMON_COMMON_HH_
+
+#undef REGULAR_UID_MIN
+#define REGULAR_UID_MIN 5000
+
+#endif // AUL_COMMON_COMMON_HH_