Skip to content

Commit f9640e0

Browse files
Merge pull request #50 from FoxRoboticsUK/feature/service-server-client
Added new service server clientThank you very much. It works. Lets merge it with the melodic branch. We still will need to do some porting work to master and noetic. and client behaviour bases
2 parents 987e479 + dc0cc10 commit f9640e0

22 files changed

+976
-0
lines changed

smacc/include/smacc/client_bases/smacc_service_client.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class SmaccServiceClient : public smacc::ISmaccClient
2323
{
2424
initialized_ = false;
2525
}
26+
SmaccServiceClient(std::string service_name)
27+
{
28+
serviceName_ = service_name;
29+
initialized_ = false;
30+
}
2631

2732
virtual void initialize() override
2833
{
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#pragma once
2+
3+
#include <smacc/smacc_client.h>
4+
#include <smacc/smacc_signal.h>
5+
6+
#include <boost/optional/optional_io.hpp>
7+
8+
#include <std_srvs/Empty.h>
9+
10+
namespace smacc {
11+
namespace client_bases {
12+
template <typename TService>
13+
class SmaccServiceServerClient : public smacc::ISmaccClient
14+
{
15+
using TServiceRequest = typename TService::Request;
16+
using TServiceResponse = typename TService::Response;
17+
18+
public:
19+
boost::optional<std::string> serviceName_;
20+
SmaccServiceServerClient() { initialized_ = false; }
21+
SmaccServiceServerClient(std::string service_name)
22+
{
23+
serviceName_ = service_name;
24+
initialized_ = false;
25+
}
26+
27+
virtual ~SmaccServiceServerClient() { server_.shutdown(); }
28+
29+
smacc::SmaccSignal<bool(TServiceRequest&, std::shared_ptr<TServiceResponse>)>
30+
onServiceRequestReceived_;
31+
32+
template <typename T>
33+
boost::signals2::connection onServiceRequestReceived(
34+
bool (T::*callback)(TServiceRequest&, std::shared_ptr<TServiceResponse>),
35+
T* object) {
36+
return this->getStateMachine()->createSignalConnection(
37+
onServiceRequestReceived_, callback, object);
38+
}
39+
40+
virtual void initialize() override {
41+
if (!initialized_) {
42+
if (!serviceName_) {
43+
ROS_ERROR("service server with no service name set. Skipping.");
44+
} else {
45+
ROS_INFO_STREAM("[" << this->getName()
46+
<< "] Client Service: " << serviceName_);
47+
48+
server_ = nh_.advertiseService(
49+
*serviceName_,
50+
&SmaccServiceServerClient<TService>::serviceCallback, this);
51+
this->initialized_ = true;
52+
}
53+
}
54+
}
55+
56+
protected:
57+
ros::NodeHandle nh_;
58+
59+
private:
60+
bool serviceCallback(TServiceRequest& req, TServiceResponse& res) {
61+
std::shared_ptr<TServiceResponse> response{new TServiceResponse};
62+
auto ret_val = onServiceRequestReceived_(req, response);
63+
if(!ret_val) // Check if response is empty
64+
{
65+
ROS_WARN("No return value receieved from service call. Are you returning a value?");
66+
return false;
67+
}
68+
res = *response;
69+
return *ret_val;
70+
}
71+
ros::ServiceServer server_;
72+
bool initialized_;
73+
};
74+
} // namespace client_bases
75+
} // namespace smacc
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#include <smacc/smacc_client_behavior.h>
3+
4+
namespace smacc {
5+
template <typename TService>
6+
class CbServiceServerCallbackBase : public smacc::SmaccClientBehavior {
7+
public:
8+
virtual void onEntry() override {
9+
this->requiresClient(attachedClient_);
10+
attachedClient_->onServiceRequestReceived(
11+
&CbServiceServerCallbackBase::onServiceRequestReceived, this);
12+
}
13+
14+
virtual bool onServiceRequestReceived(typename TService::Request& req,
15+
std::shared_ptr<typename TService::Response> res) = 0;
16+
17+
protected:
18+
smacc::client_bases::SmaccServiceServerClient<TService>* attachedClient_ =
19+
nullptr;
20+
};
21+
} // namespace smacc
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2+
Changelog for package sm_atomic
3+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+
Forthcoming
6+
-----------
7+
8+
* creating feature smacc_runtime test
9+
* Merge branch 'master' into melodic-devel
10+
* adding xterm dependency to examples
11+
* Final CbTimer Push
12+
* Merge branch 'master' into melodic-devel
13+
* fixed Doxygen Client Namespaces
14+
* refactoring client namespaces names
15+
* Merge branch 'master' into melodic-devel
16+
* Merge branch 'master' of https://github.com/reelrbtx/SMACC
17+
* Update README.md
18+
* sm_atomic diagrams
19+
* Update README.md
20+
* Update README.md
21+
* Update README.md
22+
* Merge branch 'master' of https://github.com/reelrbtx/SMACC
23+
* Improved sm_atomic
24+
* more formatting & commenting
25+
* renaming runtimeConfiguration to runtimeConfigure
26+
* pushing renaming of runtimeConfigure
27+
* more on smacc behaviors
28+
* Changed static_configure to configure_orthogonal
29+
* unpushed code
30+
* Replaced all smacc::transition's with Transition
31+
* Merge branch 'master' of https://github.com/reelrbtx/SMACC
32+
* Update README.md
33+
* Update README.md
34+
* Adding sm images
35+
* Update README.md
36+
* Update README.md
37+
* Merge branch 'master' of https://github.com/reelrbtx/SMACC
38+
* Update README.md
39+
* adding launch file to sm_atomic
40+
* Renaming transition
41+
* sm dance bot and refactoring namings
42+
* namespaces iteration 3, orthogonal recurrent pattern, more tsts on sm_dance_bot_2
43+
* more refactoring and renaming examples and namespaces
44+
* progressing in the API and testing timers and callbacks
45+
* ros timer client behaviors, refactoring sm_atomic and logic unit hierarchy. other improvements on rosout
46+
* Update README.md
47+
* Update README.md
48+
* Update README.md
49+
* Update README.md
50+
* Update README.md
51+
* Update README.md
52+
* Create README.md
53+
* more naming refactoring in move_base_z_client
54+
* renaming move_base client to ClMoveBaseZ (zorro)
55+
* renaming orthogonals
56+
* more on refactoring renaming
57+
* adding object tagging to clients, specifically action clients
58+
* renaming consistently SmAtomic
59+
* testing countdown logic unit more refactoring and analyzing propagating issue
60+
* Contributors: Brett Aldrich, Pablo Iñigo Blasco, Pabo Iñigo Blasco, Unknown, Víctor Ferrer García, [email protected], brettpac, pablo.inigo.blasco, reelrbtx
61+
62+
* creating feature smacc_runtime test
63+
* Merge branch 'master' into melodic-devel
64+
* adding xterm dependency to examples
65+
* Final CbTimer Push
66+
* Merge branch 'master' into melodic-devel
67+
* fixed Doxygen Client Namespaces
68+
* refactoring client namespaces names
69+
* Merge branch 'master' into melodic-devel
70+
* Merge branch 'master' of https://github.com/reelrbtx/SMACC
71+
* Update README.md
72+
* sm_atomic diagrams
73+
* Update README.md
74+
* Update README.md
75+
* Update README.md
76+
* Merge branch 'master' of https://github.com/reelrbtx/SMACC
77+
* Improved sm_atomic
78+
* more formatting & commenting
79+
* renaming runtimeConfiguration to runtimeConfigure
80+
* pushing renaming of runtimeConfigure
81+
* more on smacc behaviors
82+
* Changed static_configure to configure_orthogonal
83+
* unpushed code
84+
* Replaced all smacc::transition's with Transition
85+
* Merge branch 'master' of https://github.com/reelrbtx/SMACC
86+
* Update README.md
87+
* Update README.md
88+
* Adding sm images
89+
* Update README.md
90+
* Update README.md
91+
* Merge branch 'master' of https://github.com/reelrbtx/SMACC
92+
* Update README.md
93+
* adding launch file to sm_atomic
94+
* Renaming transition
95+
* sm dance bot and refactoring namings
96+
* namespaces iteration 3, orthogonal recurrent pattern, more tsts on sm_dance_bot_2
97+
* more refactoring and renaming examples and namespaces
98+
* progressing in the API and testing timers and callbacks
99+
* ros timer client behaviors, refactoring sm_atomic and logic unit hierarchy. other improvements on rosout
100+
* Update README.md
101+
* Update README.md
102+
* Update README.md
103+
* Update README.md
104+
* Update README.md
105+
* Update README.md
106+
* Create README.md
107+
* more naming refactoring in move_base_z_client
108+
* renaming move_base client to ClMoveBaseZ (zorro)
109+
* renaming orthogonals
110+
* more on refactoring renaming
111+
* adding object tagging to clients, specifically action clients
112+
* renaming consistently SmAtomic
113+
* testing countdown logic unit more refactoring and analyzing propagating issue
114+
* Contributors: Brett Aldrich, Pablo Iñigo Blasco, Pabo Iñigo Blasco, Unknown, Víctor Ferrer García, [email protected], brettpac, pablo.inigo.blasco, reelrbtx

0 commit comments

Comments
 (0)