This commit changes how the objects in OpenThread access each other.
It adds a template `Get<Type>()` method in `InstanceLocator`. This
method returns a reference to a given `Type` object belonging to the
OpenThread instance (e.g. `Get<MeshForwarder>()` returns a reference
to `MeshForwarder` object on the OpenThread instance). The
`InstanceLocator` is used as base class of all OpenThread classes so
every class can easily access any other object. This commit also
changes how the main instance is retrieved in `InstanceLocator` for
the single-instance case. The method `GetInstance()` directly uses the
raw buffer `gInstanceRaw`. This change helps make the `GetInstance()`
and in turn all `Get<Type>()` methods in-line. This commit also
removes the existing getters across all classes to use the new
`Get<Type>()` model.
This commit makes the following changes: It defines the public
`otInstance` as an empty opaque structure which is used by all public
C OpenThread APIs. It defines a new class `ot::Instance` (inheriting
from `otInstance) which is then used in core source files. The
functionality related to the instance is also moved/added into the
newly added `Instance` class (as class/static or member methods).
This commit updates the `MessageQueue` implementation to allow
messages to be added to head/front of the queue. It adds new methods
to the `MessageQueue` class and a corresponding one in public
OpenThread APIs (`otMessageQueueEnqueueAtHead()`). This commit also
updates the `test_message_queue` unit test to add cases/scenarios for
testing the new methods and public APIs.
This commit new configuration option `enable-multiple-instances` and
its corresponding option `OPENTHREAD_ENABLE_MULTIPLE_INSTANCES`. When
enabled OpenThread supports handling of multiple instances. By default
this is disabled.
This commit also adds two optimizations for single instance case to
simplify the code and also help reduce memory/RAM usage:
(1) OpenThread objects/classes typically keep a reference to a higher
level object (e.g., many classes keep track of owning `ThreadNetif`)
to be able to access other objects/methods within OpenThread class
hierarchy. In single instance mode, the reference member variables are
removed and instead global functions are used to access the singleton
objects from one class to the other. To implement this, a group of
`<Object>Locator` classes are defined (e.g., `ThreadNetifLocator`,
etc.) which are then used as base class of other OpenThread classes.
(2) OpenThread objects which provide a callback/handler (e.g.,
`Timer`, `Tasklet`, etc.) have `void *mContext` member variable which
is used to keep track of the owner of the object. In single instance
mode the `mConext` member variables are removed since the owner is
expected to be a singleton and can be uniquely determined from the
callback function.
To implement this, two changes are made: First the handler methods are
modified to provide a reference to the object (e.g., `Timer` handler
will provide a `Timer &aTimer` as a parameter of its handler
callback). Second, a new base class `Context` is introduced which
hides the implementation providing an arbitrary context information. A
new static method `GetOwner(aContext)` is added to classes which own a
callback providing objects. This method help convert a `Context` to
the reference of the owner class object.
* change user mode openthread to enable dynamic memory allocation in mbedtls
* complete merge by adding OPENTHREAD_MULTIPLE_INSTANCE to last file
* remove some extraneous changes that got pulled in accidentally
* fix spacing
* fix crash in existing tests due to this change
* fix x86 build
This commit contains the following:
- It adds methods to `Message` to assign a priority level to messages.
Currently there are four priority levels: High, Medium, Low, VeryLow
but this is easily changeable.
- It introduces a new class `PriorityQueue` which implements a FIFO queue
for storing messages based on their priority level in addition to oder
in which they are added.
If the priority level of an already queued message in a `PriorityQueue`
is changed, the associated queue will automatically move the message
within the queue based on its new priority level.
Internally the implementation uses a circular doubly linked-list with
an array of tail pointers associated with different priority levels.
- It adds new methods and an `Iterator` class in `MessagePool` to access
the priority queue where all allocated and queued messages from this
pool are stored. The `Iterator` class allows bi-directional iteration
through the list (from highest priority to lowest or reverse).
- This commit also contain detailed unit-test for all the newly added
features/methods.
This commit makes the following changes:
- It adds a unit test for testing different `MessageQueue` operations.
- It modifies how the `MessageQueue` determines the lists (the `kListAll`
is maintained by the message pool and the `kListInterface` is accessed
from the `MessageQueue` associated with the list).
- It modifies the underlying list implementation to use a circular doubly
linked-list.