Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2SomeIP
Commits
75e2790c
Commit
75e2790c
authored
Sep 23, 2019
by
Florian Raeth
Browse files
fixed publisher and added mutex to subscriber
parent
7bb171b3
Pipeline
#186133
failed with stages
in 1 minute and 54 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/resources/de/monticore/lang/monticar/generator/someip/template/Adapter.cpp.ftl
View file @
75e2790c
...
...
@@ -13,59 +13,63 @@ void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::init(${model.getEscaped
//
I
ntitialize
S
ubscriber
<#
list
model
.getIncomingPorts
()
as
sub
>
$
{
sub
.getName
()}
_
S
ubscriber
=
vsomeip
::
runtime
::
get
()->
create_application
(
"Subscriber"
)
;
$
{
sub
.getName
()}
_
S
ubscriber
=
vsomeip
::
runtime
::
get
()->
create_application
(
"Subscriber
${sub.getName()}
"
)
;
if
(
!$
{
sub
.getName
()}
_
S
ubscriber-
>
init
())
{
std
::
cerr
<<
"Couldn't initialize Subscriber ${sub.getName()}"
<<
std
::
endl
;
return
false
;
}
$
{
sub
.getName
()}
_
S
ubscriber-
>
register_
state_handler
(
std
::
bind
(
&
S
omeIPAdapter_
$
{
model
.getEscapedCompName
()}::
on_state
,
this
,
std
::
placeholders
::
_
1
)
;
$
{
sub
.getName
()}
_
S
ubscriber-
>
register_
availability_handler
(
$
{
model
.getServiceId
(
sub
)},
$
{
model
.getInstanceId
(
sub
)},
std
::
bind
(
&
S
omeIPAdapter_
$
{
model
.getEscapedCompName
()}::
on_availability_
$
{
sub
.getName
()},
this
,
std
::
placeholders
::
_
1
,
std
::
placeholders
::
_
2
,
std
::
placeholders
::
_
3
)
)
;
$
{
sub
.getName
()}
_
S
ubscriber-
>
request_service
(
$
{
model
.getServiceId
(
sub
)},
$
{
model
.getInstanceId
(
sub
)})
;
$
{
sub
.getName
()}
_
S
ubscriber-
>
register_message_handler
(
$
{
model
.getServiceId
(
sub
)},
$
{
model
.getInstanceId
(
sub
)},
$
{
model
.getMethodId
(
sub
)},
std
::
bind
(
&
S
omeIPAdapter_
$
{
model
.getEscapedCompName
()}::
on_message_
$
{
sub
.getName
()},
this
,
std
::
placeholders
::
_
1
))
;
$
{
sub
.getName
()}
_
S
ubscriber-
>
register_availability_handler
(
$
{
model
.getServiceId
(
sub
)},
$
{
model
.getInstanceId
(
sub
)},
std
::
bind
(
&
S
omeIPAdapter_
$
{
model
.getEscapedCompName
()}::
on_availability
,
this
,
std
::
placeholders
::
_
1
,
std
::
placeholders
::
_
2
,
std
::
placeholders
::
_
3
))
;
//
S
ubscribe
std
::
set
<
vsomeip
::
eventgroup_t
>
event_group
;
event_group
.insert
(
$
{
model
.getEventGroupId
(
sub
)})
;
$
{
sub
.getName
()}
_
S
ubscriber-
>
request_event
(
$
{
model
.getServiceId
(
sub
)},
$
{
model
.getInstanceId
(
sub
)},
$
{
model
.getEventId
(
sub
)},
event_group
,
true
)
;
$
{
sub
.getName
()}
_
S
ubscriber-
>
subscribe
(
$
{
model
.getServiceId
(
sub
)},
$
{
model
.getInstanceId
(
sub
)},
$
{
model
.getEventGroupId
(
sub
)})
;
std
::
thread
sender_
$
{
sub
.getName
()}(
std
::
bind
(
&
S
omeIPAdapter_
$
{
model
.getEscapedCompName
()}::
run_
$
{
sub
.getName
()},
this
))
;
$
{
sub
.getName
()}
_
S
ubscriber-
>
start
()
;
</#
list
>
//
I
ntitialize
P
ublisher
<#
list
model
.getOutgoingPorts
()
as
pub
>
$
{
pub
.getName
()}
_
P
ublisher
=
vsomeip
::
runtime
::
get
()->
create_application
(
"Publisher"
)
;
$
{
pub
.getName
()}
_
P
ublisher
=
vsomeip
::
runtime
::
get
()->
create_application
(
"Publisher
${pub.getName()}
"
)
;
if
(
!$
{
pub
.getName
()}
_
P
ublisher-
>
init
())
{
std
::
cerr
<<
"Couldn't initialize Publisher ${pub.getName()}"
<<
std
::
endl
;
return
false
;
}
$
{
pub
.getName
()}
_
P
ublisher-
>
offer_service
(
$
{
model
.getServiceId
(
pub
)},
$
{
model
.getInstanceId
(
pub
)})
;
</#
list
>
//
S
tart
S
ubscriber
<#
list
model
.getIncomingPorts
()
as
sub
>
$
{
sub
.getName
()}
_
S
ubscriber-
>
start
()
;
</#
list
>
//
S
tart
P
ublisher
<#
list
model
.getOutgoingPorts
()
as
pub
>
$
{
pub
.getName
()}
_
P
ublisher-
>
start
()
;
</#
list
>
}
<#
list
model.getIncomingPorts() as sub>
void
<@m.mwIdent/>Adapter_$
{
model
.getEscapedCompName
()}
::on_message_$
{
sub
.getName
()}
(const std::shared_ptr<vsomeip::message> &_request)
{
void
<@m.mwIdent/>Adapter_$
{
model
.getEscapedCompName
()}
::run_$
{
sub
.getName
()}
()
{
std
::
unique_lock
<
std
::
mutex
>
its_lock
(
mutex_
$
{
sub
.getName
()})
;
condition_
$
{
sub
.getName
()}
.wait
(
its_lock
)
;
std
::
set
<
vsomeip
::
eventgroup_t
>
event_group
;
event_group
.insert
(
$
{
model
.getEventGroupId
(
sub
)})
;
$
{
sub
.getName
()}
_
S
ubscriber-
>
request_event
(
$
{
model
.getServiceId
(
sub
)},
$
{
model
.getInstanceId
(
sub
)},
$
{
model
.getEventId
(
sub
)},
event_group
,
true
)
;
$
{
sub
.getName
()}
_
S
ubscriber-
>
subscribe
(
$
{
model
.getServiceId
(
sub
)},
$
{
model
.getInstanceId
(
sub
)},
$
{
model
.getEventGroupId
(
sub
)})
;
}
void
<@m.mwIdent/>Adapter_$
{
model
.getEscapedCompName
()}
::on_message_$
{
sub
.getName
()}
(const std::shared_ptr<vsomeip::message> &_message)
{
//
read
received
message
std
::
shared_ptr
<
vsomeip
::
payload
>
its_payload
=
_
request
-
>
get_payload
()
;
std
::
shared_ptr
<
vsomeip
::
payload
>
its_payload
=
_
message
-
>
get_payload
()
;
vsomeip
::
length_t
l
=
its_payload-
>
get_length
()
;
double
dataFromMessage
=
*
((
double
*
)
its_payload-
>
get_data
())
;
component-
>$
{
sub
.getName
()}
=
dataFromMessage
;
//
print
data
to
std
out
std
::
cout
<<
"SERVICE ${sub.getName()}: Received message from ["
<<
std
::
setw
(
4
)
<<
std
::
setfill
(
'
0
'
)
<<
std
::
hex
<<
_
request
-
>
get_client
()
<<
"/"
<<
std
::
setw
(
4
)
<<
std
::
setfill
(
'
0
'
)
<<
std
::
hex
<<
_
request
-
>
get_session
()
<<
"]: "
<<
std
::
setw
(
4
)
<<
std
::
setfill
(
'
0
'
)
<<
std
::
hex
<<
_
message
-
>
get_client
()
<<
"/"
<<
std
::
setw
(
4
)
<<
std
::
setfill
(
'
0
'
)
<<
std
::
hex
<<
_
message
-
>
get_session
()
<<
"]: "
<<
dataFromMessage
<<
std
::
endl
;
}
void
<@m.mwIdent/>Adapter_$
{
model
.getEscapedCompName
()}
::on_availability_$
{
sub
.getName
()}
(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available)
{
std
::
cout
<<
"Service ["
<<
std
::
setw
(
4
)
<<
std
::
setfill
(
'
0
'
)
<<
std
::
hex
<<
_
service
<<
"."
<<
_
instance
<<
"] is "
<<
(
_
is_available
?
"available."
:
"NOT available."
)
<<
std
::
endl
;
condition_
$
{
sub
.getName
()}
.notify_one
()
;
}
</#
list
>
...
...
@@ -75,11 +79,9 @@ void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::publish${pub.getName()}
//Read data from component
double d = component->$
{
pub
.getName
()}
;
//Create message
uint8_t
*
byteArray = (uint8_t
*
)&d;
vsomeip::byte_t
*
p;
p = byteArray;
std::shared_ptr< vsomeip::payload > payload = vsomeip::runtime::get()->create_payload(p,8);
const vsomeip::byte_t its_data[] =
{
(
uint8_t
)
d
}
;
std::shared_ptr<vsomeip::payload> payload = vsomeip::runtime::get()->create_payload();
payload->set_data(its_data, sizeof(its_data));
//Publish
std::set<vsomeip::eventgroup_t> event_group;
...
...
@@ -89,23 +91,6 @@ void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::publish${pub.getName()}
}
</#
list
>
<#
list
model.getIncomingPorts() as sub>
void
<@m.mwIdent/>Adapter_$
{
model
.getEscapedCompName
()}
::on_state_$
{
sub
.getName
()}
(vsomeip::state_type_e _state)
{
if
(
_
state
==
vsomeip
::
state_type_e
::
ST
_
REGISTERED
)
{
$
{
sub
.getName
()}
_
S
ubscriber-
>
request_service
(
$
{
model
.getServiceId
(
sub
)},
$
{
model
.getInstanceId
(
sub
)})
;
}
}
</#
list
>
void
<@m.mwIdent/>Adapter_$
{
model
.getEscapedCompName
()}
::on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available)
{
std
::
cout
<<
"Service ["
<<
std
::
setw
(
4
)
<<
std
::
setfill
(
'
0
'
)
<<
std
::
hex
<<
_
service
<<
"."
<<
_
instance
<<
"] is "
<<
(
_
is_available
?
"available."
:
"NOT available."
)
<<
std
::
endl
;
}
void
<@m.mwIdent/>Adapter_$
{
model
.getEscapedCompName
()}
::tick()
{
...
...
src/main/resources/de/monticore/lang/monticar/generator/someip/template/Adapter.h.ftl
View file @
75e2790c
...
...
@@ -3,7 +3,6 @@
#
pragma
once
#
include
"$
{
model
.getEscapedCompName
()}
.h"
#
include
"IAdapter_$
{
model
.getEscapedCompName
()}
.h"
#
include
<iomanip>
#
include
<iostream>
#
include
<sstream>
...
...
@@ -32,16 +31,17 @@ private:
<#
list
model
.getIncomingPorts
()
as
sub
>
std
::
shared_ptr
<
vsomeip
::
application
>
$
{
sub
.getName
()}
_
S
ubscriber
;
std
::
mutex
mutex_
$
{
sub
.getName
()}
;
std
::
condition_variable
condition_
$
{
sub
.getName
()}
;
void
on_message_
$
{
sub
.getName
()}(
const
std
::
shared_ptr
<
vsomeip
::
message
>
&_
request
)
;
void
on_state_
$
{
sub
.getName
()}(
vsomeip
::
state_type_e
_
state
)
;
void
run_
$
{
sub
.getName
()}()
;
void
on_message_
$
{
sub
.getName
()}(
const
std
::
shared_ptr
<
vsomeip
::
message
>
&_
message
)
;
void
on_availability_
$
{
sub
.getName
()}(
vsomeip
::
service_t
_
service
,
vsomeip
::
instance_t
_
instance
,
bool
_
is_available
)
;
</#
list
>
<#
list
model
.getOutgoingPorts
()
as
pub
>
std
::
shared_ptr
<
vsomeip
::
application
>
$
{
pub
.getName
()}
_
P
ublisher
;
void
publish
$
{
pub
.getName
()}
_
P
ublisher
()
()
;
void
publish
$
{
pub
.getName
()}
_
P
ublisher
()
;
</#
list
>
void
on_availability
(
vsomeip
::
service_t
_
service
,
vsomeip
::
instance_t
_
instance
,
bool
_
is_available
)
;
}
;
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