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
7bc2b539
Commit
7bc2b539
authored
Dec 14, 2016
by
legoc
Browse files
Implemented unmanaged applications.
parent
665f6a18
Changes
7
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
7bc2b539
...
...
@@ -6,4 +6,5 @@
* Removed StateException, setRunning now returns a boolean.
* Added InvalidArgumentException to replace invalid_argument exception.
* Added SocketException thrown when the Server connect fails.
* Renamed ERROR into FAILURE
\ No newline at end of file
* Renamed ERROR into FAILURE.
* Implementation of unmanaged applications.
\ No newline at end of file
src/cameo/Application.cpp
View file @
7bc2b539
...
...
@@ -92,12 +92,19 @@ std::string This::getReference() {
}
void
This
::
terminate
()
{
// Tell the cameo server that the application is terminated if it is unmanaged.
if
(
!
m_instance
->
m_managed
)
{
m_instance
->
terminateUnmanagedApplication
();
}
delete
m_instance
;
}
This
::
This
(
int
argc
,
char
*
argv
[])
:
Services
(),
m_id
(
-
1
)
{
m_id
(
-
1
),
m_managed
(
false
),
m_starterId
(
0
)
{
m_impl
=
new
ApplicationImpl
();
Services
::
setImpl
(
m_impl
);
...
...
@@ -127,28 +134,38 @@ This::This(int argc, char *argv[]) :
string
nameId
=
tokens
[
3
];
int
index
=
nameId
.
find_last_of
(
'.'
);
m_name
=
nameId
.
substr
(
0
,
index
);
string
sid
=
nameId
.
substr
(
index
+
1
);
{
istringstream
is
(
sid
);
is
>>
m_id
;
// Search for the . character meaning that the application is managed and already has an id.
if
(
index
!=
string
::
npos
)
{
m_managed
=
true
;
m_name
=
nameId
.
substr
(
0
,
index
);
string
sid
=
nameId
.
substr
(
index
+
1
);
{
istringstream
is
(
sid
);
is
>>
m_id
;
}
}
else
{
m_managed
=
false
;
m_name
=
nameId
;
m_id
=
initUnmanagedApplication
();
}
if
(
tokens
.
size
()
>=
7
)
{
index
=
tokens
[
4
].
find_last_of
(
'@'
);
m_starterEndpoint
=
tokens
[
4
].
substr
(
index
+
1
)
+
":"
+
tokens
[
5
]
+
":"
+
tokens
[
6
];
string
starterNameId
=
tokens
[
4
].
substr
(
0
,
index
);
index
=
starterNameId
.
find_last_of
(
'.'
);
m_starterName
=
starterNameId
.
substr
(
0
,
index
);
sid
=
starterNameId
.
substr
(
index
+
1
);
string
sid
=
starterNameId
.
substr
(
index
+
1
);
{
istringstream
is
(
sid
);
is
>>
m_starterId
;
}
}
init
();
// Must be here because the server endpoint is required.
initStatus
();
// Create the local server
m_server
=
auto_ptr
<
Server
>
(
new
Server
(
m_serverEndpoint
));
...
...
@@ -218,10 +235,28 @@ void This::cancelWaitings() {
m_instance
->
m_waitingSet
->
cancelAll
();
}
void
This
::
init
()
{
int
This
::
init
UnmanagedApplication
()
{
// initialises the status port
initStatus
();
string
strRequestType
=
m_impl
->
createRequest
(
PROTO_STARTEDUNMANAGED
);
string
strRequestData
=
m_impl
->
createStartedUnmanagedRequest
(
m_name
);
zmq
::
message_t
*
reply
=
m_impl
->
tryRequestWithOnePartReply
(
strRequestType
,
strRequestData
,
m_serverEndpoint
);
proto
::
RequestResponse
requestResponse
;
requestResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
delete
reply
;
return
requestResponse
.
value
();
}
void
This
::
terminateUnmanagedApplication
()
{
string
strRequestType
=
m_impl
->
createRequest
(
PROTO_TERMINATEDUNMANAGED
);
string
strRequestData
=
m_impl
->
createTerminatedUnmanagedRequest
(
m_id
);
zmq
::
message_t
*
reply
=
m_impl
->
tryRequestWithOnePartReply
(
strRequestType
,
strRequestData
,
m_serverEndpoint
);
proto
::
RequestResponse
requestResponse
;
requestResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
delete
reply
;
}
bool
This
::
setRunning
()
{
...
...
@@ -394,7 +429,6 @@ void This::handleStopImpl(StopFunctionType function) {
m_impl
->
handleStop
(
m_instance
,
function
);
}
///////////////////////////////////////////////////////////////////////////////
// Instance
...
...
src/cameo/Application.h
View file @
7bc2b539
...
...
@@ -141,10 +141,14 @@ public:
private:
This
(
int
argc
,
char
*
argv
[]);
~
This
();
void
init
();
static
std
::
string
getReference
();
static
State
parseState
(
const
std
::
string
&
value
);
State
getState
(
int
id
)
const
;
int
initUnmanagedApplication
();
void
terminateUnmanagedApplication
();
bool
destroyPublisher
(
const
std
::
string
&
name
)
const
;
bool
removePort
(
const
std
::
string
&
name
)
const
;
State
waitForStop
();
...
...
@@ -153,6 +157,7 @@ private:
ApplicationImpl
*
m_impl
;
std
::
string
m_name
;
int
m_id
;
bool
m_managed
;
std
::
string
m_starterEndpoint
;
std
::
string
m_starterName
;
...
...
src/cameo/ProtoType.h
View file @
7bc2b539
...
...
@@ -45,7 +45,9 @@ enum ProtoType {
PROTO_REQUEST
,
PROTO_RESPONSE
,
PROTO_CANCEL
,
PROTO_SETRESULT
PROTO_SETRESULT
,
PROTO_STARTEDUNMANAGED
,
PROTO_TERMINATEDUNMANAGED
};
}
...
...
src/cameo/impl/ServicesImpl.cpp
View file @
7bc2b539
...
...
@@ -310,6 +310,24 @@ std::string ServicesImpl::createRemovePortRequest(int id, const std::string& nam
return
result
;
}
std
::
string
ServicesImpl
::
createStartedUnmanagedRequest
(
const
std
::
string
&
name
)
const
{
proto
::
StartedUnmanagedCommand
command
;
command
.
set_name
(
name
);
std
::
string
result
;
command
.
SerializeToString
(
&
result
);
return
result
;
}
std
::
string
ServicesImpl
::
createTerminatedUnmanagedRequest
(
int
id
)
const
{
proto
::
TerminatedUnmanagedCommand
command
;
command
.
set_id
(
id
);
std
::
string
result
;
command
.
SerializeToString
(
&
result
);
return
result
;
}
bool
ServicesImpl
::
isAvailable
(
const
std
::
string
&
strRequestType
,
const
std
::
string
&
strRequestData
,
const
std
::
string
&
endpoint
,
int
timeout
)
{
try
{
...
...
@@ -409,6 +427,10 @@ proto::MessageType_Type ServicesImpl::convertToProtoType(ProtoType type) const {
return
proto
::
MessageType_Type_RESPONSE
;
}
else
if
(
type
==
PROTO_CANCEL
)
{
return
proto
::
MessageType_Type_CANCEL
;
}
else
if
(
type
==
PROTO_STARTEDUNMANAGED
)
{
return
proto
::
MessageType_Type_STARTEDUNMANAGED
;
}
else
if
(
type
==
PROTO_TERMINATEDUNMANAGED
)
{
return
proto
::
MessageType_Type_TERMINATEDUNMANAGED
;
}
else
{
cerr
<<
"unsupported proto type"
<<
endl
;
return
proto
::
MessageType_Type
(
0
);
...
...
src/cameo/impl/ServicesImpl.h
View file @
7bc2b539
...
...
@@ -57,6 +57,8 @@ public:
std
::
string
createRequestPortRequest
(
int
id
,
const
std
::
string
&
name
)
const
;
std
::
string
createConnectPortRequest
(
int
id
,
const
std
::
string
&
name
)
const
;
std
::
string
createRemovePortRequest
(
int
id
,
const
std
::
string
&
name
)
const
;
std
::
string
createStartedUnmanagedRequest
(
const
std
::
string
&
name
)
const
;
std
::
string
createTerminatedUnmanagedRequest
(
int
id
)
const
;
zmq
::
socket_t
*
createEventSubscriber
(
const
std
::
string
&
endpoint
,
const
std
::
string
&
cancelEndpoint
);
zmq
::
socket_t
*
createCancelPublisher
(
const
std
::
string
&
endpoint
);
...
...
src/proto/Messages.proto
View file @
7bc2b539
...
...
@@ -33,6 +33,8 @@ message MessageType {
REMOVEPORT
=
24
;
REQUEST
=
25
;
RESPONSE
=
26
;
STARTEDUNMANAGED
=
27
;
TERMINATEDUNMANAGED
=
28
;
}
required
Type
type
=
1
;
...
...
@@ -211,6 +213,14 @@ message Request {
required
string
endpoint
=
3
;
}
message
StartedUnmanagedCommand
{
required
string
name
=
1
;
}
message
TerminatedUnmanagedCommand
{
required
int32
id
=
1
;
}
message
StringValue
{
required
string
value
=
1
;
}
...
...
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