Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1498189
AppSystem.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Size
9 KB
Referenced Files
None
Subscribers
None
AppSystem.hpp
View Options
//===-- rosa/app/AppSystem.hpp ----------------------------------*- C++ -*-===//
//
// The RoSA Framework
//
// Distributed under the terms and conditions of the Boost Software License 1.0.
// See accompanying file LICENSE.
//
// If you did not receive a copy of the license file, see
// http://www.boost.org/LICENSE_1_0.txt.
//
//===----------------------------------------------------------------------===//
///
/// \file rosa/app/AppSystem.hpp
///
/// \author David Juhasz (david.juhasz@tuwien.ac.at)
///
/// \date 2017-2020
///
/// \brief Specialization of \c rosa::MessagingSystem for the *application
/// interface*.
///
/// \see \c rosa::app::Application
///
//===----------------------------------------------------------------------===//
#ifndef ROSA_APP_APPSYSTEM_HPP
#define ROSA_APP_APPSYSTEM_HPP
#include
"rosa/core/MessagingSystem.hpp"
#include
"rosa/app/AppAgent.hpp"
#include
"rosa/app/AppSensor.hpp"
namespace
rosa
{
namespace
app
{
/// Implements and extends the \c rosa::MessagingSystem interface to be
/// used by \c rosa::app::Application.
///
/// The class is a specialization of \c rosa::MessagingSystem, where objects
/// of two specialized subtypes of \c rosa::Agent, \c rosa::app::AppSensor
/// and \c rosa::app::AppAgent, constitute a system. The class extends the
/// \c rosa::MessagingSystem interface with features required to implement the
/// *application interface*.
///
/// \see rosa::app::Application
class
AppSystem
:
public
MessagingSystem
{
friend
class
Application
;
friend
class
AppExecutionPolicy
;
public
:
/// Returns an object implementing the \c rosa::app::AppSystem
/// interface.
///
/// \param Name name of the new instance
///
/// \return \c std::unique_ptr for the new instance of
/// \c rosa::AppSystem
static
std
::
unique_ptr
<
AppSystem
>
createSystem
(
const
std
::
string
&
Name
)
noexcept
;
protected
:
/// Creates a new instance.
///
/// \note Protected constructor restricts instantiation for subclasses.
AppSystem
(
void
)
noexcept
=
default
;
public
:
/// Creates a \c rosa::app::AppSensor instance owned by \p this object
/// and returns a \p rosa::AgentHandle for it.
///
/// \tparam MT type of master-input the new \c rosa::app::AppSensor
/// receives
/// \tparam T type of data the new \c rosa::app::AppSensor operates on
///
/// \note Type arguments \p MT and \p T must be instances of \c
/// rosa::app::AppTuple.
///
/// \param Name name of the new \c rosa::app::AppSensor
/// \param MF function to process master-input values
/// \param F function to generate the next value with during normal operation
///
/// \see \c rosa::app::AppSensor::AppSensor.
///
/// \return \c rosa::AgentHandle for new \c rosa::app::AppSensor
template
<
typename
MT
,
typename
T
>
AgentHandle
createSensor
(
const
std
::
string
&
Name
,
std
::
function
<
void
(
std
::
pair
<
MT
,
bool
>
)
>
&&
MF
,
std
::
function
<
T
(
void
)
>
&&
F
)
noexcept
;
/// Creates a \c rosa::app::AppAgent instance owned by \p this object
/// and returns a \c rosa::AgentHandle for it.
///
/// \tparam MT type of master-input the new \c rosa::app::AppAgent
/// receives
/// \tparam T type of data the new \c rosa::app::AppAgent outputs
/// \tparam Ts types of master-output the new \c rosa::app::AppAgent
/// produces
/// \tparam As types of inputs the new \c rosa::app::AppAgent takes
///
/// \note Type arguments \p MT, \p T, \p Ts..., and \p As... must be
/// instances of \c rosa::app::AppTuple.
///
/// \param Name name of the new \c rosa::app::AppAgent
/// \param MF function for the new \c rosa::app::AppAgent to process
/// master-input values and generate master-output with
/// \param F function for the new \c rosa::app::AppAgent to process
/// input values and generate output and master-output with
///
/// \see \c rosa::app::AppAgent::AppAgent.
///
/// \return \c rosa::AgentHandle for new \c rosa::app::AppAgent
template
<
typename
MT
,
typename
T
,
typename
...
Ts
,
typename
...
As
>
AgentHandle
createAgent
(
const
std
::
string
&
Name
,
std
::
function
<
std
::
tuple
<
Optional
<
Ts
>
...
>
(
std
::
pair
<
MT
,
bool
>
)
>
&&
MF
,
std
::
function
<
std
::
tuple
<
Optional
<
T
>
,
Optional
<
Ts
>
...
>
(
std
::
pair
<
As
,
bool
>
...)
>
&&
F
)
noexcept
;
protected
:
/// Tells whether a \c rosa::AgentHandle refers to a
/// \c rosa::app::AppSensor owned by \p this object.
///
/// \param H \c rosa::AgentHandle to check
///
/// \return whether \p H refers to a \c rosa::app::AppSensor owned by
/// \p this object
virtual
bool
isAppSensor
(
const
AgentHandle
&
H
)
const
noexcept
=
0
;
/// Extracts a const qualified \c rosa::app::AppSensor reference from a
/// const qualified \c rosa::AgentHandle if possible.
///
/// The function returns a \c rosa::Optional object containing a const
/// qualified reference to a \c rosa::app::AppSensor object extracted
/// from a const qualified \c rosa::AgentHandle instance if the referred
/// object is of type \c rosa::appAppSensor and owned by \p this object.
/// The returned \c rosa::Optional object is empty otherwise.
///
/// \see rosa::app::AppSystem::isAppSensor
///
/// \param H \c rosa::AgentHandle to extract a \c rosa::app::AppSensor
/// from
///
/// \return const qualified reference to \c rosa::app::AppSensor if
/// \p H refers to an object which is of that type and is owned by \p this
/// object
Optional
<
const
AppSensor
&>
getAppSensor
(
const
AgentHandle
&
H
)
const
noexcept
;
/// Extracts a \c rosa::app::AppSensor reference from a
/// \c rosa::AgentHandle if possible.
///
/// The function returns a \c rosa::Optional object containing a reference to
/// a \c rosa::app::AppSensor object extracted from a
/// \c rosa::AgentHandle instance if the referred object is of type
/// \c rosa::appAppSensor and owned by \p this object. The returned
/// \c rosa::Optional object is empty otherwise.
///
/// \see rosa::app::AppSystem::isAppSensor
///
/// \param H \c rosa::AgentHandle to extract a \c rosa::app::AppSensor
/// from
///
/// \return reference to \c rosa::app::AppSensor if \p H refers to an
/// object which is of that type and is owned by \p this object
Optional
<
AppSensor
&>
getAppSensor
(
AgentHandle
&
H
)
const
noexcept
;
/// Tells whether a \c rosa::AgentHandle refers to a
/// \c rosa::app::AppAgent owned by \p this object.
///
/// \param H \c rosa::AgentHandle to check
///
/// \return whether \p H refers to a \c rosa::app::AppAgent owned by
/// \p this object
virtual
bool
isAppAgent
(
const
AgentHandle
&
H
)
const
noexcept
=
0
;
/// Extracts a const qualified \c rosa::app::AppAgent reference from a
/// const qualified \c rosa::AgentHandle if possible.
///
/// The function returns a \c rosa::Optional object containing a const
/// qualified reference to a \c rosa::app::AppAgent object extracted
/// from a const qualified \c rosa::AgentHandle instance if the referred
/// object is of type \c rosa::appAppAgent and owned by \p this object.
/// The returned \c rosa::Optional object is empty otherwise.
///
/// \see rosa::app::AppSystem::isAppAgent
///
/// \param H \c rosa::AgentHandle to extract a \c rosa::app::AppAgent
/// from
///
/// \return const qualified reference to \c rosa::app::AppAgent if \p H
/// refers to an object which is of that type and is owned by \p this object
Optional
<
const
AppAgent
&>
getAppAgent
(
const
AgentHandle
&
H
)
const
noexcept
;
/// Extracts a \c rosa::app::AppAgent reference from a
/// \c rosa::AgentHandle if possible.
///
/// The function returns a \c rosa::Optional object containing a reference to
/// a \c rosa::app::AppAgent object extracted from a
/// \c rosa::AgentHandle instance if the referred object is of type
/// \c rosa::app::AppAgent and owned by \p this object. The returned
/// \c rosa::Optional object is empty otherwise.
///
/// \see rosa::app::AppSystem::isAppAgent
///
/// \param H \c rosa::AgentHandle to extract a \c rosa::app::AppAgent
/// from
///
/// \return reference to \c rosa::app::AppAgent if \p H refers to an
/// object which is of that type and is owned by \p this object
Optional
<
AppAgent
&>
getAppAgent
(
AgentHandle
&
H
)
const
noexcept
;
};
template
<
typename
MT
,
typename
T
>
AgentHandle
AppSystem
::
createSensor
(
const
std
::
string
&
Name
,
std
::
function
<
void
(
std
::
pair
<
MT
,
bool
>
)
>
&&
MF
,
std
::
function
<
T
(
void
)
>
&&
F
)
noexcept
{
Agent
&
AS
=
createUnit
<
AppSensor
,
MessagingSystem
>
(
[
&
](
const
id_t
Id
,
MessagingSystem
&
S
)
{
return
new
AppSensor
(
atoms
::
SensorKind
,
Id
,
Name
,
S
,
std
::
move
(
MF
),
std
::
move
(
F
));
});
return
{
AS
};
}
template
<
typename
MT
,
typename
T
,
typename
...
Ts
,
typename
...
As
>
AgentHandle
AppSystem
::
createAgent
(
const
std
::
string
&
Name
,
std
::
function
<
std
::
tuple
<
Optional
<
Ts
>
...
>
(
std
::
pair
<
MT
,
bool
>
)
>
&&
MF
,
std
::
function
<
std
::
tuple
<
Optional
<
T
>
,
Optional
<
Ts
>
...
>
(
std
::
pair
<
As
,
bool
>
...)
>
&&
F
)
noexcept
{
Agent
&
AA
=
createUnit
<
AppAgent
,
AppSystem
>
([
&
](
const
id_t
Id
,
AppSystem
&
S
)
{
return
new
AppAgent
(
atoms
::
AgentKind
,
Id
,
Name
,
S
,
std
::
move
(
MF
),
std
::
move
(
F
));
});
return
{
AA
};
}
}
// End namespace app
}
// End namespace rosa
#endif
// ROSA_APP_APPSYSTEM_HPP
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sun, Mar 1, 10:24 PM (23 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
287005
Default Alt Text
AppSystem.hpp (9 KB)
Attached To
Mode
R20 SoC_Rosa_repo
Attached
Detach File
Event Timeline
Log In to Comment