OSDN Git Service

次バージョンの準備。
[gokigen/mangle.git] / app / src / main / java / jp / osdn / gokigen / gokigenassets / camera / theta / operation / ThetaOptionGetControl.kt
1 package jp.osdn.gokigen.gokigenassets.camera.theta.operation
2
3 import android.util.Log
4 import jp.osdn.gokigen.gokigenassets.camera.theta.status.IThetaSessionIdProvider
5 import jp.osdn.gokigen.gokigenassets.utils.communication.SimpleHttpClient
6
7 class ThetaOptionGetControl(private val sessionIdProvider: IThetaSessionIdProvider, private val executeUrl : String = "http://192.168.1.1")
8 {
9     private val httpClient = SimpleHttpClient()
10
11     /**
12      *
13      *
14      */
15     fun getOptions(options: String, useOSCv2: Boolean, callBack: IOperationCallback? = null)
16     {
17         Log.v(TAG, "getOptions() OSCv2:$useOSCv2 MSG : $options")
18         try
19         {
20             val thread = Thread {
21                 try
22                 {
23                     val getOptionsUrl = "${executeUrl}/osc/commands/execute"
24                     val postData = if (useOSCv2) "{\"name\":\"camera.getOptions\",\"parameters\":{\"timeout\":0, \"optionNames\": $options}}" else "{\"name\":\"camera.getOptions\",\"parameters\":{\"sessionId\": \"" + sessionIdProvider.sessionId + "\", \"optionNames\": $options}}"
25                     val result: String? = httpClient.httpPostWithHeader(getOptionsUrl, postData, null, "application/json;charset=utf-8", timeoutMs)
26                     if ((result != null) && (result.isNotEmpty()))
27                     {
28                         Log.v(TAG, " getOptions() : $result")
29                         callBack?.operationExecuted(0, result)
30                     }
31                     else
32                     {
33                         Log.v(TAG, "getOptions() reply is null or empty.  $postData")
34                         callBack?.operationExecuted(-1, "")
35                     }
36                 }
37                 catch (e: Exception)
38                 {
39                     e.printStackTrace()
40                     callBack?.operationExecuted(-1, e.localizedMessage)
41                 }
42             }
43             thread.start()
44         }
45         catch (e: Exception)
46         {
47             e.printStackTrace()
48             callBack?.operationExecuted(-1, e.localizedMessage)
49         }
50     }
51
52     companion object
53     {
54         private val TAG = ThetaOptionGetControl::class.java.simpleName
55         private const val timeoutMs = 1500
56     }
57 }