From: Yu Date: Fri, 4 Sep 2020 00:42:47 +0000 (+0900) Subject: Use initializer X-Git-Tag: submit/tizen/20200904.033548^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4913defef6bc99e5f29a073a5d525ca359207474;p=platform%2Fcore%2Fconnectivity%2Fuwb-manager.git Use initializer Change-Id: I5a2fbb5f82d57128f9fc55fdd8ec639e253f93b7 Signed-off-by: Yu jiung --- diff --git a/include/Node.h b/include/Node.h index 8baa2fd..000c92f 100644 --- a/include/Node.h +++ b/include/Node.h @@ -39,29 +39,17 @@ public: _is_remote(false), _is_calculated(false), _tech(TECH_UNKNOWN), _last_update(std::chrono::steady_clock::now()) {}; - Node(unsigned long long distance, int pan_id, unsigned long long node_id, - int x, int y, int z, bool is_remote, bool is_calculated, int tech) : - _distance(distance), _pan_id(pan_id), _node_id(node_id), - _x(x), _y(y), _z(z), _is_remote(is_remote), _is_calculated(is_calculated), - _tech(tech), _last_update(std::chrono::steady_clock::now()) {}; - Node(uwb_hpi_node_s *node) : _distance(node->distance), _pan_id(node->pan_id), _node_id(node->node_id), _x(node->x), _y(node->y), _z(node->z), _is_remote(node->is_remote), _is_calculated(false), _tech(TECH_UWB), _last_update(std::chrono::steady_clock::now()){}; - Node(const Node *node) { - _distance = node->_distance; - _pan_id = node->_pan_id; - _node_id = node->_node_id; - _x = node->_x; - _y = node->_y; - _z = node->_z; - _is_remote = node->_is_remote; - _is_calculated = node->_is_calculated; - _tech = node->_tech; - _last_update = node->_last_update; - } + + Node(Node *node) : + _distance(node->_distance), _pan_id(node->_pan_id), _node_id(node->_node_id), + _x(node->_x), _y(node->_y), _z(node->_z), _is_remote(node->_is_remote), + _is_calculated(node->_is_calculated), _tech(node->_tech), + _last_update(node->_last_update){}; //~Node(){UWB_LOGI("%llu removed", _node_id);} Node(const Node &node) = default; diff --git a/packaging/uwb-manager.spec b/packaging/uwb-manager.spec index fd697d7..9664937 100644 --- a/packaging/uwb-manager.spec +++ b/packaging/uwb-manager.spec @@ -1,6 +1,6 @@ Name: uwb-manager Summary: This is the daemon managing UWB related functionalities -Version: 0.0.3 +Version: 0.0.4 Release: 1 Group: Network & Connectivity/Wireless License: Apache-2.0 diff --git a/src/LocationManager.cpp b/src/LocationManager.cpp index e9f98ab..5d51634 100644 --- a/src/LocationManager.cpp +++ b/src/LocationManager.cpp @@ -344,7 +344,7 @@ void LocationManager::updateUwbNodes(void) p_node->setLastUpdate(std::chrono::steady_clock::now()); this->_node_map[p_node->getNodeId()] = - std::unique_ptr((Node *)new Node(p_node)); + std::unique_ptr((Node *)new Node{p_node}); if (added) { if (this->_node_added_cb) diff --git a/src/UwbDbusIfaceAdapter.cpp b/src/UwbDbusIfaceAdapter.cpp index 984afbb..09b09e8 100644 --- a/src/UwbDbusIfaceAdapter.cpp +++ b/src/UwbDbusIfaceAdapter.cpp @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include @@ -499,36 +500,27 @@ static gboolean __handle_send_message_to( return TRUE; } -typedef gboolean (*method_handler)( - UwbGdbuslibManager *gdbus_manager, - GDBusMethodInvocation *invocation, - gpointer user_data); +static std::pair handlers[] = { + std::make_pair(std::string{"handle-test"}, (void *)__handle_test), + std::make_pair(std::string{"handle-reset"}, (void *)__handle_reset), + std::make_pair(std::string{"handle-factory-reset"}, (void *)__handle_factory_reset), -static struct { - const char *method_name; - //trick - void * handler; -} handlers[] = { - {"handle-test", (void *)__handle_test}, - {"handle-reset", (void *)__handle_reset}, - {"handle-factory-reset", (void *)__handle_factory_reset}, + std::make_pair(std::string{"handle-enable-network"}, (void *)__handle_enable_network), + std::make_pair(std::string{"handle-disable-network"}, (void *)__handle_disable_network), - {"handle-enable-network", (void *)__handle_enable_network}, - {"handle-disable-network", (void *)__handle_disable_network}, + std::make_pair(std::string{"handle-start-location-engine"}, (void *)__handle_start_location_engine), + std::make_pair(std::string{"handle-stop-location-engine"}, (void *)__handle_stop_location_engine), - {"handle-start-location-engine", (void *)__handle_start_location_engine}, - {"handle-stop-location-engine", (void *)__handle_stop_location_engine}, + std::make_pair(std::string{"handle-get-own-node"}, (void *)__handle_get_own_node), + std::make_pair(std::string{"handle-get-network-info"}, (void *)__handle_get_network_info), - {"handle-get-own-node", (void *)__handle_get_own_node}, - {"handle-get-network-info", (void *)__handle_get_network_info}, + std::make_pair(std::string{"handle-set-configurations"}, (void *)__handle_set_configurations), + std::make_pair(std::string{"handle-get-configurations"}, (void *)__handle_get_configurations), - {"handle-set-configurations", (void *)__handle_set_configurations}, - {"handle-get-configurations", (void *)__handle_get_configurations}, + std::make_pair(std::string{"handle-set-position"}, (void *)__handle_set_position), - {"handle-set-position", (void *)__handle_set_position}, - - {"handle-send-message", (void *)__handle_send_message}, - {"handle-send-message-to", (void *)__handle_send_message_to} + std::make_pair(std::string{"handle-send-message"}, (void *)__handle_send_message), + std::make_pair(std::string{"handle-send-message-to"}, (void *)__handle_send_message_to) }; void UwbDbusIfaceAdapter::init(GDBusConnection *connection, @@ -540,8 +532,8 @@ void UwbDbusIfaceAdapter::init(GDBusConnection *connection, for (const auto &handler : handlers) g_signal_connect( manager_skeleton, - handler.method_name, - G_CALLBACK(handler.handler), + handler.first.c_str(), + G_CALLBACK(handler.second), gpointer(this)); /* Set connection to 'manager' */ diff --git a/src/UwbPosition.cpp b/src/UwbPosition.cpp index 443aeda..e2b97b6 100644 --- a/src/UwbPosition.cpp +++ b/src/UwbPosition.cpp @@ -33,7 +33,7 @@ int UwbPosition::updateUwbOwnNode() if (res != 0 || !own_node) return -1; - this->setOwnNode(Node(own_node)); + this->setOwnNode(Node{own_node}); free(own_node); return 0; diff --git a/tests/uwb-manager-gtest.cpp b/tests/uwb-manager-gtest.cpp index e36938e..9498b1b 100644 --- a/tests/uwb-manager-gtest.cpp +++ b/tests/uwb-manager-gtest.cpp @@ -733,8 +733,8 @@ TEST_F(UwbMqttMessageTest, create_location_uwb_mqtt_message_Positive) int test_x = 0x98ad; int test_y = 0x8234; int test_z = 0x2389; - UwbManagerNamespace::Node uwb_node(test_pan_id, test_node_id, - test_x, test_y, test_z); + UwbManagerNamespace::Node uwb_node{test_pan_id, test_node_id, + test_x, test_y, test_z}; UwbManagerNamespace::UwbMqttMessage mqtt_msg(uwb_node); ASSERT_EQ(true, (std::string("/TIZEN/UWB/BROADCAST/") + std::to_string(test_node_id)) == mqtt_msg.getTopic());