Masterarbeit Richard Stern. Flutter App, sich mit einem Bluetooth-Gerät verbindet und Berührungen auf einem Sensor visualisiert.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FlutterChannels.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. // Copyright 2013 The Flutter Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef FLUTTER_FLUTTERCHANNELS_H_
  5. #define FLUTTER_FLUTTERCHANNELS_H_
  6. #include "FlutterBinaryMessenger.h"
  7. #include "FlutterCodecs.h"
  8. NS_ASSUME_NONNULL_BEGIN
  9. /**
  10. * A message reply callback.
  11. *
  12. * Used for submitting a reply back to a Flutter message sender. Also used in
  13. * the dual capacity for handling a message reply received from Flutter.
  14. *
  15. * @param reply The reply.
  16. */
  17. typedef void (^FlutterReply)(id _Nullable reply);
  18. /**
  19. * A strategy for handling incoming messages from Flutter and to send
  20. * asynchronous replies back to Flutter.
  21. *
  22. * @param message The message.
  23. * @param callback A callback for submitting a reply to the sender.
  24. */
  25. typedef void (^FlutterMessageHandler)(id _Nullable message, FlutterReply callback);
  26. /**
  27. * A channel for communicating with the Flutter side using basic, asynchronous
  28. * message passing.
  29. */
  30. FLUTTER_EXPORT
  31. @interface FlutterBasicMessageChannel : NSObject
  32. /**
  33. * Creates a `FlutterBasicMessageChannel` with the specified name and binary
  34. * messenger.
  35. *
  36. * The channel name logically identifies the channel; identically named channels
  37. * interfere with each other's communication.
  38. *
  39. * The binary messenger is a facility for sending raw, binary messages to the
  40. * Flutter side. This protocol is implemented by `FlutterEngine` and `FlutterViewController`.
  41. *
  42. * The channel uses `FlutterStandardMessageCodec` to encode and decode messages.
  43. *
  44. * @param name The channel name.
  45. * @param messenger The binary messenger.
  46. */
  47. + (instancetype)messageChannelWithName:(NSString*)name
  48. binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger;
  49. /**
  50. * Creates a `FlutterBasicMessageChannel` with the specified name, binary
  51. * messenger, and message codec.
  52. *
  53. * The channel name logically identifies the channel; identically named channels
  54. * interfere with each other's communication.
  55. *
  56. * The binary messenger is a facility for sending raw, binary messages to the
  57. * Flutter side. This protocol is implemented by `FlutterEngine` and `FlutterViewController`.
  58. *
  59. * @param name The channel name.
  60. * @param messenger The binary messenger.
  61. * @param codec The message codec.
  62. */
  63. + (instancetype)messageChannelWithName:(NSString*)name
  64. binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
  65. codec:(NSObject<FlutterMessageCodec>*)codec;
  66. /**
  67. * Initializes a `FlutterBasicMessageChannel` with the specified name, binary
  68. * messenger, and message codec.
  69. *
  70. * The channel name logically identifies the channel; identically named channels
  71. * interfere with each other's communication.
  72. *
  73. * The binary messenger is a facility for sending raw, binary messages to the
  74. * Flutter side. This protocol is implemented by `FlutterEngine` and `FlutterViewController`.
  75. *
  76. * @param name The channel name.
  77. * @param messenger The binary messenger.
  78. * @param codec The message codec.
  79. */
  80. - (instancetype)initWithName:(NSString*)name
  81. binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
  82. codec:(NSObject<FlutterMessageCodec>*)codec;
  83. /**
  84. * Sends the specified message to the Flutter side, ignoring any reply.
  85. *
  86. * @param message The message. Must be supported by the codec of this
  87. * channel.
  88. */
  89. - (void)sendMessage:(id _Nullable)message;
  90. /**
  91. * Sends the specified message to the Flutter side, expecting an asynchronous
  92. * reply.
  93. *
  94. * @param message The message. Must be supported by the codec of this channel.
  95. * @param callback A callback to be invoked with the message reply from Flutter.
  96. */
  97. - (void)sendMessage:(id _Nullable)message
  98. reply:(FlutterReply _Nullable)callback
  99. // TODO: Add macOS support for replies once
  100. // https://github.com/flutter/flutter/issues/18852 is fixed.
  101. API_UNAVAILABLE(macos);
  102. /**
  103. * Registers a message handler with this channel.
  104. *
  105. * Replaces any existing handler. Use a `nil` handler for unregistering the
  106. * existing handler.
  107. *
  108. * @param handler The message handler.
  109. */
  110. - (void)setMessageHandler:(FlutterMessageHandler _Nullable)handler;
  111. @end
  112. /**
  113. * A method call result callback.
  114. *
  115. * Used for submitting a method call result back to a Flutter caller. Also used in
  116. * the dual capacity for handling a method call result received from Flutter.
  117. *
  118. * @param result The result.
  119. */
  120. typedef void (^FlutterResult)(id _Nullable result);
  121. /**
  122. * A strategy for handling method calls.
  123. *
  124. * @param call The incoming method call.
  125. * @param result A callback to asynchronously submit the result of the call.
  126. * Invoke the callback with a `FlutterError` to indicate that the call failed.
  127. * Invoke the callback with `FlutterMethodNotImplemented` to indicate that the
  128. * method was unknown. Any other values, including `nil`, are interpreted as
  129. * successful results.
  130. */
  131. typedef void (^FlutterMethodCallHandler)(FlutterMethodCall* call, FlutterResult result);
  132. /**
  133. * A constant used with `FlutterMethodCallHandler` to respond to the call of an
  134. * unknown method.
  135. */
  136. FLUTTER_EXPORT
  137. extern NSObject const* FlutterMethodNotImplemented;
  138. /**
  139. * A channel for communicating with the Flutter side using invocation of
  140. * asynchronous methods.
  141. */
  142. FLUTTER_EXPORT
  143. @interface FlutterMethodChannel : NSObject
  144. /**
  145. * Creates a `FlutterMethodChannel` with the specified name and binary messenger.
  146. *
  147. * The channel name logically identifies the channel; identically named channels
  148. * interfere with each other's communication.
  149. *
  150. * The binary messenger is a facility for sending raw, binary messages to the
  151. * Flutter side. This protocol is implemented by `FlutterEngine` and `FlutterViewController`.
  152. *
  153. * The channel uses `FlutterStandardMethodCodec` to encode and decode method calls
  154. * and result envelopes.
  155. *
  156. * @param name The channel name.
  157. * @param messenger The binary messenger.
  158. */
  159. + (instancetype)methodChannelWithName:(NSString*)name
  160. binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger;
  161. /**
  162. * Creates a `FlutterMethodChannel` with the specified name, binary messenger, and
  163. * method codec.
  164. *
  165. * The channel name logically identifies the channel; identically named channels
  166. * interfere with each other's communication.
  167. *
  168. * The binary messenger is a facility for sending raw, binary messages to the
  169. * Flutter side. This protocol is implemented by `FlutterEngine` and `FlutterViewController`.
  170. *
  171. * @param name The channel name.
  172. * @param messenger The binary messenger.
  173. * @param codec The method codec.
  174. */
  175. + (instancetype)methodChannelWithName:(NSString*)name
  176. binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
  177. codec:(NSObject<FlutterMethodCodec>*)codec;
  178. /**
  179. * Initializes a `FlutterMethodChannel` with the specified name, binary messenger,
  180. * and method codec.
  181. *
  182. * The channel name logically identifies the channel; identically named channels
  183. * interfere with each other's communication.
  184. *
  185. * The binary messenger is a facility for sending raw, binary messages to the
  186. * Flutter side. This protocol is implemented by `FlutterEngine` and `FlutterViewController`.
  187. *
  188. * @param name The channel name.
  189. * @param messenger The binary messenger.
  190. * @param codec The method codec.
  191. */
  192. - (instancetype)initWithName:(NSString*)name
  193. binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
  194. codec:(NSObject<FlutterMethodCodec>*)codec;
  195. // clang-format off
  196. /**
  197. * Invokes the specified Flutter method with the specified arguments, expecting
  198. * no results.
  199. *
  200. * @see [MethodChannel.setMethodCallHandler](https://docs.flutter.io/flutter/services/MethodChannel/setMethodCallHandler.html)
  201. *
  202. * @param method The name of the method to invoke.
  203. * @param arguments The arguments. Must be a value supported by the codec of this
  204. * channel.
  205. */
  206. // clang-format on
  207. - (void)invokeMethod:(NSString*)method arguments:(id _Nullable)arguments;
  208. /**
  209. * Invokes the specified Flutter method with the specified arguments, expecting
  210. * an asynchronous result.
  211. *
  212. * @param method The name of the method to invoke.
  213. * @param arguments The arguments. Must be a value supported by the codec of this
  214. * channel.
  215. * @param callback A callback that will be invoked with the asynchronous result.
  216. * The result will be a `FlutterError` instance, if the method call resulted
  217. * in an error on the Flutter side. Will be `FlutterMethodNotImplemented`, if
  218. * the method called was not implemented on the Flutter side. Any other value,
  219. * including `nil`, should be interpreted as successful results.
  220. */
  221. - (void)invokeMethod:(NSString*)method
  222. arguments:(id _Nullable)arguments
  223. result:(FlutterResult _Nullable)callback
  224. // TODO: Add macOS support for replies once
  225. // https://github.com/flutter/flutter/issues/18852 is fixed.
  226. API_UNAVAILABLE(macos);
  227. /**
  228. * Registers a handler for method calls from the Flutter side.
  229. *
  230. * Replaces any existing handler. Use a `nil` handler for unregistering the
  231. * existing handler.
  232. *
  233. * @param handler The method call handler.
  234. */
  235. - (void)setMethodCallHandler:(FlutterMethodCallHandler _Nullable)handler;
  236. @end
  237. /**
  238. * An event sink callback.
  239. *
  240. * @param event The event.
  241. */
  242. typedef void (^FlutterEventSink)(id _Nullable event);
  243. /**
  244. * A strategy for exposing an event stream to the Flutter side.
  245. */
  246. FLUTTER_EXPORT
  247. @protocol FlutterStreamHandler
  248. /**
  249. * Sets up an event stream and begin emitting events.
  250. *
  251. * Invoked when the first listener is registered with the Stream associated to
  252. * this channel on the Flutter side.
  253. *
  254. * @param arguments Arguments for the stream.
  255. * @param events A callback to asynchronously emit events. Invoke the
  256. * callback with a `FlutterError` to emit an error event. Invoke the
  257. * callback with `FlutterEndOfEventStream` to indicate that no more
  258. * events will be emitted. Any other value, including `nil` are emitted as
  259. * successful events.
  260. * @return A FlutterError instance, if setup fails.
  261. */
  262. - (FlutterError* _Nullable)onListenWithArguments:(id _Nullable)arguments
  263. eventSink:(FlutterEventSink)events;
  264. /**
  265. * Tears down an event stream.
  266. *
  267. * Invoked when the last listener is deregistered from the Stream associated to
  268. * this channel on the Flutter side.
  269. *
  270. * The channel implementation may call this method with `nil` arguments
  271. * to separate a pair of two consecutive set up requests. Such request pairs
  272. * may occur during Flutter hot restart.
  273. *
  274. * @param arguments Arguments for the stream.
  275. * @return A FlutterError instance, if teardown fails.
  276. */
  277. - (FlutterError* _Nullable)onCancelWithArguments:(id _Nullable)arguments;
  278. @end
  279. /**
  280. * A constant used with `FlutterEventChannel` to indicate end of stream.
  281. */
  282. FLUTTER_EXPORT
  283. extern NSObject const* FlutterEndOfEventStream;
  284. /**
  285. * A channel for communicating with the Flutter side using event streams.
  286. */
  287. FLUTTER_EXPORT
  288. @interface FlutterEventChannel : NSObject
  289. /**
  290. * Creates a `FlutterEventChannel` with the specified name and binary messenger.
  291. *
  292. * The channel name logically identifies the channel; identically named channels
  293. * interfere with each other's communication.
  294. *
  295. * The binary messenger is a facility for sending raw, binary messages to the
  296. * Flutter side. This protocol is implemented by `FlutterViewController`.
  297. *
  298. * The channel uses `FlutterStandardMethodCodec` to decode stream setup and
  299. * teardown requests, and to encode event envelopes.
  300. *
  301. * @param name The channel name.
  302. * @param messenger The binary messenger.
  303. */
  304. + (instancetype)eventChannelWithName:(NSString*)name
  305. binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger;
  306. /**
  307. * Creates a `FlutterEventChannel` with the specified name, binary messenger,
  308. * and method codec.
  309. *
  310. * The channel name logically identifies the channel; identically named channels
  311. * interfere with each other's communication.
  312. *
  313. * The binary messenger is a facility for sending raw, binary messages to the
  314. * Flutter side. This protocol is implemented by `FlutterViewController`.
  315. *
  316. * @param name The channel name.
  317. * @param messenger The binary messenger.
  318. * @param codec The method codec.
  319. */
  320. + (instancetype)eventChannelWithName:(NSString*)name
  321. binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
  322. codec:(NSObject<FlutterMethodCodec>*)codec;
  323. /**
  324. * Initializes a `FlutterEventChannel` with the specified name, binary messenger,
  325. * and method codec.
  326. *
  327. * The channel name logically identifies the channel; identically named channels
  328. * interfere with each other's communication.
  329. *
  330. * The binary messenger is a facility for sending raw, binary messages to the
  331. * Flutter side. This protocol is implemented by `FlutterEngine` and `FlutterViewController`.
  332. *
  333. * @param name The channel name.
  334. * @param messenger The binary messenger.
  335. * @param codec The method codec.
  336. */
  337. - (instancetype)initWithName:(NSString*)name
  338. binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
  339. codec:(NSObject<FlutterMethodCodec>*)codec;
  340. /**
  341. * Registers a handler for stream setup requests from the Flutter side.
  342. *
  343. * Replaces any existing handler. Use a `nil` handler for unregistering the
  344. * existing handler.
  345. *
  346. * @param handler The stream handler.
  347. */
  348. - (void)setStreamHandler:(NSObject<FlutterStreamHandler>* _Nullable)handler;
  349. @end
  350. NS_ASSUME_NONNULL_END
  351. #endif // FLUTTER_FLUTTERCHANNELS_H_