The swu-core library stores objects that represent pending software updates and accessible target systems. It automates many aspects of interacting with these objects, including memory management, data storage, and state transitions throughout the update lifecycle.
The library encapsulates the update data by hiding the implementation of objects. Instead of offering direct access to individual data fields, the library provides a high-level API that uses handles to refer to objects. For example, instead of working with C-strings in an Update object, the caller must use the swu_update_get_name() API function with an swu_update_t handle to access the update name stored in that object.
Many objects in the swu-core library are reference-counted, including:
When working with these handle types, you should call swu_object_retain() to increment the reference count. Most API functions that return these handle types must call this function before exiting. When you're finished with a handle, you should call swu_object_release() to decrement the reference count, to indicate that you no longer need the object associated with that handle. When the reference count reaches zero, the library frees the associated object's memory. Calling the release function when you no longer need a handle is important to prevent memory leaks.
An Update object represents a software update that can be installed by a registered UpdateTarget. All configuration information for the update and all actions to be performed as part of it are specified in API calls to the Update object.
Each Update object contains a state machine that drives the software update process. The machine's state-transition diagram looks like this:
The states of the Update object are:
An UpdateTarget represents a system with updatable software. This object type is generic so the swu-core library can support many different software update models. You can register multiple UpdateTarget objects with the library, each of which has its own implementation. For example, you could register multiple target objects to support updating different micro-controllers on a car's vehicle network.