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
c1e104a6
Commit
c1e104a6
authored
Oct 20, 2020
by
legoc
Browse files
(split) Added port requests to the Com classes
parent
895e4d18
Changes
7
Hide whitespace changes
Inline
Side-by-side
include/Application.h
View file @
c1e104a6
...
...
@@ -113,6 +113,10 @@ public:
std
::
string
getKeyValue
(
const
std
::
string
&
key
)
const
;
void
removeKey
(
const
std
::
string
&
key
)
const
;
int
requestPort
()
const
;
void
setPortUnavailable
(
int
port
)
const
;
void
releasePort
(
int
port
)
const
;
private:
Com
(
Server
*
server
,
int
applicationId
);
...
...
include/Server.h
View file @
c1e104a6
...
...
@@ -133,10 +133,15 @@ private:
Response
stopApplicationAsynchronously
(
int
id
,
bool
immediately
)
const
;
std
::
unique_ptr
<
application
::
Subscriber
>
createSubscriber
(
int
id
,
const
std
::
string
&
publisherName
,
const
std
::
string
&
instanceName
);
int
getAvailableTimeout
()
const
;
void
storeKeyValue
(
int
id
,
const
std
::
string
&
key
,
const
std
::
string
&
value
);
std
::
string
getKeyValue
(
int
id
,
const
std
::
string
&
key
);
void
removeKey
(
int
id
,
const
std
::
string
&
key
);
int
requestPort
(
int
id
);
void
setPortUnavailable
(
int
id
,
int
port
);
void
releasePort
(
int
id
,
int
port
);
std
::
mutex
m_eventListenersMutex
;
std
::
vector
<
EventListener
*>
m_eventListeners
;
std
::
unique_ptr
<
EventThread
>
m_eventThread
;
...
...
src/Application.cpp
View file @
c1e104a6
...
...
@@ -69,6 +69,18 @@ void This::Com::removeKey(const std::string& key) const {
m_server
->
removeKey
(
m_applicationId
,
key
);
}
int
This
::
Com
::
requestPort
()
const
{
return
m_server
->
requestPort
(
m_applicationId
);
}
void
This
::
Com
::
setPortUnavailable
(
int
port
)
const
{
m_server
->
setPortUnavailable
(
m_applicationId
,
port
);
}
void
This
::
Com
::
releasePort
(
int
port
)
const
{
m_server
->
releasePort
(
m_applicationId
,
port
);
}
State
This
::
parseState
(
const
std
::
string
&
value
)
{
if
(
value
==
"UNKNOWN"
)
{
...
...
src/Server.cpp
View file @
c1e104a6
...
...
@@ -570,6 +570,50 @@ void Server::removeKey(int id, const std::string& key) {
}
}
int
Server
::
requestPort
(
int
id
)
{
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createRequestPortRequest
(
id
));
// Get the JSON response.
json
::
Object
response
;
json
::
parse
(
response
,
reply
.
get
());
int
value
=
response
[
message
::
RequestResponse
::
VALUE
].
GetInt
();
if
(
value
==
-
1
)
{
throw
UndefinedApplicationException
(
response
[
message
::
RequestResponse
::
MESSAGE
].
GetString
());
}
return
value
;
}
void
Server
::
setPortUnavailable
(
int
id
,
int
port
)
{
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createPortUnavailableRequest
(
id
,
port
));
// Get the JSON response.
json
::
Object
response
;
json
::
parse
(
response
,
reply
.
get
());
int
value
=
response
[
message
::
RequestResponse
::
VALUE
].
GetInt
();
if
(
value
==
-
1
)
{
throw
UndefinedApplicationException
(
response
[
message
::
RequestResponse
::
MESSAGE
].
GetString
());
}
}
void
Server
::
releasePort
(
int
id
,
int
port
)
{
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createReleasePortRequest
(
id
,
port
));
// Get the JSON response.
json
::
Object
response
;
json
::
parse
(
response
,
reply
.
get
());
int
value
=
response
[
message
::
RequestResponse
::
VALUE
].
GetInt
();
if
(
value
==
-
1
)
{
throw
UndefinedApplicationException
(
response
[
message
::
RequestResponse
::
MESSAGE
].
GetString
());
}
}
std
::
vector
<
EventListener
*>
Server
::
getEventListeners
()
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_eventListenersMutex
);
return
m_eventListeners
;
...
...
src/impl/ServicesImpl.cpp
View file @
c1e104a6
...
...
@@ -466,6 +466,48 @@ std::string ServicesImpl::createRemoveKeyRequest(int id, const std::string& key)
return
request
.
toString
();
}
std
::
string
ServicesImpl
::
createRequestPortRequest
(
int
id
)
{
json
::
StringObject
request
;
request
.
pushKey
(
message
::
TYPE
);
request
.
pushInt
(
message
::
REQUEST_PORT
);
request
.
pushKey
(
message
::
RequestPortRequest
::
ID
);
request
.
pushInt
(
id
);
return
request
.
toString
();
}
std
::
string
ServicesImpl
::
createPortUnavailableRequest
(
int
id
,
int
port
)
{
json
::
StringObject
request
;
request
.
pushKey
(
message
::
TYPE
);
request
.
pushInt
(
message
::
PORT_UNAVAILABLE
);
request
.
pushKey
(
message
::
PortUnavailableRequest
::
ID
);
request
.
pushInt
(
id
);
request
.
pushKey
(
message
::
PortUnavailableRequest
::
PORT
);
request
.
pushInt
(
port
);
return
request
.
toString
();
}
std
::
string
ServicesImpl
::
createReleasePortRequest
(
int
id
,
int
port
)
{
json
::
StringObject
request
;
request
.
pushKey
(
message
::
TYPE
);
request
.
pushInt
(
message
::
RELEASE_PORT
);
request
.
pushKey
(
message
::
ReleasePortRequest
::
ID
);
request
.
pushInt
(
id
);
request
.
pushKey
(
message
::
ReleasePortRequest
::
PORT
);
request
.
pushInt
(
port
);
return
request
.
toString
();
}
zmq
::
socket_t
*
ServicesImpl
::
createEventSubscriber
(
const
std
::
string
&
endpoint
,
const
std
::
string
&
cancelEndpoint
)
{
zmq
::
socket_t
*
subscriber
=
new
zmq
::
socket_t
(
m_context
,
ZMQ_SUB
);
...
...
src/impl/ServicesImpl.h
View file @
c1e104a6
...
...
@@ -65,6 +65,9 @@ public:
std
::
string
createStoreKeyValueRequest
(
int
id
,
const
std
::
string
&
key
,
const
std
::
string
&
value
);
std
::
string
createGetKeyValueRequest
(
int
id
,
const
std
::
string
&
key
);
std
::
string
createRemoveKeyRequest
(
int
id
,
const
std
::
string
&
key
);
std
::
string
createRequestPortRequest
(
int
id
);
std
::
string
createPortUnavailableRequest
(
int
id
,
int
port
);
std
::
string
createReleasePortRequest
(
int
id
,
int
port
);
zmq
::
socket_t
*
createEventSubscriber
(
const
std
::
string
&
endpoint
,
const
std
::
string
&
cancelEndpoint
);
zmq
::
socket_t
*
createOutputStreamSubscriber
(
const
std
::
string
&
endpoint
,
const
std
::
string
&
cancelEndpoint
);
...
...
src/message/Message.h
View file @
c1e104a6
...
...
@@ -59,7 +59,7 @@ namespace message {
const
int
GET_KEY_VALUE
=
32
;
const
int
REMOVE_KEY
=
33
;
const
int
REQUEST_PORT
=
34
;
const
int
UNAVAILABLE
_PORT
=
35
;
const
int
PORT_
UNAVAILABLE
=
35
;
const
int
RELEASE_PORT
=
36
;
const
int
PORTS
=
37
;
...
...
@@ -289,7 +289,7 @@ namespace message {
constexpr
const
char
*
ID
=
"id"
;
// int32
}
namespace
Unavailable
Port
Request
{
namespace
Port
UnavailableRequest
{
constexpr
const
char
*
ID
=
"id"
;
// int32
constexpr
const
char
*
PORT
=
"port"
;
// int32
}
...
...
Shervin Nourbakhsh
@nourbakhsh
mentioned in commit
46e44691
·
Apr 23, 2021
mentioned in commit
46e44691
mentioned in commit 46e44691a03808a23a464818487b0dd014a9c57e
Toggle commit list
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