From: Jihoon Jung Date: Mon, 24 Aug 2020 07:44:56 +0000 (+0900) Subject: Initial repository commit X-Git-Tag: submit/tizen/20200824.092644^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d92bb7efcd7e36407c51526ca971023a5bf303f4;p=platform%2Fcore%2Fconnectivity%2Fuwb-manager.git Initial repository commit Change-Id: I6cb8e134bec8a28ea7835237c6f8f3163fd9edfa Signed-off-by: Jihoon Jung --- diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..277031e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @file CMakeLists.txt +# + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(uwb-manager C CXX) + +SET(DAEMON "uwb-manager") + +INCLUDE(FindPkgConfig) + +ADD_SUBDIRECTORY(interface) +ADD_SUBDIRECTORY(src) + +IF(BUILD_GTESTS) + ADD_SUBDIRECTORY(unittest) +ENDIF(BUILD_GTESTS) +IF(BUILD_TEST_APP) + ADD_SUBDIRECTORY(test) +ENDIF(BUILD_TEST_APP) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..96560be --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# uwb-manager \ No newline at end of file diff --git a/hpi/uwb-hpi.c b/hpi/uwb-hpi.c new file mode 100755 index 0000000..8e2ef72 --- /dev/null +++ b/hpi/uwb-hpi.c @@ -0,0 +1,129 @@ +/* + * UWB Service Plug-in Interface for Range + * + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * This file implements UWB Hardware Plug-in Interface(HPI) functions. + * + * @file uwb-hpi.c + * @author Jiung Yu (jiung.yu@samsung.com) + */ + +#include + +#include "uwb-hpi.h" + +int uwb_hpi_init(uwb_hpi_ops_s *ops, uwb_hpi_event_cbs_s *event_cbs) +{ + if (!ops->init) + return -1; + + return ops->init(event_cbs); +} + +int uwb_hpi_deinit(uwb_hpi_ops_s *ops) +{ + if (!ops->deinit) + return -1; + + return ops->deinit(); +} + +int uwb_hpi_test(uwb_hpi_ops_s *ops) +{ + if (!ops->test) + return -1; + + return ops->test(); +} + +int uwb_hpi_reset(uwb_hpi_ops_s *ops) +{ + if (!ops->reset) + return -1; + + return ops->reset(); +} + +int uwb_hpi_factory_reset(uwb_hpi_ops_s *ops) +{ + if (!ops->factory_reset) + return -1; + + return ops->factory_reset(); +} + +int uwb_hpi_get_own_node(uwb_hpi_ops_s *ops, uwb_hpi_node_s **own_node) +{ + if (!ops->get_own_node) + return -1; + + return ops->get_own_node(own_node); +} + +int uwb_hpi_get_network_info(uwb_hpi_ops_s *ops, uwb_hpi_network_s **network_info) +{ + if (!ops->reset) + return -1; + + return ops->get_network_info(network_info); + +} + +int uwb_hpi_set_configurations(uwb_hpi_ops_s *ops, uint16_t node_id, const GVariant *configurations) +{ + if (!ops->set_configurations) + return -1; + + return ops->set_configurations(node_id, configurations); +} + +int uwb_hpi_get_configurations(uwb_hpi_ops_s *ops, uint16_t node_id, GVariant **configurations) +{ + if (!ops->get_configurations) + return -1; + + return ops->get_configurations(node_id, configurations); + +} + +int uwb_hpi_set_position(uwb_hpi_ops_s *ops, uint16_t node_id, int x, int y, int z) +{ + if (!ops->set_position) + return -1; + + return ops->set_position(node_id, x, y, z); +} + +int uwb_hpi_send_message(uwb_hpi_ops_s *ops, + const unsigned char *message, int message_length) +{ + if (!ops->send_message) + return -1; + + return ops->send_message(message, message_length); +} + +int uwb_hpi_send_message_to(uwb_hpi_ops_s *ops, uint16_t node_id, + const unsigned char *message, int message_length) +{ + if (!ops->send_message_to) + return -1; + + return ops->send_message_to(node_id, message, message_length); +} diff --git a/hpi/uwb-hpi.h b/hpi/uwb-hpi.h new file mode 100755 index 0000000..6164e79 --- /dev/null +++ b/hpi/uwb-hpi.h @@ -0,0 +1,95 @@ +/* + * UWB Service Plug-in Interface for Range + * + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * This file declares UWB Hardware Plug-in Interface(HPI) functions and structures. + * + * @file uwb-hpi.h + * @author Jiung Yu (jiung.yu@samsung.com) + */ + +#ifndef __UWB_HPI_H__ +#define __UWB_HPI_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* TODO: replace below headers*/ +#include +#include + +#include + +#include + +typedef struct { + uint64_t node_id; + uint16_t pan_id; + bool is_remote; + uint64_t distance; + int x; + int y; + int z; +} uwb_hpi_node_s; + +typedef struct { + uint16_t pan_id; + GSList *remote_node_list; + int remote_node_count; +} uwb_hpi_network_s; + +typedef struct { + void (*message_received_cb) (uint16_t node_id, unsigned char *message, int message_length); + void (*position_changed_cb) (uint16_t node_id, int x, int y, int z); +} uwb_hpi_event_cbs_s; + +typedef struct { + int (*init) (uwb_hpi_event_cbs_s *event_cbs); + int (*deinit) (void); + int (*test) (void); + int (*reset) (void); + int (*factory_reset) (void); + int (*get_network_info) (uwb_hpi_network_s **network_info); + int (*set_configurations) (uint16_t node_id, const GVariant *configurations); + int (*get_configurations) (uint16_t node_id, GVariant **configurations); + int (*set_position) (uint16_t node_id, int x, int y, int z); + int (*get_own_node) (uwb_hpi_node_s **own_node); + int (*send_message) (const unsigned char *message, int message_length); + int (*send_message_to) (uint16_t node_id, const unsigned char *message, int message_length); +} uwb_hpi_ops_s; + +int uwb_hpi_init(uwb_hpi_ops_s *ops, uwb_hpi_event_cbs_s *event_cbs); +int uwb_hpi_deinit(uwb_hpi_ops_s *ops); +int uwb_hpi_test(uwb_hpi_ops_s *ops); +int uwb_hpi_reset(uwb_hpi_ops_s *ops); +int uwb_hpi_factory_reset(uwb_hpi_ops_s *ops); +int uwb_hpi_get_network_info(uwb_hpi_ops_s *ops, uwb_hpi_network_s **network_info); +int uwb_hpi_set_configurations(uwb_hpi_ops_s *ops, uint16_t node_id, const GVariant *configurations); +int uwb_hpi_get_configurations(uwb_hpi_ops_s *ops, uint16_t node_id, GVariant **configurations); +int uwb_hpi_set_position(uwb_hpi_ops_s *ops, uint16_t node_id, int x, int y, int z); +int uwb_hpi_get_own_node(uwb_hpi_ops_s *ops, uwb_hpi_node_s **own_node); +int uwb_hpi_send_message(uwb_hpi_ops_s *ops, const unsigned char *message, int message_length); +int uwb_hpi_send_message_to(uwb_hpi_ops_s *ops, uint16_t node_id, const unsigned char *message, int message_length); + +#ifdef __cplusplus +} +#endif + +#endif /* __UWB_HPI_H__ */ diff --git a/include/GdbusError.h b/include/GdbusError.h new file mode 100644 index 0000000..7cf065a --- /dev/null +++ b/include/GdbusError.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __GDBUS_ERROR_H__ +#define __GDBUS_ERROR_H__ + +#include + +#include + +#include + +namespace UwbManagerNamespace { + +class GdbusError { + +public: + void registerGdbusError(); + void deregisterGdbusError(); + void setGerror(uwb_error_e error_code, GError **error); + +private: + const std::string _uwb_quark_str = + std::string("uwb-manager-error-quark"); + const std::string _invalid_parameter_str = + std::string("org.tizen.uwb.Error.InvalidParameter"); + const std::string _out_of_memory_str = + std::string("org.tizen.uwb.Error.OutOfMemory"); + const std::string _permission_denied_str = + std::string("org.tizen.uwb.Error.NotPermitted"); + const std::string _operation_failed_str = + std::string("org.tizen.uwb.Error.OperationFailed"); +}; + +} + +#endif /* __GDBUS_ERROR_H__ */ diff --git a/include/MethodHandler.h b/include/MethodHandler.h new file mode 100644 index 0000000..27d0027 --- /dev/null +++ b/include/MethodHandler.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __METHOD_HANDLER_H__ +#define __METHOD_HANDLER_H__ + +#include + +#include + +#include "generated-code.h" + +#include + +namespace UwbManagerNamespace { + +class MethodHandler { + +public: + virtual ~MethodHandler() {}; + virtual void registerHandler(UwbGdbuslibManager *manager_skeleton) = 0; + virtual UwbManager *getManager() = 0; +}; + +} + +#endif /* __METHOD_HANDLER_H__ */ diff --git a/include/UwbConfig.h b/include/UwbConfig.h new file mode 100644 index 0000000..f065111 --- /dev/null +++ b/include/UwbConfig.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_CONFIG_H__ +#define __UWB_CONFIG_H__ + +#include + +namespace UwbManagerNamespace { + +class UwbConfig { +public: + UwbConfig() : + _node_id(0), _configurations(nullptr) {}; + + UwbConfig(int node_id, int pan_id, GVariant *configurations); + UwbConfig(const UwbConfig* config); + ~UwbConfig(); + + int setNodeId(int node_id); + int getNodeId(); + int setPanId(int pan_id); + int getPanId(); + int setConfigurations(const GVariant *configurations); + GVariant *getConfigurations(); +private: + int _node_id; + int _pan_id; + GVariant *_configurations; +}; + +} + +#endif /* __UWB_CONFIG_H__ */ diff --git a/include/UwbDbusManager.h b/include/UwbDbusManager.h new file mode 100644 index 0000000..62626e2 --- /dev/null +++ b/include/UwbDbusManager.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_DBUS_MANAGER_H__ +#define __UWB_DBUS_MANAGER_H__ + +#include + +#include + +namespace UwbManagerNamespace { + +class UwbDbusManager { +public: + UwbDbusManager() : _owner_id(0) {}; + ~UwbDbusManager(); + + /* TODO: Make this pointer to vector if there's multiple handlers */ + void init(UwbIfaceHandler *iface_handler); + void deinit(void); + static void emitMessageReceivedSignal(uint16_t node_id, + const unsigned char *message, int message_length); + static void emitPositionChangedSignal(uint16_t node_id, int x, int y, int z); + +private: + const std::string uwb_dbus_service_str = + std::string("org.tizen.uwb"); + guint _owner_id; + static void onBusAcquired(GDBusConnection *connection, const gchar *name, gpointer user_data); +}; + +} + +#endif /* __UWB_DBUS_MANAGER_H__ */ diff --git a/include/UwbIfaceHandler.h b/include/UwbIfaceHandler.h new file mode 100644 index 0000000..35b2b8a --- /dev/null +++ b/include/UwbIfaceHandler.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_IFACE_HANDLER_H__ +#define __UWB_IFACE_HANDLER_H__ + +#include +#include + +#include + +#include "generated-code.h" + +#include +#include + +namespace UwbManagerNamespace { + +class UwbIfaceHandler { +public: + UwbIfaceHandler(UwbManager* uwb_manager); + ~UwbIfaceHandler(); + + std::string get_dbus_path_str(void); + void registerHandler(UwbGdbuslibManager *manager_skeleton); +private: + const std::string _uwb_dbus_path_str = + std::string("/org/tizen/uwb/manager"); + std::vector _handler_vec; +}; + +} + +#endif /* __UWB_IFACE_HANDLER_H__ */ diff --git a/include/UwbManager.h b/include/UwbManager.h new file mode 100644 index 0000000..d3c8504 --- /dev/null +++ b/include/UwbManager.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_MANAGER_H__ +#define __UWB_MANAGER_H__ + +#include +#include +#include + +namespace UwbManagerNamespace { + +class UwbManager { +public: + UwbManager() : + _uwb_config(nullptr), _range_plugin(nullptr) {}; + UwbManager(UwbConfig *uwb_config, UwbRangePlugin *range_plugin) : + _uwb_config(uwb_config), _range_plugin(range_plugin) {}; + int test(void); + int reset(void); + int factoryReset(void); + int setPosition(int node_id, int x, int y, int z); + int setDefaultConfigurations(void); + int setConfigurations(int node_id, GVariant *configurations); + int getConfigurations(int node_id, GVariant **configurations); + UwbNetwork *getNetwork(); + UwbNode *getOwnNode(); + int sendMessage(const unsigned char *message, int message_length); + int sendMessageTo(uint16_t node_id, const unsigned char *message, int message_length); +private: + UwbConfig *_uwb_config; + UwbRangePlugin *_range_plugin; +}; + +} + +#endif /* __UWB_MANAGER_H__ */ diff --git a/include/UwbNetwork.h b/include/UwbNetwork.h new file mode 100644 index 0000000..dedb5be --- /dev/null +++ b/include/UwbNetwork.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_NETWORK_H__ +#define __UWB_NETWORK_H__ + +#include + +#include + +namespace UwbManagerNamespace { + +class UwbNetwork { +public: + UwbNetwork(int pan_id) : + _pan_id(pan_id) {}; + ~UwbNetwork(); + void setPanId(int pan_id); + int getPanId(); + int addNode(UwbNode *node); + int removeNode(UwbNode *node); + std::list *getNodeList(); + +private: + int _pan_id; + std::list _node_list; +}; + +} + +#endif /* __UWB_NETWORK_H__ */ diff --git a/include/UwbNode.h b/include/UwbNode.h new file mode 100644 index 0000000..bc781bc --- /dev/null +++ b/include/UwbNode.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_NODE_H__ +#define __UWB_NODE_H__ + +namespace UwbManagerNamespace { + +class UwbNode { +public: + UwbNode(): _distance(0), _pan_id(0), _node_id(0), _x(0), _y(0), _z(0), _is_remote(false) {}; + UwbNode(unsigned long long distance, int pan_id, unsigned long long node_id, int x, int y, int z, bool is_remote): + _distance(distance), _pan_id(pan_id), _node_id(node_id), _x(x), _y(y), _z(z), _is_remote(is_remote) {}; + UwbNode(UwbNode *node); + void setDistance(unsigned long long distance); + unsigned long long getDistance(); + void setPanId(int id); + int getPanId(); + void setNodeId(unsigned long long id); + unsigned long long getNodeId(); + int getX(); + void setX(int x); + int getY(); + void setY(int y); + int getZ(); + void setZ(int z); + bool getIsRemote(); + void setIsRemote(bool is_remote); +private: + unsigned long long _distance; + int _pan_id; + unsigned long long _node_id; + int _x; + int _y; + int _z; + bool _is_remote; +}; + +} + +#endif /* __UWB_NETWORK_H__ */ diff --git a/include/UwbPluginManager.h b/include/UwbPluginManager.h new file mode 100644 index 0000000..c6683eb --- /dev/null +++ b/include/UwbPluginManager.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_PLUGIN_MANAGER_H__ +#define __UWB_PLUGIN_MANAGER_H__ + +#include + +namespace UwbManagerNamespace { + +class UwbPluginManager { +public: + UwbPluginManager(): _dl_handle(nullptr) {}; + ~UwbPluginManager(); + int load(const std::string lib_path_str); + void unload(void); + void *get_symbol(const std::string symbol_str); +private: + void *_dl_handle; +}; + +} + +#endif /* __UWB_PLUGIN_MANAGER_H__ */ diff --git a/include/UwbRangePlugin.h b/include/UwbRangePlugin.h new file mode 100644 index 0000000..a1acae5 --- /dev/null +++ b/include/UwbRangePlugin.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_RANGE_PLUGIN_H__ +#define __UWB_RANGE_PLUGIN_H__ + +#include + +#include +#include +#include + +namespace UwbManagerNamespace { + +class UwbRangePlugin { +public: + int init(UwbPluginManager *plugin_manager); + int deinit(void); + int test(void); + int reset(void); + int factoryReset(void); + int getOwnNode(uwb_hpi_node_s **own_node); + int getNetworkInfo(uwb_hpi_network_s **network_info); + int setConfigurations(uint16_t node_id, const GVariant *configurations); + int getConfigurations(uint16_t node_id, GVariant **configurations); + int setPosition(uint16_t node_id, int x, int y, int z); + int sendMessage(const unsigned char *message, int message_length); + int sendMessageTo(uint16_t node_id, const unsigned char *message, int message_length); + static void messageReceivedCb(uint16_t node_id, unsigned char *message, int message_length); + static void positionChangedCb(uint16_t node_id, int x, int y, int z); +private: + uwb_hpi_event_cbs_s event_cbs; + uwb_hpi_ops_s ops; +}; + +} + +#endif /* __UWB_RANGE_PLUGIN_H__ */ diff --git a/include/uwb-error-def.h b/include/uwb-error-def.h new file mode 100644 index 0000000..b963405 --- /dev/null +++ b/include/uwb-error-def.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_ERROR_DEF_H__ +#define __UWB_ERROR_DEF_H__ + +typedef enum { + UWB_ERROR_NONE, /**< Successful */ + UWB_ERROR_IO_ERROR, /**< I/O error */ + UWB_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + UWB_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + UWB_ERROR_PERMISSION_DENIED, /**< Permission denied */ + UWB_ERROR_NOT_SUPPORTED, /**< Not supported */ + UWB_ERROR_OPERATION_FAILED +} uwb_error_e; +#endif /* __UWB_ERROR_DEF_H__ */ diff --git a/include/uwb-log-def.h b/include/uwb-log-def.h new file mode 100644 index 0000000..4d2010f --- /dev/null +++ b/include/uwb-log-def.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_LOG_DEF_H__ +#define __UWB_LOG_DEF_H__ + +#include + +#define DLOG_TAG "UWB_MANAGER" + +#define UWB_LOGD(format, arg...) LOG(LOG_DEBUG, DLOG_TAG, format, ##arg) +#define UWB_LOGI(format, arg...) LOG(LOG_INFO, DLOG_TAG, format, ##arg) +#define UWB_LOGW(format, arg...) LOG(LOG_WARN, DLOG_TAG, format, ##arg) +#define UWB_LOGE(format, arg...) LOG(LOG_ERROR, DLOG_TAG, format, ##arg) + +#define __UWB_LOG_FUNC_ENTER__ UWB_LOGI("Enter") +#define __UWB_LOG_FUNC_EXIT__ UWB_LOGI("Quit") + +#endif /* __UWB_LOG_DEF_H__ */ diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt new file mode 100644 index 0000000..ffa7c2f --- /dev/null +++ b/interface/CMakeLists.txt @@ -0,0 +1,27 @@ +# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @file CMakeLists.txt +# + +ADD_CUSTOM_COMMAND( + WORKING_DIRECTORY + OUTPUT dbus + COMMAND gdbus-codegen --interface-prefix org.tizen.uwb. + --generate-c-code generated-code + --c-namespace UwbGdbuslib + ./uwb-manager-iface.xml + COMMENT "Generating GDBus .c/.h") + +ADD_CUSTOM_TARGET(GENERATED_DBUS_CODE DEPENDS dbus) \ No newline at end of file diff --git a/interface/uwb-manager-iface.xml b/interface/uwb-manager-iface.xml new file mode 100755 index 0000000..4cba98f --- /dev/null +++ b/interface/uwb-manager-iface.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packaging/dbus-uwb-manager.conf b/packaging/dbus-uwb-manager.conf new file mode 100644 index 0000000..c4ba630 --- /dev/null +++ b/packaging/dbus-uwb-manager.conf @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/packaging/org.tizen.uwb.service b/packaging/org.tizen.uwb.service new file mode 100755 index 0000000..8bbb9b3 --- /dev/null +++ b/packaging/org.tizen.uwb.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.tizen.uwb +Exec=/bin/false +SystemdService=uwb-manager.service \ No newline at end of file diff --git a/packaging/uwb-manager.service b/packaging/uwb-manager.service new file mode 100644 index 0000000..c47f61d --- /dev/null +++ b/packaging/uwb-manager.service @@ -0,0 +1,11 @@ +[Unit] +Description=UWB Manager + +[Service] +Type=dbus +BusName=org.tizen.uwb +ExecStart=/usr/bin/uwb-manager +KillSignal=SIGKILL +User=root +Group=root +SmackProcessLabel=System diff --git a/packaging/uwb-manager.spec b/packaging/uwb-manager.spec new file mode 100644 index 0000000..a1f4fea --- /dev/null +++ b/packaging/uwb-manager.spec @@ -0,0 +1,100 @@ +Name: uwb-manager +Summary: This is the daemon managing UWB related functionalities +Version: 0.0.1 +Release: 1 +Group: Network & Connectivity/Wireless +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz + +BuildRequires: cmake +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(json-glib-1.0) +Source1: dbus-uwb-manager.conf +Source2: org.tizen.uwb.service +Source3: uwb-manager.service + +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%if 0%{?gtests:1} +BuildRequires: pkgconfig(gmock) +%endif + +%description +Manager for handling UWB functionalities + +%prep +%setup -q + +chmod 644 %{SOURCE0} +chmod 644 %{SOURCE1} +chmod 644 %{SOURCE2} +chmod 644 %{SOURCE3} +cp -a %{SOURCE1} ./uwb-manager.conf +cp -a %{SOURCE2} . +cp -a %{SOURCE3} . + +%build + +export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" +export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" + +%if 0%{?gcov:1} +export CFLAGS+=" -fprofile-arcs -ftest-coverage" +export CXXFLAGS+=" -fprofile-arcs -ftest-coverage" +export FFLAGS+=" -fprofile-arcs -ftest-coverage" +export LDFLAGS+=" -lgcov" +%endif + +%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ +%if "%{?_lib}" == "lib64" + -DTIZEN_ARCH_64=1 \ +%endif + -DLIB_DIR=%{_libdir} \ + -DBIN_DIR=%{_bindir} \ + -DTZ_SYS_RO_ETC=%{TZ_SYS_RO_ETC} \ + -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \ + -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0} \ + -DBUILD_TEST_APP=%{?test_app:1}%{!?test_app:0} + +make %{?_smp_mflags} + +%install +rm -rf %{buildroot} + +%make_install + +mkdir -p %{buildroot}%{_datadir}/dbus-1/system-services/ +cp org.tizen.uwb.service %{buildroot}%{_datadir}/dbus-1/system-services/ +mkdir -p %{buildroot}%{_libdir}/systemd/system/ +cp uwb-manager.service %{buildroot}%{_libdir}/systemd/system/uwb-manager.service +%if "%{?_lib}" == "lib64" +mkdir -p %{buildroot}%{_unitdir} +cp uwb-manager.service %{buildroot}%{_unitdir}/uwb-manager.service +%endif +mkdir -p %{buildroot}%{_sysconfdir}/uwb/ + +#DBus DAC +mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d +cp uwb-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/uwb-manager.conf + +%post + +%files +%manifest %{name}.manifest +%license LICENSE +%defattr(-,root,root,-) +%attr(500,root,root) %{_bindir}/* + +%attr(644,root,root) %{_datadir}/dbus-1/system-services/org.tizen.uwb.service +%attr(644,root,root) %{_libdir}/systemd/system/* +%if "%{?_lib}" == "lib64" +%attr(644,root,root) %{_unitdir}/uwb-manager.service +%endif + +#DBus DAC +%attr(644,root,root) %{_sysconfdir}/dbus-1/system.d/uwb-manager.conf diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100755 index 0000000..b3931db --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,78 @@ +# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @file CMakeLists.txt +# + +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/hpi + ${CMAKE_SOURCE_DIR}/src + ) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/interface) + + +AUX_SOURCE_DIRECTORY(./ SRCS) +SET(SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/hpi/uwb-hpi.c) +SET(SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/interface/generated-code.c) + +SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/interface/generated-code.c PROPERTIES GENERATED TRUE) + +PKG_CHECK_MODULES(daemon_pkgs REQUIRED glib-2.0 gio-2.0 gio-unix-2.0 dlog libtzplatform-config json-glib-1.0) + +IF(TIZEN_ARCH_64) + ADD_DEFINITIONS(-DTIZEN_ARCH_64) +ENDIF(TIZEN_ARCH_64) + +FOREACH(flag ${daemon_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +FOREACH(flag ${daemon_pkgs_CXXFLAGS}) + SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") +ENDFOREACH(flag) + +INCLUDE_DIRECTORIES(${daemon_pkgs_INCLUDE_DIRS}) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror -fPIE") +SET(CMAKE_C_FLAGS_DEBUG "O0 -g -fPIE") +SET(CMAKE_C_FLAGS_RELEASE "O2 -fPIE") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -g -Werror -fPIE") +SET(CMAKE_CXX_FLAGS_DEBUG "O0 -g -fPIE") +SET(CMAKE_CXX_FLAGS_RELEASE "O2 -fPIE") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +ADD_EXECUTABLE(${DAEMON} ${SRCS}) +ADD_DEPENDENCIES(${DAEMON} GENERATED_DBUS_CODE) + +TARGET_LINK_LIBRARIES(${DAEMON} ${daemon_pkgs_LDFLAGS} -ldl) +INSTALL(TARGETS ${DAEMON} DESTINATION bin) + +IF (BUILD_GTESTS) +SET(DAEMON_LIB "uwb-mgr") + +ADD_LIBRARY(${DAEMON_LIB} SHARED ${SRCS}) + +SET_TARGET_PROPERTIES(${DAEMON_LIB} + PROPERTIES + SOVERSION 0.1.0 + CLEAN_DIRECT_OUTPUT 1) + +TARGET_LINK_LIBRARIES(${DAEMON_LIB} ${daemon_pkgs_LDFLAGS} -ldl) +ADD_DEPENDENCIES(${DAEMON_LIB} GENERATED_DBUS_CODE) + +INSTALL(TARGETS ${DAEMON_LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +ENDIF (BUILD_GTESTS) diff --git a/src/GdbusError.cpp b/src/GdbusError.cpp new file mode 100644 index 0000000..fd379f9 --- /dev/null +++ b/src/GdbusError.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2020 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 + +using namespace UwbManagerNamespace; + +void GdbusError::registerGdbusError() +{ + GQuark uwb_manager_quark = g_quark_from_string(_uwb_quark_str.c_str()); + + g_dbus_error_register_error(uwb_manager_quark, + UWB_ERROR_INVALID_PARAMETER, + _invalid_parameter_str.c_str()); + + g_dbus_error_register_error(uwb_manager_quark, + UWB_ERROR_OUT_OF_MEMORY, + _out_of_memory_str.c_str()); + + g_dbus_error_register_error(uwb_manager_quark, + UWB_ERROR_PERMISSION_DENIED, + _permission_denied_str.c_str()); + + g_dbus_error_register_error(uwb_manager_quark, + UWB_ERROR_OPERATION_FAILED, + _operation_failed_str.c_str()); +} + +void GdbusError::deregisterGdbusError() +{ + GQuark uwb_manager_quark = g_quark_from_string(_uwb_quark_str.c_str()); + + g_dbus_error_unregister_error(uwb_manager_quark, + UWB_ERROR_INVALID_PARAMETER, + _invalid_parameter_str.c_str()); + + g_dbus_error_unregister_error(uwb_manager_quark, + UWB_ERROR_OUT_OF_MEMORY, + _out_of_memory_str.c_str()); + + g_dbus_error_unregister_error(uwb_manager_quark, + UWB_ERROR_PERMISSION_DENIED, + _permission_denied_str.c_str()); + + g_dbus_error_unregister_error(uwb_manager_quark, + UWB_ERROR_OPERATION_FAILED, + _operation_failed_str.c_str()); +} + +void GdbusError::setGerror(uwb_error_e error_code, GError **error) +{ + switch (error_code) { + case UWB_ERROR_INVALID_PARAMETER: + *error = g_dbus_error_new_for_dbus_error( + this->_invalid_parameter_str.c_str(), + this->_invalid_parameter_str.c_str()); + break; + case UWB_ERROR_OUT_OF_MEMORY: + *error = g_dbus_error_new_for_dbus_error( + this->_out_of_memory_str.c_str(), + this->_out_of_memory_str.c_str()); + break; + case UWB_ERROR_PERMISSION_DENIED: + *error = g_dbus_error_new_for_dbus_error( + this->_permission_denied_str.c_str(), + this->_permission_denied_str.c_str()); + break; + case UWB_ERROR_OPERATION_FAILED: + *error = g_dbus_error_new_for_dbus_error( + this->_operation_failed_str.c_str(), + this->_operation_failed_str.c_str()); + break; + default: + UWB_LOGI("Error Not handled [%d]", error_code); + *error = g_dbus_error_new_for_dbus_error( + this->_operation_failed_str.c_str(), + this->_operation_failed_str.c_str()); + } +} diff --git a/src/UwbConfig.cpp b/src/UwbConfig.cpp new file mode 100755 index 0000000..501c8e3 --- /dev/null +++ b/src/UwbConfig.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2020 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 + +using namespace UwbManagerNamespace; + +UwbConfig::UwbConfig(int node_id, int pan_id, GVariant *configurations) +{ + __UWB_LOG_FUNC_ENTER__; + + _node_id = node_id; + _pan_id = pan_id; + _configurations = configurations; + + __UWB_LOG_FUNC_EXIT__; +} + + +UwbConfig::UwbConfig(const UwbConfig* config) +{ + _node_id = config->_node_id; + _node_id = config->_pan_id; + _configurations = config->_configurations; +} + +UwbConfig::~UwbConfig() +{ + __UWB_LOG_FUNC_ENTER__; + + __UWB_LOG_FUNC_EXIT__; +} + +int UwbConfig::setNodeId(int node_id) +{ + __UWB_LOG_FUNC_ENTER__; + + _node_id = node_id; + + __UWB_LOG_FUNC_EXIT__; + return 0; +} + +int UwbConfig::getNodeId() +{ + __UWB_LOG_FUNC_ENTER__; + + __UWB_LOG_FUNC_EXIT__; + return _node_id; +} + +int UwbConfig::setPanId(int pan_id) +{ + __UWB_LOG_FUNC_ENTER__; + + _pan_id = pan_id; + + __UWB_LOG_FUNC_EXIT__; + return 0; +} + +int UwbConfig::getPanId() +{ + __UWB_LOG_FUNC_ENTER__; + + __UWB_LOG_FUNC_EXIT__; + return _pan_id; +} + +int UwbConfig::setConfigurations(const GVariant *configurations) +{ + __UWB_LOG_FUNC_ENTER__; + + //_configurations = configurations; + + __UWB_LOG_FUNC_EXIT__; + return 0; + +} + +GVariant *UwbConfig::getConfigurations() +{ + __UWB_LOG_FUNC_ENTER__; + __UWB_LOG_FUNC_EXIT__; + return _configurations; +} diff --git a/src/UwbDbusManager.cpp b/src/UwbDbusManager.cpp new file mode 100644 index 0000000..4f58e51 --- /dev/null +++ b/src/UwbDbusManager.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2020 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 + +using namespace UwbManagerNamespace; + +UwbDbusManager::~UwbDbusManager() +{ + if (_owner_id) { + g_bus_unown_name(_owner_id); + _owner_id = 0; + } +} + +void UwbDbusManager::init(UwbIfaceHandler *iface_handler) +{ + GdbusError gdbus_error = GdbusError(); + if (_owner_id) { + UWB_LOGI("Already initialized"); + return; + } + + gdbus_error.registerGdbusError(); + _owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, + uwb_dbus_service_str.c_str(), + G_BUS_NAME_OWNER_FLAGS_NONE, + onBusAcquired, + NULL, + NULL, + (gpointer)iface_handler, + NULL); + UWB_LOGI("Request to Own [%u]", _owner_id); +} + +void UwbDbusManager::deinit(void) +{ + GdbusError gdbus_error = GdbusError(); + + gdbus_error.deregisterGdbusError(); + if (_owner_id) { + g_bus_unown_name(_owner_id); + _owner_id = 0; + } +} + +UwbGdbuslibManager *manager_skeleton; + +void UwbDbusManager::onBusAcquired(GDBusConnection *connection, const gchar *name, gpointer user_data) +{ + gboolean ret = FALSE; + GError *error = NULL; + + GDBusObjectManagerServer *manager; + UwbIfaceHandler *iface_handler = (UwbIfaceHandler *)user_data; + + __UWB_LOG_FUNC_ENTER__; + /* Add interface to default object path */ + manager_skeleton = uwb_gdbuslib_manager_skeleton_new(); + + /* Register method callbacks as signal callback */ + iface_handler->registerHandler(manager_skeleton); + + /* Set connection to 'manager' */ + manager = g_dbus_object_manager_server_new(iface_handler->get_dbus_path_str().c_str()); + g_dbus_object_manager_server_set_connection(manager, connection); + + /* Export 'manager' interface on UWB DBUS */ + ret = g_dbus_interface_skeleton_export( + G_DBUS_INTERFACE_SKELETON(manager_skeleton), + connection, iface_handler->get_dbus_path_str().c_str(), &error); + + if (ret == FALSE) { + UWB_LOGE("Can not skeleton_export %s", error->message); + g_error_free(error); + } + __UWB_LOG_FUNC_EXIT__; +} + +static GVariant *__data_to_variant(const unsigned char *data, int length) +{ + GVariantBuilder builder; + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)")); + + if (data && length > 0) + { + for(int i = 0; i < length; i++) + g_variant_builder_add(&builder, "(y)", *(data + i)); + } + + return g_variant_builder_end(&builder); +} + +void UwbDbusManager::emitMessageReceivedSignal(uint16_t node_id, + const unsigned char *message, int message_length) +{ + GVariant *data = __data_to_variant(message, message_length); + + uwb_gdbuslib_manager_emit_message_received(manager_skeleton, node_id, data, message_length); + + g_variant_unref(data); +} + +void UwbDbusManager::emitPositionChangedSignal(uint16_t node_id, int x, int y, int z) +{ + uwb_gdbuslib_manager_emit_position_changed(manager_skeleton, node_id, x, y, z); +} + diff --git a/src/UwbIfaceHandler.cpp b/src/UwbIfaceHandler.cpp new file mode 100644 index 0000000..940312c --- /dev/null +++ b/src/UwbIfaceHandler.cpp @@ -0,0 +1,759 @@ +/* + * Copyright (c) 2020 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 + +using namespace UwbManagerNamespace; + +static void __dbus_return_err(uwb_error_e ret, GDBusMethodInvocation *invocation) +{ + GdbusError gdbus_error; + GError *err = NULL; + gchar* dbus_error_name = NULL; + + if (!invocation) + return; + + gdbus_error.setGerror(ret, &err); + dbus_error_name = g_dbus_error_encode_gerror(err); + UWB_LOGI("g_dbus_method_invocation_return_gerror with [%s]", dbus_error_name); + g_free(dbus_error_name); + g_dbus_method_invocation_return_gerror(invocation, err); + g_clear_error(&err); + return; +} + +static UwbManager *__get_uwb_manager(MethodHandler *handler) +{ + if (!handler) + return NULL; + + return handler->getManager(); +} + +class testMethodHandler : MethodHandler +{ +public: + testMethodHandler(UwbManager* manager): _manager(manager) {}; + ~testMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } + +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-test"); + + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + int result = uwb_manager->test(); + if (result != 0) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + uwb_gdbuslib_manager_complete_test(gdbus_manager, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + + +class resetMethodHandler : MethodHandler +{ +public: + resetMethodHandler(UwbManager* manager): _manager(manager) {}; + ~resetMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } + +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-reset"); + + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + int result = uwb_manager->reset(); + if (result != 0) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + uwb_gdbuslib_manager_complete_reset(gdbus_manager, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + +class factoryResetMethodHandler : MethodHandler +{ +public: + factoryResetMethodHandler(UwbManager* manager): _manager(manager) {}; + ~factoryResetMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-factory-reset"); + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + int result = uwb_manager->factoryReset(); + if (result != 0) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + uwb_gdbuslib_manager_complete_factory_reset(gdbus_manager, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + +class getOwnNodeMethodHandler : MethodHandler +{ +public: + getOwnNodeMethodHandler(UwbManager* manager): _manager(manager) {}; + ~getOwnNodeMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-get-own-node"); + static void buildNodeGvar(UwbNode *node, GVariant **node_gvar) + { + GVariantBuilder *builder; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_open(builder, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(builder, "{sv}", "Distance", + g_variant_new_uint64(node->getDistance())); + g_variant_builder_add(builder, "{sv}", "PanID", + g_variant_new_uint16(node->getPanId())); + g_variant_builder_add(builder, "{sv}", "NodeID", + g_variant_new_uint64(node->getNodeId())); + g_variant_builder_add(builder, "{sv}", "X", + g_variant_new_int32(node->getX())); + g_variant_builder_add(builder, "{sv}", "Y", + g_variant_new_int32(node->getY())); + g_variant_builder_add(builder, "{sv}", "Z", + g_variant_new_int32(node->getZ())); + g_variant_builder_close(builder); + + *node_gvar = g_variant_builder_end(builder); + g_variant_builder_unref(builder); + } + + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + UwbNode *uwb_node = uwb_manager->getOwnNode(); + if (!uwb_node) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + GVariant *node_gvar = nullptr; + buildNodeGvar(uwb_node, &node_gvar); + delete uwb_node; + + uwb_gdbuslib_manager_complete_get_own_node(gdbus_manager, invocation, node_gvar); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + +class getNetworkMethodHandler : MethodHandler +{ +public: + getNetworkMethodHandler(UwbManager* manager): _manager(manager) {}; + ~getNetworkMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-get-network-info"); + static void buildNetworkGvar(std::list *node_list, GVariant **networks_gvar) + { + GVariantBuilder *builder; + std::list::iterator it; + + builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}")); + it = node_list->begin(); + for (; it != node_list->end(); ++it) { + UwbNode *node = *it; + g_variant_builder_open(builder, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(builder, "{sv}", "Distance", + g_variant_new_uint64(node->getDistance())); + g_variant_builder_add(builder, "{sv}", "PanID", + g_variant_new_uint16(node->getPanId())); + g_variant_builder_add(builder, "{sv}", "NodeID", + g_variant_new_uint64(node->getNodeId())); + g_variant_builder_add(builder, "{sv}", "X", + g_variant_new_int32(node->getX())); + g_variant_builder_add(builder, "{sv}", "Y", + g_variant_new_int32(node->getY())); + g_variant_builder_add(builder, "{sv}", "Z", + g_variant_new_int32(node->getZ())); + g_variant_builder_close(builder); + } + + *networks_gvar = g_variant_builder_end(builder); + g_variant_builder_unref(builder); + } + + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + UwbNetwork *uwb_network = uwb_manager->getNetwork(); + if (!uwb_network) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + std::list *node_list = uwb_network->getNodeList(); + if (!node_list) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + GVariant *networks_gvar = nullptr; + buildNetworkGvar(node_list, &networks_gvar); + delete uwb_network; + + uwb_gdbuslib_manager_complete_get_network_info(gdbus_manager, invocation, + (uint16_t)uwb_network->getPanId(), networks_gvar); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + +class setConfigurationsMethodHandler : MethodHandler +{ +public: + setConfigurationsMethodHandler(UwbManager* manager): _manager(manager) {}; + ~setConfigurationsMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-set-configurations"); + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + guint16 node_id, + GVariant *configurations, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + int result = uwb_manager->setConfigurations(node_id, configurations); + if (result != 0) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + uwb_gdbuslib_manager_complete_set_configurations(gdbus_manager, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + +class getConfigurationsMethodHandler : MethodHandler +{ +public: + getConfigurationsMethodHandler(UwbManager* manager): _manager(manager) {}; + ~getConfigurationsMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-get-configurations"); + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + guint16 node_id, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + GVariant *config_gvar = nullptr; + int result = uwb_manager->getConfigurations(node_id, &config_gvar); + if (result != 0) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + uwb_gdbuslib_manager_complete_get_configurations(gdbus_manager, invocation, config_gvar); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + +class setPositionMethodHandler : MethodHandler +{ +public: + setPositionMethodHandler(UwbManager* manager): _manager(manager) {}; + ~setPositionMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-set-position"); + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + guint16 node_id, + gint x, + gint y, + gint z, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + int result = uwb_manager->setPosition(node_id, x, y, z); + if (result != 0) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + uwb_gdbuslib_manager_complete_set_position(gdbus_manager, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + +static gint __ay_to_guchar(GVariant *src, int size, guchar **dst) +{ + if (src == nullptr || dst == nullptr || size == 0) + return 0; + + GVariantIter *iter; + g_variant_get(src, "a(y)", &iter); + + int result_size = g_variant_iter_n_children(iter); + if (result_size == 0 || result_size != size) + return 0; + + guchar *buffer = (guchar *)g_try_malloc0(result_size); + if (!buffer) + return 0; + + guint8 element; + guint pos = 0; + + while (g_variant_iter_loop(iter, "(y)", &element)) { + *(buffer + pos) = element; + ++pos; + } + + g_variant_iter_free(iter); + + *dst = buffer; + return result_size; +} + +class sendMessageMethodHandler : MethodHandler +{ +public: + sendMessageMethodHandler(UwbManager* manager): _manager(manager) {}; + ~sendMessageMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-send-message"); + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + GVariant * message, + gint message_length, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + guchar *buffer = nullptr; + if (__ay_to_guchar(message, message_length, &buffer) == 0) { + __dbus_return_err(UWB_ERROR_INVALID_PARAMETER, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + int result = uwb_manager->sendMessage(buffer, message_length); + if (result != 0) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + g_free(buffer); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + uwb_gdbuslib_manager_complete_send_message(gdbus_manager, invocation); + g_free(buffer); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + +class sendMessageToMethodHandler : MethodHandler +{ +public: + sendMessageToMethodHandler(UwbManager* manager): _manager(manager) {}; + ~sendMessageToMethodHandler() + { + + } + + void registerHandler(UwbGdbuslibManager *manager_skeleton) override + { + g_signal_connect( + manager_skeleton, + this->_method_name.c_str(), + G_CALLBACK(__uwb_iface_handler_callback), + gpointer(this)); + } + + UwbManager *getManager() + { + return this->_manager; + } +private: + UwbManager *_manager; + const std::string _method_name = + std::string("handle-send-message-to"); + static gboolean __uwb_iface_handler_callback( + UwbGdbuslibManager *gdbus_manager, + GDBusMethodInvocation *invocation, + guint16 node_id, + GVariant * message, + gint message_length, + gpointer user_data) + { + __UWB_LOG_FUNC_ENTER__; + + UwbManager *uwb_manager = __get_uwb_manager((MethodHandler *)user_data); + if (!uwb_manager) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + guchar *buffer = nullptr; + if (__ay_to_guchar(message, message_length, &buffer) == 0) { + __dbus_return_err(UWB_ERROR_INVALID_PARAMETER, invocation); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + int result = uwb_manager->sendMessageTo(node_id, buffer, message_length); + if (result != 0) { + __dbus_return_err(UWB_ERROR_OPERATION_FAILED, invocation); + g_free(buffer); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } + + uwb_gdbuslib_manager_complete_send_message_to(gdbus_manager, invocation); + g_free(buffer); + __UWB_LOG_FUNC_EXIT__; + return TRUE; + } +}; + +UwbIfaceHandler::UwbIfaceHandler(UwbManager* uwb_manager) +{ + /* create handler objects */ + + _handler_vec.push_back((MethodHandler *)new testMethodHandler(uwb_manager)); + _handler_vec.push_back((MethodHandler *)new resetMethodHandler(uwb_manager)); + _handler_vec.push_back((MethodHandler *)new factoryResetMethodHandler(uwb_manager)); + _handler_vec.push_back((MethodHandler *)new getOwnNodeMethodHandler(uwb_manager)); + _handler_vec.push_back((MethodHandler *)new getNetworkMethodHandler(uwb_manager)); + _handler_vec.push_back((MethodHandler *)new setConfigurationsMethodHandler(uwb_manager)); + _handler_vec.push_back((MethodHandler *)new getConfigurationsMethodHandler(uwb_manager)); + _handler_vec.push_back((MethodHandler *)new setPositionMethodHandler(uwb_manager)); + _handler_vec.push_back((MethodHandler *)new sendMessageMethodHandler(uwb_manager)); + _handler_vec.push_back((MethodHandler *)new sendMessageToMethodHandler(uwb_manager)); +} + +UwbIfaceHandler::~UwbIfaceHandler() +{ + /* destroy handler objects */ + + std::vector::iterator itr = _handler_vec.begin(); + for (; itr != _handler_vec.end(); ++itr) { + MethodHandler *handler = *itr; + delete handler; + } +} + +std::string UwbIfaceHandler::get_dbus_path_str(void) +{ + return _uwb_dbus_path_str; +} + +void UwbIfaceHandler::registerHandler(UwbGdbuslibManager *manager_skeleton) +{ + /* Register for method callbacks as signal callbacks */ + std::vector::iterator itr = _handler_vec.begin(); + for (; itr != _handler_vec.end(); ++itr) { + MethodHandler * handler = *itr; + handler->registerHandler(manager_skeleton); + } +} diff --git a/src/UwbManager.cpp b/src/UwbManager.cpp new file mode 100755 index 0000000..aacdab3 --- /dev/null +++ b/src/UwbManager.cpp @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2020 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 + +#define CONFIGFILE tzplatform_mkpath(TZ_SYS_RO_ETC, "/uwb/uwb-plugin.conf") + +using namespace UwbManagerNamespace; + +int UwbManager::test(void) +{ + int res; + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + res = _range_plugin->test(); + + __UWB_LOG_FUNC_EXIT__; + return res; +} + +int UwbManager::reset(void) +{ + int res; + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + res = _range_plugin->reset(); + + __UWB_LOG_FUNC_EXIT__; + return res; +} + +int UwbManager::factoryReset(void) +{ + int res; + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + res = _range_plugin->factoryReset(); + + __UWB_LOG_FUNC_EXIT__; + return res; +} + +int UwbManager::setPosition(int node_id, int x, int y, int z) +{ + int res; + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + res = _range_plugin->setPosition(node_id, x, y, z); + + __UWB_LOG_FUNC_EXIT__; + return res; +} + +int UwbManager::setDefaultConfigurations() +{ + int res; + int node_id = 0; + GVariant *configurations = NULL; + JsonParser *parser = NULL; + GError *error = NULL; + + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + + parser = json_parser_new(); + + json_parser_load_from_file(parser, CONFIGFILE, &error); + if (error != NULL) { + UWB_LOGD("json_parser_load_from_file failed : %s", error->message); + return -1; + } + + configurations = json_gvariant_deserialize(json_parser_get_root(parser), "a{sv}", &error); + if (error != NULL) { + UWB_LOGD("json_gvariant_deserialize failed : %s", error->message); + return -1; + } + + res = _range_plugin->setConfigurations(node_id, configurations); + if (res != 0) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + + __UWB_LOG_FUNC_EXIT__; + return res; +} + +int UwbManager::setConfigurations(int node_id, GVariant *configurations) +{ + int res; + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + + res = _range_plugin->setConfigurations(node_id, configurations); + if (res != 0) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + + __UWB_LOG_FUNC_EXIT__; + return res; +} + +int UwbManager::getConfigurations(int node_id, GVariant **configurations) +{ + int res; + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + + res = _range_plugin->getConfigurations(node_id, configurations); + if (res != 0) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + + __UWB_LOG_FUNC_EXIT__; + return res; +} + +static void __foreach_node(gpointer data, gpointer user_data) +{ + uwb_hpi_node_s *node = (uwb_hpi_node_s *)data; + UwbNetwork *uwb_network = (UwbNetwork *)user_data; + UwbNode uwb_node = new UwbNode(); + + uwb_node.setDistance(node->distance); + uwb_node.setPanId(node->pan_id); + uwb_node.setNodeId(node->node_id); + uwb_node.setX(node->x); + uwb_node.setY(node->y); + uwb_node.setZ(node->z); + uwb_node.setIsRemote(node->is_remote); + + uwb_network->addNode(&uwb_node); +} + +UwbNetwork *UwbManager::getNetwork(void) +{ + uwb_hpi_network_s *network_info = nullptr; + UwbNetwork *uwb_network_ret; + int res; + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return nullptr; + } + + res = _range_plugin->getNetworkInfo(&network_info); + if (res != 0 || !network_info) { + __UWB_LOG_FUNC_EXIT__; + return nullptr; + } + UWB_LOGD("panid : 0x%x, count : %d", network_info->pan_id, network_info->remote_node_count); + uwb_network_ret = new UwbNetwork(network_info->pan_id); + if (!uwb_network_ret) { + __UWB_LOG_FUNC_EXIT__; + return nullptr; + } + + g_slist_foreach(network_info->remote_node_list, __foreach_node, uwb_network_ret); + + __UWB_LOG_FUNC_EXIT__; + return uwb_network_ret; + +} + + +UwbNode *UwbManager::getOwnNode(void) +{ + uwb_hpi_node_s *own_node = nullptr; + UwbNode *uwb_node_ret; + int res; + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return nullptr; + } + + res = _range_plugin->getOwnNode(&own_node); + if (res != 0 || !own_node) { + __UWB_LOG_FUNC_EXIT__; + return nullptr; + } + + uwb_node_ret = new UwbNode(own_node->distance, own_node->pan_id, own_node->node_id, + own_node->x, own_node->y, own_node->z, own_node->is_remote); + if (!uwb_node_ret) { + __UWB_LOG_FUNC_EXIT__; + return nullptr; + } + + __UWB_LOG_FUNC_EXIT__; + return uwb_node_ret; +} + +int UwbManager::sendMessage(const unsigned char *message, int message_length) +{ + int res = 0; + + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return res; + } + + res = _range_plugin->sendMessage(message, message_length); + if (res != 0) { + __UWB_LOG_FUNC_EXIT__; + return res; + } + + __UWB_LOG_FUNC_EXIT__; + return res; +} + +int UwbManager::sendMessageTo(uint16_t node_id, const unsigned char *message, int message_length) +{ + int res = 0; + + __UWB_LOG_FUNC_ENTER__; + + if (!_range_plugin) { + __UWB_LOG_FUNC_EXIT__; + return res; + } + + res = _range_plugin->sendMessageTo(node_id, message, message_length); + if (res != 0) { + __UWB_LOG_FUNC_EXIT__; + return res; + } + + __UWB_LOG_FUNC_EXIT__; + return res; +} + diff --git a/src/UwbNetwork.cpp b/src/UwbNetwork.cpp new file mode 100755 index 0000000..9df0a07 --- /dev/null +++ b/src/UwbNetwork.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 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 + +using namespace UwbManagerNamespace; + +UwbNetwork::~UwbNetwork() +{ + std::list::iterator it; + + it = _node_list.begin(); + for (; it != _node_list.end(); ++it) { + UwbNode *node = *it; + delete node; + } + + _node_list.clear(); + + return; +} + +void UwbNetwork::setPanId(int pan_id) +{ + _pan_id = pan_id; + + return; +} + +int UwbNetwork::getPanId() +{ + return _pan_id; +} + +int UwbNetwork::addNode(UwbNode *node) +{ + UwbNode *dst; + + if (!node) + return -1; + + dst = new UwbNode(node); + _node_list.push_front(dst); + + return 0; +} + +int UwbNetwork::removeNode(UwbNode *node) +{ + std::list::iterator it; + + if (!node) + return -1; + + it = _node_list.begin(); + for (; it != _node_list.end(); ++it) { + UwbNode *it_node = *it; + if (it_node->getNodeId() == node->getNodeId()) { + _node_list.erase(it); + break; + } + } + + return 0; +} + +std::list *UwbNetwork::getNodeList() +{ + std::list *node_list = new std::list(_node_list); + + return node_list; +} diff --git a/src/UwbNode.cpp b/src/UwbNode.cpp new file mode 100755 index 0000000..a94c203 --- /dev/null +++ b/src/UwbNode.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020 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 + +using namespace UwbManagerNamespace; + +UwbNode::UwbNode(UwbNode *node) +{ + _distance = node->_distance; + _pan_id = node->_pan_id; + _node_id = node->_node_id; + _x = node->_x; + _y = node->_y; + _z = node->_z; +} + +void UwbNode::setDistance(unsigned long long distance) +{ + _distance = distance; + + return; +} + +unsigned long long UwbNode::getDistance() +{ + return _distance; +} + +void UwbNode::setPanId(int id) +{ + _pan_id = id; + + return; +} + +int UwbNode::getPanId() +{ + return _pan_id; +} + +void UwbNode::setNodeId(unsigned long long id) +{ + _node_id = id; + + return; +} + +unsigned long long UwbNode::getNodeId() +{ + return _node_id; +} + +int UwbNode::getX() +{ + return _x; +} + +void UwbNode::setX(int x) +{ + _x = x; + + return; +} + +int UwbNode::getY() +{ + return _y; +} + +void UwbNode::setY(int y) +{ + _y = y; + + return; +} + +int UwbNode::getZ() +{ + return _z; +} + +void UwbNode::setZ(int z) +{ + _z = z; + + return; +} + +bool UwbNode::getIsRemote() +{ + return _is_remote; +} + +void UwbNode::setIsRemote(bool is_remote) +{ + _is_remote = is_remote; + + return; +} diff --git a/src/UwbPluginManager.cpp b/src/UwbPluginManager.cpp new file mode 100644 index 0000000..3aab122 --- /dev/null +++ b/src/UwbPluginManager.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2020 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 + +using namespace UwbManagerNamespace; + +UwbPluginManager::~UwbPluginManager() +{ + int res; + __UWB_LOG_FUNC_ENTER__; + + if (_dl_handle) { + res = dlclose(_dl_handle); + if (res != 0) + UWB_LOGE("dlclose failed, [%d] : %s", errno, dlerror()); // LCOV_EXCL_LINE + + _dl_handle = nullptr; + } + __UWB_LOG_FUNC_EXIT__; +} + +int UwbPluginManager::load(const std::string lib_path_str) +{ + int res; + __UWB_LOG_FUNC_ENTER__; + + if (_dl_handle) { + res = dlclose(_dl_handle); + if (res != 0) + UWB_LOGE("dlclose failed, [%d] : %s", errno, dlerror()); // LCOV_EXCL_LINE + _dl_handle = nullptr; + } + + _dl_handle = dlopen(lib_path_str.c_str(), RTLD_LAZY); + if (_dl_handle == NULL) { + UWB_LOGE("dlopen failed, [%d] : %s", errno, dlerror()); // LCOV_EXCL_LINE + __UWB_LOG_FUNC_EXIT__; + return -1; + } + + __UWB_LOG_FUNC_EXIT__; + return 0; +} + +void UwbPluginManager::unload(void) +{ + int res; + __UWB_LOG_FUNC_ENTER__; + + if (_dl_handle) { + res = dlclose(_dl_handle); + if (res != 0) + UWB_LOGE("dlclose failed, [%d] : %s", errno, dlerror()); // LCOV_EXCL_LINE + _dl_handle = nullptr; + } + __UWB_LOG_FUNC_EXIT__; +} + +void *UwbPluginManager::get_symbol(const std::string symbol_str) +{ + void * ret; + __UWB_LOG_FUNC_ENTER__; + + ret = dlsym(_dl_handle, symbol_str.c_str()); + if (!ret) + UWB_LOGE("dlsym failed, [%d] : %s", errno, dlerror()); // LCOV_EXCL_LINE + + __UWB_LOG_FUNC_EXIT__; + return ret; +} diff --git a/src/UwbRangePlugin.cpp b/src/UwbRangePlugin.cpp new file mode 100755 index 0000000..b682625 --- /dev/null +++ b/src/UwbRangePlugin.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2020 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 + +using namespace UwbManagerNamespace; + +void UwbRangePlugin::messageReceivedCb(uint16_t node_id, unsigned char *message, int message_length) +{ + UWB_LOGI("Call signal emit method in dbus class"); // LCOV_EXCL_LINE + UwbDbusManager::emitMessageReceivedSignal(node_id, message, message_length); +} + +void UwbRangePlugin::positionChangedCb(uint16_t node_id, int x, int y, int z) +{ + UWB_LOGI("Call signal emit method in dbus class"); // LCOV_EXCL_LINE + UwbDbusManager::emitPositionChangedSignal(node_id, x, y, z); +} + +int UwbRangePlugin::init(UwbPluginManager *plugin_manager) +{ + int (*uwb_plugin_load)(uwb_hpi_ops_s *interfaces); + + uwb_plugin_load = + (int (*)(uwb_hpi_ops_s*))plugin_manager->get_symbol("uwb_plugin_load"); + if (uwb_plugin_load == NULL) + return -1; + + if (uwb_plugin_load(&ops) < 0) { + UWB_LOGE("onload failed"); // LCOV_EXCL_LINE + return -1; + } + + event_cbs.message_received_cb = messageReceivedCb; + event_cbs.position_changed_cb = positionChangedCb; + + return uwb_hpi_init(&ops, &event_cbs); +} + +int UwbRangePlugin::deinit(void) +{ + return uwb_hpi_deinit(&ops); +} + +int UwbRangePlugin::test(void) +{ + return uwb_hpi_test(&ops); +} + +int UwbRangePlugin::reset(void) +{ + return uwb_hpi_reset(&ops); +} + +int UwbRangePlugin::factoryReset(void) +{ + return uwb_hpi_factory_reset(&ops); +} + +int UwbRangePlugin::getOwnNode(uwb_hpi_node_s **own_node) +{ + return uwb_hpi_get_own_node(&ops, own_node); +} + +int UwbRangePlugin::getNetworkInfo(uwb_hpi_network_s **network_info) +{ + return uwb_hpi_get_network_info(&ops, network_info); +} + +int UwbRangePlugin::setConfigurations(uint16_t node_id, const GVariant *configurations) +{ + return uwb_hpi_set_configurations(&ops, node_id, configurations); +} + +int UwbRangePlugin::getConfigurations(uint16_t node_id, GVariant **configurations) +{ + return uwb_hpi_get_configurations(&ops, node_id, configurations); +} + +int UwbRangePlugin::setPosition(uint16_t node_id, int x, int y, int z) +{ + return uwb_hpi_set_position(&ops, node_id, x, y, z); +} + +int UwbRangePlugin::sendMessage(const unsigned char *message, int message_length) +{ + return uwb_hpi_send_message(&ops, message, message_length); +} + +int UwbRangePlugin::sendMessageTo(uint16_t node_id, const unsigned char *message, int message_length) +{ + return uwb_hpi_send_message_to(&ops, node_id, message, message_length); +} + diff --git a/src/main.cpp b/src/main.cpp new file mode 100755 index 0000000..97a1b8d --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 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 + +#define DWM1001_PLUGIN_PATH "/usr/lib/uwb-plugin-dwm1001.so" +#define DWM1001_PLUGIN_64BIT_PATH "/usr/lib64/uwb-plugin-dwm1001.so" + +using namespace UwbManagerNamespace; + +GMainLoop *main_loop; + +int main(int argc, char *argv[]) +{ + UwbPluginManager *plugin_manager = new UwbPluginManager(); + UwbRangePlugin *range_plugin = new UwbRangePlugin(); + UwbManager *manager = new UwbManager(nullptr, range_plugin); + UwbIfaceHandler *iface_handler = new UwbIfaceHandler(manager); + UwbDbusManager *dbus_manager = new UwbDbusManager(); + +#if defined(TIZEN_ARCH_64) + plugin_manager->load(DWM1001_PLUGIN_64BIT_PATH); +#else + plugin_manager->load(DWM1001_PLUGIN_PATH); +#endif + range_plugin->init(plugin_manager); + manager->setDefaultConfigurations(); + dbus_manager->init(iface_handler); + + main_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(main_loop); + + dbus_manager->deinit(); + plugin_manager->unload(); + + delete iface_handler; + delete dbus_manager; + delete range_plugin; + delete plugin_manager; + + return 0; +} diff --git a/uwb-manager.manifest b/uwb-manager.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/uwb-manager.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/uwb-plugin-dwm1001.manifest b/uwb-plugin-dwm1001.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/uwb-plugin-dwm1001.manifest @@ -0,0 +1,5 @@ + + + + +