Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F27036599
MessagingSystem.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
MessagingSystem.hpp
View Options
/*******************************************************************************
*
* File: MessagingSystem.hpp
*
* Contents: Declaration of the class MessagingSystem.
*
* Copyright 2017
*
* Author: David Juhasz (david.juhasz@tuwien.ac.at)
*
******************************************************************************/
#ifndef ROSA_CORE_MESSAGINGSYSTEM_HPP
#define ROSA_CORE_MESSAGINGSYSTEM_HPP
#include
"rosa/core/AgentHandle.hpp"
#include
"rosa/core/System.hpp"
#include
"rosa/support/atom.hpp"
namespace
rosa
{
// Extends the System interface with features to create Agents and register
// Messages for them.
class
MessagingSystem
:
public
System
{
friend
class
AgentHandle
;
// AgentHandle is our friend.
public
:
// Returns an object implementing the interface defined by the class.
static
std
::
unique_ptr
<
MessagingSystem
>
createSystem
(
const
std
::
string
&
Name
)
noexcept
;
private
:
// Kind used for Unit categorization of Agents.
static
constexpr
AtomValue
AgentKind
=
atom
(
"agent"
);
protected
:
// Ctor.
MessagingSystem
(
void
)
noexcept
=
default
;
protected
:
// Creates an Agent owned by the MessagingSystem and returns a handle for it.
// NOTE: Agent requires at least one Fun for its constructor, but derived
// classes may do not need that. That's the reason of allowing even zero Funs
// for this template function.
// STATIC PRE: std::is_base_of<Agent, T>::value
template
<
typename
T
,
typename
...
Funs
>
AgentHandle
createAgent
(
const
std
::
string
&
Name
,
Funs
&&
...
Fs
);
public
:
// Sends the given Message to the Agent referred by the given AgentHandle.
// NOTE: If the given Message cannot be handled by the referred Agent, the
// Message is simply ignored.
// PRE: isUnitRegistered(H.agent())
virtual
void
send
(
const
AgentHandle
&
H
,
message_t
&&
M
)
noexcept
=
0
;
// Convenience template, which creates the Message from the given constant
// lvalue references and sends to the Agent.
// PRE: isUnitRegistered(H.agent())
template
<
typename
Type
,
typename
...
Types
>
void
send
(
const
AgentHandle
&
H
,
const
Type
&
T
,
const
Types
&
...
Ts
)
noexcept
;
// Convenience template, which creates the Message from the given rvalue
// references and sends to the Agent.
// PRE: isUnitRegistered(H.agent())
template
<
typename
Type
,
typename
...
Types
>
void
send
(
const
AgentHandle
&
H
,
Type
&&
T
,
Types
&&
...
Ts
)
noexcept
;
};
template
<
typename
T
,
typename
...
Funs
>
AgentHandle
MessagingSystem
::
createAgent
(
const
std
::
string
&
Name
,
Funs
&&
...
Fs
)
{
STATIC_ASSERT
((
std
::
is_base_of
<
Agent
,
T
>::
value
),
"not an Agent"
);
Agent
&
A
=
createUnit
<
T
,
MessagingSystem
>
([
&
](
const
id_t
Id
,
MessagingSystem
&
S
)
noexcept
{
return
new
T
(
AgentKind
,
Id
,
Name
,
S
,
std
::
move
(
Fs
)...);
});
return
{
A
};
}
template
<
typename
Type
,
typename
...
Types
>
void
MessagingSystem
::
send
(
const
AgentHandle
&
H
,
const
Type
&
T
,
const
Types
&
...
Ts
)
noexcept
{
send
(
H
,
Message
::
create
<
Type
,
Types
...
>
(
T
,
Ts
...));
}
template
<
typename
Type
,
typename
...
Types
>
void
MessagingSystem
::
send
(
const
AgentHandle
&
H
,
Type
&&
T
,
Types
&&
...
Ts
)
noexcept
{
send
(
H
,
Message
::
create
<
Type
,
Types
...
>
(
std
::
move
(
T
),
std
::
move
(
Ts
)...));
}
}
// End namespace rosa
#endif
// ROSA_CORE_MESSAGINGSYSTEM_HPP
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Tue, Oct 27, 8:04 PM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
411437
Default Alt Text
MessagingSystem.hpp (3 KB)
Attached To
Mode
R20 SoC_Rosa_repo
Attached
Detach File
Event Timeline