Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Cameo
cameo
Commits
41ae26d8
Commit
41ae26d8
authored
Mar 05, 2020
by
legoc
Browse files
Use request socket for Server
parent
c2fa6de2
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cameo/Server.cpp
View file @
41ae26d8
...
...
@@ -24,6 +24,7 @@
#include
"ProtoType.h"
#include
"EventThread.h"
#include
"impl/StreamSocketImpl.h"
#include
"impl/RequestSocketImpl.h"
using
namespace
std
;
...
...
@@ -110,10 +111,7 @@ std::unique_ptr<application::Instance> Server::start(const std::string& name, Op
int
Server
::
getStreamPort
(
const
std
::
string
&
name
)
{
string
strRequestType
=
m_impl
->
createRequestType
(
PROTO_OUTPUT
);
string
strRequestData
=
m_impl
->
createOutputRequest
(
name
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_impl
->
tryRequestWithOnePartReply
(
strRequestType
,
strRequestData
,
m_serverEndpoint
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createRequestType
(
PROTO_OUTPUT
),
m_impl
->
createOutputRequest
(
name
));
proto
::
RequestResponse
requestResponse
;
requestResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
...
...
@@ -133,16 +131,13 @@ std::unique_ptr<application::Instance> Server::start(const std::string& name, co
try
{
if
(
outputStream
)
{
//
w
e connect to the stream port before starting the application
// so that we are sure that the ENDSTREAM message will be received even if the application terminates rapidly
//
W
e connect to the stream port before starting the application
// so that we are sure that the ENDSTREAM message will be received even if the application terminates rapidly
.
unique_ptr
<
OutputStreamSocket
>
socket
=
createOutputStreamSocket
(
getStreamPort
(
name
));
instance
->
setOutputStreamSocket
(
socket
);
}
string
strRequestType
=
m_impl
->
createRequestType
(
PROTO_START
);
string
strRequestData
=
m_impl
->
createStartRequest
(
name
,
args
,
application
::
This
::
getReference
());
unique_ptr
<
zmq
::
message_t
>
reply
=
m_impl
->
tryRequestWithOnePartReply
(
strRequestType
,
strRequestData
,
m_serverEndpoint
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createRequestType
(
PROTO_START
),
m_impl
->
createStartRequest
(
name
,
args
,
application
::
This
::
getReference
()));
proto
::
RequestResponse
requestResponse
;
requestResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
...
...
@@ -162,18 +157,18 @@ std::unique_ptr<application::Instance> Server::start(const std::string& name, co
Response
Server
::
stopApplicationAsynchronously
(
int
id
,
bool
immediately
)
const
{
string
strR
equestType
;
string
strR
equestData
;
string
r
equestType
Part
;
string
r
equestData
Part
;
if
(
immediately
)
{
strR
equestType
=
m_impl
->
createRequestType
(
PROTO_KILL
);
strR
equestData
=
m_impl
->
createKillRequest
(
id
);
r
equestType
Part
=
m_impl
->
createRequestType
(
PROTO_KILL
);
r
equestData
Part
=
m_impl
->
createKillRequest
(
id
);
}
else
{
strR
equestType
=
m_impl
->
createRequestType
(
PROTO_STOP
);
strR
equestData
=
m_impl
->
createStopRequest
(
id
);
r
equestType
Part
=
m_impl
->
createRequestType
(
PROTO_STOP
);
r
equestData
Part
=
m_impl
->
createStopRequest
(
id
);
}
unique_ptr
<
zmq
::
message_t
>
reply
=
m_
impl
->
tryRequestWithOnePartReply
(
strR
equestType
,
strR
equestData
,
m_serverEndpoin
t
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_
requestSocket
->
request
(
r
equestType
Part
,
r
equestData
Par
t
);
proto
::
RequestResponse
requestResponse
;
requestResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
...
...
@@ -187,9 +182,7 @@ application::InstanceArray Server::connectAll(const std::string& name, Option op
application
::
InstanceArray
instances
;
string
strRequestType
=
m_impl
->
createRequestType
(
PROTO_CONNECT
);
string
strRequestData
=
m_impl
->
createConnectRequest
(
name
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_impl
->
tryRequestWithOnePartReply
(
strRequestType
,
strRequestData
,
m_serverEndpoint
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createRequestType
(
PROTO_CONNECT
),
m_impl
->
createConnectRequest
(
name
));
proto
::
ApplicationInfoListResponse
response
;
response
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
...
...
@@ -269,9 +262,7 @@ void Server::killAllAndWaitFor(const std::string& name) {
bool
Server
::
isAlive
(
int
id
)
const
{
string
strRequestType
=
m_impl
->
createRequestType
(
PROTO_ISALIVE
);
string
strRequestData
=
m_impl
->
createIsAliveRequest
(
id
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_impl
->
tryRequestWithOnePartReply
(
strRequestType
,
strRequestData
,
m_serverEndpoint
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createRequestType
(
PROTO_ISALIVE
),
m_impl
->
createIsAliveRequest
(
id
));
proto
::
IsAliveResponse
isAliveResponse
;
isAliveResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
...
...
@@ -283,9 +274,7 @@ std::vector<application::Configuration> Server::getApplicationConfigurations() c
vector
<
application
::
Configuration
>
configVector
;
string
strRequestType
=
m_impl
->
createRequestType
(
PROTO_ALLAVAILABLE
);
string
strRequestData
=
m_impl
->
createAllAvailableRequest
();
unique_ptr
<
zmq
::
message_t
>
reply
=
m_impl
->
tryRequestWithOnePartReply
(
strRequestType
,
strRequestData
,
m_serverEndpoint
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createRequestType
(
PROTO_ALLAVAILABLE
),
m_impl
->
createAllAvailableRequest
());
proto
::
AllAvailableResponse
allAvailableResponse
;
allAvailableResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
...
...
@@ -309,11 +298,9 @@ std::vector<application::Configuration> Server::getApplicationConfigurations() c
std
::
vector
<
application
::
Info
>
Server
::
getApplicationInfos
()
const
{
vector
<
application
::
Info
>
info
Vector
;
vector
<
application
::
Info
>
info
s
;
string
strRequestType
=
m_impl
->
createRequestType
(
PROTO_SHOWALL
);
string
strRequestData
=
m_impl
->
createShowAllRequest
();
unique_ptr
<
zmq
::
message_t
>
reply
=
m_impl
->
tryRequestWithOnePartReply
(
strRequestType
,
strRequestData
,
m_serverEndpoint
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createRequestType
(
PROTO_SHOWALL
),
m_impl
->
createShowAllRequest
());
proto
::
ApplicationInfoListResponse
response
;
response
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
...
...
@@ -328,10 +315,10 @@ std::vector<application::Info> Server::getApplicationInfos() const {
info
.
pastapplicationstates
(),
info
.
args
());
info
Vector
.
push_back
(
applicationInfo
);
info
s
.
push_back
(
applicationInfo
);
}
return
info
Vector
;
return
info
s
;
}
std
::
vector
<
application
::
Info
>
Server
::
getApplicationInfos
(
const
std
::
string
&
name
)
const
{
...
...
@@ -355,10 +342,8 @@ std::unique_ptr<EventStreamSocket> Server::openEventStream() {
std
::
unique_ptr
<
application
::
Subscriber
>
Server
::
createSubscriber
(
int
id
,
const
std
::
string
&
publisherName
,
const
std
::
string
&
instanceName
)
const
{
string
strRequestType
=
m_impl
->
createRequestType
(
PROTO_CONNECTPUBLISHER
);
string
strRequestData
=
m_impl
->
createConnectPublisherRequest
(
id
,
publisherName
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createRequestType
(
PROTO_CONNECTPUBLISHER
),
m_impl
->
createConnectPublisherRequest
(
id
,
publisherName
));
unique_ptr
<
zmq
::
message_t
>
reply
=
m_impl
->
tryRequestWithOnePartReply
(
strRequestType
,
strRequestData
,
m_serverEndpoint
);
proto
::
PublisherResponse
requestResponse
;
requestResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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