Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit 5440407

Browse files
committed
Rearanged Source Code to final a more layout that matches the current design
1 parent 6dc2754 commit 5440407

File tree

28 files changed

+420
-11
lines changed

28 files changed

+420
-11
lines changed

cmake/cmake-common_logic.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function(add_source_files var)
100100
source_group("${_l_SOURCE_GROUP}" FILES ${__new_entries})
101101
endif()
102102
if(_l_DEBUG)
103-
#message(STATUS "CHILDLIST( result ${_l_LOCATION})")
103+
message(STATUS "CHILDLIST( result ${_l_LOCATION})")
104104
endif()
105105
CHILDLIST( result ${_l_LOCATION})
106106

framework.sublime-project

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"folders":
3+
[
4+
{
5+
"path": "projects"
6+
}
7+
]
8+
}

projects/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ endif()
3535
###############################################################################
3636
add_subdirectory(libpfc_net)
3737
add_subdirectory(registry_server)
38-
add_subdirectory(simple_service)
38+
add_subdirectory(service_pubsub)
39+
add_subdirectory(service_reqrep)
40+
add_subdirectory(service_survey)
3941
add_subdirectory(unit_test)
4042
###############################################################################
4143
# Step 3: Global Doxygen configuration

projects/libpfc_net/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ message(STATUS "Configuring ${PROJECT_NAME}")
3838
#Scenario Driver
3939

4040
add_source_files(HDRS LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/include/sustain
41-
REGEX "*.h" "*.hpp" SOURCE_GROUP "Headers\\Public" DEBUG)
41+
REGEX "*.h" "*.hpp" SOURCE_GROUP "Headers\\Public")
4242
add_source_files(HDRS LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/cpp
4343
REGEX "*.h" "*.hpp" SOURCE_GROUP "Headers\\Private")
4444
add_source_files(SRCS LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/cpp
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#include <sustain/framework/Service.h>
2+
3+
#include <sustain/framework/Protocol.h>
4+
#include <sustain/framework/net/Multicast_Receiver.h>
5+
#include <sustain/framework/net/Multicast_Sender.h>
6+
#include <sustain/framework/util/Error.h>
7+
8+
namespace pfc {
9+
struct Service::Implementation {
10+
Implementation(const std::string& bind_address, const std::string& multicast_address);
11+
~Implementation();
12+
Implementation(const Implementation&) = delete;
13+
Implementation(Implementation&&) = default;
14+
Implementation& operator=(const Implementation&) = delete;
15+
Implementation& operator=(Implementation&&) = delete;
16+
17+
void announce_service_creation(std::ostream&);
18+
void handle_service_broadcasr_message(std::istream&);
19+
20+
std::function<void(pfc_service_announcment&)> service_broadcast_callback;
21+
22+
pfc_service_announcment service_config;
23+
Config::protocol style;
24+
25+
Multicast_Sender multicast_announcment;
26+
Multicast_Receiver multicast_broadcast_listiner;
27+
pfc::Error server_status;
28+
};
29+
//-----------------------------------------------------------------------------
30+
Service::Implementation::Implementation(const std::string& bind_address, const std::string& multicast_address)
31+
: multicast_announcment(multicast_address, g_pfc_registry_reg_port)
32+
, multicast_broadcast_listiner(bind_address, multicast_address, g_pfc_registry_announce_port)
33+
{
34+
}
35+
//-----------------------------------------------------------------------------
36+
Service::Implementation::~Implementation()
37+
{
38+
multicast_announcment.stop();
39+
multicast_broadcast_listiner.stop();
40+
41+
multicast_announcment.join();
42+
multicast_broadcast_listiner.join();
43+
}
44+
//-----------------------------------------------------------------------------
45+
void Service::Implementation::announce_service_creation(std::ostream& os)
46+
{
47+
service_config.serialize(os);
48+
std::cout << "Sending: " << service_config << "\n";
49+
}
50+
//-----------------------------------------------------------------------------
51+
void Service::Implementation::handle_service_broadcasr_message(std::istream& is)
52+
{
53+
pfc_service_announcment announcment;
54+
if (announcment.deserialize(is).is_ok()) {
55+
std::cout << "Registry Sent:" << announcment << "\n";
56+
if(service_broadcast_callback)
57+
{ service_broadcast_callback(announcment); }
58+
}
59+
}
60+
//-----------------------------------------------------------------------------
61+
Service::Service(const Config config, const std::string& multicast_bind_address, const std::string& registry_multicast_address)
62+
: _impl(std::make_unique<Implementation>(std::move(multicast_bind_address), std::move(registry_multicast_address)))
63+
{
64+
pfc_service_announcment service;
65+
service._name = config.name;
66+
service._protacol = (config.style == Config::pub_sub) ? pfc_protocol::pub_sub : pfc_protocol::req_req;
67+
service._address = config.address;
68+
service._brief = config.brief;
69+
service._port = config.port;
70+
71+
_impl->style = config.style;
72+
_impl->service_config = service;
73+
}
74+
//-----------------------------------------------------------------------------
75+
Service::Service(Service&& obj)
76+
: _impl(std::move(obj._impl))
77+
{
78+
}
79+
//-----------------------------------------------------------------------------
80+
Service::~Service()
81+
{
82+
stop();
83+
join();
84+
}
85+
//-----------------------------------------------------------------------------
86+
void Service::start()
87+
{
88+
using namespace std::placeholders;
89+
auto& impl = *_impl;
90+
_impl->multicast_announcment.async_send(std::bind(&Implementation::announce_service_creation, _impl.get(), _1));
91+
_impl->multicast_broadcast_listiner.async_receive(std::bind(&Implementation::handle_service_broadcasr_message, _impl.get(), _1));
92+
}
93+
//-----------------------------------------------------------------------------
94+
void Service::stop()
95+
{
96+
_impl->multicast_announcment.stop();
97+
_impl->multicast_broadcast_listiner.stop();
98+
}
99+
//-----------------------------------------------------------------------------
100+
void Service::join()
101+
{
102+
_impl->multicast_announcment.join();
103+
_impl->multicast_broadcast_listiner.join();
104+
}
105+
//-----------------------------------------------------------------------------
106+
void Service::set_service_announcment_callback(std::function<void(pfc_service_announcment&)> func)
107+
{
108+
_impl->service_broadcast_callback = func;
109+
}
110+
//-----------------------------------------------------------------------------
111+
auto Service::name() const -> std::string
112+
{
113+
return _impl->service_config._name;
114+
}
115+
//-----------------------------------------------------------------------------
116+
auto Service::address() const -> std::string
117+
{
118+
return _impl->service_config._address;
119+
}
120+
//-----------------------------------------------------------------------------
121+
auto Service::brief() const -> std::string
122+
{
123+
return _impl->service_config._brief;
124+
}
125+
//-----------------------------------------------------------------------------
126+
auto Service::port() const -> uint16_t
127+
{
128+
return _impl->service_config._port;
129+
}
130+
//-----------------------------------------------------------------------------
131+
auto Service::style() const -> Config::protocol
132+
{
133+
return _impl->style;
134+
}
135+
//-----------------------------------------------------------------------------
136+
bool Service::valid() const
137+
{
138+
return _impl->server_status.is_ok();
139+
}
140+
//-----------------------------------------------------------------------------
141+
Error Service::error() const
142+
{
143+
return _impl->server_status;
144+
}
145+
//-----------------------------------------------------------------------------
146+
Service& Service::operator=(Service&& obj)
147+
{
148+
_impl = std::move(obj._impl);
149+
return *this;
150+
}
151+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)