--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
+PROJECT(united-service)
+
+SET(PC_NAME "united-service")
+SET(PC_DESCRIPTION "United Service library")
+SET(PC_VERSION "${FULLVER}")
+SET(PC_REQUIRED "capi-base-common bundle tizen-core")
+SET(PC_LDFLAGS "-lunited-service")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-zdefs -fvisibility=hidden -g -Wall -Werror -fpic")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_C_FLAGS_RELEASE "-O2")
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} -std=c++23")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
+
+SET(TARGET_UNITED_SERVICE "united-service")
+
+INCLUDE(FindPkgConfig)
+INCLUDE(ApplyPkgConfig)
+
+PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle)
+PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog)
+PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0)
+PKG_CHECK_MODULES(TIZEN_CORE_DEPS REQUIRED tizen-core)
+
+ADD_SUBDIRECTORY(src)
+
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_UNITED_SERVICE}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_UNITED_SERVICE}.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_UNITED_SERVICE}.pc
+ DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
+ DESTINATION include/tizen-base
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "include/*.h*")
--- /dev/null
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
--- /dev/null
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE.APLv2 file for Apache License terms and conditions.
--- /dev/null
+# Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+#
+# This function applies external (out of source tree) dependencies
+# to given target. Arguments are:
+# TARGET - valid cmake target
+# PRIVACY - dependency can be inherited by dependent targets or not:
+# PUBLIC - this should be used by default, cause compile/link flags passing
+# PRIVATE - do not passes any settings to dependent targets,
+# may be usefull for static libraries from the inside of the project
+# Argument ARGV2 and following are supposed to be names of checked pkg config
+# packages. This function will use variables created by check_pkg_modules().
+# - ${DEP_NAME}_LIBRARIES
+# - ${DEP_NAME}_INCLUDE_DIRS
+# - ${DEP_NAME}_CFLAGS
+#
+FUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)
+ MATH(EXPR DEST_INDEX "${ARGC}-1")
+ FOREACH(I RANGE 2 ${DEST_INDEX})
+ IF(NOT ${ARGV${I}}_FOUND)
+ MESSAGE(FATAL_ERROR "Not found dependency - ${ARGV${I}}_FOUND")
+ ENDIF(NOT ${ARGV${I}}_FOUND)
+ TARGET_LINK_LIBRARIES(${TARGET} ${PRIVACY} "${${ARGV${I}}_LIBRARIES}")
+ TARGET_INCLUDE_DIRECTORIES(${TARGET} ${PRIVACY} SYSTEM "${${ARGV${I}}_INCLUDE_DIRS}")
+ STRING(REPLACE ";" " " CFLAGS_STR "${${ARGV${I}}_CFLAGS}")
+ SET(CFLAGS_LIST ${CFLAGS_STR})
+ SEPARATE_ARGUMENTS(CFLAGS_LIST)
+ FOREACH(OPTION ${CFLAGS_LIST})
+ TARGET_COMPILE_OPTIONS(${TARGET} ${PRIVACY} ${OPTION})
+ ENDFOREACH(OPTION)
+ SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SKIP_BUILD_RPATH true)
+ ENDFOREACH(I RANGE 2 ${DEST_INDEX})
+ENDFUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)
--- /dev/null
+/*
+ * Copyright (c) 2025 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 __SERVICE_H__
+#define __SERVICE_H__
+
+#include <bundle.h>
+#include <tizen_core.h>
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ SERVICE_ERROR_NONE = TIZEN_ERROR_NONE,
+ SERVICE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,
+ SERVICE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,
+ SERVICE_ERROR_INVALID_CONTEXT = TIZEN_ERROR_APPLICATION | 0x01,
+ SERVICE_ERROR_ALREADY_EXIST = TIZEN_ERROR_FILE_EXISTS,
+} service_error_e;
+
+typedef enum {
+ SERVICE_STATE_INITIALIZED,
+ SERVICE_STATE_CREATED,
+ SERVICE_STATE_RUNNING,
+ SERVICE_STATE_DESTROYED,
+} service_state_e;
+
+typedef void (*service_create_cb)(void *user_data);
+
+typedef void (*service_destroy_cb)(void *user_data);
+
+typedef void (*service_message_cb)(const char *sender, bundle *envelope,
+ void *user_data);
+
+typedef struct {
+ service_create_cb create;
+ service_destroy_cb destroy;
+ service_message_cb message;
+} service_lifecycle_callback_s;
+
+typedef void *service_h;
+
+int service_create(const char *name, service_lifecycle_callback_s *callback,
+ void *user_data, service_h *service);
+
+int service_run(service_h service);
+
+int service_quit(service_h service);
+
+int service_send_message(service_h service, bundle *envelope);
+
+int service_destroy(service_h service);
+
+int service_get_name(service_h service, char **name);
+
+int service_get_state(service_h service, service_state_e *state);
+
+int service_get_tizen_core(service_h service, tizen_core_h *core);
+
+int service_get_tizen_core_channel_sender(service_h service,
+ tizen_core_channel_sender_h *sender);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2025 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 __SERVICE_LOADER_H__
+#define __SERVICE_LOADER_H__
+
+#include <bundle.h>
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ SERVICE_LOADER_ERROR_NONE = TIZEN_ERROR_NONE,
+ SERVICE_LOADER_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,
+ SERVICE_LOADER_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,
+ SERVICE_LOADER_ERROR_INVALID_CONTEXT = TIZEN_ERROR_APPLICATION | 0x01,
+ SERVICE_LOADER_ERROR_ALREADY_RUNNING = TIZEN_ERROR_FILE_EXISTS,
+} service_error_e;
+
+typedef void (*service_loader_create_cb)(void *user_data);
+
+typedef void (*service_loader_destroy_cb)(void *user_data);
+
+typedef void (*service_loader_message_cb)(const char *sender, bundle *envelope,
+ void *user_data);
+
+typedef struct {
+ service_loader_create_cb create;
+ service_loader_destroy_cb destroy;
+ service_loader_message_cb message;
+} service_loader_lifecycle_callback_s;
+
+int service_loader_run(int argc, char **argv, const char *name,
+ service_loader_lifecycle_callback_s *callback,
+ void *user_data);
+
+int service_loader_quit(void);
+
+int service_loader_send_message(bundle *envelope);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_LOADER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2025 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 __SERVICE_MANAGER_H__
+#define __SERVICE_MANAGER_H__
+
+#include <service.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *service_manager_event_h;
+
+typedef void (*service_state_changed_cb)(service_h service,
+ service_state_e state,
+ void *user_data);
+
+int service_manager_add_event_handler(service_state_changed_cb callback,
+ void *user_data,
+ service_manager_event_h *event_handler);
+
+int service_manager_remove_event_handler(service_manager_event_h event_handler);
+
+int service_manager_get_service(const char *name, service_h *service);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_MANAGER_H__ */
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+Name: united-service
+Summary: United Service
+Version: 0.0.1
+Release: 0
+Group: App Framework/Application Core
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Source1001: %{name}.manifest
+BuildRequires: cmake
+BuildRequires: hash-signer
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(bundle)
+BuildRequires: pkgconfig(tizen-core)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(iniparser)
+
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description
+United service is to integrate multiple currently independent daemons into one process
+to improve management efficiency, optimize resource usage, and ensure consistency between services.
+
+%package devel
+Summary: Development files for United Service
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+Development files for United Service.
+
+%prep
+%setup -q
+cp %{SOURCE1001} .
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%cmake \
+ -DFULLVER=%{version} \
+ -DMAJORVER=${MAJORVER} \
+ -DBINDIR=%{__bindir} \
+ .
+
+%__make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+install --directory %{buildroot}/%{__bindir}
+
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest %{name}.manifest
+%license LICENSE.APLv2
+%{_libdir}/libunited-service.so.*
+
+%files devel
+%manifest %{name}.manifest
+%{_includedir}/tizen-base/*.h
+%{_libdir}/libunited-service.so
+%{_libdir}/pkgconfig/united-service.pc
--- /dev/null
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS)
+
+ADD_LIBRARY(${TARGET_UNITED_SERVICE} SHARED ${SRCS})
+
+SET_TARGET_PROPERTIES(${TARGET_UNITED_SERVICE} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${TARGET_UNITED_SERVICE} PROPERTIES VERSION ${FULLVER})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_UNITED_SERVICE} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include/
+)
+
+APPLY_PKG_CONFIG(${TARGET_UNITED_SERVICE} PUBLIC
+ BUNDLE_DEPS
+ DLOG_DEPS
+ GLIB_DEPS
+ TIZEN_CORE_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_UNITED_SERVICE} PUBLIC "-lpthread -ldl")
+
+INSTALL(TARGETS ${TARGET_UNITED_SERVICE}
+ DESTINATION ${LIB_INSTALL_DIR}
+ COMPONENT RuntimeLibraries
+)
--- /dev/null
+/*
+ * Copyright (c) 2025 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 LOG_PRIVATE_HH_
+#define LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "UNITED_SERVICE"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif // LOG_PRIVATE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2025 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.
+ */
+
+#include "service.hh"
+
+#include <tizen_core.h>
+
+#include <utility>
+#include <stdexcept>
+
+#include "log_private.hh"
+#include "service_manager.hh"
+
+namespace tizen_base {
+
+Service::Service(std::string name) : name_(std::move(name)) {
+ if (!Init()) {
+ Shutdown();
+ throw new std::runtime_error("Failed to initialize service");
+ }
+
+ ServiceManager::GetInst().NotifyServiceStateChanged(this);
+}
+
+Service::~Service() {
+ Quit();
+ Shutdown();
+}
+
+bool Service::Init() {
+ tizen_core_init();
+ int ret = tizen_core_task_create(name_.c_str(), true, &task_);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ _E("tizen_core_task_create() is failed. name=%s", name_.c_str());
+ return false;
+ }
+
+ tizen_core_task_get_tizen_core(task_, &core_);
+
+ ret = tizen_core_channel_make_pair(&sender_, &receiver_);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ _E("tizen_core_channel_make_pair() is failed");
+ return false;
+ }
+
+ ret = tizen_core_add_channel(core_, receiver_, ChannelReceiveCb, this,
+ &source_);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ _E("tizen_core_add_channel() is failed");
+ return false;
+ }
+
+ receiver_ = nullptr;
+ return true;
+}
+
+void Service::Shutdown() {
+ if (source_) {
+ tizen_core_source_destroy(source_);
+ source_ = nullptr;
+ }
+
+ if (receiver_) {
+ tizen_core_channel_receiver_destroy(receiver_);
+ receiver_ = nullptr;
+ }
+
+ if (sender_) {
+ tizen_core_channel_sender_destroy(sender_);
+ sender_ = nullptr;
+ }
+
+ if (task_) {
+ tizen_core_task_destroy(task_);
+ task_ = nullptr;
+ }
+}
+
+const std::string& Service::GetName() const { return name_; }
+
+Service::State Service::GetState() const { return state_; }
+
+tizen_core_h Service::GetCore() const { return core_; }
+
+tizen_core_channel_sender_h Service::GetChannelSender() const { return sender_; }
+
+void Service::Run() {
+ if (running_) {
+ _E("Already running");
+ return;
+ }
+
+ tizen_core_source_h source = nullptr;
+ tizen_core_add_idle_job(
+ core_, [](void* user_data) -> bool {
+ auto* service = static_cast<Service*>(user_data);
+ service->OnCreate();
+ service->state_ = Service::State::Running;
+ ServiceManager::GetInst().NotifyServiceStateChanged(service);
+ return false;
+ }, this, &source);
+
+ int ret = tizen_core_task_run(task_);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ _E("tizen_core_task_run() is failed");
+ throw new std::runtime_error("Failed to run service");
+ }
+ running_ = true;
+}
+
+void Service::Quit() {
+ if (!running_) return;
+
+ tizen_core_source_h source = nullptr;
+ tizen_core_add_idle_job(
+ core_,
+ [](void* user_data) -> bool {
+ auto* service = static_cast<Service*>(user_data);
+ service->OnDestroy();
+ return false;
+ },
+ this, &source);
+
+ tizen_core_task_quit(task_);
+ running_ = false;
+}
+
+void Service::SendMessage(const tizen_base::Bundle& envelope) {
+ tizen_base::Bundle msg(envelope);
+ tizen_core_channel_object_h object = nullptr;
+ tizen_core_channel_object_create(&object);
+ tizen_core_channel_object_set_data(object, msg.Detach());
+
+ int ret = tizen_core_channel_sender_send(sender_, object);
+ tizen_core_channel_object_destroy(object);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ _E("tizen_core_channel_send() is failed. error=%d", ret);
+ throw new std::runtime_error("Failed to send message");
+ }
+}
+
+void Service::OnCreate() {
+ state_ = State::Created;
+ ServiceManager::GetInst().NotifyServiceStateChanged(this);
+}
+
+void Service::OnDestroy() {
+ state_ = State::Destroyed;
+ ServiceManager::GetInst().NotifyServiceStateChanged(this);
+}
+
+void Service::OnMessageReceived(const std::string& sender,
+ const tizen_base::Bundle& envelope) {}
+
+void Service::ChannelReceiveCb(tizen_core_channel_object_h object,
+ void* user_data) {
+ bundle* data = nullptr;
+ tizen_core_channel_object_get_data(object, reinterpret_cast<void**>(&data));
+ const char* task_name = nullptr;
+ tizen_core_channel_object_get_sender_task_name(object, &task_name);
+ auto* service = static_cast<Service*>(user_data);
+ service->OnMessageReceived(task_name != nullptr ? task_name : "",
+ tizen_base::Bundle(data, false, true));
+}
+
+} // namespace tizen_base
--- /dev/null
+/*
+ * Copyright (c) 2025 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 SERVICE_HH_
+#define SERVICE_HH_
+
+#include <tizen_core.h>
+#include <tizen_core_channel.h>
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+namespace tizen_base {
+
+class Service {
+ public:
+ enum class State {
+ Initialized,
+ Created,
+ Running,
+ Destroyed,
+ };
+
+ Service(std::string name);
+ virtual ~Service();
+
+ void Run();
+ void Quit();
+
+ const std::string& GetName() const;
+ State GetState() const;
+ tizen_core_h GetCore() const;
+ tizen_core_channel_sender_h GetChannelSender() const;
+ void SendMessage(const tizen_base::Bundle& envelope);
+
+ virtual void OnCreate();
+ virtual void OnDestroy();
+ virtual void OnMessageReceived(const std::string& sender,
+ const tizen_base::Bundle& envelope);
+
+ private:
+ bool Init();
+ void Shutdown();
+ static void ChannelReceiveCb(tizen_core_channel_object_h object,
+ void* user_data);
+
+ private:
+ std::string name_;
+ State state_ = State::Initialized;
+ tizen_core_task_h task_ = nullptr;
+ tizen_core_h core_ = nullptr;
+ tizen_core_channel_sender_h sender_ = nullptr;
+ tizen_core_channel_receiver_h receiver_ = nullptr;
+ tizen_core_source_h source_ = nullptr;
+ bool running_ = false;
+};
+
+} // namespace tizen_base
+
+#endif // SERVICE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2025 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.
+ */
+
+#include "service_loader.hh"
+
+#include <tizen_core.h>
+#include <tizen_core_channel.h>
+
+#include <utility>
+
+#include "log_private.hh"
+
+namespace tizen_base {
+
+ServiceLoader::ServiceLoader(int argc, char** argv, std::string name)
+ : argc_(argc), argv_(argv), name_(std::move(name)) {
+ if (!Init()) {
+ Shutdown();
+ throw new std::runtime_error("Failed to initializer service loader");
+ }
+}
+
+ServiceLoader::~ServiceLoader() {
+ Quit();
+ Shutdown();
+}
+
+bool ServiceLoader::Init() {
+ int ret = tizen_core_task_create("main", false, &task_);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ _E("tizen_core_task_create() is failed");
+ return false;
+ }
+
+ tizen_core_task_get_tizen_core(task_, &core_);
+
+ ret = tizen_core_channel_make_pair(&sender_, &receiver_);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ _E("tizen_core_channel_make_pair() is failed");
+ return false;
+ }
+
+ ret = tizen_core_add_channel(core_, receiver_, ChannelReceiveCb, this,
+ &source_);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ _E("tizen_core_add_channel() is failed");
+ return false;
+ }
+
+ receiver_ = nullptr;
+ return false;
+}
+
+void ServiceLoader::Shutdown() {
+ if (source_) {
+ tizen_core_source_destroy(source_);
+ source_ = nullptr;
+ }
+
+ if (receiver_) {
+ tizen_core_channel_receiver_destroy(receiver_);
+ receiver_ = nullptr;
+ }
+
+ if (sender_) {
+ tizen_core_channel_sender_destroy(sender_);
+ sender_ = nullptr;
+ }
+
+ if (task_) {
+ tizen_core_task_destroy(task_);
+ task_ = nullptr;
+ }
+}
+
+int ServiceLoader::Run() {
+ OnCreate();
+ running_ = true;
+ tizen_core_task_run(task_);
+ running_ = false;
+ OnDestroy();
+ return 0;
+}
+
+void ServiceLoader::Quit() {
+ if (!running_) return;
+
+ tizen_core_task_quit(task_);
+}
+
+void ServiceLoader::SendMessage(const tizen_base::Bundle& envelope) {
+ tizen_base::Bundle msg(envelope);
+ tizen_core_channel_object_h object = nullptr;
+ tizen_core_channel_object_create(&object);
+ tizen_core_channel_object_set_data(object, msg.Detach());
+
+ int ret = tizen_core_channel_sender_send(sender_, object);
+ tizen_core_channel_object_destroy(object);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ _E("tizen_core_channel_send() is failed. error=%d", ret);
+ throw new std::runtime_error("Failed to send message");
+ }
+}
+
+void ServiceLoader::OnCreate() {}
+
+void ServiceLoader::OnDestroy() {}
+
+void ServiceLoader::OnMessageReceived(const std::string& sender,
+ const tizen_base::Bundle& envelope) {}
+
+void ServiceLoader::ChannelReceiveCb(tizen_core_channel_object_h object,
+ void* user_data) {
+ bundle* data = nullptr;
+ tizen_core_channel_object_get_data(object, reinterpret_cast<void**>(&data));
+ const char* task_name = nullptr;
+ tizen_core_channel_object_get_sender_task_name(object, &task_name);
+ auto* service = static_cast<ServiceLoader*>(user_data);
+ service->OnMessageReceived(task_name != nullptr ? task_name : "",
+ tizen_base::Bundle(data, false, true));
+}
+
+} // namespace tizen_base
--- /dev/null
+/*
+ * Copyright (c) 2025 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.
+ */
+
+#include <tizen_core.h>
+
+#include <bundle_cpp.h>
+
+#include <string>
+
+namespace tizen_base {
+
+class ServiceLoader {
+ public:
+ ServiceLoader(int argc, char** argv, std::string name);
+ ~ServiceLoader();
+
+ int Run();
+ void Quit();
+ void SendMessage(const tizen_base::Bundle& envelope);
+
+ virtual void OnCreate();
+ virtual void OnDestroy();
+ virtual void OnMessageReceived(const std::string& sender,
+ const tizen_base::Bundle& envelope);
+
+ private:
+ bool Init();
+ void Shutdown();
+ static void ChannelReceiveCb(tizen_core_channel_object_h object,
+ void* user_data);
+
+ private : int argc_;
+ char** argv_;
+ std::string name_;
+ tizen_core_task_h task_ = nullptr;
+ tizen_core_h core_ = nullptr;
+ tizen_core_channel_sender_h sender_ = nullptr;
+ tizen_core_channel_receiver_h receiver_ = nullptr;
+ tizen_core_source_h source_ = nullptr;
+ bool running_ = false;
+};
+
+} // namespace tizen_base
--- /dev/null
+/*
+ * Copyright (c) 2025 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.
+ */
+
+#include "service_manager.hh"
+
+#include <stdexcept>
+#include <utility>
+
+#include "log_private.hh"
+#include "service.hh"
+
+namespace tizen_base {
+
+ServiceManager& ServiceManager::GetInst() {
+ static ServiceManager inst;
+ return inst;
+}
+
+bool ServiceManager::Insert(std::string name,
+ std::shared_ptr<Service> service) {
+ if (services_.find(name) != services_.end()) {
+ _E("Service(%s) already exists", name.c_str());
+ return false;
+ }
+
+ services_[name] = std::move(service);
+ return true;
+}
+
+std::shared_ptr<Service> ServiceManager::Get(const std::string& name) const {
+ if (services_.find(name) == services_.end()) {
+ _W("Service(%s) does not exist", name.c_str());
+ return nullptr;
+ }
+
+ return services_.at(name);
+}
+
+bool ServiceManager::Contains(const std::string& name) const {
+ return services_.find(name) != services_.end();
+}
+
+void ServiceManager::Remove(const std::string& name) { services_.erase(name); }
+
+void ServiceManager::AddEventListener(ServiceManager::IEvent* listener) {
+ listeners_.push_back(listener);
+}
+
+void ServiceManager::RemoveEventListener(ServiceManager::IEvent* listener) {
+ auto found = std::find(listeners_.begin(), listeners_.end(), listener);
+ if (found == listeners_.end()) return;
+
+ listeners_.erase(found);
+}
+
+void ServiceManager::NotifyServiceStateChanged(const Service* service) {
+ for (auto* listener : listeners_) listener->OnServiceStateChanged(service);
+}
+
+ServiceManager::ServiceManager() {}
+
+ServiceManager::~ServiceManager() {}
+
+} // namespace tizen_base
--- /dev/null
+/*
+ * Copyright (c) 2025 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 SERVICE_MANAGER_HH_
+#define SERVICE_MANAGER_HH_
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "service.hh"
+
+namespace tizen_base {
+
+class ServiceManager {
+ public:
+ class IEvent {
+ public:
+ virtual ~IEvent() = default;
+ virtual void OnServiceStateChanged(const Service* service) = 0;
+ };
+
+ static ServiceManager& GetInst();
+
+ bool Insert(std::string name, std::shared_ptr<Service> service);
+ std::shared_ptr<Service> Get(const std::string& name) const;
+ bool Contains(const std::string& name) const;
+ void Remove(const std::string& name);
+ void AddEventListener(IEvent* listener);
+ void RemoveEventListener(IEvent* listener);
+ void NotifyServiceStateChanged(const Service* service);
+
+ private:
+ ServiceManager();
+ ~ServiceManager();
+
+ private:
+ std::unordered_map<std::string, std::shared_ptr<Service>> services_;
+ std::vector<IEvent*> listeners_;
+};
+
+} // namespace tizen_base
+
+#endif // SERVICE_MANAGER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2025 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.
+ */
+
+#include "service_manager.h"
+#include "service.h"
+
+#include <new>
+#include <stdexcept>
+#include <utility>
+
+#include "log_private.hh"
+#include "service.hh"
+#include "service_manager.hh"
+
+#undef EXPORT
+#define EXPORT __attribute__((visibility("default")))
+
+#undef API
+#define API extern "C" EXPORT
+
+namespace {
+
+class ServiceExt : public tizen_base::Service {
+ public:
+ ServiceExt(std::string name) : tizen_base::Service(std::move(name)) {}
+
+ virtual ~ServiceExt() {}
+
+ void SetCallback(service_lifecycle_callback_s *callback, void* user_data) {
+ callback_ = *callback;
+ user_data_ = user_data;
+ }
+
+ private:
+ void OnCreate() override {
+ tizen_base::Service::OnCreate();
+ if (callback_.create) callback_.create(user_data_);
+ }
+
+ void OnDestroy() override {
+ tizen_base::Service::OnDestroy();
+ if (callback_.destroy) callback_.destroy(user_data_);
+ }
+
+ void OnMessageReceived(const std::string& sender,
+ const tizen_base::Bundle& envelope) override {
+ tizen_base::Service::OnMessageReceived(sender, envelope);
+ if (callback_.message) {
+ callback_.message(sender.c_str(), envelope.GetHandle(), user_data_);
+ }
+ }
+
+ private:
+ service_lifecycle_callback_s callback_ = { nullptr, };
+ void* user_data_ = nullptr;
+};
+
+class EventHandler : public tizen_base::ServiceManager::IEvent {
+ public:
+ EventHandler(service_state_changed_cb callback, void* user_data)
+ : callback_(callback), user_data_(user_data) {}
+
+ virtual ~EventHandler() {}
+
+ void OnServiceStateChanged(const tizen_base::Service* service) override {
+ if (callback_) {
+ callback_(
+ reinterpret_cast<service_h>(
+ const_cast<tizen_base::Service*>(service)),
+ static_cast<service_state_e>(service->GetState()),
+ user_data_);
+ }
+ }
+
+ private:
+ service_state_changed_cb callback_ = nullptr;
+ void* user_data_ = nullptr;
+};
+
+} // namespace
+
+API int service_create(const char* name, service_lifecycle_callback_s* callback,
+ void* user_data, service_h* service) {
+ if (!name || !callback || !service) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto& inst = tizen_base::ServiceManager::GetInst();
+ if (inst.Contains(name)) return SERVICE_ERROR_ALREADY_EXIST;
+
+ try {
+ auto handle = std::make_shared<ServiceExt>(name);
+ handle->SetCallback(callback, user_data);
+ *service = reinterpret_cast<service_h>(handle.get());
+ inst.Insert(name, std::move(handle));
+ } catch (const std::bad_alloc&) {
+ _E("Out of memory");
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ } catch (const std::runtime_error&) {
+ _E("Failed to create service");
+ return SERVICE_ERROR_INVALID_CONTEXT;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+API int service_run(service_h service) {
+ if (!service) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = reinterpret_cast<ServiceExt*>(service);
+ try {
+ handle->Run();
+ } catch (const std::runtime_error&) {
+ _E("Failed to run service");
+ return SERVICE_ERROR_INVALID_CONTEXT;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+API int service_quit(service_h service) {
+ if (!service) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = reinterpret_cast<ServiceExt*>(service);
+ handle->Quit();
+ return SERVICE_ERROR_NONE;
+}
+
+API int service_send_message(service_h service, bundle *envelope) {
+ if (!service || !envelope) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = reinterpret_cast<ServiceExt*>(service);
+ try {
+ handle->SendMessage(tizen_base::Bundle(envelope));
+ } catch (const std::runtime_error&) {
+ _E("Failed to send message");
+ return SERVICE_ERROR_INVALID_CONTEXT;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+API int service_destroy(service_h service) {
+ if (!service) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = reinterpret_cast<ServiceExt*>(service);
+ tizen_base::ServiceManager::GetInst().Remove(handle->GetName());
+ return SERVICE_ERROR_NONE;
+}
+
+
+API int service_get_name(service_h service, char** name) {
+ if (!service || !name) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = reinterpret_cast<ServiceExt*>(service);
+ *name = strdup(handle->GetName().c_str());
+ if (*name == nullptr) {
+ _E("Out of memory");
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+int service_get_state(service_h service, service_state_e* state) {
+ if (!service || !state) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = reinterpret_cast<ServiceExt*>(service);
+ *state = static_cast<service_state_e>(handle->GetState());
+ return SERVICE_ERROR_NONE;
+}
+
+int service_get_tizen_core(service_h service, tizen_core_h* core) {
+ if (!service || !core) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = reinterpret_cast<ServiceExt*>(service);
+ *core = handle->GetCore();
+ return SERVICE_ERROR_NONE;
+}
+
+int service_get_tizen_core_channel_sender(service_h service,
+ tizen_core_channel_sender_h* sender) {
+ if (!service || !sender) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = reinterpret_cast<ServiceExt*>(service);
+ *sender = handle->GetChannelSender();
+ return SERVICE_ERROR_NONE;
+}
+
+API int service_manager_add_event_handler(service_state_changed_cb callback,
+ void *user_data,
+ service_manager_event_h *event_handler) {
+ if (!callback || !event_handler) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = new (std::nothrow) EventHandler(callback, user_data);
+ if (!handle) {
+ _E("Out of memory");
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ }
+
+ tizen_base::ServiceManager::GetInst().AddEventListener(handle);
+ *event_handler = reinterpret_cast<service_manager_event_h>(handle);
+ return SERVICE_ERROR_NONE;
+}
+
+API int service_manager_remove_event_handler(
+ service_manager_event_h event_handler) {
+ if (!event_handler) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = reinterpret_cast<EventHandler*>(event_handler);
+ tizen_base::ServiceManager::GetInst().RemoveEventListener(handle);
+ delete handle;
+ return SERVICE_ERROR_NONE;
+}
+
+API int service_manager_get_service(const char* name, service_h* service) {
+ if (!name || !service) {
+ _E("Invalid parameter");
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto& inst = tizen_base::ServiceManager::GetInst();
+ if (!inst.Contains(name)) return SERVICE_ERROR_INVALID_PARAMETER;
+
+ *service = reinterpret_cast<service_h>(inst.Get(name).get());
+ return SERVICE_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2025 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.
+ */
+
+ #include "service_loader.h"
+
+ #include <new>
+ #include <stdexcept>
+ #include <utility>
+
+ #include "log_private.hh"
+ #include "service_loader.hh"
+
+ #undef EXPORT
+ #define EXPORT __attribute__((visibility("default")))
+
+ #undef API
+ #define API extern "C" EXPORT
+
+namespace {
+
+class ServiceLoaderExt;
+
+ServiceLoaderExt* context = nullptr;
+
+class ServiceLoaderExt : public tizen_base::ServiceLoader {
+ public:
+ ServiceLoaderExt(int argc, char** argv, std::string name)
+ : tizen_base::ServiceLoader(argc, argv, std::move(name)) {
+ if (context != nullptr) throw std::runtime_error("Already exits");
+ }
+
+ virtual ~ServiceLoaderExt() { context = nullptr; }
+
+ void SetCallback(service_loader_lifecycle_callback_s* callback,
+ void* user_data) {
+ callback_ = *callback;
+ user_data_ = user_data;
+ }
+
+ void OnCreate() override {
+ if (callback_.create) callback_.create(user_data_);
+ }
+
+ void OnDestroy() override {
+ if (callback_.destroy) callback_.destroy(user_data_);
+ }
+
+ void OnMessageReceived(const std::string& sender,
+ const tizen_base::Bundle& envelope) override {
+ if (callback_.message)
+ callback_.message(sender.c_str(), envelope.GetHandle(), user_data_);
+ }
+
+ private:
+ service_loader_lifecycle_callback_s callback_;
+ void* user_data_;
+};
+
+} // namespace
+
+API int service_loader_run(int argc, char** argv, const char* name,
+ service_loader_lifecycle_callback_s* callback,
+ void* user_data) {
+ if (argc < 1 || argv == nullptr || name == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return SERVICE_LOADER_ERROR_INVALID_PARAMETER;
+ }
+
+ if (::context != nullptr) {
+ _E("Already running");
+ return SERVICE_LOADER_ERROR_ALREADY_RUNNING;
+ }
+
+ try {
+ ::ServiceLoaderExt loader(argc, argv, name);
+ loader.SetCallback(callback, user_data);
+ loader.Run();
+ } catch (const std::runtime_error& e) {
+ _E("Exception occurs. error: %s", e.what());
+ return SERVICE_LOADER_ERROR_INVALID_CONTEXT;
+ }
+
+ return SERVICE_LOADER_ERROR_NONE;
+}
+
+API int service_loader_quit(void) {
+ if (!::context) return SERVICE_LOADER_ERROR_INVALID_CONTEXT;
+
+ ::context->Quit();
+ return SERVICE_LOADER_ERROR_NONE;
+}
+
+API int service_loader_send_message(bundle* envelope) {
+ if (!envelope) {
+ _E("Invalid parameter");
+ return SERVICE_LOADER_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!::context) return SERVICE_LOADER_ERROR_INVALID_CONTEXT;
+
+ ::context->SendMessage(tizen_base::Bundle(envelope));
+ return SERVICE_LOADER_ERROR_NONE;
+}
--- /dev/null
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@/tizen-base
+
+Name: @PC_NAME@
+Description: @PC_DESCRIPTION@
+Version: @PC_VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}