Skip to content

Commit

Permalink
App: Show tensor_query_server's port number in activity
Browse files Browse the repository at this point in the history
This patch shows tensor_query_server's port number the clinet application will use on the screen.

Signed-off-by: Yelin Jeong <[email protected]>
  • Loading branch information
niley7464 authored and wooksong committed Jun 3, 2024
1 parent 931e311 commit beea612
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Bundle
import android.os.IBinder
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -48,7 +49,9 @@ class MainActivity : ComponentActivity() {

val start = findViewById<Button>(R.id.start)
start.setOnClickListener(View.OnClickListener {
mService?.startServer()
val serverPort = mService?.startServer()
val portTextView = findViewById<TextView>(R.id.port)
portTextView.text = "Listening on port: " + serverPort.toString();
})

val stop = findViewById<Button>(R.id.stop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.os.Looper
import android.os.Message
import android.os.Process
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.core.app.NotificationCompat
import androidx.core.app.ServiceCompat
Expand Down Expand Up @@ -240,7 +241,7 @@ class MainService : Service() {
return port
}

fun startServer() {
fun startServer(): Int {
val hostAddress = getIpAddress()
if (!isPortAvailable(port)) {
port = findPort()
Expand All @@ -252,6 +253,8 @@ class MainService : Service() {
"other/tensor,format=static,dimension=(string)1001:1,type=uint8,framerate=0/1 ! tensor_query_serversink async=false"
tensorQueryServer = Pipeline(desc, null)
tensorQueryServer.start()

return port
}

fun stopServer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
Expand All @@ -12,4 +13,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop" />
<TextView
android:id="@+id/port"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

0 comments on commit beea612

Please sign in to comment.