Commit 14876b2e authored by Jens Korinth's avatar Jens Korinth
Browse files

Implement support for capability field in Status Core

parent 2a3e6856
......@@ -28,5 +28,8 @@
}, {
"Domain" : "Memory",
"Frequency" : 200
} ]
}
\ No newline at end of file
} ],
"Capabilities" : {
"Capabilities 0" : 1
}
}
......@@ -166,13 +166,31 @@ package object json {
}
/** Clocks @} */
/** @{ Capabilities **/
implicit object CapBitsWrites extends Writes[CapBits] {
def reads(json: JsValue): JsResult[CapBits] = json match {
case JsNumber(d) => JsSuccess(d.toLong)
case _ => JsError(Seq(JsPath() -> Seq(JsonValidationError("validation.error.expected.jsnumber"))))
}
def writes(cs: CapBits): JsValue = JsNumber(cs)
}
implicit val capabilitiesReads: Reads[Capabilities] =
(JsPath \ "Capabilities 0").read[CapBits] fmap (Capabilities.apply _)
implicit object CapabilitiesWrites extends Writes[Capabilities] {
def writes(cs: Capabilities): JsValue = JsObject(Seq("Capabilities 0" -> Json.toJson(cs.cap0)))
}
/** Capabilities @} */
/** @{ Status */
implicit val statusFormat: Format[Status] = (
(JsPath \ "Composition").format[Seq[Slot]] ~
(JsPath \ "Timestamp").format[Int] ~
(JsPath \ "Interrupt Controllers").format[Int] ~
(JsPath \ "Versions").format[Versions] ~
(JsPath \ "Clocks").format[Clocks]
(JsPath \ "Clocks").format[Clocks] ~
(JsPath \ "Capabilities").format[Capabilities]
) (Status.apply _, unlift(Status.unapply _))
/** Status @} */
}
......
......@@ -61,11 +61,15 @@ package object tapasco_status {
final case class Empty (slot: SlotId) extends Slot
}
type CapBits = Long
final case class Capabilities(cap0: CapBits)
final case class Status(config: Seq[Slot],
timestamp: Int,
interruptControllers: Int,
versions: Versions,
clocks: Clocks) {
clocks: Clocks,
capabilities: Capabilities) {
require (config.nonEmpty, "a status configuration must not be empty")
require ((config map (_.slot)).toSet.size == config.length, "slot ids must be unique")
}
......
......@@ -65,11 +65,18 @@ package object generators {
slots <- Gen.pick(n, Gen.lzy(genSlot(Some(0))), Gen.lzy(genSlot(Some(1))), 2 until NUM_SLOTS map (s => Gen.lzy(genSlot(Some(s)))):_*)
} yield slots
val genCapBits: Gen[CapBits] = Gen.choose(0L, (1L << 32) - 1)
val genCapabilities: Gen[Capabilities] = for {
cap0 <- genCapBits
} yield Capabilities(cap0)
implicit val genStatus: Gen[Status] = for {
config <- genConfig
timestamp <- genTimestamp
interruptControllers <- genInterruptControllers
versions <- genVersions
clocks <- genClocks
} yield Status(config, timestamp, interruptControllers, versions, clocks)
capabilities <- genCapabilities
} yield Status(config, timestamp, interruptControllers, versions, clocks, capabilities)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment