Skip to content

Commit

Permalink
Merge pull request eclipse-uprotocol#9 from neelam-kushwah/main
Browse files Browse the repository at this point in the history
Align with up-client-android-java version 0.1.2
  • Loading branch information
Steven Hartley authored Apr 12, 2024
2 parents 27981e3 + 7083db1 commit 01abc5d
Show file tree
Hide file tree
Showing 20 changed files with 177 additions and 85 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0


- name: Build with Gradle Wrapper
run: ./gradlew build


12 changes: 8 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ dependencies {
implementation libs.androidx.annotation
implementation libs.androidx.appcompat
implementation libs.android.material
implementation libs.up.client.android.java
implementation libs.up.java
implementation libs.opencsv
implementation (libs.up.java){
exclude group: 'org.eclipse.uprotocol', module: 'uprotocol-core-api'
}
implementation libs.grpc.protobuf
implementation files('libs/uservices-api-0.1.0-SNAPSHOT.jar')
implementation (libs.covesa.uservices)
{
exclude group: 'org.eclipse.uprotocol', module: 'uprotocol-core-api'
}
implementation libs.up.client.android.java

}
Binary file removed app/libs/uservices-api-0.1.0-SNAPSHOT.jar
Binary file not shown.
46 changes: 35 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,135 +51,159 @@
<service
android:name=".vehicleservice.BodyMirrors"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="body.mirrors" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.Braking"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="chassis.braking" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.CabinClimate"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="body.cabin_climate" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.Chassis"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="chassis" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.Engine"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="propulsion.engine" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.Exterior"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="vehicle.exterior" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.HelloWorld"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="example.hello_world" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.Horn"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="body.horn" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.Suspension"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="chassis.suspension" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>

<service
android:name=".vehicleservice.Transmission"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="propulsion.transmission" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.Seating"
android:enabled="true"
>
<meta-data
android:name="uprotocol.entity.name"
android:value="body.seating" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>
<service
android:name=".vehicleservice.Vehicle"
android:enabled="true"
android:singleUser="true">
>
<meta-data
android:name="uprotocol.entity.name"
android:value="vehicle" />

<meta-data
android:name="uprotocol.entity.version"
android:value="1" />

</service>

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@
import org.eclipse.uprotocol.common.util.log.Key;
import org.eclipse.uprotocol.core.usubscription.v3.CreateTopicRequest;
import org.eclipse.uprotocol.core.usubscription.v3.USubscription;
import org.eclipse.uprotocol.rpc.URpcListener;
import org.eclipse.uprotocol.simulatorproxy.utils.Constants;
import org.eclipse.uprotocol.transport.UListener;
import org.eclipse.uprotocol.uri.factory.UResourceBuilder;
import org.eclipse.uprotocol.uri.serializer.LongUriSerializer;
import org.eclipse.uprotocol.v1.UEntity;
import org.eclipse.uprotocol.v1.UMessage;
import org.eclipse.uprotocol.v1.UPayload;
import org.eclipse.uprotocol.v1.UStatus;
import org.eclipse.uprotocol.v1.UUri;
import org.json.JSONException;
Expand All @@ -79,13 +78,27 @@
public class BaseService extends Service {
public static final String CHANNEL_ID = "BaseService";
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
private final URpcListener mURpcListener = this::handleRequestMessage;
private final UListener mURpcListener = this::handleRequestMessage;
private Descriptors.ServiceDescriptor serviceDescriptor;
private UUri SERVICE_URI;
private String TAG;
private UPClient mUPClient;
private USubscription.Stub mUSubscriptionStub;

static synchronized void sendRpcRequestToHost(Socket mClientSocket, UMessage requestMessage) {
JSONObject jsonObj = new JSONObject();
try {
PrintWriter wr = new PrintWriter(mClientSocket.getOutputStream());
String serializedMsg = Base64ProtobufSerializer.deserialize(requestMessage.toByteArray());
jsonObj.put(Constants.ACTION, Constants.ACTION_RPC_REQUEST);
jsonObj.put(Constants.ACTION_DATA, serializedMsg);
Log.d(LOG_TAG, "Sending rpc request to host: " + jsonObj);
wr.println(jsonObj);
wr.flush();
} catch (JSONException | IOException e) {
Log.e(LOG_TAG, Objects.requireNonNullElse(e.getMessage(), "Exception occurs while sending rpc request to host"));
}
}

public void initializeUPClient(Descriptors.ServiceDescriptor serviceDescriptor) {
this.serviceDescriptor = serviceDescriptor;
Expand Down Expand Up @@ -117,9 +130,8 @@ public void onCreate() {
}

public UStatus registerMethod(@NonNull UUri methodUri) {
final UStatus status = mUPClient.registerRpcListener(methodUri, mURpcListener);

return logStatus("registerMethod", status, Key.URI, stringify(methodUri));
final UStatus status = mUPClient.registerListener(methodUri, mURpcListener);
return logStatus("registerMethod", status, Key.URI, stringify(methodUri));

}

Expand All @@ -129,9 +141,15 @@ public UStatus publish(@NonNull UMessage message) {
return status;
}

public UStatus send_response(@NonNull UMessage message) {
final UStatus status = mUPClient.send(message);
logStatus("successfully send rpc response", status, Key.TOPIC, stringify(message.getAttributes().getSource()));
return status;
}

private CompletableFuture<UStatus> unregisterMethod(@NonNull UUri methodUri) {
return CompletableFuture.supplyAsync(() -> {
final UStatus status = mUPClient.unregisterRpcListener(methodUri, mURpcListener);
final UStatus status = mUPClient.unregisterListener(methodUri, mURpcListener);
return logStatus("unregisterMethod", status, Key.URI, stringify(methodUri));
});
}
Expand All @@ -149,35 +167,21 @@ public int onStartCommand(Intent intent, int flags, int startId) {
return START_NOT_STICKY;
}

private void handleRequestMessage(@NonNull UMessage requestMessage, @NonNull CompletableFuture<UPayload> responseFuture) {
private void handleRequestMessage(@NonNull UMessage requestMessage) {
System.out.println("Request received");
final UUri methodUri = requestMessage.getAttributes().getSink();

String uri= LongUriSerializer.instance().serialize(methodUri);
//save responseFuture to send rpc response received from mock service to Bus.
Constants.COMPLETE_FUTURE_REQ_RES.put(uri, responseFuture);
// Send this request to python service and set the response to completable future
if(Constants.RPC_SOCKET_LIST.containsKey(uri)){
Socket socket=Constants.RPC_SOCKET_LIST.get(uri);
String uri = LongUriSerializer.instance().serialize(methodUri);

// Send this request to python service
if (Constants.RPC_SOCKET_LIST.containsKey(uri)) {
Socket socket = Constants.RPC_SOCKET_LIST.get(uri);
//write data to socket
if(socket != null)
sendRpcRequestToHost(socket,requestMessage);
if (socket != null)
sendRpcRequestToHost(socket, requestMessage);
}

}
static synchronized void sendRpcRequestToHost(Socket mClientSocket, UMessage requestMessage) {
JSONObject jsonObj = new JSONObject();
try {
PrintWriter wr = new PrintWriter(mClientSocket.getOutputStream());
String serializedMsg = Base64ProtobufSerializer.deserialize(requestMessage.toByteArray());
jsonObj.put(Constants.ACTION, Constants.ACTION_RPC_REQUEST);
jsonObj.put(Constants.ACTION_DATA, serializedMsg);
Log.d(LOG_TAG, "Sending rpc request to host: " + jsonObj);
wr.println(jsonObj);
wr.flush();
} catch (JSONException | IOException e) {
Log.e(LOG_TAG, Objects.requireNonNullElse(e.getMessage(), "Exception occurs while sending rpc request to host"));
}
}

public String getVehicleServiceName() {
final DescriptorProtos.ServiceOptions options = serviceDescriptor.getOptions();
Expand Down
Loading

0 comments on commit 01abc5d

Please sign in to comment.