-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathAndroidCallbacks.h
More file actions
169 lines (133 loc) · 7.47 KB
/
AndroidCallbacks.h
File metadata and controls
169 lines (133 loc) · 7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
*
* Copyright (c) 2020-2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <app/BufferedReadCallback.h>
#include <app/CommandSender.h>
#include <app/ReadClient.h>
#include <app/WriteClient.h>
#include <controller/CHIPDeviceController.h>
#include <jni.h>
#include <lib/core/CHIPError.h>
#include <lib/support/JniTypeWrappers.h>
#include <list>
#include <unordered_map>
#include <utility>
namespace chip {
namespace Controller {
CHIP_ERROR CreateChipAttributePath(JNIEnv * env, const app::ConcreteDataAttributePath & aPath, jobject & outObj);
// Callback for success and failure cases of GetConnectedDevice().
struct GetConnectedDeviceCallback
{
GetConnectedDeviceCallback(
jobject wrapperCallback, jobject javaCallback,
const char * callbackClassSignature = "chip/devicecontroller/GetConnectedDeviceCallbackJni$GetConnectedDeviceCallback");
~GetConnectedDeviceCallback();
static void OnDeviceConnectedFn(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);
static void OnDeviceConnectionFailureFn(void * context, const OperationalSessionSetup::ConnectionFailureInfo & failureInfo);
Callback::Callback<OnDeviceConnected> mOnSuccess;
Callback::Callback<OperationalSessionSetup::OnSetupFailure> mOnFailure;
JniGlobalReference mWrapperCallbackRef;
JniGlobalReference mJavaCallbackRef;
private:
const char * mCallbackClassSignature = nullptr;
};
struct ReportCallback : public app::ClusterStateCache::Callback
{
/** Subscription established callback can be nullptr. */
ReportCallback(jobject wrapperCallback, jobject subscriptionEstablishedCallback, jobject resubscriptionAttemptCallback,
const char * nodeStateClassSignature);
~ReportCallback();
void OnReportBegin() override;
void OnReportEnd() override;
void OnAttributeData(const app::ConcreteDataAttributePath & aPath, TLV::TLVReader * apData,
const app::StatusIB & aStatus) override;
void OnEventData(const app::EventHeader & aEventHeader, TLV::TLVReader * apData, const app::StatusIB * apStatus) override;
void OnError(CHIP_ERROR aError) override;
void OnDone(app::ReadClient *) override;
void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override;
CHIP_ERROR OnResubscriptionNeeded(app::ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override;
void OnDeallocatePaths(app::ReadPrepareParams && aReadPrepareParams) override;
/** Report errors back to Java layer. attributePath may be nullptr for general errors. */
void ReportError(const app::ConcreteAttributePath * attributePath, const app::ConcreteEventPath * eventPath, CHIP_ERROR err);
void ReportError(const app::ConcreteAttributePath * attributePath, const app::ConcreteEventPath * eventPath,
Protocols::InteractionModel::Status status);
void ReportError(const app::ConcreteAttributePath * attributePath, const app::ConcreteEventPath * eventPath,
const char * message, ChipError::StorageType errorCode);
void UpdateClusterDataVersion();
app::ReadClient * mReadClient = nullptr;
app::ClusterStateCache mClusterCacheAdapter;
JniGlobalReference mWrapperCallbackRef;
JniGlobalReference mSubscriptionEstablishedCallbackRef;
JniGlobalReference mResubscriptionAttemptCallbackRef;
const char * mNodeStateClassSignature;
};
struct WriteAttributesCallback : public app::WriteClient::Callback
{
WriteAttributesCallback(jobject wrapperCallback);
~WriteAttributesCallback();
app::WriteClient::Callback * GetChunkedWriteCallback() { return &mChunkedWriteCallback; }
void OnResponse(const app::WriteClient * apWriteClient, const app::ConcreteDataAttributePath & aPath,
app::StatusIB aStatus) override;
/** Report errors back to Java layer. attributePath may be nullptr for general errors. */
void OnError(const app::WriteClient * apWriteClient, CHIP_ERROR aProtocolError) override;
void OnDone(app::WriteClient * apWriteClient) override;
void ReportError(const app::ConcreteAttributePath * attributePath, CHIP_ERROR err);
void ReportError(const app::ConcreteAttributePath * attributePath, Protocols::InteractionModel::Status status);
void ReportError(const app::ConcreteAttributePath * attributePath, const char * message, ChipError::StorageType errorCode);
app::WriteClient * mWriteClient = nullptr;
app::ChunkedWriteCallback mChunkedWriteCallback;
JniGlobalReference mWrapperCallbackRef;
};
struct InvokeCallback : public app::CommandSender::Callback
{
InvokeCallback(jobject wrapperCallback);
~InvokeCallback();
void OnResponse(app::CommandSender * apCommandSender, const app::ConcreteCommandPath & aPath, const app::StatusIB & aStatusIB,
TLV::TLVReader * apData) override;
/** Report errors back to Java layer. attributePath may be nullptr for general errors. */
void OnError(const app::CommandSender * apCommandSender, CHIP_ERROR aError) override;
void OnDone(app::CommandSender * apCommandSender) override;
void ReportError(CHIP_ERROR err);
void ReportError(Protocols::InteractionModel::Status status);
void ReportError(const char * message, ChipError::StorageType errorCode);
app::CommandSender * mCommandSender = nullptr;
JniGlobalReference mWrapperCallbackRef;
};
struct ExtendableInvokeCallback : public app::CommandSender::ExtendableCallback
{
ExtendableInvokeCallback(jobject wrapperCallback);
~ExtendableInvokeCallback();
void OnResponse(app::CommandSender * commandSender, const app::CommandSender::ResponseData & aResponseData) override;
void OnNoResponse(app::CommandSender * commandSender, const app::CommandSender::NoResponseData & aNoResponseData) override;
void OnError(const app::CommandSender * apCommandSender, const app::CommandSender::ErrorData & aErrorData) override;
void OnDone(app::CommandSender * apCommandSender) override;
app::CommandSender * mCommandSender = nullptr;
JniGlobalReference mWrapperCallbackRef;
};
jlong newConnectedDeviceCallback(JNIEnv * env, jobject self, jobject callback);
void deleteConnectedDeviceCallback(JNIEnv * env, jobject self, jlong callbackHandle);
jlong newReportCallback(JNIEnv * env, jobject self, jobject subscriptionEstablishedCallbackJava,
jobject resubscriptionAttemptCallbackJava, const char * nodeStateClassSignature);
void deleteReportCallback(JNIEnv * env, jobject self, jlong callbackHandle);
jlong newWriteAttributesCallback(JNIEnv * env, jobject self);
void deleteWriteAttributesCallback(JNIEnv * env, jobject self, jlong callbackHandle);
jlong newInvokeCallback(JNIEnv * env, jobject self);
void deleteInvokeCallback(JNIEnv * env, jobject self, jlong callbackHandle);
jlong newExtendableInvokeCallback(JNIEnv * env, jobject self);
void deleteExtendableInvokeCallback(JNIEnv * env, jobject self, jlong callbackHandle);
} // namespace Controller
} // namespace chip