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

Commit 2f54068

Browse files
committed
Revision 1.0 Basic Registry Working Implementing Req/Rep Impl Tommorow
1 parent 6b4b7ee commit 2f54068

31 files changed

+1188
-483
lines changed

projects/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ endif()
3434
# this list
3535
###############################################################################
3636
add_subdirectory(libpfc_net)
37-
add_subdirectory(registry_client)
38-
add_subdirectory(service_example)
37+
add_subdirectory(registry_server)
38+
add_subdirectory(simple_service)
3939
add_subdirectory(unit_test)
4040
###############################################################################
4141
# Step 3: Global Doxygen configuration

projects/libpfc_net/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ set(${PREFIX}_SOURCES ${SRCS} ${GEN_SRCS})
5252
###############################################################################
5353
if(WIN32)
5454
list(APPEND ${PREFIX}_CPPFLAGS_EXPORT )
55-
list(APPEND ${PREFIX}_CPPFLAGS "-D_SCL_SECURE_NO_WARNINGS" "-D_CRT_SECURE_NO_WARNINGS" $ENV{PARALLEL_COMPILE} )
55+
list(APPEND ${PREFIX}_CPPFLAGS "-D_SCL_SECURE_NO_WARNINGS" "-D_CRT_SECURE_NO_WARNINGS" $ENV{PARALLEL_COMPILE} )
5656
elseif(CMAKE_COMPILER_IS_GNUCXX)
5757
list(APPEND ${PREFIX}_CPPFLAGS_EXPORT )
5858
list(APPEND ${PREFIX}_CPPFLAGS ${CodeSynthesis_CPPFLAGS})

projects/libpfc_net/cpp/Protocol.cpp

Lines changed: 26 additions & 289 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,60 @@
55

66
namespace pfc {
77

8-
pfc_service_registry_request::~pfc_service_registry_request()
8+
std::ostream& operator<<(std::ostream& os, const pfc_protocol& rhs)
9+
{
10+
os << ((rhs == pub_sub) ? "pub_sub" : "req_rep");
11+
return os;
12+
}
13+
//-----------------------------------------------------------------------------
14+
pfc_service_announcment::~pfc_service_announcment()
915
{
1016
_name.resize(0);
1117
_address.resize(0);
1218
_brief.resize(0);
1319
};
1420
//-----------------------------------------------------------------------------
15-
size_t pfc_service_registry_request::Length() const
21+
size_t pfc_service_announcment::Length() const
1622
{
1723
size_t length = size_of_pfc_type<
18-
decltype(_message_type)
19-
//, decltype(_port)
20-
//, decltype(_protacol)
21-
//, decltype(_name)
22-
//, decltype(_address)
23-
//, decltype(_brief)
24-
>(_message_type); //, _port, _protacol, _name, _address, _brief);
24+
decltype(_message_type), decltype(_port), decltype(_protacol), decltype(_name), decltype(_address), decltype(_brief)>(_message_type, _port, _protacol, _name, _address, _brief);
2525
return length;
2626
}
2727
//-----------------------------------------------------------------------------
28-
pfc_uint pfc_service_registry_request::Type() const
28+
pfc_uint pfc_service_announcment::Type() const
2929
{
3030
return _message_type;
3131
}
3232
//-----------------------------------------------------------------------------
33-
Error pfc_service_registry_request::serialize(std::ostream& is) const
33+
Error pfc_service_announcment::serialize(std::ostream& os) const
3434
{
3535

3636
return serialize_pfc_type<
37-
decltype(_message_type), decltype(_port), decltype(_protacol), decltype(_name), decltype(_address), decltype(_brief)>(is, _message_type, _port, _protacol, _name, _address, _brief);
37+
decltype(_message_type), decltype(_port), decltype(_protacol), decltype(_name), decltype(_address), decltype(_brief)>(os, _message_type, _port, _protacol, _name, _address, _brief);
3838
}
3939
//-----------------------------------------------------------------------------
40-
Error pfc_service_registry_request::deserialize(std::istream& os)
40+
Error pfc_service_announcment::deserialize(std::istream& is)
4141
{
4242
return deserialize_pfc_type<
43-
decltype(_message_type), decltype(_port), decltype(_protacol), decltype(_name), decltype(_address), decltype(_brief)>(os, _message_type, _port, _protacol, _name, _address, _brief);
43+
decltype(_message_type), decltype(_port), decltype(_protacol), decltype(_name), decltype(_address), decltype(_brief)>(is, _message_type, _port, _protacol, _name, _address, _brief);
44+
}
45+
std::ostream& operator<<(std::ostream& os, const pfc_service_announcment& msg)
46+
{
47+
os << "pfc_service_announcment("
48+
<< "name=" << msg._name << ","
49+
<< " address=" << msg._protacol << "://" << msg._address << ":" << msg._port << ","
50+
<< " brief=" << msg._brief
51+
<< ")";
52+
return os;
4453
}
45-
//-----------------------------------------------------------------------------
46-
size_t pfc_service_registry_response::Length() const { return sizeof(_message_type); }
47-
//-----------------------------------------------------------------------------
48-
pfc_uint pfc_service_registry_response::Type() const { return _message_type; }
49-
//-----------------------------------------------------------------------------
50-
Error pfc_service_registry_response::serialize(std::ostream& result) const { return Error(); }
51-
//-----------------------------------------------------------------------------
52-
Error pfc_service_registry_response::deserialize(std::istream& data) { return Error(); }
5354
//-----------------------------------------------------------------------------
5455
//!
5556
//! comparison of mesages
5657
//!
5758
//-----------------------------------------------------------------------
58-
bool operator==(const pfc_service_registry_request& lhs, const pfc_service_registry_request& rhs)
59+
bool operator==(const pfc_service_announcment& lhs, const pfc_service_announcment& rhs)
5960
{
61+
6062
return lhs._message_type == rhs._message_type
6163
&& lhs._protacol == rhs._protacol
6264
&& lhs._port == rhs._port
@@ -65,273 +67,8 @@ bool operator==(const pfc_service_registry_request& lhs, const pfc_service_regis
6567
&& lhs._brief == rhs._brief;
6668
}
6769
//-----------------------------------------------------------------------
68-
bool operator!=(const pfc_service_registry_request& lhs, const pfc_service_registry_request& rhs)
70+
bool operator!=(const pfc_service_announcment& lhs, const pfc_service_announcment& rhs)
6971
{
7072
return !(lhs == rhs);
7173
}
72-
//-----------------------------------------------------------------------
73-
bool operator==(const pfc_service_registry_response& lhs, const pfc_service_registry_response& rhs)
74-
{
75-
return lhs._message_type == rhs._message_type;
76-
}
77-
//-----------------------------------------------------------------------
78-
bool operator!=(const pfc_service_registry_response& lhs, const pfc_service_registry_response& rhs)
79-
{
80-
return !(lhs == rhs);
81-
}
82-
//-----------------------------------------------------------------------------
83-
//!
84-
//! size_of_pfc_types
85-
//!
86-
inline size_t size_of_pfc_type(const pfc_byte& result)
87-
{
88-
return sizeof(pfc_byte);
89-
}
90-
//-----------------------------------------------------------------------------
91-
inline size_t size_of_pfc_type(const pfc_char& result)
92-
{
93-
return sizeof(pfc_char);
94-
}
95-
//-----------------------------------------------------------------------------
96-
inline size_t size_of_pfc_type(const pfc_uint& result)
97-
{
98-
return sizeof(pfc_uint);
99-
}
100-
//-----------------------------------------------------------------------------
101-
inline size_t size_of_pfc_type(const pfc_int& result)
102-
{
103-
return sizeof(pfc_int);
104-
}
105-
//-----------------------------------------------------------------------------
106-
inline size_t size_of_pfc_type(const pfc_float& result)
107-
{
108-
return sizeof(pfc_float);
109-
}
110-
//-----------------------------------------------------------------------------
111-
inline size_t size_of_pfc_type(const pfc_double& result)
112-
{
113-
return sizeof(pfc_double);
114-
}
115-
//-----------------------------------------------------------------------------
116-
inline size_t size_of_pfc_type(const pfc_string& result)
117-
{
118-
return result.size();
119-
}
120-
//-------------------------------------------------------------------------------
121-
//!
122-
//! Serilization of pfc_types
123-
//!
124-
Error serialize_pfc_type(std::ostream& os, const pfc_byte& data)
125-
{
126-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
127-
if (os.good()) {
128-
return Error();
129-
} else {
130-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
131-
}
132-
}
133-
//-------------------------------------------------------------------------------
134-
Error serialize_pfc_type(std::ostream& os, const pfc_char& data)
135-
{
136-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
137-
if (os.good()) {
138-
return Error();
139-
} else {
140-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
141-
}
142-
}
143-
//-------------------------------------------------------------------------------
144-
Error serialize_pfc_type(std::ostream& os, const pfc_ushort& data)
145-
{
146-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
147-
if (os.good()) {
148-
return Error();
149-
} else {
150-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
151-
}
152-
}
153-
//-------------------------------------------------------------------------------
154-
Error serialize_pfc_type(std::ostream& os, const pfc_short& data)
155-
{
156-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
157-
if (os.good()) {
158-
return Error();
159-
} else {
160-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
161-
}
162-
}
163-
//-------------------------------------------------------------------------------
164-
Error serialize_pfc_type(std::ostream& os, const pfc_uint& data)
165-
{
166-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
167-
if (os.good()) {
168-
return Error();
169-
} else {
170-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
171-
}
172-
}
173-
//-------------------------------------------------------------------------------
174-
Error serialize_pfc_type(std::ostream& os, const pfc_int& data)
175-
{
176-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
177-
if (os.good()) {
178-
return Error();
179-
} else {
180-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
181-
}
182-
}
183-
//-------------------------------------------------------------------------------
184-
Error serialize_pfc_type(std::ostream& os, const pfc_float& data)
185-
{
186-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
187-
if (os.good()) {
188-
return Error();
189-
} else {
190-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
191-
}
192-
}
193-
//-------------------------------------------------------------------------------
194-
Error serialize_pfc_type(std::ostream& os, const pfc_double& data)
195-
{
196-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
197-
if (os.good()) {
198-
return Error();
199-
} else {
200-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
201-
}
202-
}
203-
//-------------------------------------------------------------------------------
204-
Error serialize_pfc_type(std::ostream& os, const pfc_string& data)
205-
{
206-
auto size = data.size();
207-
os.write(reinterpret_cast<const char*>(&size), sizeof(size));
208-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
209-
if (os.good()) {
210-
return Error();
211-
} else {
212-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
213-
}
214-
}
215-
//-----------------------------------------------------------------------------
216-
Error serialize_pfc_type(std::ostream& os, const pfc_protocol& data)
217-
{
218-
os.write(reinterpret_cast<const char*>(&data), sizeof(data));
219-
if (os.good()) {
220-
return Error();
221-
} else {
222-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
223-
}
224-
}
225-
//-------------------------------------------------------------------------------
226-
//!
227-
//! Deserialization of pfc_types
228-
//!
229-
Error deserialize_pfc_type(std::istream& is, pfc_byte& result)
230-
{
231-
if (is.good()) {
232-
is.read(reinterpret_cast<char*>(&result), sizeof(result));
233-
return Error();
234-
} else {
235-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
236-
}
237-
}
238-
//-------------------------------------------------------------------------------
239-
Error deserialize_pfc_type(std::istream& is, pfc_char& result)
240-
{
241-
if (is.good()) {
242-
is.read(reinterpret_cast<char*>(&result), sizeof(result));
243-
return Error();
244-
} else {
245-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
246-
}
247-
}
248-
//-----------------------------------------------------------------------------
249-
Error deserialize_pfc_type(std::istream& is, pfc_ushort& result)
250-
{
251-
if (is.good()) {
252-
is.read(reinterpret_cast<char*>(&result), sizeof(result));
253-
return Error();
254-
} else {
255-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
256-
}
257-
}
258-
//-------------------------------------------------------------------------------
259-
Error deserialize_pfc_type(std::istream& is, pfc_short& result)
260-
{
261-
if (is.good()) {
262-
is.read(reinterpret_cast<char*>(&result), sizeof(result));
263-
return Error();
264-
} else {
265-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
266-
}
267-
}
268-
//-------------------------------------------------------------------------------
269-
Error deserialize_pfc_type(std::istream& is, pfc_uint& result)
270-
{
271-
if (is.good()) {
272-
is.read(reinterpret_cast<char*>(&result), sizeof(result));
273-
return Error();
274-
} else {
275-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
276-
}
277-
}
278-
//-----------------------------------------------------------------------------
279-
Error deserialize_pfc_type(std::istream& is, pfc_int& result)
280-
{
281-
if (is.good()) {
282-
is.read(reinterpret_cast<char*>(&result), sizeof(result));
283-
return Error();
284-
} else {
285-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
286-
}
287-
}
288-
//-------------------------------------------------------------------------------
289-
Error deserialize_pfc_type(std::istream& is, pfc_float& result)
290-
{
291-
if (is.good()) {
292-
is.read(reinterpret_cast<char*>(&result), sizeof(result));
293-
return Error();
294-
} else {
295-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
296-
}
297-
}
298-
//-------------------------------------------------------------------------------
299-
Error deserialize_pfc_type(std::istream& is, pfc_double& result)
300-
{
301-
if (is.good()) {
302-
is.read(reinterpret_cast<char*>(&result), sizeof(result));
303-
return Error();
304-
} else {
305-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
306-
}
307-
}
308-
//-------------------------------------------------------------------------------
309-
Error deserialize_pfc_type(std::istream& is, pfc_string& result)
310-
{
311-
//TODO:Fix \0 contained in original string;
312-
auto size = result.size();
313-
if (is.good()) {
314-
is.read(reinterpret_cast<char*>(&size), sizeof(size));
315-
result.resize(size);
316-
if (is.good()) {
317-
is.read(result.data(), sizeof(size));
318-
} else {
319-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
320-
}
321-
return Error();
322-
} else {
323-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
324-
}
325-
}
326-
//-----------------------------------------------------------------------------
327-
Error deserialize_pfc_type(std::istream& is, pfc_protocol& result)
328-
{
329-
if (is.good()) {
330-
is.read(reinterpret_cast<char*>(&result), sizeof(result));
331-
return Error();
332-
} else {
333-
return Error(Error::Code::PFC_IP_SERIALIZATION_ERROR);
334-
}
33574
}
336-
//-------------------------------------------------------------------------------
337-
}

0 commit comments

Comments
 (0)