Skip to content

Commit

Permalink
feat: refractor akushon
Browse files Browse the repository at this point in the history
  • Loading branch information
marfanr committed Oct 29, 2023
1 parent 98b906c commit 959a557
Show file tree
Hide file tree
Showing 19 changed files with 868 additions and 407 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ add_library(${PROJECT_NAME} SHARED
"src/${PROJECT_NAME}/config/node/config_node.cpp"
"src/${PROJECT_NAME}/config/utils/config.cpp"
"src/${PROJECT_NAME}/config/grpc/config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_base.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_get_config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_save_config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_publish_set_joints.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_publish_set_torques.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_subscribe_current_joints.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_run_action.cpp"
"src/${PROJECT_NAME}/node/akushon_node.cpp"
"${akushon_proto_srcs}"
"${akushon_proto_hdrs}"
Expand Down
61 changes: 61 additions & 0 deletions include/akushon/config/grpc/call_data.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2023 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, 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:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// 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, 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.

#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_
#define AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_

#include "akushon.grpc.pb.h"
#include "akushon.pb.h"
#include "grpc/support/log.h"
#include "grpcpp/grpcpp.h"
#include "akushon/config/grpc/call_data_base.hpp"

namespace akushon
{
template <class ConfigRequest, class ConfigReply>
class CallData : CallDataBase
{
public:
CallData(
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string path);

virtual void Proceed() override;

protected:
virtual void AddNextToCompletionQueue() = 0;

enum CallStatus { CREATE, PROCESS, FINISH };

CallStatus status_; // The current serving state.

akushon_interfaces::proto::Config::AsyncService * service_;

const std::string path_;

grpc::ServerCompletionQueue * cq_;
grpc::ServerContext ctx_;
ConfigRequest request_;
ConfigReply reply_;
grpc::ServerAsyncResponseWriter<ConfigReply> responder_;
};
} // namespace akushon

#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_
38 changes: 38 additions & 0 deletions include/akushon/config/grpc/call_data_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2023 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, 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:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// 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, 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.

#ifndef __AKUSHON__CONFIG__GRPC__CALL_DATA_BASE_HPP__
#define __AKUSHON__CONFIG__GRPC__CALL_DATA_BASE_HPP__
namespace akushon
{
class CallDataBase
{
public:
CallDataBase();

virtual void Proceed() = 0;

protected:
virtual void WaitForRequest() = 0;
virtual void HandleRequest() = 0;
};
} // namespace akushon

#endif // __AKUSHON__CONFIG__GRPC__CALL_DATA_BASE_HPP__
43 changes: 43 additions & 0 deletions include/akushon/config/grpc/call_data_get_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2023 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, 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:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// 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, 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.

#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_GET_CONFIG_HPP_
#define AKUSHON__CONFIG__GRPC__CALL_DATA_GET_CONFIG_HPP_

#include "akushon/config/grpc/call_data.hpp"

namespace akushon
{
class CallDataGetConfig
: CallData<akushon_interfaces::proto::Empty, akushon_interfaces::proto::ConfigActions>
{
public:
CallDataGetConfig(
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string path);

protected:
virtual void AddNextToCompletionQueue() override;
virtual void WaitForRequest() override;
virtual void HandleRequest() override;
};
} // namespace akushon

#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_GET_CONFIG_HPP_
47 changes: 47 additions & 0 deletions include/akushon/config/grpc/call_data_publish_set_joints.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2023 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, 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:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// 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, 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.

#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_JOINTS_HPP_
#define AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_JOINTS_HPP_

#include "akushon/config/grpc/call_data.hpp"
#include "tachimawari_interfaces/msg/set_joints.hpp"
#include "rclcpp/rclcpp.hpp"

namespace akushon
{
class CallDataPublishSetJoints
: CallData<akushon_interfaces::proto::SetJointsData, akushon_interfaces::proto::Empty>
{
public:
CallDataPublishSetJoints(
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string path, rclcpp::Node::SharedPtr node);

protected:
virtual void AddNextToCompletionQueue() override;
virtual void WaitForRequest() override;
virtual void HandleRequest() override;
rclcpp::Node::SharedPtr node_;
rclcpp::Publisher<tachimawari_interfaces::msg::SetJoints>::SharedPtr set_joints_publisher_;
};
} // namespace akushon

#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_JOINTS_HPP_
47 changes: 47 additions & 0 deletions include/akushon/config/grpc/call_data_publish_set_torques.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2023 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, 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:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// 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, 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.

#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_TORQUES_HPP_
#define AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_TORQUES_HPP_

#include "akushon/config/grpc/call_data.hpp"
#include "tachimawari_interfaces/msg/set_torques.hpp"
#include "rclcpp/rclcpp.hpp"

namespace akushon
{
class CallDataPublishSetTorques
: CallData<akushon_interfaces::proto::SetTorquesData, akushon_interfaces::proto::Empty>
{
public:
CallDataPublishSetTorques(
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string path, rclcpp::Node::SharedPtr node);

protected:
virtual void AddNextToCompletionQueue() override;
virtual void WaitForRequest() override;
virtual void HandleRequest() override;
rclcpp::Node::SharedPtr node_;
rclcpp::Publisher<tachimawari_interfaces::msg::SetTorques>::SharedPtr set_torque_publisher_;
};
} // namespace akushon

#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_TORQUES_HPP_
47 changes: 47 additions & 0 deletions include/akushon/config/grpc/call_data_run_action.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2023 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, 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:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// 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, 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.

#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_RUN_ACTION_HPP_
#define AKUSHON__CONFIG__GRPC__CALL_DATA_RUN_ACTION_HPP_

#include "akushon/config/grpc/call_data.hpp"
#include "akushon_interfaces/msg/run_action.hpp"
#include "rclcpp/rclcpp.hpp"

namespace akushon
{
class CallDataRunAction
: CallData<akushon_interfaces::proto::ConfigRunAction, akushon_interfaces::proto::Empty>
{
public:
CallDataRunAction(
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string path, rclcpp::Node::SharedPtr node);

protected:
virtual void AddNextToCompletionQueue() override;
virtual void WaitForRequest() override;
virtual void HandleRequest() override;
rclcpp::Node::SharedPtr node_;
rclcpp::Publisher<akushon_interfaces::msg::RunAction>::SharedPtr run_action_publisher_;
};
} // namespace akushon

#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_RUN_ACTION_HPP_
43 changes: 43 additions & 0 deletions include/akushon/config/grpc/call_data_save_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2023 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, 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:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// 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, 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.

#ifndef AKUSHON__CONFIG__GRPC__SAVE_CONFIG_HPP_
#define AKUSHON__CONFIG__GRPC__SAVE_CONFIG_HPP_

#include "akushon/config/grpc/call_data.hpp"

namespace akushon
{
class CallDataSaveConfig
: CallData<akushon_interfaces::proto::ConfigActions, akushon_interfaces::proto::Empty>
{
public:
CallDataSaveConfig(
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string path);

protected:
virtual void AddNextToCompletionQueue() override;
virtual void WaitForRequest() override;
virtual void HandleRequest() override;
};
} // namespace akushon

#endif // AKUSHON__CONFIG__GRPC__SAVE_CONFIG_HPP_
Loading

0 comments on commit 959a557

Please sign in to comment.