-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
roCECStatus
component (#430)
* Implemented `roCECStatus` * Updating the interface name of other event objects * Updated limitations document * Added test case for Events and fixed issues
- Loading branch information
Showing
18 changed files
with
274 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { BrsValue, ValueKind, BrsInvalid, BrsBoolean } from "../BrsType"; | ||
import { BrsComponent } from "./BrsComponent"; | ||
import { BrsEvent, BrsType, RoMessagePort } from ".."; | ||
import { Callable, StdlibArgument } from "../Callable"; | ||
import { Interpreter } from "../../interpreter"; | ||
import { RoCECStatusEvent } from "./RoCECStatusEvent"; | ||
import { DataType } from "../../common"; | ||
|
||
export class RoCECStatus extends BrsComponent implements BrsValue { | ||
readonly kind = ValueKind.Object; | ||
private readonly interpreter: Interpreter; | ||
private port?: RoMessagePort; | ||
private active: number; | ||
|
||
constructor(interpreter: Interpreter) { | ||
super("roCECStatus"); | ||
this.interpreter = interpreter; | ||
this.active = 1; // Default to active | ||
this.registerMethods({ | ||
ifCECStatus: [this.isActiveSource, this.getMessagePort, this.setMessagePort], | ||
}); | ||
} | ||
|
||
toString(parent?: BrsType): string { | ||
return "<Component: roCECStatus>"; | ||
} | ||
|
||
equalTo(other: BrsType) { | ||
return BrsBoolean.False; | ||
} | ||
|
||
dispose() { | ||
this.port?.unregisterCallback(this.getComponentName()); | ||
} | ||
|
||
// System Log Event ------------------------------------------------------------------------------- | ||
|
||
private getNewEvents() { | ||
const events: BrsEvent[] = []; | ||
const cecActive = Atomics.load(this.interpreter.sharedArray, DataType.CEC); | ||
if (cecActive >= 0 && cecActive !== this.active) { | ||
this.active = cecActive; | ||
events.push(new RoCECStatusEvent(this.active !== 0)); | ||
} | ||
return events; | ||
} | ||
|
||
// ifCECStatus --------------------------------------------------------------------------------- | ||
|
||
/** Indicates whether the device is the active source. */ | ||
private readonly isActiveSource = new Callable("isActiveSource", { | ||
signature: { | ||
args: [], | ||
returns: ValueKind.Boolean, | ||
}, | ||
impl: (_: Interpreter) => { | ||
const cecActive = Atomics.load(this.interpreter.sharedArray, DataType.CEC); | ||
return BrsBoolean.from(cecActive !== 0); | ||
}, | ||
}); | ||
|
||
/** Returns the message port (if any) currently associated with the object */ | ||
private readonly getMessagePort = new Callable("getMessagePort", { | ||
signature: { | ||
args: [], | ||
returns: ValueKind.Object, | ||
}, | ||
impl: (_: Interpreter) => { | ||
return this.port ?? BrsInvalid.Instance; | ||
}, | ||
}); | ||
|
||
/** Sets the roMessagePort to be used for all events from the screen */ | ||
private readonly setMessagePort = new Callable("setMessagePort", { | ||
signature: { | ||
args: [new StdlibArgument("port", ValueKind.Dynamic)], | ||
returns: ValueKind.Void, | ||
}, | ||
impl: (_: Interpreter, port: RoMessagePort) => { | ||
const component = port.getComponentName(); | ||
this.port?.unregisterCallback(component); | ||
this.port = port; | ||
this.port.registerCallback(component, this.getNewEvents.bind(this)); | ||
return BrsInvalid.Instance; | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { BrsValue, ValueKind, BrsBoolean, BrsString } from "../BrsType"; | ||
import { BrsComponent } from "./BrsComponent"; | ||
import { BrsType, Int32, toAssociativeArray } from ".."; | ||
import { Callable } from "../Callable"; | ||
import { Interpreter } from "../../interpreter"; | ||
|
||
export class RoCECStatusEvent extends BrsComponent implements BrsValue { | ||
readonly kind = ValueKind.Object; | ||
private readonly active: boolean; | ||
|
||
constructor(active: boolean) { | ||
super("roCECStatusEvent"); | ||
this.active = active; | ||
this.registerMethods({ | ||
ifroCECStatusEvent: [this.getInfo, this.getIndex, this.getMessage], | ||
}); | ||
} | ||
|
||
toString(parent?: BrsType): string { | ||
return "<Component: roCECStatusEvent>"; | ||
} | ||
|
||
equalTo(other: BrsType) { | ||
return BrsBoolean.False; | ||
} | ||
|
||
/** The index value of this event is not used and is always set to 0. */ | ||
private readonly getIndex = new Callable("getIndex", { | ||
signature: { | ||
args: [], | ||
returns: ValueKind.Int32, | ||
}, | ||
impl: (_: Interpreter) => { | ||
return new Int32(0); | ||
}, | ||
}); | ||
|
||
/** Returns the string "CECStatus". */ | ||
private readonly getMessage = new Callable("getMessage", { | ||
signature: { | ||
args: [], | ||
returns: ValueKind.String, | ||
}, | ||
impl: (_: Interpreter) => { | ||
return new BrsString("CECStatus"); | ||
}, | ||
}); | ||
|
||
/** Returns an roAssociativeArray with the current status of the device or the caption mode. */ | ||
private readonly getInfo = new Callable("getInfo", { | ||
signature: { | ||
args: [], | ||
returns: ValueKind.Object, | ||
}, | ||
impl: (_: Interpreter) => { | ||
const state = this.active ? "ACTIVE" : "INACTIVE"; | ||
return toAssociativeArray({ Active: this.active, ActiveSourceState: state }); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
sub main() | ||
port = CreateObject("roMessagePort") | ||
di = CreateObject("roDeviceInfo") | ||
di.SetMessagePort(port) | ||
cec = CreateObject("roCECStatus") | ||
print "roCECStatus.isActiveSource() = "; cec.isActiveSource() | ||
cec.SetMessagePort(port) | ||
syslog = CreateObject("roSystemLog") | ||
syslog.SetMessagePort(port) | ||
syslog.EnableType("bandwidth.minute") | ||
store = CreateObject("roChannelStore") | ||
store.SetMessagePort(port) | ||
store.GetCatalog() | ||
for t = 1 to 10 | ||
msg = port.getMessage() | ||
print type(msg) | ||
if type(msg) = "roCECStatusEvent" | ||
print msg.getMessage() | ||
print msg.getIndex() | ||
print msg.getInfo() | ||
print FindMemberFunction(msg, "getInfo") | ||
else if type(msg) = "roDeviceInfoEvent" | ||
print "roDeviceInfoEvent.isCaptionModeChanged = "; msg.isCaptionModeChanged() | ||
print "roDeviceInfoEvent.isStatusMessage = "; msg.isStatusMessage() | ||
print msg.getInfo() | ||
print FindMemberFunction(msg, "getInfo") | ||
else if type(msg) = "roChannelStoreEvent" | ||
print msg.getResponse() | ||
print FindMemberFunction(msg, "getResponse") | ||
else if type(msg) = "roSystemLogEvent" | ||
logEvent = msg.getInfo() | ||
if logEvent.logType = "bandwidth.minute" | ||
print logEvent.logType, logEvent.dateTime.toISOString(), logEvent.bandwidth | ||
end if | ||
print FindMemberFunction(msg, "getInfo") | ||
else msg = invalid | ||
exit for | ||
end if | ||
end for | ||
end sub |
Oops, something went wrong.