2 * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "include/aul_launcher_service.h"
23 #include <bundle_internal.h>
27 #include "include/aul_app_com.h"
28 #include "include/aul_error.h"
29 #include "include/aul_sock.h"
31 #include "app_request.h"
33 struct aul_launcher_serivce_s {
37 using namespace aul::internal;
40 class LauncherService {
42 LauncherService(std::string name, aul_launcher_service_cb cb,
44 : name_(std::move(name)), cb_(cb), user_data_(user_data) {
49 aul_app_com_leave(conn_);
56 std::string endpoint = "launcher_service:" + name_ + ":" +
57 std::to_string(getpid());
58 int ret = aul_app_com_create(endpoint.c_str(), nullptr, AppComCb,
61 _E("Failed to create app com. error(%d)", ret);
69 static int AppComCb(const char* endpoint, aul_app_com_result_e result,
70 bundle* envelope, void* user_data) {
71 const char* appid = bundle_get_val(envelope, AUL_K_APPID);
72 if (appid == nullptr) {
73 _E("Failed to get application ID");
77 const char* instance_id = bundle_get_val(envelope, AUL_K_INSTANCE_ID);
78 if (instance_id == nullptr) {
79 _E("Failed to get instance ID");
83 const char* pid_str = bundle_get_val(envelope, AUL_K_PID);
84 if (pid_str == nullptr) {
85 _E("Failed to get process ID");
88 int pid = atoi(pid_str);
90 const char* serial_str = bundle_get_val(envelope,
91 AUL_K_LAUNCHER_SERVICE_SERIAL);
92 if (serial_str == nullptr) {
93 _E("Failed to get serial");
96 uint32_t serial = strtoul(serial_str, NULL, 10);
98 auto* launcher_service = static_cast<LauncherService*>(user_data);
99 launcher_service->cb_(appid, instance_id, pid, serial,
100 launcher_service->user_data_);
106 aul_launcher_service_cb cb_;
108 aul_app_com_connection_h conn_ = nullptr;
113 extern "C" API int aul_launcher_service_create(const char* name,
114 aul_launcher_service_cb callback, void* user_data,
115 aul_launcher_service_h* handle) {
116 if (callback == nullptr || name == nullptr || handle == nullptr) {
117 _E("Invalid parameter");
121 auto* service = new (std::nothrow) LauncherService(name, callback, user_data);
122 if (service == nullptr) {
127 *handle = reinterpret_cast<aul_launcher_service_h>(service);
131 extern "C" API int aul_launcher_service_listen(aul_launcher_service_h handle) {
132 if (handle == nullptr) {
133 _E("Invalid parameter");
137 auto* service = reinterpret_cast<LauncherService*>(handle);
138 return service->Listen();
141 extern "C" API int aul_launcher_service_destroy(aul_launcher_service_h handle) {
142 if (handle == nullptr) {
143 _E("Invalid parameter");
147 auto* service = reinterpret_cast<LauncherService*>(handle);
152 extern "C" API int aul_launcher_service_notify_animation_started(void) {
153 return AppRequest(LAUNCHER_SERVICE_NOTIFY_ANIMATION_STARTED, getuid())
154 .SendCmdOnly(AUL_SOCK_NOREPLY);
157 extern "C" API int aul_launcher_service_notify_animation_finished(void) {
158 return AppRequest(LAUNCHER_SERVICE_NOTIFY_ANIMATION_FINISHED, getuid())
159 .SendCmdOnly(AUL_SOCK_NOREPLY);