# mirror defined list of parameters to a remote object (e.g. SECoP)
namespace eval mirror {
}

proc stdConfig::mirror {pars} {
  controller syncedprot
  variable node

  pollperiod 0.25 0.25

  obj MIRROR -text wr
  default $pars
  prop read mirror::update
  prop write mirror::stdSct::completeUpdate
  kids "mirror settings" {
  }
}

proc mirror::update {} {
  if {[catch {
    set vpar [hval [sct]]
    set pars [hlist $vpar]
    set now [DoubleTime]
    set timestamp 0
    foreach par $pars {
      if {$par ne "timestamp"} {
        set par [string map {_ .} $par]
        set value [get_var_value $par]
        if {$value != [hval $vpar/$par]} {
          hset $vpar/$par $value
          set timestamp $now
        }
      }
    }
    if {$timestamp != 0} {
      hset $vpar/timestamp $timestamp
    }

  } msg]} {
    hset $vpar/timestamp [DoubleTime]
    hupdate [sct]/status $msg
  } else {
    hupdate [sct]/status ""
  }
  return idle
}
