Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Cameo
cameo
Commits
8853fa53
Commit
8853fa53
authored
Oct 26, 2020
by
legoc
Browse files
(split) Replaced string endpoint by Endpoint into the API services classes
parent
f1cc3517
Changes
7
Show whitespace changes
Inline
Side-by-side
include/Application.h
View file @
8853fa53
...
...
@@ -138,7 +138,7 @@ public:
static
int
getId
();
static
void
setTimeout
(
int
timeout
);
static
int
getTimeout
();
static
const
std
::
str
in
g
&
getEndpoint
();
static
const
Endpo
in
t
&
getEndpoint
();
static
Server
&
getServer
();
static
const
Com
&
getCom
();
...
...
@@ -235,7 +235,7 @@ public:
const
std
::
string
&
getName
()
const
;
int
getId
()
const
;
const
std
::
string
&
getUrl
()
const
;
const
std
::
str
in
g
&
getEndpoint
()
const
;
const
Endpo
in
t
&
getEndpoint
()
const
;
std
::
string
getNameId
()
const
;
const
Com
&
getCom
()
const
;
...
...
include/Server.h
View file @
8853fa53
...
...
@@ -48,13 +48,14 @@ class Server : private Services {
public:
typedef
std
::
function
<
void
(
bool
)
>
ConnectionCheckerType
;
Server
(
const
Endpoint
&
endpoint
,
int
timeoutMs
=
0
);
Server
(
const
std
::
string
&
endpoint
,
int
timeoutMs
=
0
);
~
Server
();
void
setTimeout
(
int
timeoutMs
);
int
getTimeout
()
const
;
const
std
::
str
in
g
&
getEndpoint
()
const
;
const
Endpo
in
t
&
getEndpoint
()
const
;
const
std
::
string
&
getUrl
()
const
;
std
::
array
<
int
,
3
>
getVersion
()
const
;
int
getPort
()
const
;
...
...
@@ -132,6 +133,7 @@ public:
void
unregisterEventListener
(
EventListener
*
listener
);
private:
void
initServer
(
const
Endpoint
&
endpoint
,
int
timeoutMs
);
std
::
unique_ptr
<
application
::
Instance
>
makeInstance
();
bool
isAlive
(
int
id
)
const
;
...
...
include/Services.h
View file @
8853fa53
...
...
@@ -19,6 +19,7 @@
#include <string>
#include <vector>
#include "Strings.h"
#include "EventStreamSocket.h"
#include "OutputStreamSocket.h"
...
...
@@ -41,7 +42,7 @@ public:
void
setTimeout
(
int
timeout
);
int
getTimeout
()
const
;
const
std
::
str
in
g
&
getEndpoint
()
const
;
const
Endpo
in
t
&
getEndpoint
()
const
;
const
std
::
string
&
getUrl
()
const
;
std
::
array
<
int
,
3
>
getVersion
()
const
;
int
getPort
()
const
;
...
...
@@ -56,7 +57,7 @@ public:
std
::
unique_ptr
<
RequestSocketImpl
>
createRequestSocket
(
const
std
::
string
&
endpoint
);
std
::
unique_ptr
<
RequestSocketImpl
>
createRequestSocket
(
const
std
::
string
&
endpoint
,
int
timeout
);
std
::
str
in
g
m_serverEndpoint
;
Endpo
in
t
m_serverEndpoint
;
std
::
array
<
int
,
3
>
m_serverVersion
;
std
::
string
m_url
;
int
m_port
;
...
...
src/Application.cpp
View file @
8853fa53
...
...
@@ -176,15 +176,10 @@ void This::initApplication(int argc, char *argv[]) {
json
::
Object
infoObject
;
json
::
parse
(
infoObject
,
info
);
Endpoint
e
ndpoint
=
Endpoint
::
parse
(
infoObject
[
message
::
ApplicationIdentity
::
SERVER
].
GetString
());
m_serverE
ndpoint
=
Endpoint
::
parse
(
infoObject
[
message
::
ApplicationIdentity
::
SERVER
].
GetString
());
m_url
=
endpoint
.
getProtocol
()
+
"://"
+
endpoint
.
getAddress
();
m_port
=
endpoint
.
getPort
();
// We separated host endpoint and server in the past (server being tcp://localhost)
// but that generates troubles when two applications communicate remotely.
// However leave the same value seems to be ok.
m_serverEndpoint
=
m_url
+
":"
+
to_string
(
m_port
);
m_url
=
m_serverEndpoint
.
getProtocol
()
+
"://"
+
m_serverEndpoint
.
getAddress
();
m_port
=
m_serverEndpoint
.
getPort
();
// Create the request socket. The server endpoint has been defined.
Services
::
initRequestSocket
();
...
...
@@ -289,11 +284,11 @@ int This::getTimeout() {
return
m_instance
.
Services
::
getTimeout
();
}
const
std
::
str
in
g
&
This
::
getEndpoint
()
{
const
Endpo
in
t
&
This
::
getEndpoint
()
{
if
(
m_instance
.
m_impl
!=
nullptr
)
{
return
m_instance
.
m_serverEndpoint
;
}
static
str
in
g
result
;
static
Endpo
in
t
result
;
return
result
;
}
...
...
@@ -550,7 +545,7 @@ const std::string& Instance::getUrl() const {
return
m_server
->
getUrl
();
}
const
std
::
str
in
g
&
Instance
::
getEndpoint
()
const
{
const
Endpo
in
t
&
Instance
::
getEndpoint
()
const
{
return
m_server
->
getEndpoint
();
}
...
...
@@ -1119,7 +1114,7 @@ std::unique_ptr<Requester> Requester::create(Instance & instance, const std::str
int
responderId
=
instance
.
getId
();
string
responderUrl
=
instance
.
getUrl
();
string
responderEndpoint
=
instance
.
getEndpoint
();
string
responderEndpoint
=
instance
.
getEndpoint
()
.
toString
()
;
// Create a request socket to the server of the instance.
unique_ptr
<
RequestSocketImpl
>
instanceRequestSocket
=
This
::
m_instance
.
createRequestSocket
(
responderEndpoint
);
...
...
src/Server.cpp
View file @
8853fa53
...
...
@@ -32,22 +32,13 @@ using namespace std;
namespace
cameo
{
Server
::
Server
(
const
std
::
string
&
endpoint
,
int
timeoutMs
)
:
Services
()
{
void
Server
::
initServer
(
const
Endpoint
&
endpoint
,
int
timeoutMs
)
{
Services
::
init
();
vector
<
string
>
tokens
=
split
(
endpoint
);
if
(
tokens
.
size
()
<
3
)
{
throw
InvalidArgumentException
(
endpoint
+
" is not a valid endpoint"
);
}
m_url
=
tokens
[
0
]
+
":"
+
tokens
[
1
];
string
port
=
tokens
[
2
];
istringstream
is
(
port
);
is
>>
m_port
;
m_serverEndpoint
=
m_url
+
":"
+
port
;
m_serverEndpoint
=
endpoint
;
m_url
=
endpoint
.
getProtocol
()
+
"://"
+
endpoint
.
getAddress
();
m_port
=
endpoint
.
getPort
();
// Set the timeout.
Services
::
setTimeout
(
timeoutMs
);
...
...
@@ -70,6 +61,27 @@ Server::Server(const std::string& endpoint, int timeoutMs) :
}
}
Server
::
Server
(
const
Endpoint
&
endpoint
,
int
timeoutMs
)
:
Services
()
{
Services
::
init
();
initServer
(
endpoint
,
timeoutMs
);
}
Server
::
Server
(
const
std
::
string
&
endpoint
,
int
timeoutMs
)
:
Services
()
{
Services
::
init
();
try
{
initServer
(
Endpoint
::
parse
(
endpoint
),
timeoutMs
);
}
catch
(...)
{
throw
InvalidArgumentException
(
endpoint
+
" is not a valid endpoint"
);
}
}
Server
::~
Server
()
{
// Stop the event thread.
if
(
m_eventThread
.
get
()
!=
nullptr
)
{
...
...
@@ -85,7 +97,7 @@ int Server::getTimeout() const {
return
Services
::
getTimeout
();
}
const
std
::
str
in
g
&
Server
::
getEndpoint
()
const
{
const
Endpo
in
t
&
Server
::
getEndpoint
()
const
{
return
Services
::
getEndpoint
();
}
...
...
@@ -537,7 +549,7 @@ std::unique_ptr<application::Subscriber> Server::createSubscriber(int id, const
int
synchronizerPort
=
response
[
message
::
PublisherResponse
::
SYNCHRONIZER_PORT
].
GetInt
();
int
numberOfSubscribers
=
response
[
message
::
PublisherResponse
::
NUMBER_OF_SUBSCRIBERS
].
GetInt
();
unique_ptr
<
application
::
Subscriber
>
subscriber
(
new
application
::
Subscriber
(
this
,
getUrl
(),
publisherPort
,
synchronizerPort
,
publisherName
,
numberOfSubscribers
,
instanceName
,
id
,
m_serverEndpoint
,
m_serverStatusEndpoint
));
unique_ptr
<
application
::
Subscriber
>
subscriber
(
new
application
::
Subscriber
(
this
,
getUrl
(),
publisherPort
,
synchronizerPort
,
publisherName
,
numberOfSubscribers
,
instanceName
,
id
,
m_serverEndpoint
.
toString
()
,
m_serverStatusEndpoint
));
subscriber
->
init
();
return
subscriber
;
...
...
@@ -667,7 +679,7 @@ void Server::unregisterEventListener(EventListener * listener) {
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
cameo
::
Server
&
server
)
{
os
<<
"server@"
<<
server
.
m_serverEndpoint
;
os
<<
"server@"
<<
server
.
m_serverEndpoint
.
toString
()
;
return
os
;
}
...
...
src/Services.cpp
View file @
8853fa53
...
...
@@ -60,7 +60,7 @@ void Services::init() {
void
Services
::
initRequestSocket
()
{
// Create the request socket. The server endpoint must have been initialized.
m_requestSocket
=
std
::
move
(
createRequestSocket
(
m_serverEndpoint
,
m_impl
->
m_timeout
));
m_requestSocket
=
std
::
move
(
createRequestSocket
(
m_serverEndpoint
.
toString
()
,
m_impl
->
m_timeout
));
}
std
::
vector
<
std
::
string
>
Services
::
split
(
const
std
::
string
&
info
)
{
...
...
@@ -91,7 +91,7 @@ int Services::getTimeout() const {
return
m_impl
->
getTimeout
();
}
const
std
::
str
in
g
&
Services
::
getEndpoint
()
const
{
const
Endpo
in
t
&
Services
::
getEndpoint
()
const
{
return
m_serverEndpoint
;
}
...
...
src/impl/PublisherImpl.cpp
View file @
8853fa53
...
...
@@ -60,7 +60,7 @@ int PublisherImpl::getApplicationId() const {
}
const
std
::
string
&
PublisherImpl
::
getApplicationEndpoint
()
const
{
return
m_application
->
getEndpoint
();
return
m_application
->
getEndpoint
()
.
toString
()
;
}
bool
PublisherImpl
::
waitForSubscribers
()
{
...
...
Shervin Nourbakhsh
@nourbakhsh
mentioned in commit
46e44691
·
Apr 23, 2021
mentioned in commit
46e44691
mentioned in commit 46e44691a03808a23a464818487b0dd014a9c57e
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment