From: saerome.kim Date: Tue, 12 Dec 2017 00:28:10 +0000 (+0900) Subject: Enable dbus activation X-Git-Tag: submit/tizen/20190131.065036~299 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0340f4d468eaa6e32a43a640ed939e5f08d04587;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git Enable dbus activation Signed-off-by: saerome.kim --- diff --git a/packaging/d2d-manager.service b/packaging/d2d-manager.service deleted file mode 100644 index 5f4f684..0000000 --- a/packaging/d2d-manager.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=OCF D2D Manager -Requires=dbus.socket -After=dbus.socket - -[Service] -Type=dbus -User=network_fw -Group=network_fw -BusName=net.d2d.manager -SmackProcessLabel=System -ExecStart=/usr/bin/d2d-manager diff --git a/packaging/d2d-manager.spec b/packaging/d2d-manager.spec old mode 100755 new mode 100644 index 7f64aa1..455b07e --- a/packaging/d2d-manager.spec +++ b/packaging/d2d-manager.spec @@ -5,14 +5,14 @@ Release: 0 Group: Network & Connectivity/Other License: Apache-2.0 Source0: %{name}-%{version}.tar.gz -Source2: %{name}.service +Source2: d2dm.service Source3: %{name}.manifest Source4: %{name}-devel.manifest -Source5: net.d2d.manager.service -Source6: fn-manager.service -Source7: net.fn.manager.service -Source8: d2d-subowner.service -Source9: net.d2d.subowner.service +Source5: net.d2dm.service +Source6: fnm.service +Source7: net.fnm.service +Source8: d2ds.service +Source9: net.d2ds.service BuildRequires: cmake BuildRequires: pkgconfig(iotivity) @@ -81,17 +81,17 @@ rm -rf %{buildroot}/BUILD/%{name}* %make_install mkdir -p %{buildroot}%{_datadir}/dbus-1/system-services/ -cp %{SOURCE5} %{buildroot}%{_datadir}/dbus-1/system-services/net.d2d.manager.service +cp %{SOURCE5} %{buildroot}%{_datadir}/dbus-1/system-services/net.d2dm.service mkdir -p %{buildroot}%{_unitdir} -cp %{SOURCE2} %{buildroot}%{_unitdir}/%{name}.service +cp %{SOURCE2} %{buildroot}%{_unitdir}/d2dm.service -cp %{SOURCE7} %{buildroot}%{_datadir}/dbus-1/system-services/net.fn.manager.service +cp %{SOURCE7} %{buildroot}%{_datadir}/dbus-1/system-services/net.fnm.service mkdir -p %{buildroot}%{_unitdir} -cp %{SOURCE6} %{buildroot}%{_unitdir}/fn-manager.service +cp %{SOURCE6} %{buildroot}%{_unitdir}/fnm.service -cp %{SOURCE9} %{buildroot}%{_datadir}/dbus-1/system-services/net.d2d.subowner.service +cp %{SOURCE9} %{buildroot}%{_datadir}/dbus-1/system-services/net.d2ds.service mkdir -p %{buildroot}%{_unitdir} -cp %{SOURCE8} %{buildroot}%{_unitdir}/d2d-subowner.service +cp %{SOURCE8} %{buildroot}%{_unitdir}/d2ds.service cp test/oic_svr_db_client.dat oic_svr_db_subowner_client.dat @@ -103,9 +103,9 @@ cp test/oic_svr_db_client.dat oic_svr_db_subowner_client.dat %{_bindir}/subowner %{_bindir}/fn-manager %attr(644,root,root) %{_datadir}/dbus-1/system-services/* -%attr(644,root,root) %{_unitdir}/%{name}.service -%attr(644,root,root) %{_unitdir}/fn-manager.service -%attr(644,root,root) %{_unitdir}/d2d-subowner.service +%attr(644,root,root) %{_unitdir}/d2dm.service +%attr(644,root,root) %{_unitdir}/fnm.service +%attr(644,root,root) %{_unitdir}/d2ds.service %files devel %manifest %{name}-devel.manifest diff --git a/packaging/d2d-subowner.service b/packaging/d2d-subowner.service deleted file mode 100755 index ca0fc1d..0000000 --- a/packaging/d2d-subowner.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=OCF D2D Sub-Owner Client -Requires=dbus.socket -After=dbus.socket - -[Service] -Type=dbus -User=network_fw -Group=network_fw -BusName=net.d2d.subowner -SmackProcessLabel=System -ExecStart=/usr/bin/d2d-subowner diff --git a/packaging/d2dm.service b/packaging/d2dm.service new file mode 100644 index 0000000..5e613a5 --- /dev/null +++ b/packaging/d2dm.service @@ -0,0 +1,12 @@ +[Unit] +Description=OCF D2D Manager +Requires=dbus.socket +After=dbus.socket + +[Service] +Type=dbus +User=network_fw +Group=network_fw +BusName=net.d2dm.enabler +SmackProcessLabel=System +ExecStart=/usr/bin/d2d-manager diff --git a/packaging/d2ds.service b/packaging/d2ds.service new file mode 100644 index 0000000..70f6105 --- /dev/null +++ b/packaging/d2ds.service @@ -0,0 +1,12 @@ +[Unit] +Description=OCF D2D Sub-Owner Client +Requires=dbus.socket +After=dbus.socket + +[Service] +Type=dbus +User=network_fw +Group=network_fw +BusName=net.d2ds.enabler +SmackProcessLabel=System +ExecStart=/usr/bin/d2d-subowner diff --git a/packaging/fn-manager.service b/packaging/fn-manager.service deleted file mode 100755 index fdba735..0000000 --- a/packaging/fn-manager.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=OCF Familynet Manager -After=feedbckd.service - -[Service] -Type=dbus -User=network_fw -Group=network_fw -BusName=net.fn.manager -SmackProcessLabel=System -ExecStart=/usr/bin/fn-manager - -[Install] -WantedBy=multi-user.target diff --git a/packaging/fnm.service b/packaging/fnm.service new file mode 100644 index 0000000..fdba735 --- /dev/null +++ b/packaging/fnm.service @@ -0,0 +1,14 @@ +[Unit] +Description=OCF Familynet Manager +After=feedbckd.service + +[Service] +Type=dbus +User=network_fw +Group=network_fw +BusName=net.fn.manager +SmackProcessLabel=System +ExecStart=/usr/bin/fn-manager + +[Install] +WantedBy=multi-user.target diff --git a/packaging/net.d2d.manager.service b/packaging/net.d2d.manager.service deleted file mode 100644 index 187065c..0000000 --- a/packaging/net.d2d.manager.service +++ /dev/null @@ -1,7 +0,0 @@ -[D-BUS Service] -Name=net.d2d.manager - -Exec=/bin/false -User=network_fw -Group=network_fw -SystemdService=d2d-manager.service diff --git a/packaging/net.d2d.subowner.service b/packaging/net.d2d.subowner.service deleted file mode 100755 index 17bed18..0000000 --- a/packaging/net.d2d.subowner.service +++ /dev/null @@ -1,7 +0,0 @@ -[D-BUS Service] -Name=net.d2d.subowner - -Exec=/bin/false -User=network_fw -Group=network_fw -SystemdService=d2d-subowner.service diff --git a/packaging/net.d2dm.service b/packaging/net.d2dm.service new file mode 100644 index 0000000..27cc224 --- /dev/null +++ b/packaging/net.d2dm.service @@ -0,0 +1,7 @@ +[D-BUS Service] +Name=net.d2dm.enabler + +Exec=/bin/false +User=network_fw +Group=network_fw +SystemdService=d2dm.service diff --git a/packaging/net.d2ds.service b/packaging/net.d2ds.service new file mode 100644 index 0000000..a6a624e --- /dev/null +++ b/packaging/net.d2ds.service @@ -0,0 +1,7 @@ +[D-BUS Service] +Name=net.d2ds.enabler + +Exec=/bin/false +User=network_fw +Group=network_fw +SystemdService=d2ds.service diff --git a/packaging/net.fn.manager.service b/packaging/net.fn.manager.service deleted file mode 100755 index 0bbecfc..0000000 --- a/packaging/net.fn.manager.service +++ /dev/null @@ -1,10 +0,0 @@ -[D-BUS Service] -Name=net.fn.manager - -Exec=/bin/false -User=network_fw -Group=network_fw -SystemdService=fn-manager.service - -[Install] -WantedBy=multi-user.target diff --git a/packaging/net.fnm.service b/packaging/net.fnm.service new file mode 100644 index 0000000..ef695d2 --- /dev/null +++ b/packaging/net.fnm.service @@ -0,0 +1,10 @@ +[D-BUS Service] +Name=net.fn.enabler + +Exec=/bin/false +User=network_fw +Group=network_fw +SystemdService=fnm.service + +[Install] +WantedBy=multi-user.target diff --git a/src/d2d-manager/CMakeLists.txt b/src/d2d-manager/CMakeLists.txt index 47be74a..778664c 100644 --- a/src/d2d-manager/CMakeLists.txt +++ b/src/d2d-manager/CMakeLists.txt @@ -1,11 +1,29 @@ -MESSAGE("===================================================================") -MESSAGE("Building...d2d-manager") MESSAGE("===================================================================") +MESSAGE("Building...d2d-manager") +MESSAGE("===================================================================") + +SET(INTROSPECTION_PATH ${CMAKE_CURRENT_SOURCE_DIR}/introspection) +MESSAGE("KSR : ${INTROSPECTION_PATH}") +ADD_CUSTOM_COMMAND( + OUTPUT dbus + COMMAND gdbus-codegen + --interface-prefix net.d2dm. + --generate-c-code d2dm-generated-code + --c-generate-object-manager + --generate-docbook generated-docs + ${INTROSPECTION_PATH}/d2dm.xml + ${INTROSPECTION_PATH}/enabler.xml + COMMENT "Generating d2dm GDBus .c/.h" +) +ADD_CUSTOM_TARGET(GENERATED_DBUS_CODE DEPENDS dbus) -MESSAGE(" - Set source folder") +MESSAGE(" - Set source folder") FILE(GLOB D2D_MANAGER_SRCS *.c) +SET(D2D_MANAGER_SRCS ${D2D_MANAGER_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/d2dm-generated-code.c) +SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/d2dm-generated-code.c PROPERTIES GENERATED TRUE) SET(D2D_MANAGER "d2d-manager") -ADD_EXECUTABLE(${D2D_MANAGER} ${D2D_MANAGER_SRCS}) -TARGET_LINK_LIBRARIES(${D2D_MANAGER} ${daemon_pkgs_LIBRARIES} pthread) +ADD_EXECUTABLE(${D2D_MANAGER} ${D2D_MANAGER_SRCS}) +ADD_DEPENDENCIES(${D2D_MANAGER} GENERATED_DBUS_CODE) +TARGET_LINK_LIBRARIES(${D2D_MANAGER} ${daemon_pkgs_LIBRARIES} pthread) INSTALL(TARGETS ${D2D_MANAGER} DESTINATION bin) diff --git a/src/d2d-manager/d2d-manager-log.h b/src/d2d-manager/d2d-manager-log.h deleted file mode 100644 index 16f04f2..0000000 --- a/src/d2d-manager/d2d-manager-log.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2017 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 __D2D_MANAGER_LOG_H__ -#define __D2D_MANAGER_LOG_H__ - -#ifdef D2D_MAN_LOG_TAG -#undef D2D_MAN_LOG_TAG -#endif - -#ifdef USE_DLOG -#include - -#undef D2D_MAN_LOG_TAG -#define D2D_MAN_LOG_TAG "D2D_MANAGER" - -#define D2DM_LOGV(format, args...) LOGV(format, ##args) -#define D2DM_LOGD(format, args...) LOGD(format, ##args) -#define D2DM_LOGI(format, args...) LOGI(format, ##args) -#define D2DM_LOGW(format, args...) LOGW(format, ##args) -#define D2DM_LOGE(format, args...) LOGE(format, ##args) -#define D2DM_LOGF(format, args...) LOGF(format, ##args) - -#define __D2DM_LOG_FUNC_ENTER__ LOGD("Enter") -#define __D2DM_LOG_FUNC_EXIT__ LOGD("Quit") - -#define D2DM_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, D2D_MAN_LOG_TAG, format, ##args) -#define D2DM_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, D2D_MAN_LOG_TAG, format, ##args) - -#else /* USE_DLOG */ - -#define D2DM_LOGV(format, args...) -#define D2DM_LOGD(format, args...) -#define D2DM_LOGI(format, args...) -#define D2DM_LOGW(format, args...) -#define D2DM_LOGE(format, args...) -#define D2DM_LOGF(format, args...) - -#define __D2DM_LOG_FUNC_ENTER__ -#define __D2DM_LOG_FUNC_EXIT__ - -#define D2DM_SECLOGI(format, args...) -#define D2DM_SECLOGD(format, args...) - -#endif /* USE_DLOG */ - -#endif /* __D2D_MANAGER_LOG_H__ */ diff --git a/src/d2d-manager/d2d-manager.c b/src/d2d-manager/d2d-manager.c deleted file mode 100644 index 2edd988..0000000 --- a/src/d2d-manager/d2d-manager.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2017 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 -#include -#include - -#include - -#include "d2d-common.h" -#include "d2d-manager.h" -#include "d2d-manager-log.h" - -/**< d2d-manager service */ -d2d_service *d2dsvc; - -int main(int argc, char *argv[]) -{ - d2d_service *service = NULL; - int ret_code = 0; - gboolean ret; - - __D2DM_LOG_FUNC_ENTER__; - -#if !GLIB_CHECK_VERSION(2, 32, 0) - if (!g_thread_supported()) - g_thread_init(NULL); -#endif - -#if !GLIB_CHECK_VERSION(2, 36, 0) - g_type_init(); -#endif - NOTUSED(argc); - NOTUSED(argv); - - D2DM_LOGI("service mainloop start"); -#if 0 - /* Create d2d-manager service */ - d2dsvc = service = d2dm_service_new(); - - /* Initialize d2d-manager service interface layer */ - ret = d2dm_service_interface_init(service); - if (G_UNLIKELY(FALSE == ret)) { - D2DM_LOGE("wmeshd_service_interface_init failed!"); - goto END; - } - - /* Run mesh service */ - ret = wmeshd_service_run(service); - if (G_UNLIKELY(FALSE == ret)) { - D2DM_LOGE("Run service failed!"); - ret_code = EXIT_FAILURE; - } - -END: - /* Free d2d-manager service */ - d2dm_service_interface_deinit(service); - d2dm_service_free(service); - d2dsvc = NULL; -#endif - __D2DM_LOG_FUNC_EXIT__; - return 0; -} - diff --git a/src/d2d-manager/d2d-manager.h b/src/d2d-manager/d2d-manager.h deleted file mode 100644 index 9f907be..0000000 --- a/src/d2d-manager/d2d-manager.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2017 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 __D2D_MANAGER_H__ -#define __D2D_MANAGER_H__ - -#include -#include -#include - -/**< Internal error code with mesh daemon. It should be matched with API side */ -typedef enum { - D2D_ERROR_NONE = 0, /**< Successful */ - D2D_ERROR_IO_ERROR, /**< I/O error */ - D2D_ERROR_NO_DATA, /**< Data not exists */ - D2D_ERROR_OUT_OF_MEMORY, /**< out of memory */ - D2D_ERROR_OPERATION_FAILED, /**< operation failed */ - D2D_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - D2D_ERROR_ALREADY_REGISTERED, /**< Request already registered */ - D2D_ERROR_IN_PROGRESS /**< operation is in progress */ -} meshd_error_e; - -/**< mesh service structure */ -typedef struct _d2d_service { - GMainLoop *main_loop; /**< Service main-loop */ - guint dbus_id; /**< D-Bus id */ - guint activation_dbus_id; /**< D-Bus id for activation */ - - gpointer connection; /**< Connection handle for D-Bus call to other process */ - GCancellable *ca; /**< Cancellable object for D-Bus call (Daemon->other) */ - GList *dbus_sub_ids; /**< The list of subscribed signals */ - -} d2d_service; - -#endif /* __D2D_MANAGER_H__ */ diff --git a/src/d2d-manager/d2dm-gdbus.c b/src/d2d-manager/d2dm-gdbus.c new file mode 100644 index 0000000..f97dbe7 --- /dev/null +++ b/src/d2d-manager/d2dm-gdbus.c @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2017 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 "d2dm-log.h" +#include "d2dm-util.h" +#include "d2dm-gdbus.h" + +static int _d2dm_close_gdbus_call(d2dm_service *service) +{ + /* CHECK: is connection ref count required? */ + g_object_unref(service->connection); + service->connection = NULL; + + return D2DM_ERROR_NONE; +} + +static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec, + gpointer *user_data) +{ + GDBusProxy *proxy = G_DBUS_PROXY(object); + gchar *name_owner = g_dbus_proxy_get_name_owner(proxy); + d2dm_service *service = (d2dm_service*)user_data; + + NOTUSED(pspec); + + if (NULL == name_owner) { + D2DM_LOGE("name_owner is not exists !"); + _d2dm_close_gdbus_call(service); + } + + g_free(name_owner); +} + +static int _d2dm_create_gdbus_call(d2dm_service *service) +{ + int id; + GError *error = NULL; + + if (NULL == service) + return D2DM_ERROR_INVALID_PARAMETER; + + if (NULL != service->connection) + return D2DM_ERROR_ALREADY_REGISTERED; + + service->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (service->connection == NULL) { + if (error != NULL) { + D2DM_LOGE("Failed to connect to the D-BUS daemon [%s]", error->message); + g_error_free(error); + } + return D2DM_ERROR_IO_ERROR; + } + + id = g_signal_connect(service->connection, "notify::g-name-owner", + G_CALLBACK(_dbus_name_owner_notify), service); + if (0 == id) { + D2DM_LOGE("g_signal_connect() Fail"); + g_object_unref(service->connection); + service->connection = NULL; + return D2DM_ERROR_IO_ERROR; + } + + return D2DM_ERROR_NONE; +} + +static void _d2dm_subscribe_event(d2dm_service *service) +{ + unsigned int id = 0; + + d2dm_check_null_ret("service", service); +#if 0 + id = g_dbus_connection_signal_subscribe( + (GDBusConnection *)service->connection, + CONNMAN_SERVER_NAME, CONNMAN_INTERFACE_MANAGER, + "ScanDone", "/", NULL, + G_DBUS_CALL_FLAGS_NONE, _wmeshd_signal_handler, service, NULL); + if (0 == id) { + WMESH_LOGE("g_dbus_connection_signal_subscribe(ScanDone) Fail(%d)", errno); + return; + } + service->dbus_sub_ids = g_list_append(service->dbus_sub_ids, GUINT_TO_POINTER(id)); + WMESH_LOGD("[Signal subscribe] : ScanDone (%d)", id); + + /* To monitor mesh profiles */ + id = g_dbus_connection_signal_subscribe( + (GDBusConnection *)service->connection, + CONNMAN_SERVER_NAME, + CONNMAN_INTERFACE_MESH, + "PropertyChanged", + NULL, /* Path */ + NULL, + G_DBUS_CALL_FLAGS_NONE, _wmeshd_signal_handler, service, NULL); + if (0 == id) { + WMESH_LOGE("g_dbus_connection_signal_subscribe(ScanDone) Fail(%d)", errno); + return; + } + service->dbus_sub_ids = g_list_append(service->dbus_sub_ids, GUINT_TO_POINTER(id)); + WMESH_LOGD("[Signal subscribe] : PropertyChanged (%d)", id); +#endif + /* End of subscription */ +} + + +static void _on_unsubscribe_ids(gpointer data, gpointer user_data) +{ + unsigned int id = GPOINTER_TO_UINT(data); + d2dm_service *service = (d2dm_service*)user_data; + + D2DM_LOGD("[Signal unsubscribe] : %d", id); + g_dbus_connection_signal_unsubscribe((GDBusConnection *)service->connection, id); +} + +static void _wmeshd_unsubscribe_event(d2dm_service *service) +{ + d2dm_check_null_ret("service", service); + + g_list_foreach(service->dbus_sub_ids, _on_unsubscribe_ids, service); + + g_list_free(service->dbus_sub_ids); + service->dbus_sub_ids = NULL; +} + + +int d2dm_dbus_start(d2dm_service *service) +{ + int rv; + + rv = _d2dm_create_gdbus_call(service); + if (D2DM_ERROR_NONE != rv) + return rv; + + service->ca = g_cancellable_new(); + + /* Create all required proxies here */ +#if 0 + _gproxy_connman = _proxy_get_connman(service); + wmeshd_check_null_ret_error("_gproxy_connman", _gproxy_connman, + WMESHD_ERROR_IO_ERROR); + g_dbus_proxy_set_default_timeout( + G_DBUS_PROXY(_gproxy_connman), WMESH_DBUS_PROXY_TIMEOUT); +#endif + /* Subscribe events */ + _d2dm_subscribe_event(service); + + return D2DM_ERROR_NONE; +} + +int d2dm_dbus_stop(d2dm_service *service) +{ + int rv; + + if (NULL == service) + return D2DM_ERROR_INVALID_PARAMETER; + + /* Unsubscribe events */ + _wmeshd_unsubscribe_event(service); + + g_cancellable_cancel(service->ca); + g_object_unref(service->ca); + service->ca = NULL; + + rv = _d2dm_close_gdbus_call(service); + return rv; +} + diff --git a/src/d2d-manager/d2dm-gdbus.h b/src/d2d-manager/d2dm-gdbus.h new file mode 100644 index 0000000..c1714f5 --- /dev/null +++ b/src/d2d-manager/d2dm-gdbus.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017 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 __D2DM_GDBUS_H__ +#define __D2DM_GDBUS_H__ + +#include "d2dm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int d2dm_dbus_start(d2dm_service *service); +int d2dm_dbus_stop(d2dm_service *service); + +#ifdef __cplusplus +} +#endif + +#endif /** __D2DM_GDBUS_H__ */ + diff --git a/src/d2d-manager/d2dm-log.h b/src/d2d-manager/d2dm-log.h new file mode 100644 index 0000000..571dd25 --- /dev/null +++ b/src/d2d-manager/d2dm-log.h @@ -0,0 +1,62 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 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 __D2D_LOG_H__ +#define __D2D_LOG_H__ + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#ifdef USE_DLOG +#include + +#undef LOG_TAG +#define LOG_TAG "D2D_MANAGER" + +#define D2DM_LOGV(format, args...) LOGV(format, ##args) +#define D2DM_LOGD(format, args...) LOGD(format, ##args) +#define D2DM_LOGI(format, args...) LOGI(format, ##args) +#define D2DM_LOGW(format, args...) LOGW(format, ##args) +#define D2DM_LOGE(format, args...) LOGE(format, ##args) +#define D2DM_LOGF(format, args...) LOGF(format, ##args) + +#define __D2DM_LOG_FUNC_ENTER__ LOGD("Enter") +#define __D2DM_LOG_FUNC_EXIT__ LOGD("Quit") + +#define D2DM_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args) +#define D2DM_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args) + +#else /* USE_DLOG */ + +#define D2DM_LOGV(format, args...) +#define D2DM_LOGD(format, args...) +#define D2DM_LOGI(format, args...) +#define D2DM_LOGW(format, args...) +#define D2DM_LOGE(format, args...) +#define D2DM_LOGF(format, args...) + +#define __D2DM_LOG_FUNC_ENTER__ +#define __D2DM_LOG_FUNC_EXIT__ + +#define D2DM_SECLOGI(format, args...) +#define D2DM_SECLOGD(format, args...) + +#endif /* USE_DLOG */ + +#endif /* __D2D_LOG_H__ */ diff --git a/src/d2d-manager/d2dm-service-interface.c b/src/d2d-manager/d2dm-service-interface.c new file mode 100644 index 0000000..9e03d06 --- /dev/null +++ b/src/d2d-manager/d2dm-service-interface.c @@ -0,0 +1,354 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 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 + +#include "d2dm.h" +#include "d2dm-log.h" +#include "d2dm-util.h" +#include "d2dm-service.h" +#include "d2dm-service-interface.h" +#include "d2dm-generated-code.h" + +static NetD2dm *d2dm_dbus_object; +static Enabler *d2dm_activator_dbus_object; + +/* global list to care resource handle for each client */ +static GList *d2dm_dbus_client_list; +static GMutex d2dm_dbus_client_list_mutex; + +typedef struct _d2dm_dbus_client_s { + gchar *bus_name; +} d2dm_dbus_client_s; + +NetD2dm* d2dm_dbus_get_object() +{ + return d2dm_dbus_object; +} + +static int _d2dm_dbus_client_list_cleanup(GList *client_list) +{ + d2dm_dbus_client_s *client; + + d2dm_check_null_ret_error("client_list", client_list, FALSE); + + client = client_list->data; + + g_free(client->bus_name); + client->bus_name = NULL; + g_free(client); + g_list_free(client_list); + + return D2DM_ERROR_NONE; +} + +static int _d2dm_dbus_client_list_compare_bus_name(const void *a, const void *b) +{ + const d2dm_dbus_client_s *client = a; + return g_strcmp0(client->bus_name, b); +} + +static inline GList* _d2dm_dbus_client_list_find_client(const gchar *owner) +{ + return g_list_find_custom(d2dm_dbus_client_list, owner, + _d2dm_dbus_client_list_compare_bus_name); +} + +static void _d2dm_dbus_name_owner_changed_cb(GDBusConnection *conn, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + int ret; + GList *client = NULL; + gchar *name, *old_owner, *new_owner; + + NOTUSED(conn); + NOTUSED(sender_name); + NOTUSED(object_path); + NOTUSED(interface_name); + NOTUSED(signal_name); + NOTUSED(user_data); + + g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner); + + if (0 == strlen(new_owner)) { + g_mutex_lock(&d2dm_dbus_client_list_mutex); + client = _d2dm_dbus_client_list_find_client(old_owner); + if (client) { /* found bus name in our bus list */ + D2DM_LOGD("bus(%s) stopped", old_owner); + d2dm_dbus_client_list = g_list_remove_link(d2dm_dbus_client_list, client); + } + g_mutex_unlock(&d2dm_dbus_client_list_mutex); + + if (client) { + ret = _d2dm_dbus_client_list_cleanup(client); + if (D2DM_ERROR_NONE != ret) + D2DM_LOGE("_d2dm_dbus_client_list_cleanup() Fail(%d)", ret); + } + } +} + +static int _d2dm_dbus_subscribe_name_owner_changed(GDBusConnection *conn) +{ + unsigned int id; + + id = g_dbus_connection_signal_subscribe(conn, + "org.freedesktop.DBus", /* bus name */ + "org.freedesktop.DBus", /* interface */ + "NameOwnerChanged", /* member */ + "/org/freedesktop/DBus", /* path */ + NULL, /* arg0 */ + G_DBUS_SIGNAL_FLAGS_NONE, + _d2dm_dbus_name_owner_changed_cb, + NULL, + NULL); + if (0 == id) { + D2DM_LOGE("g_dbus_connection_signal_subscribe() Fail"); + return D2DM_ERROR_IO_ERROR; + } + + return D2DM_ERROR_NONE; +} + + +static gboolean _d2dm_dbus_handle_find_peer(NetD2dm *object, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + int ret = D2DM_ERROR_NONE; + d2dm_service *service = (d2dm_service *)user_data; + + d2dm_check_null_ret_error("service", service, FALSE); + +#if 0 + ret = d2dm_request_find_peers(service); + if (D2DM_ERROR_NONE != ret) + D2DM_LOGE("Failed to wmesh_request_scan !"); +#endif + net_d2dm_complete_find_peer(object, invocation, ret); + + return TRUE; +} + + +static void _d2dm_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name, + gpointer user_data) +{ + gboolean ret; + GError *error = NULL; + d2dm_service *service = (d2dm_service *)user_data; + + NOTUSED(name); + + d2dm_dbus_object = net_d2dm_skeleton_new(); + if (NULL == d2dm_dbus_object) { + D2DM_LOGE("net_d2dm_skeleton_new() Fail"); + return; + } + + g_signal_connect(d2dm_dbus_object, "handle-find-peers", + G_CALLBACK(_d2dm_dbus_handle_find_peer), service); + + ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(d2dm_dbus_object), + conn, D2DM_DBUS_OBJPATH, &error); + if (FALSE == ret) { + D2DM_LOGE("g_dbus_interface_skeleton_export() Fail(%s)", error->message); + g_error_free(error); + } + + ret = _d2dm_dbus_subscribe_name_owner_changed(conn); + if (D2DM_ERROR_NONE != ret) { + D2DM_LOGE("_d2dm_dbus_subscribe_name_owner_changed() Fail(%d)", ret); + return; + } + +} + +static void _d2dm_dbus_on_name_lost(GDBusConnection *conn, const gchar *name, + gpointer user_data) +{ + NOTUSED(conn); + NOTUSED(user_data); + + D2DM_LOGD("Lost the name %s", name); +} + +static void _d2dm_dbus_on_name_acquired(GDBusConnection *conn, const gchar *name, + gpointer user_data) +{ + NOTUSED(conn); + NOTUSED(user_data); + + D2DM_LOGD("Acquired the name %s", name); +} + +static gboolean _d2dm_dbus_handle_enable(Enabler *object, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + int ret = D2DM_ERROR_NONE; + d2dm_service *service = (d2dm_service *)user_data; + + __D2DM_LOG_FUNC_ENTER__; + + /* Do API response first */ + enabler_complete_enable(object, invocation, ret); + service->d2dm_activated = TRUE; + + if (service->d2dp_activated) { + /* Enable d2d proxy */ + } + service->d2dp_activated = TRUE; + + /* Notify d2d-manager enabled */ + net_d2dm_emit_proxy_enabled(d2dm_dbus_get_object(), ret); + + __D2DM_LOG_FUNC_EXIT__; + + return TRUE; +} + +static gboolean _d2dm_dbus_handle_disable(Enabler *object, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + int ret = D2DM_ERROR_NONE; + d2dm_service *service = (d2dm_service *)user_data; + + __D2DM_LOG_FUNC_ENTER__; + + /* Make response first */ + enabler_complete_disable(object, invocation, ret); + + /* Terminate daemon */ + d2dm_service_exit(service); + + return TRUE; +} + +static void _d2dm_dbus_on_activator_bus_acquired(GDBusConnection *conn, + const gchar *name, gpointer user_data) +{ + gboolean ret; + GError *error = NULL; + d2dm_service *service = (d2dm_service *)user_data; + + NOTUSED(name); + + __D2DM_LOG_FUNC_ENTER__; + + d2dm_activator_dbus_object = enabler_skeleton_new(); + if (NULL == d2dm_activator_dbus_object) { + D2DM_LOGE("enabler_skeleton_new() Fail"); + return; + } + + g_signal_connect(d2dm_activator_dbus_object, "handle-enable", + G_CALLBACK(_d2dm_dbus_handle_enable), service); + g_signal_connect(d2dm_activator_dbus_object, "handle-disable", + G_CALLBACK(_d2dm_dbus_handle_disable), service); + + ret = g_dbus_interface_skeleton_export( + G_DBUS_INTERFACE_SKELETON(d2dm_activator_dbus_object), + conn, D2DM_DBUS_ENABLER_OBJPATH, &error); + if (FALSE == ret) { + D2DM_LOGE("g_dbus_interface_skeleton_export() Fail(%s)", error->message); + g_error_free(error); + } + + __D2DM_LOG_FUNC_EXIT__; + +} + +static gboolean _d2dm_dbus_interface_init(d2dm_service *service) +{ + guint id; + guint activation_dbus_id; + d2dm_check_null_ret_error("service", service, FALSE); + + id = g_bus_own_name(G_BUS_TYPE_SYSTEM, + D2DM_DBUS_INTERFACE, + G_BUS_NAME_OWNER_FLAGS_REPLACE, + _d2dm_dbus_on_bus_acquired, + _d2dm_dbus_on_name_acquired, + _d2dm_dbus_on_name_lost, + service, + NULL); + if (0 == id) { + D2DM_LOGE("g_bus_own_name() Fail"); + return FALSE; + } + + /* Get D-Bus owner to activate mesh service daemon */ + activation_dbus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, + D2DM_DBUS_INTERFACE".enabler", + G_BUS_NAME_OWNER_FLAGS_REPLACE, + _d2dm_dbus_on_activator_bus_acquired, + NULL, + NULL, + service, + NULL); + + service->dbus_id = id; + service->activation_dbus_id = activation_dbus_id; + + /* Intiailze DBus sender */ + d2dm_dbus_start(service); + + return TRUE; +} + +static void _d2dm_dbus_deinit(d2dm_service *service) +{ + d2dm_check_null_ret("service", service); + + g_bus_unown_name(service->dbus_id); + g_bus_unown_name(service->activation_dbus_id); +} + +gboolean d2dm_service_interface_init(d2dm_service *service) +{ + guint ret; + d2dm_check_null_ret_error("service", service, FALSE); + + __D2DM_LOG_FUNC_ENTER__; + + /* Initialize dbus interface */ + ret = _d2dm_dbus_interface_init(service); + if (FALSE == ret) { + D2DM_LOGE("_d2dm_dbus_interface_init failed!!!"); + return FALSE; + } + + __D2DM_LOG_FUNC_EXIT__; + + return TRUE; +} + +void d2dm_service_interface_deinit(d2dm_service *service) +{ + d2dm_check_null_ret("service", service); + + /* De-initialize dbus interface */ + _d2dm_dbus_deinit(service); +} + diff --git a/src/d2d-manager/d2dm-service-interface.h b/src/d2d-manager/d2dm-service-interface.h new file mode 100644 index 0000000..343ccb5 --- /dev/null +++ b/src/d2d-manager/d2dm-service-interface.h @@ -0,0 +1,52 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 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 __D2DM_SERVICE_INTERFACE_H__ +#define __D2DM_SERVICE_INTERFACE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/**< Mesh D-BUS service*/ +#define D2DM_DBUS_SERVICE "net.d2dm" + +/**< Mesh D-BUS service path */ +#define D2DM_DBUS_PATH "/net/d2dm" + +#ifndef D2DM_DBUS_INTERFACE +#define D2DM_DBUS_INTERFACE "net.d2dm" +#endif + +#ifndef D2DM_DBUS_OBJPATH +#define D2DM_DBUS_OBJPATH "/net/d2dm" +#endif + +#ifndef D2DM_DBUS_ENABLER_OBJPATH +#define D2DM_DBUS_ENABLER_OBJPATH "/net/d2dm/enabler" +#endif + +gboolean d2dm_service_interface_init(d2dm_service *service); +void d2dm_service_interface_deinit(d2dm_service *service); + +#ifdef __cplusplus +} +#endif + +#endif /* __D2DM_SERVICE_INTERFACE_H__ */ + diff --git a/src/d2d-manager/d2dm-service.c b/src/d2d-manager/d2dm-service.c new file mode 100644 index 0000000..6c3cdbf --- /dev/null +++ b/src/d2d-manager/d2dm-service.c @@ -0,0 +1,71 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 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 + +#include "d2dm.h" +#include "d2dm-log.h" +#include "d2dm-util.h" + +d2dm_service *d2dm_service_new() +{ + d2dm_service *service; + + service = g_malloc0(sizeof(struct _d2d_service)); + + /* Create g-main loop */ + service->main_loop = g_main_loop_new(NULL, FALSE); + if (G_UNLIKELY(NULL == service->main_loop)) { + D2DM_LOGE("g-main loop creation failed!!!"); + g_free(service); + return NULL; + } + + return service; +} + +void d2dm_service_free(d2dm_service *service) +{ + d2dm_check_null_ret("service", service); + + /* Unref 'g-main loop' */ + if (service->main_loop) + g_main_loop_unref(service->main_loop); + + g_free(service); +} + +gboolean d2dm_service_run(d2dm_service *service) +{ + d2dm_check_null_ret_error("service", service, FALSE); + d2dm_check_null_ret_error("service->main_loop", service->main_loop, FALSE); + + g_main_loop_run(service->main_loop); + + return TRUE; +} + +gboolean d2dm_service_exit(d2dm_service *service) +{ + d2dm_check_null_ret_error("service", service, FALSE); + d2dm_check_null_ret_error("service->main_loop", service->main_loop, FALSE); + + g_main_loop_quit(service->main_loop); + + return TRUE; +} diff --git a/src/d2d-manager/d2dm-service.h b/src/d2d-manager/d2dm-service.h new file mode 100644 index 0000000..71230c9 --- /dev/null +++ b/src/d2d-manager/d2dm-service.h @@ -0,0 +1,36 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 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 __D2DM_SERVICE_H__ +#define __D2DM_SERVICE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +d2dm_service *d2dm_service_new(); +void d2dm_service_free(d2dm_service *service); +gboolean d2dm_service_run(d2dm_service *service); +gboolean d2dm_service_exit(d2dm_service *service); + +#ifdef __cplusplus +} +#endif + +#endif /* __D2DM_SERVICE_H__ */ + diff --git a/src/d2d-manager/d2dm-util.h b/src/d2d-manager/d2dm-util.h new file mode 100644 index 0000000..db7537c --- /dev/null +++ b/src/d2d-manager/d2dm-util.h @@ -0,0 +1,44 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 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 __D2DM_UTIL_H__ +#define __D2DM_UTIL_H__ + +#include +#include +#include + +#include "d2dm-log.h" + +#define NOTUSED(var) (var = var) + +#define d2dm_check_null_ret_error(name, value, error) do { \ + if (G_UNLIKELY(NULL == (value))) { \ + D2DM_LOGE("%s is NULL", name); \ + return error; \ + } \ +} while (FALSE) + +#define d2dm_check_null_ret(name, value) do { \ + if (G_UNLIKELY(NULL == (value))) { \ + D2DM_LOGE("%s is NULL", name); \ + return; \ + } \ +} while (FALSE) + +#endif /* __D2DM_UTIL_H__ */ diff --git a/src/d2d-manager/d2dm.c b/src/d2d-manager/d2dm.c new file mode 100644 index 0000000..0b7d099 --- /dev/null +++ b/src/d2d-manager/d2dm.c @@ -0,0 +1,79 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 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 +#include +#include + +#include + +#include "d2dm.h" +#include "d2dm-log.h" +#include "d2dm-util.h" +#include "d2dm-service.h" + +/**< d2d-manager service */ +d2dm_service *d2dsvc; + +int main(int argc, char *argv[]) +{ + d2dm_service *service = NULL; + int ret_code = 0; + gboolean ret; + + __D2DM_LOG_FUNC_ENTER__; + +#if !GLIB_CHECK_VERSION(2, 32, 0) + if (!g_thread_supported()) + g_thread_init(NULL); +#endif + +#if !GLIB_CHECK_VERSION(2, 36, 0) + g_type_init(); +#endif + NOTUSED(argc); + NOTUSED(argv); + + D2DM_LOGI("service mainloop start"); + + /* Create d2d-manager service */ + d2dsvc = service = d2dm_service_new(); + + /* Initialize d2d-manager service interface layer */ + ret = d2dm_service_interface_init(service); + if (G_UNLIKELY(FALSE == ret)) { + D2DM_LOGE("Service interface init. failed!"); + goto END; + } + /* Run mesh service */ + ret = d2dm_service_run(service); + if (G_UNLIKELY(FALSE == ret)) { + D2DM_LOGE("Run service failed!"); + ret_code = EXIT_FAILURE; + } + +END: + /* Free d2d-manager service */ + d2dm_service_interface_deinit(service); + d2dm_service_free(service); + d2dsvc = NULL; + + __D2DM_LOG_FUNC_EXIT__; + return 0; +} + diff --git a/src/d2d-manager/d2dm.h b/src/d2d-manager/d2dm.h new file mode 100644 index 0000000..4a4abad --- /dev/null +++ b/src/d2d-manager/d2dm.h @@ -0,0 +1,53 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 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 __D2D_MANAGER_H__ +#define __D2D_MANAGER_H__ + +#include +#include +#include + +/**< Internal error code with mesh daemon. It should be matched with API side */ +typedef enum { + D2DM_ERROR_NONE = 0, /**< Successful */ + D2DM_ERROR_IO_ERROR, /**< I/O error */ + D2DM_ERROR_NO_DATA, /**< Data not exists */ + D2DM_ERROR_OUT_OF_MEMORY, /**< out of memory */ + D2DM_ERROR_OPERATION_FAILED, /**< operation failed */ + D2DM_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + D2DM_ERROR_ALREADY_REGISTERED, /**< Request already registered */ + D2DM_ERROR_IN_PROGRESS /**< operation is in progress */ +} d2dm_error_e; + +/**< mesh service structure */ +typedef struct _d2d_service { + GMainLoop *main_loop; /**< Service main-loop */ + guint dbus_id; /**< D-Bus id */ + guint activation_dbus_id; /**< D-Bus id for activation */ + + gpointer connection; /**< Connection handle for D-Bus call to other process */ + GCancellable *ca; /**< Cancellable object for D-Bus call (Daemon->other) */ + GList *dbus_sub_ids; /**< The list of subscribed signals */ + + gboolean d2dp_activated; /**< Whetehr d2d-proxy enabled or not */ + gboolean d2dm_activated; /**< Whether d2d-manager enabled or not */ + +} d2dm_service; + +#endif /* __D2D_MANAGER_H__ */ diff --git a/src/d2d-manager/introspection/.d2d-generated-code.h.swp b/src/d2d-manager/introspection/.d2d-generated-code.h.swp new file mode 100644 index 0000000..d6676cb Binary files /dev/null and b/src/d2d-manager/introspection/.d2d-generated-code.h.swp differ diff --git a/src/d2d-manager/introspection/d2dm.xml b/src/d2d-manager/introspection/d2dm.xml new file mode 100644 index 0000000..9184d21 --- /dev/null +++ b/src/d2d-manager/introspection/d2dm.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/d2d-manager/introspection/enabler.xml b/src/d2d-manager/introspection/enabler.xml new file mode 100644 index 0000000..05c396b --- /dev/null +++ b/src/d2d-manager/introspection/enabler.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + diff --git a/src/d2d-manager/introspection/gen.sh b/src/d2d-manager/introspection/gen.sh new file mode 100755 index 0000000..7017da9 --- /dev/null +++ b/src/d2d-manager/introspection/gen.sh @@ -0,0 +1,6 @@ +gdbus-codegen --interface-prefix net.d2dm. \ + --generate-c-code d2dm-generated-code \ + --c-generate-object-manager \ + --generate-docbook generated-docs \ + d2dm.xml \ + enabler.xml diff --git a/src/include/d2d-common.h b/src/include/d2d-common.h deleted file mode 100644 index 5cee265..0000000 --- a/src/include/d2d-common.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2017 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 __D2D_COMMON_H__ -#define __D2D_COMMON_H__ - -#include -#include -#include - -#define NOTUSED(var) (var = var) - -#define d2dd_check_null_ret_error(name, value, error) do { \ - if (G_UNLIKELY(NULL == (value))) { \ - WMESH_LOGE("%s is NULL", name); \ - return error; \ - } \ -} while (FALSE) - -#define d2dd_check_null_ret(name, value) do { \ - if (G_UNLIKELY(NULL == (value))) { \ - WMESH_LOGE("%s is NULL", name); \ - return; \ - } \ -} while (FALSE) - -#endif /* __D2D_COMMON_H__ */ diff --git a/src/include/hw_emul/hw_interface.h b/src/include/hw_emul/hw_interface.h old mode 100755 new mode 100644 diff --git a/src/include/hw_emul/ss_emul.h b/src/include/hw_emul/ss_emul.h old mode 100755 new mode 100644 diff --git a/src/introspection/d2d-manager.c b/src/introspection/d2d-manager.c deleted file mode 100644 index 2fb6bdb..0000000 --- a/src/introspection/d2d-manager.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include - -#include - -#include "mesh.h" -#include "mesh-log.h" -#include "mesh-util.h" -#include "mesh-service.h" -#include "mesh-service-interface.h" - -/**< mesh service */ -+mesh_service *meshsvc; - -int main(int argc, char *argv[]) -{ - mesh_service *service = NULL; - int ret_code = 0; - gboolean ret; - - __MESH_LOG_FUNC_ENTER__; - -#if !GLIB_CHECK_VERSION(2, 32, 0) - if (!g_thread_supported()) -#if !GLIB_CHECK_VERSION(2, 36, 0) - g_type_init(); -#endif - NOTUSED(argc); - NOTUSED(argv); - - MESH_LOGI("service mainloop start"); - - /* Create mesh service */ - meshsvc = service = meshd_service_new(); - - /* Initialize mesh service interface layer */ - ret = meshd_service_interface_init(service); - if (G_UNLIKELY(FALSE == ret)) { - MESH_LOGE("zigbee_service_interface_init failed!"); - goto END; - } - - /* Run mesh service */ - ret = meshd_service_run(service); - if (G_UNLIKELY(FALSE == ret)) { - MESH_LOGE("Run service failed!"); - ret_code = EXIT_FAILURE; - } - - /* Free mesh service */ - meshd_service_free(service); - meshsvc = NULL; - - __MESH_LOG_FUNC_EXIT__; - return 0; -} diff --git a/src/introspection/gen.sh b/src/introspection/gen.sh deleted file mode 100755 index 027a2bf..0000000 --- a/src/introspection/gen.sh +++ /dev/null @@ -1,5 +0,0 @@ -gdbus-codegen --interface-prefix net.d2d. \ - --generate-c-code d2d-generated-code \ - --c-generate-object-manager \ - --generate-docbook generated-docs \ - manager.xml diff --git a/src/introspection/manager.xml b/src/introspection/manager.xml deleted file mode 100644 index 3c5c658..0000000 --- a/src/introspection/manager.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/src/subownerclient/CMakeLists.txt b/src/subownerclient/CMakeLists.txt deleted file mode 100644 index ccc4e73..0000000 --- a/src/subownerclient/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(d2d-manager-daemon C CXX) - -FILE(GLOB SRCS *) - -include_directories(${CMAKE_SOURCE_DIR}/src/subownerclient) -include_directories(${CMAKE_SOURCE_DIR}/src/subownerclient/include) - -INCLUDE(FindPkgConfig) -pkg_check_modules(subownerclient_pkgs REQUIRED glib-2.0 gio-2.0 gio-unix-2.0 dlog dbus-1 iotivity uuid gmock aul) - -MESSAGE(" - Adding external C flags") -FOREACH(flag ${subownerclient_pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") - SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fpic") -SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -std=gnu++11 -fPIC -fvisibility=hidden") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") - -ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${subownerclient_pkgs_LDFLAGS}) -INSTALL(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) diff --git a/src/subownerclient/main.c b/src/subownerclient/main.c deleted file mode 100755 index eb6415d..0000000 --- a/src/subownerclient/main.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2012, 2013 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 -#include -#include -#include -#include - -int main() -{ - int ret; - - dlog_print(DLOG_DEBUG, "D2D_DAEMON", "run daemon"); - - ret = aul_launch_app("org.tizen.familynet-manager", NULL); - dlog_print(DLOG_DEBUG, "D2D_DAEMON", "launch app result : %d", ret); - - return 0; -}