Document and design the case of object creation

This commit is contained in:
Simon Edwards 2022-04-28 21:18:16 +02:00
parent c733a41d10
commit 4f40510248
5 changed files with 54 additions and 0 deletions

View File

@ -23,3 +23,8 @@ A related use case is where we want to "recycle" wrappers and ensure that for a
Another goal of this use case is to ensure that the unexpected destruction of the underlying QObject is handled in a more graceful and helpful way than just segfaulting the whole application. This requires the tracking of the QObject via its "destroy" signal and using that to communicate back to JS what has happened.
The object creation sequence runs quite differently than in the "Wrapper Keep Alive" case because the application initiates the creation of the object and NodeGui then creates the different wrappers on the JS and C++ sides.
![Wrapper recycle sequence diagram](wrapper_recycle_seq.png)
The destruction sequence in the case of the C++ object being destroyed is basically the same as the "Wrapper Keep Alive" case.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 96 KiB

View File

@ -34,6 +34,9 @@ qwindowts --> qwindowwrap: screen()
qwindowwrap --> qwindow: screen()
qwindow --> qwindowwrap: QScreen instance
qwindowwrap --> wrappercachecpp: get<QScreen, QScreenWrap>()
note over wrappercachecpp
Checks wrapper cache
end note
wrappercachecpp --> qscreenwrap: new()
activate qscreenwrap
qscreenwrap --> wrappercachecpp: QScreenWrap instance

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -0,0 +1,46 @@
@startuml
skinparam object {
backgroundColor White
borderColor Black
arrowColor Black
}
skinparam note {
backgroundColor LightYellow
borderColor Black
}
hide footbox
title Wrapper Recycle
participant App as app << ts >> #E3C800
participant "QObject.ts" as qobjectts << ts>> #E3C800
participant "WrapperCache" as wrappercachets << ts>> #E3C800
participant "QObjectWrap" as qobjectwrap << cpp >>
participant "WrapperCache" as wrappercachecpp << cpp >>
participant "QObject" as qobject << cpp >> #D5E8D4
== Wrapper construction ==
app --> qobjectts: new()
activate qobjectts
qobjectts --> qobjectwrap: new()
activate qobjectwrap
qobjectwrap --> qobject: new()
activate qobject
qobject --> qobjectwrap: QObject instance
qobjectwrap --> wrappercachecpp: store(QObject, QObjectWrap)
wrappercachecpp --> qobject: connect to destroy signal
qobjectwrap --> qobjectts: QOjectWrap instance
qobjectts --> wrappercachets: store(QObject.ts)
qobjectts --> app: QObject instance
note across: The app can use the QObject and run.
@enduml