Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Java and Kotlin
  • Loading branch information
stuartmorgan-g committed Feb 13, 2025
commit be83e5f561e5b44fb7fc9f61b37b0e7cad018390
39 changes: 19 additions & 20 deletions packages/pigeon/lib/src/java/java_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -835,15 +835,21 @@ if (wrapped == null) {
indent.addScoped('{', '}', () {
indent.writeln(
'messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix;');
String? serialBackgroundQueue;
if (api.methods.any((Method m) =>
m.taskQueueType == TaskQueueType.serialBackgroundThread)) {
serialBackgroundQueue = 'taskQueue';
indent.writeln(
'BinaryMessenger.TaskQueue $serialBackgroundQueue = binaryMessenger.makeBackgroundTaskQueue();');
}
for (final Method method in api.methods) {
_writeMethodSetUp(
generatorOptions,
root,
indent,
api,
method,
dartPackageName: dartPackageName,
);
_writeHostMethodMessageHandler(
generatorOptions, root, indent, api, method,
dartPackageName: dartPackageName,
serialBackgroundQueue:
method.taskQueueType == TaskQueueType.serialBackgroundThread
? serialBackgroundQueue
: null);
}
});
});
Expand Down Expand Up @@ -887,34 +893,27 @@ if (wrapped == null) {
indent.writeln('$returnType ${method.name}(${argSignature.join(', ')});');
}

/// Write a static setUp function in the interface.
/// Example:
/// static void setUp(BinaryMessenger binaryMessenger, Foo api) {...}
void _writeMethodSetUp(
/// Write a single method's handler for the setUp function.
void _writeHostMethodMessageHandler(
JavaOptions generatorOptions,
Root root,
Indent indent,
Api api,
final Method method, {
required String dartPackageName,
String? serialBackgroundQueue,
}) {
final String channelName = makeChannelName(api, method, dartPackageName);
indent.write('');
indent.addScoped('{', '}', () {
String? taskQueue;
if (method.taskQueueType != TaskQueueType.serial) {
taskQueue = 'taskQueue';
indent.writeln(
'BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();');
}
indent.writeln('BasicMessageChannel<Object> channel =');
indent.nest(2, () {
indent.writeln('new BasicMessageChannel<>(');
indent.nest(2, () {
indent.write(
'binaryMessenger, "$channelName" + messageChannelSuffix, getCodec()');
if (taskQueue != null) {
indent.addln(', $taskQueue);');
if (serialBackgroundQueue != null) {
indent.addln(', $serialBackgroundQueue);');
} else {
indent.addln(');');
}
Expand Down
28 changes: 17 additions & 11 deletions packages/pigeon/lib/src/kotlin/kotlin_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,14 @@ if (wrapped == null) {
indent.addScoped('{', '}', () {
indent.writeln(
r'val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""');
String? serialBackgroundQueue;
if (api.methods.any((Method m) =>
m.taskQueueType == TaskQueueType.serialBackgroundThread)) {
serialBackgroundQueue = 'taskQueue';
serialBackgroundQueue = 'taskQueue';
indent.writeln(
'val $serialBackgroundQueue = binaryMessenger.makeBackgroundTaskQueue()');
}
for (final Method method in api.methods) {
_writeHostMethodMessageHandler(
indent,
Expand All @@ -664,6 +672,10 @@ if (wrapped == null) {
parameters: method.parameters,
returnType: method.returnType,
isAsynchronous: method.isAsynchronous,
serialBackgroundQueue:
method.taskQueueType == TaskQueueType.serialBackgroundThread
? serialBackgroundQueue
: null,
);
}
});
Expand Down Expand Up @@ -1071,8 +1083,8 @@ if (wrapped == null) {
fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
sink.error(errorCode, errorMessage, errorDetails)
}
fun endOfStream() {

fun endOfStream() {
sink.endOfStream()
}
}
Expand Down Expand Up @@ -1249,24 +1261,18 @@ if (wrapped == null) {
required TypeDeclaration returnType,
String setHandlerCondition = 'api != null',
bool isAsynchronous = false,
String? serialBackgroundQueue,
String Function(List<String> safeArgNames, {required String apiVarName})?
onCreateCall,
}) {
indent.write('run ');
indent.addScoped('{', '}', () {
String? taskQueue;
if (taskQueueType != TaskQueueType.serial) {
taskQueue = 'taskQueue';
indent.writeln(
'val $taskQueue = binaryMessenger.makeBackgroundTaskQueue()');
}

indent.write(
'val channel = BasicMessageChannel<Any?>(binaryMessenger, "$channelName", codec',
);

if (taskQueue != null) {
indent.addln(', $taskQueue)');
if (serialBackgroundQueue != null) {
indent.addln(', $serialBackgroundQueue)');
} else {
indent.addln(')');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3352,6 +3352,7 @@ static void setUp(
@NonNull String messageChannelSuffix,
@Nullable HostIntegrationCoreApi api) {
messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix;
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
Expand Down Expand Up @@ -6145,7 +6146,6 @@ public void error(Throwable error) {
}
}
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ interface HostIntegrationCoreApi {
) {
val separatedMessageChannelSuffix =
if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
val taskQueue = binaryMessenger.makeBackgroundTaskQueue()
run {
val channel =
BasicMessageChannel<Any?>(
Expand Down Expand Up @@ -3404,7 +3405,6 @@ interface HostIntegrationCoreApi {
}
}
run {
val taskQueue = binaryMessenger.makeBackgroundTaskQueue()
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
Expand Down