Skip to content

Commit

Permalink
Create hardware components with no load/store services
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin.lesage committed Apr 12, 2024
1 parent 66e1b97 commit cc1e718
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,45 +82,63 @@ trait BaseHardwareNodeBuilder[T <: Hardware] extends PMLNodeBuilder[T] {
* (the name of the value enclosing the object)
* @example {{{
* val mySimpleTransporter = SimpleTransporter()
* }}}
* @param basics the set of basic services provided, if empty a default store and load services are added
* @param implicitName implicitly retrieved name from the declaration context
* @param p implicitly retrieved relation linking components to their provided services
* @param owner implicitly retrieved name of the platform
* }}}
* @param basics the set of basic services provided, if empty a default store and load services are added
* @param withDefaultServices add default Load/Store services on creation
* @param implicitName implicitly retrieved name from the declaration context
* @param p implicitly retrieved relation linking components to their provided services
* @param owner implicitly retrieved name of the platform
* @return the physical component
* @group publicConstructor
*/
def apply(basics: Set[Service] = Set.empty)(implicit implicitName: Name,
p: ProvideRelation[Hardware, Service],
owner: Owner): T =
apply(Symbol(implicitName.value), basics)
def apply(basics: Set[Service] = Set.empty, withDefaultServices: Boolean = true)(implicit implicitName: Name,
p: ProvideRelation[Hardware, Service],
owner: Owner): T =
apply(Symbol(implicitName.value), basics, withDefaultServices)

/**
* A physical component can be defined by its name and the basic services it provides
* A transporter is only defined by its name, so if the transporter already exists it will
* simply add the services provided by basics
*
* @param name the physical component name
* @param basics the set of basic services provided, if empty a default store and load services are added
* @param p implicitly retrieved relation linking components to their provided services
* @param owner implicitly retrieved name of the platform
* @param name the physical component name
* @param basics the set of basic services provided, if empty a default store and load services are added
* @param withDefaultServices add default Load/Store services on creation
* @param p implicitly retrieved relation linking components to their provided services
* @param owner implicitly retrieved name of the platform
* @return the physical component
* @group publicConstructor
*/
def apply(name: Symbol, basics: Set[Service])(implicit
p: ProvideRelation[Hardware, Service],
owner: Owner): T = {
def apply(name: Symbol, basics: Set[Service], withDefaultServices: Boolean)(implicit
p: ProvideRelation[Hardware, Service],
owner: Owner): T = {
val formattedName = formatName(name, owner)
val result = _memo.getOrElseUpdate((owner.s, formattedName), builder(formattedName))
val mutableBasic = collection.mutable.Set(basics.toSeq: _*)
if (!basics.exists(_.isInstanceOf[Load]))
if (withDefaultServices && !basics.exists(_.isInstanceOf[Load]))
mutableBasic += Load(Symbol(s"${formattedName.name}_load"))
if (!basics.exists(_.isInstanceOf[Store]))
if (withDefaultServices && !basics.exists(_.isInstanceOf[Store]))
mutableBasic += Store(Symbol(s"${formattedName.name}_store"))
p.add(result, mutableBasic)
result
}

/**
* A physical component can be defined by its name and the basic services it provides
*
* @param name the physical component name
* @param basics the set of basic services provided, if empty a default store and load services are added
* @param p implicitly retrieved relation linking components to their provided services
* @param owner implicitly retrieved name of the platform
* @return the physical component
* @group publicConstructor
*/
def apply(name: Symbol, basics: Set[Service])(implicit
p: ProvideRelation[Hardware, Service],
owner: Owner): T = {
apply(name, basics, true)
}

/**
* A physical component can be defined only its name, the services will be defined by default
* @group publicConstructor
Expand All @@ -131,5 +149,5 @@ trait BaseHardwareNodeBuilder[T <: Hardware] extends PMLNodeBuilder[T] {
*/
def apply(name: Symbol)(implicit p: ProvideRelation[Hardware, Service],
owner: Owner): T =
apply(name, Set.empty)
apply(name, Set.empty, true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@ class HardwareTest extends AnyFlatSpec with should.Matchers {
h.services.size shouldBe 2
}
}

it should "have no services when specified" in {
val t: Target = Target(withDefaultServices=false)
val s: SimpleTransporter = SimpleTransporter(withDefaultServices=false)
val i: Initiator = Initiator(withDefaultServices=false)
val v: Virtualizer = Virtualizer(withDefaultServices=false)

for (h <- List(t, s, i, v)) {
h.services shouldBe empty
}
}

}

0 comments on commit cc1e718

Please sign in to comment.