Skip to content

Add availability-polling + logging, and cleanup backend - #4

Open
deathvelt wants to merge 1 commit into
minecraft-access:devfrom
deathvelt:prism-integration
Open

Add availability-polling + logging, and cleanup backend#4
deathvelt wants to merge 1 commit into
minecraft-access:devfrom
deathvelt:prism-integration

Conversation

@deathvelt

Copy link
Copy Markdown

#2. General refactors.

These are all a lot of refactors, so this PR is bigger than usual.

backend Feature:
This was overhauled to be sleaker. It is now an enum, with 28 values only. You can check if a feature is supported using

long features = backend.getFeatures();
if(BackendFeature.SUPPORTS_STOP.isSupportedBy(features)) ...

The reason is that the old code was already very hard to maintain because there were multiple places in which the full set of 28 enum values were repeated.

BackendId:
This was made into a record with the default prism backend IDs as static constants. We can allow for any backend ID hash to be represented now where as before, we could not.

Logging:
Logging should be bound and hookable, now. It has been tested and found working. You can set listeners to pipe the output to your client's logger, determine which severity should be logged, etcetera.

Prism exception and prism error:
PrismError is now an enum. Each enum value references one of the exception classes in PrismException. Thus, the throwIfError method was heavily simplified.

Context:
Availability polling is now supported. Its values are available on context, and there is now a builder to construct the context with whatever values for PollInterval/Debounce/AutoPowerManagement/BackoffMaxMs, as well as the other functions like pause and resume availability polling.
From what tests were committed on a live instance of MC with this library, this seemed to work well enough, with repeated restarting of NVDA and a few other scenarios.
Context also now has getRegisteredBackends() to get all the backends registered with prism.

Backend:
close always frees now, as per prism convention. The owned flag was removed because it prevented the context from acquiring a better backend when availability changed due to not freeing if it was false.
A lot of the boilerplate was simplified by wrapping. locked() performs the operations of checking if closed + synchronized with the lock. OutCall is a functional interface which is used to get the resulting out values from a call, etcetera.
The backend is also now synchronized with a lock since prism docs state that backend instances are not thread-safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant