UMDF: Access device registry key inside a EVT_WDF_TIMER callback function - driver

I am having issues with a UMDF driver retrieving data stored in the device registry from a EVT_WDF_TIMER callback function. Such callback function only has WDFTIMER object as its sole parameter. To be able to access registry in UMDF, WdfDeviceOpenRegistryKey requires a pointer to the WDFDEVICE object. Prior to the callback function being called, my WDFTimer, which calls the callback function after the timer has elapsed, is created by WdfTimerCreate. I have provided the appropriate WDF_OBJECT_ATTRIBUTES as well, one of the attributes being a WDFOBJECT ParentObject where I assigned the WDFDEVICE object into.
Now, I was hoping I could retrieve the WDFDEVICE object I added in WDF_OBJECT_ATTRIBUTES, but it seems inaccessible from the WDFTIMER parameter. I am left wondering, is there any way I could retrieve a pointer to my WDFDEVICE from the EVT_WDF_TIMER callback function?

You can use WdfTimerGetParentObject to retrieve the WDFOBJECT.

Related

How do maxKeyCount and addPositiveDiagnosisKeys interact?

I'm learning the new Contact Tracing API that Apple is releasing for iOS (in partnership with Google).
I'm not gasping the relationship of the maxKeyCount property on the CTExposureDetectionSession, and its relationship with the addPositiveDiagnosisKeys: completion: method.
What I understand
A CTExposureDetectionSession is the object that allows an app to ask the framework to start trying to match a list of published Diagnosis Keys against the local database of captured Rolling Proximity Identifiers.
The app would start by calling the activateWithCompletion: method on a new session, and then call addPositiveDiagnosisKeys: one or more times, to eventually inform the framework that no more keys are to be added by calling finishedPositiveDiagnosisKeysWithCompletion:.
That last call will also indicate the block to run upon detection completion, which will be called with a CTExposureDetectionSummary object informing the amount of Diagnosis Keys that the device has been exposed to.
What I do not understand
The maxKeyCount property doc says:
This property contains the maximum number of keys to provide to this API at once. This property’s value updates after each operation complete and before the completion handler is invoked. Use this property to throttle key downloads to avoid excessive buffering of keys in memory.
But the addPositiveDiagnosisKeys: method says:
Asynchronously adds the specified keys to the session to allow them to be checked for exposure. Each call to this method must include more keys than specified by the current value of <maxKeyCount>.
maxKeyCount seems to be a maximum, but the addPositiveDiagnosisKeys: requires me to call it with more keys than the maximum.
Am I expected to call the method with a superlist of the previously sent list? That doesn't seem to fit well with the "avoid excessive buffering of keys in memory" part - if I have to use an ever-growing list of keys.
And what does the This property’s value updates after each operation complete part?
The documentation of maxKeyCount is missing a not.
The Android Contact Tracing API documentation has an analogous interface:
/**
* Provides a list of diagnosis keys for contact checking. The keys are to be
* provided by a centralized service (e.g. synced from the server).
*
* When invoked after the requestProvideDiagnosisKeys callback, this triggers a * recalculation of contact status which can be obtained via hasContact()
* after the calculation has finished. *
* Should be called with a maximum of N keys at a time. */
Task<Status> provideDiagnosisKeys(List<DailyTracingKey> keys);
/**
* The maximum number of keys to pass into provideDiagnosisKeys at any given * time.
*/
int getMaxDiagnosisKeys();
As Paulw11 suggested in a comment, the maxKeyCount property seems to be a value intended for reading that stats how many Diagnosis Keys are to be sent to the API in a single call for the matching to be performed.
Callers should re-check the value before each call, since it may get updated after each call.
The fixed documentation of addPositiveDiagnosisKeys: should, then, read:
Each call to this method must NOT include more keys than specified by the current value of <maxKeyCount>.

Swift: How do I store an array of object by reference from completion handler (closure)?

There's a API callback returns a Json format result. The requirement in short is that I need to keep calling this API and keeps implement Breadth First Search on the results it returns.
Imaging it's a map with many nodes and connections. Every time I call API call for a node, it gonna return me list of its connected nodes. All I need now, is an array, which saves all the node that has been visited to avoid repeated visits.
But this is Swift and I am new to it. I was using Array and pass as inout inside the completion handler. But there's an error: escaping closures can only capture inout parameters explicitly by value which means I cannot do it like this.
Now you may ask why the array I have has to be stored by reference. Because the API call is async, which means I have to wait until it comes back to keep progressing Breadth First Search, means I have to pass this array by reference in order to do the recursion.
What other solutions I may have?
Swift Arrays are value types (not reference types) so you will need to store you array in an object. You can then pass the object to your handler and set the array content inside the object which is carried as a reference in the closures.

Cowboy rest resource_exists callback

How does one handle the resource_exists callback in cowboy? After all, to find out whether resource exists - I must query (e.g. database) for resource. But then during the AcceptResource callback (e.g. to_html) I must query for the resource again. Is there any way to prevent this double querying?
Is there any way to preserve that resource for the AcceptResource callback, so that I don't have to pull it form database again?
Reading the cowboy docs, there is flowchart of how a rest request is handled.
In it, the callback resource_exists is called first.
In resource_exists you can add the result of the database query to the State variable that resource_exists returns.
The state is passed as input to the AcceptResource callback where you can use the cached value.

Init object with asynchronously downloaded data

I have an object that needs to be initialised with data from network and doesn't really make sense without the downloaded data. But it seems to me that doing an asynchronous network call in its init method is not a good idea because the object will not be ready to user right away and it might cause confusion. Should I only use a basic init method that will alloc init all its properties to create an empty object, and have other (non-init) methods populate the data from the network which will be called explicitly by other objects (such as the view controller using this object)? What would be a good way to approach this?
I think that the solution comes from having the right order of code running:
1) Go to network and fetch data (show the user acivity indicator in this time)
2) Server return response -> fetch the response into your object
3) Show the data or use it

Vector /List work with Storage in lwuit?

I try to save vector or default list on storage. All work fine until i close the application and open again. When i call to Storage , the storage don't find this vector.
Do have Problem to use this objects with Storage in lwuit?
The writeObject method accepts a second parameter as a Object. It returns true or false. If you object is suitable in the Storage you will get true. Try to put this vector and see what returns this method.
Last week I try to put a custom object and it doesn't work. I think hashtables can be in Storage, but ListModels doesn't.
Storage API

Resources