Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / ReadHandler.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    All rights reserved.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19 /**
20  *    @file
21  *     This file defines read handler for a CHIP Interaction Data model
22  *
23  */
24
25 #pragma once
26
27 #include <app/InteractionModelDelegate.h>
28 #include <core/CHIPCore.h>
29 #include <core/CHIPTLVDebug.hpp>
30 #include <messaging/ExchangeContext.h>
31 #include <messaging/ExchangeMgr.h>
32 #include <messaging/Flags.h>
33 #include <protocols/Protocols.h>
34 #include <support/CodeUtils.h>
35 #include <support/DLLUtil.h>
36 #include <support/logging/CHIPLogging.h>
37 #include <system/SystemPacketBuffer.h>
38
39 namespace chip {
40 namespace app {
41 /**
42  *  @class ReadHandler
43  *
44  *  @brief The read handler is responsible for processing a read request, asking the attribute/event store
45  *         for the relevant data, and sending a reply.
46  *
47  */
48 class ReadHandler
49 {
50 public:
51     /**
52      *  Initialize the ReadHandler. Within the lifetime
53      *  of this instance, this method is invoked once after object
54      *  construction until a call to Shutdown is made to terminate the
55      *  instance.
56      *
57      *  @param[in]    apDelegate       InteractionModelDelegate set by application.
58      *
59      *  @retval #CHIP_ERROR_INCORRECT_STATE If the state is not equal to
60      *          kState_NotInitialized.
61      *  @retval #CHIP_NO_ERROR On success.
62      *
63      */
64     CHIP_ERROR Init(InteractionModelDelegate * apDelegate);
65
66     /**
67      *  Shut down the ReadHandler. This terminates this instance
68      *  of the object and releases all held resources.
69      *
70      */
71     void Shutdown();
72     /**
73      *  Process a read request.  Parts of the processing may end up being asynchronous, but the ReadHandler
74      *  guarantees that it will call Shutdown on itself when processing is done (including if OnReadRequest
75      *  returns an error).
76      *
77      *  @param[in]    apExchangeContext    A pointer to the ExchangeContext.
78      *  @param[in]    aPayload             A payload that has read request data
79      *
80      *  @retval #Others If fails to process read request
81      *  @retval #CHIP_NO_ERROR On success.
82      *
83      */
84     CHIP_ERROR OnReadRequest(Messaging::ExchangeContext * apExchangeContext, System::PacketBufferHandle aPayload);
85
86     /**
87      *  Send ReportData to initiator
88      *
89      *  @param[in]    aPayload             A payload that has read request data
90      *
91      *  @retval #Others If fails to send report data
92      *  @retval #CHIP_NO_ERROR On success.
93      *
94      */
95     CHIP_ERROR SendReportData(System::PacketBufferHandle aPayload);
96
97     bool IsFree() const { return mState == HandlerState::Uninitialized; }
98
99     virtual ~ReadHandler() = default;
100
101 private:
102     enum class HandlerState
103     {
104         Uninitialized = 0, //< The handler has not been initialized
105         Initialized,       //< The handler has been initialized and is ready
106         Reportable,        //< The handler has received read request and is waiting for the data to send to be available
107     };
108
109     CHIP_ERROR ProcessReadRequest(System::PacketBufferHandle aPayload);
110
111     void MoveToState(const HandlerState aTargetState);
112
113     const char * GetStateStr() const;
114     CHIP_ERROR ClearExistingExchangeContext();
115
116     Messaging::ExchangeContext * mpExchangeCtx = nullptr;
117     InteractionModelDelegate * mpDelegate      = nullptr;
118
119     // Don't need the response for report data if true
120     bool mSuppressResponse;
121
122     // Retrieve all events
123     bool mGetToAllEvents;
124
125     // Current Handler state
126     HandlerState mState;
127 };
128 } // namespace app
129 } // namespace chip