Function device_vars_Initialize(msgPort as Object, userVariables as Object, bsp as Object)
    plugin = {}
    plugin.msgPort = msgPort
    plugin.userVariables = userVariables
    plugin.bsp = bsp
    plugin.objectName = "device_vars"
    plugin.ProcessEvent = device_vars_ProcessEvent

    device_vars_SetVars(plugin)

    return plugin
End Function


Function device_vars_ProcessEvent(event as Object) as Boolean
    return false
End Function


Sub device_vars_SetVars(plugin as Object)
    serial$ = ""
    hostname$ = ""
    ip$ = ""

    di = CreateObject("roDeviceInfo")
    if di <> invalid then
        serial$ = di.GetDeviceUniqueId()
    end if

    nc = CreateObject("roNetworkConfiguration", 0)
    if nc <> invalid then
        hostname$ = nc.GetHostname()

        current = nc.GetCurrentConfig()
        if current <> invalid then
            if current.DoesExist("ip4_address") then
                ip$ = current["ip4_address"]
            else if current.DoesExist("ip_address") then
                ip$ = current["ip_address"]
            end if
        end if
    end if

    device_vars_SetUserVar(plugin.userVariables, "bb_serial", serial$)
    device_vars_SetUserVar(plugin.userVariables, "bb_hostname", hostname$)
    device_vars_SetUserVar(plugin.userVariables, "bb_ip", ip$)
End Sub


Sub device_vars_SetUserVar(userVariables as Object, name$ as String, value$ as String)
    if userVariables = invalid then return

    uv = userVariables.Lookup(name$)
    if uv <> invalid then
        uv.SetCurrentValue(value$, true)
    end if
End Sub