| {{/* |
| * Copyright (C) 2015 The Android Open Source Project |
| * |
| * 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. |
| */}} |
| |
| {{define "Java.Value"}}{{Call "Java.Type" .}}{{end}} |
| {{define "Java.Value.nil"}}Void{{end}} |
| |
| {{define "Java.Future"}}ListenableFuture<{{Call "Java.Value" .}}>{{end}} |
| {{define "Java.Callable"}}Callable<{{Call "Java.Value" .}}>{{end}} |
| |
| {{define "Java.Parameters"}}{{range $i, $p := .Call.Params}}{{if $i}}, {{end}}{{Call "Java.Type" $p.Type}} {{$p.Name}}{{end}}{{end}} |
| {{define "Java.Arguments"}}{{range $i, $p := .Call.Params}}{{if $i}}, {{end}}{{$p.Name}}{{end}}{{end}} |
| |
| {{define "Java.Method"}}{{Call "Java.Future" .Result.Type}} {{File.MethodName .Name}}({{template "Java.Parameters" .}}){{end}} |
| |
| {{define "Java.Imports"}} |
| {{Call "Java.Import" "com.android.tools.rpclib.binary.BinaryID"}} |
| {{range .Service.Methods}} |
| {{Call "Java.Import" .Result.Type}} |
| {{range .Call.Params}}{{Call "Java.Import" .Type}}{{end}} |
| {{end}} |
| {{end}} |
| |
| {{define "Java.ClientBody"}} |
| ¶{{/*Newline after section marker*/}} |
| {{range .Service.Methods}} |
| public abstract {{template "Java.Method" .}};¶ |
| {{end}} |
| //{{/*Comment the following section marker*/}} |
| {{end}} |
| |
| {{define "Java.Client"}} |
| §{{$.Copyright}}§¶ |
| package {{.JavaPackage}};¶ |
| ¶ |
| {{template "Java.Imports" .}} |
| {{Call "Java.Import" "com.google.common.util.concurrent.ListenableFuture"}} |
| ¶ |
| public abstract class {{.Service.Name}}Client {Ȧ |
| //{{Section "Java.ClientBody"}}¶ |
| «}¶ |
| {{end}} |
| |
| {{define "Java.ClientRPC"}} |
| §{{$.Copyright}}§¶ |
| package {{.JavaPackage}};¶ |
| ¶ |
| {{template "Java.Imports" .}} |
| {{Call "Java.Import" "com.android.tools.rpclib.rpccore.Broadcaster"}} |
| {{Call "Java.Import" "java.io.InputStream"}} |
| {{Call "Java.Import" "java.io.OutputStream"}} |
| {{Call "Java.Import" "java.util.concurrent.Callable"}} |
| {{Call "Java.Import" "com.google.common.util.concurrent.ListeningExecutorService"}} |
| {{Call "Java.Import" "com.google.common.util.concurrent.ListenableFuture"}} |
| ¶ |
| public final class {{.Service.Name}}ClientRPC extends {{.Service.Name}}Client {Ȧ |
| private final Broadcaster myBroadcaster;¶ |
| private final ListeningExecutorService myExecutorService;¶ |
| ¶ |
| public {{.Service.Name}}ClientRPC(ListeningExecutorService executorService, InputStream in, OutputStream out, int mtu) {Ȧ |
| myExecutorService = executorService;¶ |
| myBroadcaster = new Broadcaster(in, out, mtu, myExecutorService);¶ |
| «}¶ |
| {{range .Service.Methods}} |
| @Override¶ |
| public {{template "Java.Method" .}} {Ȧ |
| return myExecutorService.submit(new {{.Name}}Callable({{template "Java.Arguments" .}}));¶ |
| «}¶ |
| {{end}} |
| ¶ |
| {{range .Service.Methods}} |
| private class {{.Name}}Callable implements {{Call "Java.Callable" .Result.Type}} {Ȧ |
| private final {{File.ClassName .Call}} myCall;¶ |
| ¶ |
| private {{.Name}}Callable({{template "Java.Parameters" .}}) {Ȧ |
| myCall = new {{File.ClassName .Call}}();¶ |
| {{range .Call.Params}} |
| myCall.{{File.Setter .Name}}({{.Name}});¶ |
| {{end}} |
| «}¶ |
| @Override¶ |
| public {{Call "Java.Value" .Result.Type}} call() throws Exception {Ȧ |
| {{if .Result.Type}}{{File.ClassName .Result}} result = ({{File.ClassName .Result}})myBroadcaster.Send(myCall);¶ |
| return result.myValue;¶ |
| {{else}} |
| myBroadcaster.Send(myCall);¶ |
| return null;¶ |
| {{end}} |
| «}¶ |
| «}¶ |
| {{end}} |
| «}¶ |
| {{end}} |
| |
| {{define "Java.ClientWrapper"}} |
| §{{$.Copyright}}§¶ |
| package {{.JavaPackage}};¶ |
| ¶ |
| {{template "Java.Imports" .}} |
| {{Call "Java.Import" "com.google.common.util.concurrent.ListenableFuture"}} |
| ¶ |
| public class {{.Service.Name}}ClientWrapper extends {{.Service.Name}}Client {Ȧ |
| protected final {{.Service.Name}}Client myClient;¶ |
| |
| public {{.Service.Name}}ClientWrapper({{.Service.Name}}Client client) {Ȧ |
| myClient = client;¶ |
| «}¶ |
| {{range .Service.Methods}} |
| @Override¶ |
| public {{template "Java.Method" .}} {Ȧ |
| return myClient.{{File.MethodName .Name}}({{template "Java.Arguments" .}});¶ |
| «}¶ |
| {{end}} |
| «}¶ |
| {{end}} |