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
cdc2a348
Commit
cdc2a348
authored
Nov 16, 2020
by
yannick legoc
Browse files
(split) Some minor changes for Visual Studio 19
parent
7188c0d4
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
include/Services.h
View file @
cdc2a348
/*
/*
* Copyright 2015 Institut Laue-Langevin
* Copyright 2015 Institut Laue-Langevin
*
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
* You may obtain a copy of the Licence at:
*
*
* http://joinup.ec.europa.eu/software/page/eupl
* http://joinup.ec.europa.eu/software/page/eupl
*
*
* Unless required by applicable law or agreed to in writing, software
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
* limitations under the Licence.
*/
*/
#ifndef CAMEO_SERVICES_H_
#ifndef CAMEO_SERVICES_H_
#define CAMEO_SERVICES_H_
#define CAMEO_SERVICES_H_
#include
<string>
#include
<string>
#include
<vector>
#include
<vector>
#include
"Strings.h"
#include
<array>
#include
"EventStreamSocket.h"
#include
"Strings.h"
#include
"OutputStreamSocket.h"
#include
"EventStreamSocket.h"
#include
"OutputStreamSocket.h"
namespace
cameo
{
namespace
cameo
{
class
ServicesImpl
;
class
RequestSocketImpl
;
class
ServicesImpl
;
class
RequestSocketImpl
;
class
Services
{
class
Services
{
public:
Services
();
public:
~
Services
();
Services
();
~
Services
();
void
terminate
();
void
terminate
();
void
init
();
void
initRequestSocket
();
void
init
();
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
info
);
void
initRequestSocket
();
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
info
);
void
setTimeout
(
int
timeout
);
int
getTimeout
()
const
;
void
setTimeout
(
int
timeout
);
const
Endpoint
&
getEndpoint
()
const
;
int
getTimeout
()
const
;
std
::
array
<
int
,
3
>
getVersion
()
const
;
const
Endpoint
&
getEndpoint
()
const
;
Endpoint
getStatusEndpoint
()
const
;
std
::
array
<
int
,
3
>
getVersion
()
const
;
Endpoint
getStatusEndpoint
()
const
;
bool
isAvailable
(
int
timeout
)
const
;
void
retrieveServerVersion
();
bool
isAvailable
(
int
timeout
)
const
;
void
initStatus
();
void
retrieveServerVersion
();
std
::
unique_ptr
<
EventStreamSocket
>
openEventStream
();
void
initStatus
();
int
getStreamPort
(
const
std
::
string
&
name
);
std
::
unique_ptr
<
EventStreamSocket
>
openEventStream
();
std
::
unique_ptr
<
OutputStreamSocket
>
createOutputStreamSocket
(
const
std
::
string
&
name
);
int
getStreamPort
(
const
std
::
string
&
name
);
std
::
unique_ptr
<
RequestSocketImpl
>
createRequestSocket
(
const
std
::
string
&
endpoint
);
std
::
unique_ptr
<
OutputStreamSocket
>
createOutputStreamSocket
(
const
std
::
string
&
name
);
std
::
unique_ptr
<
RequestSocketImpl
>
createRequestSocket
(
const
std
::
string
&
endpoint
,
int
timeout
);
std
::
unique_ptr
<
RequestSocketImpl
>
createRequestSocket
(
const
std
::
string
&
endpoint
);
std
::
unique_ptr
<
RequestSocketImpl
>
createRequestSocket
(
const
std
::
string
&
endpoint
,
int
timeout
);
Endpoint
m_serverEndpoint
;
std
::
array
<
int
,
3
>
m_serverVersion
;
Endpoint
m_serverEndpoint
;
int
m_statusPort
;
std
::
array
<
int
,
3
>
m_serverVersion
;
std
::
unique_ptr
<
ServicesImpl
>
m_impl
;
int
m_statusPort
;
std
::
unique_ptr
<
RequestSocketImpl
>
m_requestSocket
;
std
::
unique_ptr
<
ServicesImpl
>
m_impl
;
};
std
::
unique_ptr
<
RequestSocketImpl
>
m_requestSocket
;
};
}
}
#endif
#endif
src/Strings.cpp
View file @
cdc2a348
/*
/*
* Copyright 2015 Institut Laue-Langevin
* Copyright 2015 Institut Laue-Langevin
*
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
* You may obtain a copy of the Licence at:
*
*
* http://joinup.ec.europa.eu/software/page/eupl
* http://joinup.ec.europa.eu/software/page/eupl
*
*
* Unless required by applicable law or agreed to in writing, software
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
* limitations under the Licence.
*/
*/
#include
"Strings.h"
#include
"Strings.h"
#include
"JSON.h"
#include
"JSON.h"
#include
"message/Message.h"
#include
"message/Message.h"
#include
"BadFormatException.h"
#include
"BadFormatException.h"
#include
<regex>
#include
<regex>
#include
<ostream>
using
namespace
std
;
using
namespace
std
;
namespace
cameo
{
namespace
cameo
{
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
str
,
char
c
)
{
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
str
,
char
c
)
{
vector
<
string
>
result
;
vector
<
string
>
result
;
string
::
size_type
lastIndex
=
0
;
string
::
size_type
index
=
str
.
find
(
c
);
string
::
size_type
lastIndex
=
0
;
while
(
index
!=
string
::
npos
)
{
string
::
size_type
index
=
str
.
find
(
c
);
result
.
push_back
(
str
.
substr
(
lastIndex
,
index
-
lastIndex
));
while
(
index
!=
string
::
npos
)
{
lastIndex
=
index
+
1
;
result
.
push_back
(
str
.
substr
(
lastIndex
,
index
-
lastIndex
));
index
=
str
.
find
(
c
,
lastIndex
);
lastIndex
=
index
+
1
;
}
index
=
str
.
find
(
c
,
lastIndex
);
result
.
push_back
(
str
.
substr
(
lastIndex
));
}
result
.
push_back
(
str
.
substr
(
lastIndex
));
return
result
;
}
return
result
;
}
Endpoint
::
Endpoint
(
const
std
::
string
&
protocol
,
const
std
::
string
&
address
,
int
port
)
{
m_protocol
=
protocol
;
Endpoint
::
Endpoint
(
const
std
::
string
&
protocol
,
const
std
::
string
&
address
,
int
port
)
{
m_address
=
address
;
m_protocol
=
protocol
;
m_port
=
port
;
m_address
=
address
;
}
m_port
=
port
;
}
Endpoint
::
Endpoint
(
const
std
::
string
&
address
,
int
port
)
{
m_protocol
=
"tcp"
;
Endpoint
::
Endpoint
(
const
std
::
string
&
address
,
int
port
)
{
m_address
=
address
;
m_protocol
=
"tcp"
;
m_port
=
port
;
m_address
=
address
;
}
m_port
=
port
;
}
Endpoint
::
Endpoint
()
:
m_port
(
0
)
{
Endpoint
::
Endpoint
()
:
}
m_port
(
0
)
{
}
bool
Endpoint
::
operator
==
(
const
Endpoint
&
endpoint
)
const
{
return
m_protocol
==
endpoint
.
m_protocol
bool
Endpoint
::
operator
==
(
const
Endpoint
&
endpoint
)
const
{
&&
m_address
==
endpoint
.
m_address
return
m_protocol
==
endpoint
.
m_protocol
&&
m_port
==
endpoint
.
m_port
;
&&
m_address
==
endpoint
.
m_address
}
&&
m_port
==
endpoint
.
m_port
;
}
const
std
::
string
&
Endpoint
::
getProtocol
()
const
{
return
m_protocol
;
const
std
::
string
&
Endpoint
::
getProtocol
()
const
{
}
return
m_protocol
;
}
const
std
::
string
&
Endpoint
::
getAddress
()
const
{
return
m_address
;
const
std
::
string
&
Endpoint
::
getAddress
()
const
{
}
return
m_address
;
}
int
Endpoint
::
getPort
()
const
{
return
m_port
;
int
Endpoint
::
getPort
()
const
{
}
return
m_port
;
}
Endpoint
Endpoint
::
parse
(
const
std
::
string
&
str
)
{
Endpoint
Endpoint
::
parse
(
const
std
::
string
&
str
)
{
vector
<
string
>
tokens
=
split
(
str
,
':'
);
vector
<
string
>
tokens
=
split
(
str
,
':'
);
if
(
tokens
.
size
()
!=
3
)
{
throw
BadFormatException
(
"Bad format for endpoint "
+
str
);
if
(
tokens
.
size
()
!=
3
)
{
}
throw
BadFormatException
(
"Bad format for endpoint "
+
str
);
}
string
protocol
=
tokens
[
0
];
string
substr
=
tokens
[
1
];
string
protocol
=
tokens
[
0
];
string
substr
=
tokens
[
1
];
string
address
=
substr
.
substr
(
2
);
string
address
=
substr
.
substr
(
2
);
try
{
address
=
substr
.
substr
(
2
);
try
{
}
address
=
substr
.
substr
(
2
);
catch
(...)
{
}
throw
BadFormatException
(
"Bad format for endpoint "
+
str
);
catch
(...)
{
}
throw
BadFormatException
(
"Bad format for endpoint "
+
str
);
}
int
port
=
0
;
int
port
=
0
;
try
{
port
=
stoi
(
tokens
[
2
]);
try
{
}
port
=
stoi
(
tokens
[
2
]);
catch
(...)
{
}
throw
BadFormatException
(
"Bad format for endpoint "
+
str
);
catch
(...)
{
}
throw
BadFormatException
(
"Bad format for endpoint "
+
str
);
}
return
Endpoint
(
protocol
,
address
,
port
);
}
return
Endpoint
(
protocol
,
address
,
port
);
}
Endpoint
Endpoint
::
withPort
(
int
port
)
const
{
return
Endpoint
(
m_protocol
,
m_address
,
port
);
Endpoint
Endpoint
::
withPort
(
int
port
)
const
{
}
return
Endpoint
(
m_protocol
,
m_address
,
port
);
}
std
::
string
Endpoint
::
toString
()
const
{
if
(
m_address
!=
""
)
{
std
::
string
Endpoint
::
toString
()
const
{
return
m_protocol
+
"://"
+
m_address
+
":"
+
to_string
(
m_port
);
if
(
m_address
!=
""
)
{
}
return
m_protocol
+
"://"
+
m_address
+
":"
+
to_string
(
m_port
);
return
""
;
}
}
return
""
;
}
ApplicationIdentity
::
ApplicationIdentity
(
const
std
::
string
&
name
,
int
id
,
const
Endpoint
&
endpoint
)
:
m_name
(
name
),
ApplicationIdentity
::
ApplicationIdentity
(
const
std
::
string
&
name
,
int
id
,
const
Endpoint
&
endpoint
)
:
m_id
(
id
),
m_name
(
name
),
m_endpoint
(
endpoint
)
{
m_id
(
id
),
}
m_endpoint
(
endpoint
)
{
}
ApplicationIdentity
::
ApplicationIdentity
(
const
std
::
string
&
name
,
const
Endpoint
&
endpoint
)
:
m_name
(
name
),
ApplicationIdentity
::
ApplicationIdentity
(
const
std
::
string
&
name
,
const
Endpoint
&
endpoint
)
:
m_id
(
Null
),
m_name
(
name
),
m_endpoint
(
endpoint
)
{
m_id
(
Null
),
}
m_endpoint
(
endpoint
)
{
}
ApplicationIdentity
::
ApplicationIdentity
()
:
m_id
(
Null
)
{
ApplicationIdentity
::
ApplicationIdentity
()
:
}
m_id
(
Null
)
{
}
const
std
::
string
&
ApplicationIdentity
::
getName
()
const
{
return
m_name
;
const
std
::
string
&
ApplicationIdentity
::
getName
()
const
{
}
return
m_name
;
}
int
ApplicationIdentity
::
getId
()
const
{
return
m_id
;
int
ApplicationIdentity
::
getId
()
const
{
}
return
m_id
;
}
const
Endpoint
&
ApplicationIdentity
::
getEndpoint
()
const
{
return
m_endpoint
;
const
Endpoint
&
ApplicationIdentity
::
getEndpoint
()
const
{
}
return
m_endpoint
;
}
std
::
string
ApplicationIdentity
::
toJSONString
()
const
{
std
::
string
ApplicationIdentity
::
toJSONString
()
const
{
json
::
StringObject
jsonObject
;
json
::
StringObject
jsonObject
;
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
NAME
);
jsonObject
.
pushString
(
m_name
);
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
NAME
);
jsonObject
.
pushString
(
m_name
);
if
(
m_id
!=
Null
)
{
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
ID
);
if
(
m_id
!=
Null
)
{
jsonObject
.
pushInt
(
m_id
);
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
ID
);
}
jsonObject
.
pushInt
(
m_id
);
}
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
SERVER
);
jsonObject
.
pushString
(
m_endpoint
.
toString
());
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
SERVER
);
jsonObject
.
pushString
(
m_endpoint
.
toString
());
return
jsonObject
.
toString
();
}
return
jsonObject
.
toString
();
}
ApplicationWithStarterIdentity
::
ApplicationWithStarterIdentity
(
const
ApplicationIdentity
&
application
,
const
ApplicationIdentity
&
starter
)
:
m_application
(
application
),
ApplicationWithStarterIdentity
::
ApplicationWithStarterIdentity
(
const
ApplicationIdentity
&
application
,
const
ApplicationIdentity
&
starter
)
:
m_hasStarter
(
true
),
m_application
(
application
),
m_starter
(
starter
)
{
m_hasStarter
(
true
),
}
m_starter
(
starter
)
{
}
ApplicationWithStarterIdentity
::
ApplicationWithStarterIdentity
(
const
ApplicationIdentity
&
application
)
:
m_application
(
application
),
ApplicationWithStarterIdentity
::
ApplicationWithStarterIdentity
(
const
ApplicationIdentity
&
application
)
:
m_hasStarter
(
false
)
{
m_application
(
application
),
}
m_hasStarter
(
false
)
{
}
const
ApplicationIdentity
&
ApplicationWithStarterIdentity
::
getApplication
()
const
{
return
m_application
;
const
ApplicationIdentity
&
ApplicationWithStarterIdentity
::
getApplication
()
const
{
}
return
m_application
;
}
bool
ApplicationWithStarterIdentity
::
hasStarter
()
const
{
return
m_hasStarter
;
bool
ApplicationWithStarterIdentity
::
hasStarter
()
const
{
}
return
m_hasStarter
;
}
const
ApplicationIdentity
&
ApplicationWithStarterIdentity
::
getStarter
()
const
{
return
m_starter
;
const
ApplicationIdentity
&
ApplicationWithStarterIdentity
::
getStarter
()
const
{
}
return
m_starter
;
}
std
::
string
ApplicationWithStarterIdentity
::
toJSONString
()
const
{
std
::
string
ApplicationWithStarterIdentity
::
toJSONString
()
const
{
json
::
StringObject
jsonObject
;
json
::
StringObject
jsonObject
;
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
NAME
);
jsonObject
.
pushString
(
m_application
.
getName
());
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
NAME
);
jsonObject
.
pushString
(
m_application
.
getName
());
if
(
m_application
.
getId
()
!=
Null
)
{
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
ID
);
if
(
m_application
.
getId
()
!=
Null
)
{
jsonObject
.
pushInt
(
m_application
.
getId
());
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
ID
);
}
jsonObject
.
pushInt
(
m_application
.
getId
());
}
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
SERVER
);
jsonObject
.
pushString
(
m_application
.
getEndpoint
().
toString
());
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
SERVER
);
jsonObject
.
pushString
(
m_application
.
getEndpoint
().
toString
());
if
(
m_hasStarter
)
{
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
STARTER
);
if
(
m_hasStarter
)
{
jsonObject
.
startObject
();
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
STARTER
);
jsonObject
.
startObject
();
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
NAME
);
jsonObject
.
pushString
(
m_starter
.
getName
());
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
NAME
);
jsonObject
.
pushString
(
m_starter
.
getName
());
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
ID
);
jsonObject
.
pushInt
(
m_starter
.
getId
());
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
ID
);
jsonObject
.
pushInt
(
m_starter
.
getId
());
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
SERVER
);
jsonObject
.
pushString
(
m_starter
.
getEndpoint
().
toString
());
jsonObject
.
pushKey
(
message
::
ApplicationIdentity
::
SERVER
);
jsonObject
.
pushString
(
m_starter
.
getEndpoint
().
toString
());
jsonObject
.
endObject
();
}
jsonObject
.
endObject
();
}
return
jsonObject
.
toString
();
}
return
jsonObject
.
toString
();
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
cameo
::
Endpoint
&
endpoint
)
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
cameo
::
Endpoint
&
endpoint
)
{
os
<<
endpoint
.
toString
();
os
<<
endpoint
.
toString
();
return
os
;
}
return
os
;
}
}
}
src/impl/ServicesImpl.cpp
View file @
cdc2a348
This diff is collapsed.
Click to expand it.
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