writeHostApi method
void
writeHostApi(
- GObjectOptions generatorOptions,
- Root root,
- Indent indent,
- Api api, {
- required String dartPackageName,
override
Writes a single Host Api to indent
.
Implementation
@override
void writeHostApi(
GObjectOptions generatorOptions,
Root root,
Indent indent,
Api api, {
required String dartPackageName,
}) {
final String module = _getModule(generatorOptions, dartPackageName);
final String methodPrefix = _getMethodPrefix(module, api.name);
final String vtableName = _getVTableName(module, api.name);
indent.newln();
_writeDeclareFinalType(indent, module, api.name);
final bool hasAsyncMethod =
api.methods.any((Method method) => method.isAsynchronous);
if (hasAsyncMethod) {
indent.newln();
_writeDeclareFinalType(indent, module, '${api.name}ResponseHandle');
}
for (final Method method
in api.methods.where((Method method) => !method.isAsynchronous)) {
_writeHostApiRespondClass(indent, module, api, method);
}
indent.newln();
_writeApiVTable(indent, module, api);
indent.newln();
addDocumentationComments(
indent,
<String>[
'${methodPrefix}_set_method_handlers:',
'',
'@messenger: an #FlBinaryMessenger.',
'@suffix: (allow-none): a suffix to add to the API or %NULL for none.',
'@vtable: implementations of the methods in this API.',
'@user_data: (closure): user data to pass to the functions in @vtable.',
'@user_data_free_func: (allow-none): a function which gets called to free @user_data, or %NULL.',
'',
'Connects the method handlers in the ${api.name} API.',
],
_docCommentSpec);
indent.writeln(
'void ${methodPrefix}_set_method_handlers(FlBinaryMessenger* messenger, const gchar* suffix, const $vtableName* vtable, gpointer user_data, GDestroyNotify user_data_free_func);');
indent.newln();
addDocumentationComments(
indent,
<String>[
'${methodPrefix}_clear_method_handlers:',
'',
'@messenger: an #FlBinaryMessenger.',
'@suffix: (allow-none): a suffix to add to the API or %NULL for none.',
'',
'Clears the method handlers in the ${api.name} API.',
],
_docCommentSpec);
indent.writeln(
'void ${methodPrefix}_clear_method_handlers(FlBinaryMessenger* messenger, const gchar* suffix);');
for (final Method method
in api.methods.where((Method method) => method.isAsynchronous)) {
_writeHostApiRespondFunctionPrototype(indent, module, api, method);
}
}