Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 3.15 KB | None | 0 0
  1. package com.sielc.socket;
  2.  
  3. import com.fasterxml.jackson.annotation.JsonIgnore;
  4.  
  5. import java.util.LinkedHashMap;
  6. import java.util.Map;
  7.  
  8. public class MsgValues extends WebSocketMessage {
  9.     public long from;
  10.     public long to;
  11.     public Map<Integer, int[]> values;
  12.     @JsonIgnore
  13.     public int lastIndex;
  14.  
  15.     public MsgValues(long from, long to, int[][] values, int lastIndex) {
  16.         this.from = from;
  17.         this.to = to;
  18.         this.values = new LinkedHashMap<>(8);
  19.         for (int i = 0; i < 8; i++) {
  20.             this.values.put(i, values[i]);
  21.         }
  22.         this.lastIndex = lastIndex;
  23.     }
  24. }
  25.  
  26.  
  27.  
  28.  
  29. package com.sielc.socket
  30.  
  31. import com.fasterxml.jackson.annotation.JsonIgnoreProperties
  32. import com.fasterxml.jackson.annotation.JsonSubTypes
  33. import com.fasterxml.jackson.annotation.JsonTypeInfo
  34. import com.fasterxml.jackson.databind.ObjectMapper
  35.  
  36. @JsonIgnoreProperties(ignoreUnknown = true)
  37. @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "event")
  38. @JsonSubTypes(
  39.         JsonSubTypes.Type(value = MsgStart::class, name = "start"),
  40.         JsonSubTypes.Type(value = MsgStop::class, name = "stop"),
  41.         JsonSubTypes.Type(value = MsgCancel::class, name = "cancel"),
  42.  
  43.         JsonSubTypes.Type(value = MsgHello::class, name = "hello"),
  44.  
  45.         JsonSubTypes.Type(value = MsgStarted::class, name = "started"),
  46.         JsonSubTypes.Type(value = MsgNewMeasurement::class, name = "new measurement"),
  47.         JsonSubTypes.Type(value = MsgValues::class, name = "values"),
  48.         JsonSubTypes.Type(value = MsgCancelledMeasurement::class, name = "cancel measurement"),
  49.         JsonSubTypes.Type(value = MsgFinishedMeasurement::class, name = "finish measurement")
  50. )
  51. abstract class WebSocketMessage
  52.  
  53. abstract class WebSocketMessageWithChannel(var channel: Int = 0) : WebSocketMessage()
  54.  
  55. abstract class WebSocketDynamicMessage : WebSocketMessage() {
  56.     abstract fun createMessage(): String?
  57.     open fun onSuccess() {}
  58. }
  59.  
  60. public class ObjectMapperSingleton {
  61.     companion object {
  62.         @JvmField
  63.         public val get = ObjectMapper()
  64.     }
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71. package com.sielc.socket
  72.  
  73. import com.fasterxml.jackson.annotation.JsonIgnoreProperties
  74. import com.fasterxml.jackson.annotation.JsonSubTypes
  75. import com.fasterxml.jackson.annotation.JsonTypeInfo
  76.  
  77.  
  78. class MsgHello : WebSocketMessageWithChannel() {
  79.     val msg: String = "Hello from raspberry!"
  80. }
  81.  
  82. class MsgStart : WebSocketMessage() {
  83.     var id: Int = -1
  84.     var channel: Int = 0
  85.     var duration: Long = 0
  86.     var period: Long = 0
  87. }
  88.  
  89. class MsgStop : WebSocketMessageWithChannel()
  90.  
  91. class MsgCancel : WebSocketMessageWithChannel()
  92.  
  93. class MsgFinishedMeasurement(channel: Int) : WebSocketMessageWithChannel(channel)
  94.  
  95. class MsgCancelledMeasurement(channel: Int) : WebSocketMessageWithChannel(channel)
  96.  
  97. class MsgStarted(val id: Int, channel: Int) : WebSocketMessageWithChannel(channel)
  98.  
  99. class MsgNewMeasurement(val id: Int,
  100.                         channel: Int,
  101.                         var time: Long,
  102.                         var duration: Long,
  103.                         var period: Long) : WebSocketMessageWithChannel(channel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement