proto.go 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/openatx/androidutils"
  6. )
  7. type CpuInfo struct {
  8. Cores int `json:"cores"`
  9. Hardware string `json:"hardware"`
  10. }
  11. type MemoryInfo struct {
  12. Total int `json:"total"` // unit kB
  13. Around string `json:"around,omitempty"`
  14. }
  15. type OwnerInfo struct {
  16. IP string `json:"ip"`
  17. }
  18. type DeviceInfo struct {
  19. Udid string `json:"udid,omitempty"` // Unique device identifier
  20. PropertyId string `json:"propertyId,omitempty"` // For device managerment, eg: HIH-PHO-1122
  21. Version string `json:"version,omitempty"` // ro.build.version.release
  22. Serial string `json:"serial,omitempty"` // ro.serialno
  23. Brand string `json:"brand,omitempty"` // ro.product.brand
  24. Model string `json:"model,omitempty"` // ro.product.model
  25. HWAddr string `json:"hwaddr,omitempty"` // persist.sys.wifi.mac
  26. Notes string `json:"notes,omitempty"` // device notes
  27. IP string `json:"ip,omitempty"`
  28. Port int `json:"port,omitempty"`
  29. ReverseProxyAddr string `json:"reverseProxyAddr,omitempty"`
  30. ReverseProxyServerAddr string `json:"reverseProxyServerAddr,omitempty"`
  31. Sdk int `json:"sdk,omitempty"`
  32. AgentVersion string `json:"agentVersion,omitempty"`
  33. Display *androidutils.Display `json:"display,omitempty"`
  34. Battery *androidutils.Battery `json:"battery,omitempty"`
  35. Memory *MemoryInfo `json:"memory,omitempty"` // proc/meminfo
  36. Cpu *CpuInfo `json:"cpu,omitempty"` // proc/cpuinfo
  37. Arch string `json:"arch"`
  38. Owner *OwnerInfo `json:"owner" gorethink:"owner,omitempty"`
  39. Reserved string `json:"reserved,omitempty"`
  40. ConnectionCount int `json:"-"` // > 1 happended when phone redial server
  41. CreatedAt time.Time `json:"-" gorethink:"createdAt,omitempty"`
  42. PresenceChangedAt time.Time `json:"presenceChangedAt,omitempty"`
  43. UsingBeganAt time.Time `json:"usingBeganAt,omitempty" gorethink:"usingBeganAt,omitempty"`
  44. Ready *bool `json:"ready,omitempty"`
  45. Present *bool `json:"present,omitempty"`
  46. Using *bool `json:"using,omitempty"`
  47. Product *Product `json:"product" gorethink:"product_id,reference,omitempty" gorethink_ref:"id"`
  48. Provider *Provider `json:"provider" gorethink:"provider_id,reference,omitempty" gorethink_ref:"id"`
  49. // only works when there is provider
  50. ProviderForwardedPort int `json:"providerForwardedPort,omitempty"`
  51. // used for provider to known agent server url
  52. ServerURL string `json:"serverUrl,omitempty"`
  53. }
  54. // "Brand Model Memory CPU" together can define a phone
  55. type Product struct {
  56. Id string `json:"id" gorethink:"id,omitempty"`
  57. Name string `json:"name" gorethink:"name,omitempty"`
  58. Brand string `json:"brand" gorethink:"brand,omitempty"`
  59. Model string `json:"model" gorethink:"model,omitempty"`
  60. Memory string `json:"memory,omitempty"` // eg: 4GB
  61. Cpu string `json:"cpu,omitempty"`
  62. Coverage float32 `json:"coverage" gorethink:"coverage,omitempty"`
  63. Gpu string `json:"gpu,omitempty"`
  64. Link string `json:"link,omitempty"` // Outside link
  65. // AntutuScore int `json:"antutuScore,omitempty"`
  66. }
  67. // u2init
  68. type Provider struct {
  69. Id string `json:"id" gorethink:"id,omitempty"` // machine id
  70. IP string `json:"ip" gorethink:"ip,omitempty"`
  71. Port int `json:"port" gorethink:"port,omitempty"`
  72. Present *bool `json:"present,omitempty"`
  73. Notes string `json:"notes" gorethink:"notes,omitempty"`
  74. Devices []DeviceInfo `json:"devices" gorethink:"devices,omitempty"`
  75. CreatedAt time.Time `json:"createdAt,omitempty"`
  76. PresenceChangedAt time.Time `json:"presenceChangedAt,omitempty"`
  77. }
  78. // Addr combined with ip:port
  79. func (p *Provider) Addr() string {
  80. return fmt.Sprintf("%s:%d", p.IP, p.Port)
  81. }