--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * 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 SCREEN_CONNECTOR_LAUNCHER_SERVICE_INCLUDE_SCREEN_CONNECTOR_LAUNCHER_SERVICE_H_
+#define SCREEN_CONNECTOR_LAUNCHER_SERVICE_INCLUDE_SCREEN_CONNECTOR_LAUNCHER_SERVICE_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <Ecore_Wl2.h>
+#include <tbm_surface.h>
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ SCREEN_CONNECTOR_LAUNCHER_SERVICE_ERROR_NONE,
+ SCREEN_CONNECTOR_LAUNCHER_SERVICE_ERROR_DISQUALIFIED,
+ SCREEN_CONNECTOR_LAUNCHER_SERVICE_ERROR_WRONG_REQUEST,
+} screen_connector_launcher_service_error_e;
+
+typedef enum {
+ SCREEN_CONNECTOR_LAUNCHER_SERVICE_DIRECTION_FORWARD,
+ SCREEN_CONNECTOR_LAUNCHER_SERVICE_DIRECTION_BACKWARD,
+} screen_connector_launcher_service_direction_e;
+
+typedef enum {
+ SCREEN_CONNECTOR_LAUNCHER_SERVICE_IMAGE_TYPE_REMOTE_SURFACE_TBM,
+ SCREEN_CONNECTOR_LAUNCHER_SERVICE_IMAGE_TYPE_REMOTE_SURFACE_IMAGE_FILE,
+ SCREEN_CONNECTOR_LAUNCHER_SERVICE_IMAGE_TYPE_SPLASH_SCREEN_IMAGE,
+ SCREEN_CONNECTOR_LAUNCHER_SERVICE_IMAGE_TYPE_SPLASH_SCREEN_EDJE,
+} screen_connector_launcher_service_image_type_e;
+
+typedef void* screen_connector_launcher_service_h;
+
+typedef void* screen_connector_launcher_service_image_h;
+
+typedef void (*screen_connector_launcher_service_prepare_cb)(
+ screen_connector_launcher_service_image_h image,
+ uint32_t serial,
+ void* user_data);
+
+typedef void (*screen_connector_launcher_service_stop_cb)(
+ uint32_t serial,
+ void* user_data);
+
+typedef void (*screen_connector_launcher_service_error_cb)(
+ screen_connector_launcher_service_error_e error,
+ uint32_t serial,
+ void* user_data);
+
+typedef void (*screen_connector_launcher_service_cleanup_cb)(
+ uint32_t serial,
+ void* user_data);
+
+typedef void (*screen_connector_launcher_service_reset_cb)(
+ uint32_t serial,
+ void* user_data);
+
+typedef struct {
+ screen_connector_launcher_service_prepare_cb prepare;
+ screen_connector_launcher_service_stop_cb stop;
+ screen_connector_launcher_service_error_cb error;
+ screen_connector_launcher_service_cleanup_cb cleanup;
+ screen_connector_launcher_service_reset_cb reset;
+} screen_connector_launcher_service_ops;
+
+int screen_connector_launcher_service_create(
+ Ecore_Wl2_Window* wl2_win,
+ screen_connector_launcher_service_h* handle);
+
+int screen_connector_launcher_service_destroy(
+ screen_connector_launcher_service_h handle);
+
+int screen_connector_launcher_service_set_ops(
+ screen_connector_launcher_service_h handle,
+ screen_connector_launcher_service_ops *ops,
+ void* user_data);
+
+int screen_connector_launcher_service_launch(
+ screen_connector_launcher_service_h handle,
+ const char* app_id,
+ const char* inst_id,
+ int pid,
+ uint32_t serial);
+
+int screen_connector_launcher_service_launch_with_shared_widget(
+ screen_connector_launcher_service_h handle,
+ const char* app_id,
+ const char* inst_id,
+ int pid,
+ uint32_t serial);
+
+int screen_connector_launcher_service_launching(
+ screen_connector_launcher_service_h handle,
+ uint32_t serial);
+
+int screen_connector_launcher_service_launch_cancel(
+ screen_connector_launcher_service_h handle,
+ uint32_t serial);
+
+int screen_connector_launcher_service_launch_done(
+ screen_connector_launcher_service_h handle,
+ uint32_t serial);
+
+int screen_connector_launcher_service_image_get_direction(
+ screen_connector_launcher_service_image_h handle,
+ screen_connector_launcher_service_direction_e* direction);
+
+int screen_connector_launcher_service_image_get_type(
+ screen_connector_launcher_service_image_h handle,
+ screen_connector_launcher_service_image_type_e *image_type);
+
+int screen_connector_launcher_service_image_get_position_x(
+ screen_connector_launcher_service_image_h handle,
+ int32_t* x);
+
+int screen_connector_launcher_service_image_get_position_y(
+ screen_connector_launcher_service_image_h handle,
+ int32_t* y);
+
+int screen_connector_launcher_service_image_get_shared_widget_info(
+ screen_connector_launcher_service_image_h handle,
+ char** shared_widget_info);
+
+int screen_connector_launcher_service_image_get_tbm_surface_info(
+ screen_connector_launcher_service_image_h handle,
+ tbm_surface_info_s** tbm_surface_info);
+
+int screen_connector_launcher_service_image_get_image_file(
+ screen_connector_launcher_service_image_h handle,
+ int32_t* fd, uint32_t* size);
+
+int screen_connector_launcher_service_image_get_file_path(
+ screen_connector_launcher_service_image_h handle,
+ char** file_path);
+
+int screen_connector_launcher_service_image_get_file_group(
+ screen_connector_launcher_service_image_h handle,
+ char** file_group);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // SCREEN_CONNECTOR_LAUNCHER_SERVICE_INCLUDE_SCREEN_CONNECTOR_LAUNCHER_SERVICE_H_
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include "screen_connector_common/export.h"
+#include "screen_connector_launcher_service/include/screen_connector_launcher_service.h"
+#include "screen_connector_launcher_service/launcher_service.h"
+#include "screen_connector_launcher_service/log_internal.h"
+
+namespace {
+
+static screen_connector_launcher_service_error_e __convert_error(
+ screen_connector::Error error) {
+ if (error == screen_connector::Error::Disqualified) {
+ return SCREEN_CONNECTOR_LAUNCHER_SERVICE_ERROR_DISQUALIFIED;
+ } else if (error == screen_connector::Error::WrongRequest) {
+ return SCREEN_CONNECTOR_LAUNCHER_SERVICE_ERROR_WRONG_REQUEST;
+ } else {
+ return SCREEN_CONNECTOR_LAUNCHER_SERVICE_ERROR_NONE;
+ }
+}
+
+static screen_connector_launcher_service_direction_e __convert_direction(
+ screen_connector::Direction direction) {
+ if (direction == screen_connector::Direction::Forward)
+ return SCREEN_CONNECTOR_LAUNCHER_SERVICE_DIRECTION_FORWARD;
+
+ return SCREEN_CONNECTOR_LAUNCHER_SERVICE_DIRECTION_BACKWARD;
+}
+
+static screen_connector_launcher_service_image_type_e __convert_image_type(
+ screen_connector::ImageType image_type) {
+ if (image_type == screen_connector::ImageType::RemoteSurfaceTBM) {
+ return SCREEN_CONNECTOR_LAUNCHER_SERVICE_IMAGE_TYPE_REMOTE_SURFACE_TBM;
+ } else if (image_type == screen_connector::ImageType::RemoteSurfaceImageFile) {
+ return SCREEN_CONNECTOR_LAUNCHER_SERVICE_IMAGE_TYPE_REMOTE_SURFACE_IMAGE_FILE;
+ } else if (image_type == screen_connector::ImageType::SplashScreenImage) {
+ return SCREEN_CONNECTOR_LAUNCHER_SERVICE_IMAGE_TYPE_SPLASH_SCREEN_IMAGE;
+ } else {
+ return SCREEN_CONNECTOR_LAUNCHER_SERVICE_IMAGE_TYPE_SPLASH_SCREEN_EDJE;
+ }
+}
+
+class LauncherServiceStub
+ : public screen_connector::LauncherService,
+ public screen_connector::LauncherService::IEventListener {
+ public:
+ LauncherServiceStub(std::shared_ptr<screen_connector::Wl2Window> wl2_win)
+ : screen_connector::LauncherService(std::move(wl2_win), this) {
+ }
+
+ void SetOps(screen_connector_launcher_service_ops* ops,
+ void* user_data) {
+ ops_ = *ops;
+ user_data_ = user_data;
+ }
+
+ void OnPrepareEvent(std::shared_ptr<screen_connector::RawImage> image,
+ uint32_t serial) override {
+ raw_image_ = std::move(image);
+ if (ops_.prepare) {
+ ops_.prepare(reinterpret_cast<void*>(&raw_image_), serial, user_data_);
+ }
+ }
+
+ void OnStopEvent(uint32_t serial) override {
+ if (ops_.stop) {
+ ops_.stop(serial, user_data_);
+ }
+ }
+
+ void OnErrorEvent(screen_connector::Error error,
+ uint32_t serial) override {
+ if (ops_.error) {
+ ops_.error(__convert_error(error), serial, user_data_);
+ }
+ }
+
+ void OnCleanUpEvent(uint32_t serial) override {
+ if (ops_.cleanup) {
+ ops_.cleanup(serial, user_data_);
+ }
+ }
+
+ void OnResetEvent(uint32_t serial) override {
+ if (ops_.reset) {
+ ops_.reset(serial, user_data_);
+ }
+ raw_image_.reset();
+ }
+
+ private:
+ screen_connector_launcher_service_ops ops_ = { 0, };
+ void* user_data_ = nullptr;
+ std::shared_ptr<screen_connector::RawImage> raw_image_;
+};
+
+} // namespace
+
+extern "C" EXPORT int screen_connector_launcher_service_create(
+ Ecore_Wl2_Window* wl2_win,
+ screen_connector_launcher_service_h* handle) {
+ if (wl2_win == nullptr || handle == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto ls = new (std::nothrow) LauncherServiceStub(
+ std::shared_ptr<screen_connector::Wl2Window>(
+ new (std::nothrow) screen_connector::Wl2Window(wl2_win)));
+
+ *handle = static_cast<void*>(ls);
+
+ return 0;
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_destroy(
+ screen_connector_launcher_service_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto ls = static_cast<LauncherServiceStub*>(handle);
+ delete ls;
+
+ return 0;
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_set_ops(
+ screen_connector_launcher_service_h handle,
+ screen_connector_launcher_service_ops* ops,
+ void* user_data) {
+ if (handle == nullptr || ops == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto ls = static_cast<LauncherServiceStub*>(handle);
+ ls->SetOps(ops, user_data);
+
+ return 0;
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_launch(
+ screen_connector_launcher_service_h handle,
+ const char* app_id,
+ const char* inst_id,
+ int pid,
+ uint32_t serial) {
+ if (handle == nullptr || app_id == nullptr || pid < -1) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto ls = static_cast<LauncherServiceStub*>(handle);
+ return ls->Launch(app_id, inst_id, pid, serial);
+}
+
+extern "C" EXPORT int
+screen_connector_launcher_service_launch_with_shared_widget (
+ screen_connector_launcher_service_h handle,
+ const char* app_id,
+ const char* inst_id,
+ int pid,
+ uint32_t serial) {
+ if (handle == nullptr || app_id == nullptr || pid < -1) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto ls = static_cast<LauncherServiceStub*>(handle);
+ return ls->LaunchWithSharedWidget(app_id, inst_id, pid, serial);
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_launching(
+ screen_connector_launcher_service_h handle,
+ uint32_t serial) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto ls = static_cast<LauncherServiceStub*>(handle);
+ return ls->Launching(serial);
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_launch_cancel(
+ screen_connector_launcher_service_h handle,
+ uint32_t serial) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto ls = static_cast<LauncherServiceStub*>(handle);
+ return ls->LaunchCancel(serial);
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_launch_done(
+ screen_connector_launcher_service_h handle,
+ uint32_t serial) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto ls = static_cast<LauncherServiceStub*>(handle);
+ return ls->LaunchDone(serial);
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_image_get_direction(
+ screen_connector_launcher_service_image_h handle,
+ screen_connector_launcher_service_direction_e* direction) {
+ if (handle == nullptr || direction == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto img_ptr =
+ reinterpret_cast<std::shared_ptr<screen_connector::RawImage>*>(handle);
+ auto img = img_ptr->get();
+ if (img == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *direction = __convert_direction(img->GetDirection());
+
+ return 0;
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_image_get_type(
+ screen_connector_launcher_service_image_h handle,
+ screen_connector_launcher_service_image_type_e* image_type) {
+ if (handle == nullptr || image_type == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto img_ptr =
+ reinterpret_cast<std::shared_ptr<screen_connector::RawImage>*>(handle);
+ auto img = img_ptr->get();
+ if (img == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *image_type = __convert_image_type(img->GetImageType());
+
+ return 0;
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_image_get_position_x(
+ screen_connector_launcher_service_image_h handle,
+ int32_t* x) {
+ if (handle == nullptr || x == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto img_ptr =
+ reinterpret_cast<std::shared_ptr<screen_connector::RawImage>*>(handle);
+ auto img = img_ptr->get();
+ if (img == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *x = img->GetPositionX();
+
+ return 0;
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_image_get_position_y(
+ screen_connector_launcher_service_image_h handle,
+ int32_t* y) {
+ if (handle == nullptr || y == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto img_ptr =
+ reinterpret_cast<std::shared_ptr<screen_connector::RawImage>*>(handle);
+ auto img = img_ptr->get();
+ if (img == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *y = img->GetPositionY();
+
+ return 0;
+}
+
+extern "C" EXPORT int
+screen_connector_launcher_service_image_get_shared_widget_info(
+ screen_connector_launcher_service_image_h handle,
+ char** shared_widget_info) {
+ if (handle == nullptr || shared_widget_info == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto img_ptr =
+ reinterpret_cast<std::shared_ptr<screen_connector::RawImage>*>(handle);
+ auto img = img_ptr->get();
+ if (img == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *shared_widget_info = strdup(img->GetSharedWidgetInfo().c_str());
+ if (*shared_widget_info == nullptr) {
+ _E("Out of memory");
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+extern "C" EXPORT int
+screen_connector_launcher_service_image_get_tbm_surface_info(
+ screen_connector_launcher_service_image_h handle,
+ tbm_surface_info_s** tbm_surface_info) {
+ if (handle == nullptr || tbm_surface_info == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto img_ptr =
+ reinterpret_cast<std::shared_ptr<screen_connector::RawImage>*>(handle);
+ auto img = img_ptr->get();
+ if (img == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *tbm_surface_info = img->GetWlBuffer()->GetTbmSurfaceInfo();
+
+ return 0;
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_image_get_image_file(
+ screen_connector_launcher_service_image_h handle,
+ int32_t* fd, uint32_t* size) {
+ if (handle == nullptr || fd == nullptr || size == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto img_ptr =
+ reinterpret_cast<std::shared_ptr<screen_connector::RawImage>*>(handle);
+ auto img = img_ptr->get();
+ if (img == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *fd = img->GetImageFile()->GetRaw();
+ *size = img->GetImageFile()->GetSize();
+
+ return 0;
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_image_get_file_path(
+ screen_connector_launcher_service_image_h handle,
+ char** file_path) {
+ if (handle == nullptr || file_path == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto img_ptr =
+ reinterpret_cast<std::shared_ptr<screen_connector::RawImage>*>(handle);
+ auto img = img_ptr->get();
+ if (img == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *file_path = strdup(img->GetFilePath().c_str());
+ if (*file_path == nullptr) {
+ _E("Out of memory");
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+extern "C" EXPORT int screen_connector_launcher_service_image_get_file_group(
+ screen_connector_launcher_service_image_h handle,
+ char** file_group) {
+ if (handle == nullptr || file_group == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ auto img_ptr =
+ reinterpret_cast<std::shared_ptr<screen_connector::RawImage>*>(handle);
+ auto img = img_ptr->get();
+ if (img == nullptr) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *file_group = strdup(img->GetFileGroup().c_str());
+ if (*file_group == nullptr) {
+ _E("Out of memory");
+ return -ENOMEM;
+ }
+
+ return 0;
+}