deliver full node db when client app asks for it

This commit is contained in:
geeksville 2020-02-10 17:05:51 -08:00
parent 9a0da9ef67
commit 10b4d2395c
6 changed files with 117 additions and 116 deletions

View file

@ -8,15 +8,11 @@ import android.content.*
import android.graphics.Color
import android.os.Build
import android.os.IBinder
import android.os.Parcel
import android.os.Parcelable
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationCompat.PRIORITY_MIN
import com.geeksville.android.Logging
import com.geeksville.mesh.IMeshService
import com.geeksville.mesh.IRadioInterfaceService
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.*
import com.geeksville.mesh.MeshProtos.MeshPacket
import com.geeksville.mesh.MeshProtos.ToRadio
import com.geeksville.util.exceptionReporter
@ -28,103 +24,6 @@ import java.nio.charset.Charset
class RadioNotConnectedException() : Exception("Can't find radio")
// model objects that directly map to the corresponding protobufs
data class MeshUser(val id: String, val longName: String, val shortName: String) :
Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readString()!!,
parcel.readString()!!
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(id)
parcel.writeString(longName)
parcel.writeString(shortName)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<MeshUser> {
override fun createFromParcel(parcel: Parcel): MeshUser {
return MeshUser(parcel)
}
override fun newArray(size: Int): Array<MeshUser?> {
return arrayOfNulls(size)
}
}
}
data class Position(val latitude: Double, val longitude: Double, val altitude: Int) :
Parcelable {
constructor(parcel: Parcel) : this(
parcel.readDouble(),
parcel.readDouble(),
parcel.readInt()
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeDouble(latitude)
parcel.writeDouble(longitude)
parcel.writeInt(altitude)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Position> {
override fun createFromParcel(parcel: Parcel): Position {
return Position(parcel)
}
override fun newArray(size: Int): Array<Position?> {
return arrayOfNulls(size)
}
}
}
data class NodeInfo(
val num: Int, // This is immutable, and used as a key
var user: MeshUser? = null,
var position: Position? = null,
var lastSeen: Long? = null
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readParcelable(MeshUser::class.java.classLoader),
parcel.readParcelable(Position::class.java.classLoader),
parcel.readValue(Long::class.java.classLoader) as? Long
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(num)
parcel.writeParcelable(user, flags)
parcel.writeParcelable(position, flags)
parcel.writeValue(lastSeen)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<NodeInfo> {
override fun createFromParcel(parcel: Parcel): NodeInfo {
return NodeInfo(parcel)
}
override fun newArray(size: Int): Array<NodeInfo?> {
return arrayOfNulls(size)
}
}
}
/**
* Handles all the communication with android apps. Also keeps an internal model
@ -642,8 +541,8 @@ class MeshService : Service(), Logging {
})
}
override fun getOnline(): Array<String> = toRemoteExceptions {
val r = nodeDBbyID.keys.toTypedArray()
override fun getNodes(): Array<NodeInfo> = toRemoteExceptions {
val r = nodeDBbyID.values.toTypedArray()
info("in getOnline, count=${r.size}")
// return arrayOf("+16508675309")
r