00001 /* Copyright (C) 2015-2017 Michele Colledanchise - All Rights Reserved 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 00004 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 00005 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 00006 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 00007 * 00008 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00009 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00010 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00011 */ 00012 00013 #include <tree_node.h> 00014 #include <string> 00015 00016 00017 BT::TreeNode::TreeNode(std::string name) : tick_engine(0) 00018 { 00019 // Initialization 00020 name_ = name; 00021 has_parent_ = false; 00022 is_state_updated_ = false; 00023 set_status(BT::IDLE); 00024 } 00025 00026 BT::TreeNode::~TreeNode() {} 00027 00028 void BT::TreeNode::set_status(ReturnStatus new_status) 00029 { 00030 if (new_status != BT::IDLE) 00031 { 00032 set_color_status(new_status); 00033 } 00034 00035 // Lock acquistion 00036 std::unique_lock<std::mutex> UniqueLock(state_mutex_); 00037 00038 // state_ update 00039 status_ = new_status; 00040 } 00041 00042 BT::ReturnStatus BT::TreeNode::get_status() 00043 { 00044 // Lock acquistion 00045 DEBUG_STDOUT(get_name() << " is setting its status to " << status_); 00046 00047 std::lock_guard<std::mutex> LockGuard(state_mutex_); 00048 00049 return status_; 00050 } 00051 00052 BT::ReturnStatus BT::TreeNode::get_color_status() 00053 { 00054 // Lock acquistion 00055 std::lock_guard<std::mutex> LockGuard(color_state_mutex_); 00056 00057 return color_status_; 00058 } 00059 00060 void BT::TreeNode::set_color_status(ReturnStatus new_color_status) 00061 { 00062 // Lock acquistion 00063 std::lock_guard<std::mutex> LockGuard(color_state_mutex_); 00064 // state_ update 00065 color_status_ = new_color_status; 00066 } 00067 00068 float BT::TreeNode::get_x_pose() 00069 { 00070 return x_pose_; 00071 } 00072 00073 void BT::TreeNode::set_x_pose(float x_pose) 00074 { 00075 x_pose_ = x_pose; 00076 } 00077 00078 00079 float BT::TreeNode::get_x_shift() 00080 { 00081 return x_shift_; 00082 } 00083 00084 void BT::TreeNode::set_x_shift(float x_shift) 00085 { 00086 x_shift_ = x_shift; 00087 } 00088 00089 void BT::TreeNode::set_name(std::string new_name) 00090 { 00091 name_ = new_name; 00092 } 00093 00094 std::string BT::TreeNode::get_name() 00095 { 00096 return name_; 00097 } 00098 00099 00100 BT::NodeType BT::TreeNode::get_type() 00101 { 00102 return type_; 00103 } 00104 00105 bool BT::TreeNode::has_parent() 00106 { 00107 return has_parent_; 00108 } 00109 00110 void BT::TreeNode::set_has_parent(bool value) 00111 { 00112 has_parent_ = value; 00113 }