|
15 | 15 | * See the License for the specific language governing permissions and
|
16 | 16 | * limitations under the License.
|
17 | 17 | */
|
18 |
| - |
19 |
| -/** |
20 |
| - * @file |
21 |
| - * Definition of a handler for timed interactions. |
22 |
| - * |
23 |
| - */ |
24 |
| - |
25 | 18 | #pragma once
|
26 | 19 |
|
| 20 | +#include <app/InteractionModelDelegatePointers.h> |
27 | 21 | #include <messaging/ExchangeContext.h>
|
28 | 22 | #include <messaging/ExchangeDelegate.h>
|
29 | 23 | #include <system/SystemClock.h>
|
30 | 24 | #include <system/SystemLayer.h>
|
31 | 25 | #include <system/SystemPacketBuffer.h>
|
32 | 26 | #include <transport/raw/MessageHeader.h>
|
33 | 27 |
|
| 28 | +namespace chip { |
| 29 | +namespace app { |
| 30 | + |
| 31 | +class TimedHandler; |
| 32 | + |
34 | 33 | /**
|
35 | 34 | * A TimedHandler handles a Timed Request action and then waits for a
|
36 | 35 | * subsequent Invoke or Write action and hands those on to
|
|
43 | 42 | * either the exchange is closed or the interaction is handed on to the
|
44 | 43 | * InteractionModelEngine.
|
45 | 44 | */
|
| 45 | +class TimedHandlerDelegate |
| 46 | +{ |
| 47 | +public: |
| 48 | + virtual ~TimedHandlerDelegate() = default; |
46 | 49 |
|
47 |
| -namespace chip { |
48 |
| -namespace app { |
| 50 | + /** |
| 51 | + * Called when a timed invoke is received. This function takes over all |
| 52 | + * handling of the exchange, status reporting, and so forth. |
| 53 | + */ |
| 54 | + virtual void OnTimedInvoke(TimedHandler * apTimedHandler, Messaging::ExchangeContext * apExchangeContext, |
| 55 | + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) = 0; |
| 56 | + |
| 57 | + /** |
| 58 | + * Called when a timed write is received. This function takes over all |
| 59 | + * handling of the exchange, status reporting, and so forth. |
| 60 | + */ |
| 61 | + virtual void OnTimedWrite(TimedHandler * apTimedHandler, Messaging::ExchangeContext * apExchangeContext, |
| 62 | + const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) = 0; |
| 63 | + |
| 64 | + /** |
| 65 | + * Called when a timed interaction has failed (i.e. the exchange it was |
| 66 | + * happening on has closed while the exchange delegate was the timed |
| 67 | + * handler). |
| 68 | + */ |
| 69 | + virtual void OnTimedInteractionFailed(TimedHandler * apTimedHandler) = 0; |
| 70 | +}; |
49 | 71 |
|
50 | 72 | class TimedHandler : public Messaging::ExchangeDelegate
|
51 | 73 | {
|
52 | 74 | public:
|
53 |
| - TimedHandler() {} |
| 75 | + TimedHandler(TimedHandlerDelegate * delegate) : mDelegate(delegate) {} |
54 | 76 | ~TimedHandler() override {}
|
55 | 77 |
|
56 | 78 | // ExchangeDelegate implementation.
|
@@ -83,15 +105,31 @@ class TimedHandler : public Messaging::ExchangeDelegate
|
83 | 105 | kExpectingFollowingAction, // Expecting write or invoke.
|
84 | 106 | };
|
85 | 107 |
|
86 |
| - // Because we have a vtable pointer and mTimeLimit needs to be 8-byte |
87 |
| - // aligned on ARM, putting mState first here means we fit in 16 bytes on |
88 |
| - // 32-bit ARM, whereas if we put it second we'd be 24 bytes. |
89 |
| - // On platforms where either vtable pointers are 8 bytes or 64-bit ints can |
90 |
| - // be 4-byte-aligned the ordering here does not matter. |
91 | 108 | State mState = State::kExpectingTimedAction;
|
| 109 | + |
| 110 | + /// This may be "fake" pointer or a real delegate pointer, depending |
| 111 | + /// on CHIP_CONFIG_STATIC_GLOBAL_INTERACTION_MODEL_ENGINE setting. |
| 112 | + /// |
| 113 | + /// When this is not a real pointer, it checks that the value is always |
| 114 | + /// set to the global InteractionModelEngine and the size of this |
| 115 | + /// member is 1 byte. |
| 116 | + InteractionModelDelegatePointer<TimedHandlerDelegate> mDelegate; |
| 117 | + |
92 | 118 | // We keep track of the time limit for message reception, in case our
|
93 | 119 | // exchange's "response expected" timer gets delayed and does not fire when
|
94 | 120 | // the time runs out.
|
| 121 | + // |
| 122 | + // NOTE: mTimeLimit needs to be 8-byte aligned on ARM so we place this last, |
| 123 | + // to allow previous values to potentially use remaining packing space. |
| 124 | + // Rationale: |
| 125 | + // - vtable is 4-byte aligned on 32-bit arm |
| 126 | + // - mTimeLimit requires 8-byte aligment |
| 127 | + // => As a result we may gain 4 bytes if we place mTimeLimit last. |
| 128 | + // Expectation of memory layout: |
| 129 | + // - vtable pointer (4 bytes & 4 byte alignment) |
| 130 | + // - other members (2 bytes on embedded "global pointer" arm) |
| 131 | + // (2 bytes padding for 8-byte alignment) |
| 132 | + // - mTimeLimit (8 bytes & 8 byte alignment) |
95 | 133 | System::Clock::Timestamp mTimeLimit;
|
96 | 134 | };
|
97 | 135 |
|
|
0 commit comments