PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/external/qemu/android/protocol/core-connection.h

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk
C Header | 169 lines | 34 code | 20 blank | 115 comment | 0 complexity | 92b3cc5deb08daf377ed3a6ca6b732ca MD5 | raw file
  1. /* Copyright (C) 2010 The Android Open Source Project
  2. **
  3. ** This software is licensed under the terms of the GNU General Public
  4. ** License version 2, as published by the Free Software Foundation, and
  5. ** may be copied, distributed, and modified under those terms.
  6. **
  7. ** This program is distributed in the hope that it will be useful,
  8. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ** GNU General Public License for more details.
  11. */
  12. /*
  13. * This file contains declaration related to communication between emulator's
  14. * UI and core through a console port.
  15. */
  16. #ifndef QEMU_ANDROID_CORE_CONNECTION_H
  17. #define QEMU_ANDROID_CORE_CONNECTION_H
  18. #include "android/sync-utils.h"
  19. // Opaque CoreConnection structure.
  20. typedef struct CoreConnection CoreConnection;
  21. // Base console port
  22. #define CORE_BASE_PORT 5554
  23. // Maximum number of core porocesses running simultaneously on a machine.
  24. #define MAX_CORE_PROCS 16
  25. // Socket timeout in millisec (set to 5 seconds)
  26. #define CORE_PORT_TIMEOUT_MS 5000
  27. /* Opens core console socket.
  28. * Param:
  29. * sockaddr Socket address to the core console.
  30. * Return:
  31. * Sync socket descriptor on success, or -1 on failure, with errno appropriately
  32. * set.
  33. */
  34. SyncSocket* core_connection_open_socket(SockAddress* sockaddr);
  35. /* Creates descriptor for a console client.
  36. * Param:
  37. * console_socket Socket address for the console.
  38. * Return:
  39. * Allocated and initialized descriptor for the client on success, or NULL
  40. * on failure.
  41. */
  42. CoreConnection* core_connection_create(SockAddress* console_socket);
  43. /* Frees descriptor allocated with core_connection_create.
  44. * Param:
  45. * desc Descriptor to free. Note that this routine will simply free the memory
  46. * used by the descriptor.
  47. */
  48. void core_connection_free(CoreConnection* desc);
  49. /* Opens a socket handle to the console.
  50. * Param:
  51. * desc Console client descriptor. Note that if the descriptor has been already
  52. * opened, this routine will simply return with success.
  53. * Return:
  54. * 0 on success, or -1 on failure with errno properly set. This routine will
  55. * return in at most one second.
  56. */
  57. int core_connection_open(CoreConnection* desc);
  58. /* Closes a socket handle to the console opened with core_connection_open.
  59. * Param:
  60. * desc Console client descriptor opened with core_connection_open.
  61. */
  62. void core_connection_close(CoreConnection* desc);
  63. /* Synchronously writes to the console. See CORE_PORT_TIMEOUT_MS for the timeout
  64. * value used to wait for the write operation to complete.
  65. * Param:
  66. * desc Console client descriptor opened with core_connection_open.
  67. * buffer Buffer to write.
  68. * to_write Number of bytes to write.
  69. * written_bytes Upon success, contains number of bytes written. This parameter
  70. * is optional, and can be NULL.
  71. * Return:
  72. * 0 on success, or -1 on failure.
  73. */
  74. int core_connection_write(CoreConnection* desc,
  75. const void* buffer,
  76. size_t to_write,
  77. size_t* written_bytes);
  78. /* Synchronously reads from the console. See CORE_PORT_TIMEOUT_MS for the
  79. * timeout value used to wait for the read operation to complete.
  80. * Param:
  81. * desc Console client descriptor opened with core_connection_open.
  82. * buffer Buffer to read data to.
  83. * to_read Number of bytes to read.
  84. * read_bytes Upon success, contains number of bytes that have been actually
  85. * read. This parameter is optional, and can be NULL.
  86. * Return:
  87. * 0 on success, or -1 on failure.
  88. */
  89. int core_connection_read(CoreConnection* desc,
  90. void* buffer,
  91. size_t to_read,
  92. size_t* read_bytes);
  93. /* Switches opened console client to a given stream.
  94. * Param:
  95. * desc Console client descriptor opened with core_connection_open. Note
  96. * that this descriptor should represent console itself. In other words,
  97. * there must have been no previous calls to this routine for that
  98. * descriptor.
  99. * stream_name Name of the stream to switch to.
  100. * handshake Address of a string to allocate for a handshake message on
  101. * success, or an error message on failure. If upon return from this
  102. * routine that string is not NULL, its buffer must be freed with 'free'.
  103. * Return:
  104. * 0 on success, or -1 on failure.
  105. */
  106. int core_connection_switch_stream(CoreConnection* desc,
  107. const char* stream_name,
  108. char** handshake);
  109. /* Creates a console client, and switches it to a given stream.
  110. * console_socket Socket address for the console.
  111. * stream_name Name of the stream to switch to.
  112. * handshake Address of a string to allocate for a handshake message on
  113. * success, or an error message on failure. If upon return from this
  114. * routine that string is not NULL, its buffer must be freed with 'free'.
  115. * Return:
  116. * Allocated and initialized descriptor for the switched client on success, or
  117. * NULL on failure.
  118. */
  119. CoreConnection* core_connection_create_and_switch(SockAddress* console_socket,
  120. const char* stream_name,
  121. char** handshake);
  122. /* Detaches opened console client from the console.
  123. * By console protocol, writing "\r\n" string to the console will destroy the
  124. * console client.
  125. * Param:
  126. * desc Console client descriptor opened with core_connection_open.
  127. */
  128. void core_connection_detach(CoreConnection* desc);
  129. /* Gets socket descriptor associated with the core connection.
  130. * Param:
  131. * desc Console client descriptor opened with core_connection_open.
  132. * Return
  133. * Socket descriptor associated with the core connection.
  134. */
  135. int core_connection_get_socket(CoreConnection* desc);
  136. /* Calculates timeout for transferring the given number of bytes via core
  137. * connection.
  138. * Return:
  139. * Number of milliseconds during which the entire number of bytes is expected
  140. * to be transferred via core connection.
  141. */
  142. static inline int
  143. core_connection_get_timeout(size_t data_size)
  144. {
  145. // Min 2 seconds + 10 millisec for each transferring byte.
  146. // TODO: Come up with a better arithmetics here.
  147. return 2000 + data_size * 10;
  148. }
  149. #endif // QEMU_ANDROID_CORE_CONNECTION_H