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
f1cc3517
Commit
f1cc3517
authored
Oct 26, 2020
by
legoc
Browse files
(split) First step in json argument info
parent
08b86819
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Application.cpp
View file @
f1cc3517
...
...
@@ -36,6 +36,7 @@
#include "impl/StreamSocketImpl.h"
#include "impl/RequestSocketImpl.h"
#include "message/Message.h"
#include "Strings.h"
#include "Server.h"
#include "StarterServerException.h"
#include "StatusEvent.h"
...
...
@@ -159,22 +160,31 @@ void This::initApplication(int argc, char *argv[]) {
}
string
info
(
argv
[
argc
-
1
]);
vector
<
string
>
tokens
=
split
(
info
);
if
(
tokens
.
size
()
<
4
)
{
throw
InvalidArgumentException
(
info
+
" is not a valid argument"
);
}
// vector<string> tokens = split(info);
//
// if (tokens.size() < 4) {
// throw InvalidArgumentException(info + " is not a valid argument");
// }
//
// m_url = tokens[0] + ":" + tokens[1];
//
// string port = tokens[2];
// istringstream is(port);
// is >> m_port;
json
::
Object
infoObject
;
json
::
parse
(
infoObject
,
info
);
m_url
=
tokens
[
0
]
+
":"
+
tokens
[
1
]
;
Endpoint
endpoint
=
Endpoint
::
parse
(
infoObject
[
message
::
ApplicationIdentity
::
SERVER
].
GetString
())
;
string
port
=
tokens
[
2
];
istringstream
is
(
port
);
is
>>
m_port
;
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
+
":"
+
port
;
m_serverEndpoint
=
m_url
+
":"
+
to_string
(
m_
port
)
;
// Create the request socket. The server endpoint has been defined.
Services
::
initRequestSocket
();
...
...
@@ -182,23 +192,27 @@ void This::initApplication(int argc, char *argv[]) {
// Retrieve the server version.
Services
::
retrieveServerVersion
();
string
nameId
=
tokens
[
3
];
// string nameId = tokens[3];
//
// int index = nameId.find_last_of('.');
int
index
=
nameId
.
find_last_of
(
'.'
);
m_name
=
infoObject
[
message
::
ApplicationIdentity
::
NAME
].
GetString
(
);
// Search for the . character meaning that the application is managed and already has an id.
if
(
index
!=
string
::
npos
)
{
// // Search for the . character meaning that the application is managed and already has an id.
// if (index != string::npos) {
if
(
infoObject
.
HasMember
(
message
::
ApplicationIdentity
::
ID
))
{
m_managed
=
true
;
m_name
=
nameId
.
substr
(
0
,
index
);
string
sid
=
nameId
.
substr
(
index
+
1
);
{
istringstream
is
(
sid
);
is
>>
m_id
;
}
// m_name = nameId.substr(0, index);
// string sid = nameId.substr(index + 1);
// {
// istringstream is(sid);
// is >> m_id;
// }
m_id
=
infoObject
[
message
::
ApplicationIdentity
::
ID
].
GetInt
();
}
else
{
m_managed
=
false
;
m_name
=
nameId
;
//
m_name = nameId;
m_id
=
initUnmanagedApplication
();
if
(
m_id
==
-
1
)
{
...
...
@@ -206,18 +220,18 @@ void This::initApplication(int argc, char *argv[]) {
}
}
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
);
string
sid
=
starterNameId
.
substr
(
index
+
1
);
{
istringstream
is
(
sid
);
is
>>
m_starterId
;
}
}
//
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);
//
string sid = starterNameId.substr(index + 1);
//
{
//
istringstream is(sid);
//
is >> m_starterId;
//
}
//
}
// Must be here because the server endpoint is required.
initStatus
();
...
...
@@ -239,6 +253,15 @@ void This::initApplication(int argc, char *argv[]) {
// Init com.
m_com
=
unique_ptr
<
Com
>
(
new
Com
(
m_server
.
get
(),
m_id
));
cout
<<
"url = "
<<
m_url
<<
endl
;
cout
<<
"port = "
<<
m_port
<<
endl
;
cout
<<
"name = "
<<
m_name
<<
endl
;
cout
<<
"id = "
<<
m_id
<<
endl
;
cout
<<
"starterEndpoint = "
<<
m_starterEndpoint
<<
endl
;
cout
<<
"starterName = "
<<
m_starterName
<<
endl
;
cout
<<
"starterId = "
<<
m_starterId
<<
endl
;
}
This
::~
This
()
{
...
...
src/impl/ServicesImpl.cpp
View file @
f1cc3517
...
...
@@ -111,7 +111,7 @@ std::string ServicesImpl::createStartRequest(const std::string& name, const std:
}
request
.
endArray
();
request
.
pushKey
(
message
::
StartRequest
::
IN
STA
NCE_REFERENCE
);
request
.
pushKey
(
message
::
StartRequest
::
STA
RTER
);
request
.
pushString
(
instanceReference
);
return
request
.
toString
();
...
...
src/message/Message.h
View file @
f1cc3517
...
...
@@ -90,7 +90,7 @@ namespace message {
namespace
StartRequest
{
constexpr
const
char
*
NAME
=
"name"
;
// required string name = 1;
constexpr
const
char
*
ARGS
=
"args"
;
// repeated string args = 2;
constexpr
const
char
*
IN
STA
NCE_REFERENCE
=
"
in
sta
nceReference"
;
// required string instanceReference = 3;
constexpr
const
char
*
STA
RTER
=
"sta
rter"
;
// object
}
namespace
RequestResponse
{
...
...
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