command.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef TOOLS_ANDROID_FORWARDER2_COMMAND_H_
  5. #define TOOLS_ANDROID_FORWARDER2_COMMAND_H_
  6. namespace forwarder2 {
  7. class Socket;
  8. namespace command {
  9. enum Type {
  10. ACCEPT_ERROR = 0,
  11. ACCEPT_SUCCESS,
  12. ACK,
  13. ADB_DATA_SOCKET_ERROR,
  14. ADB_DATA_SOCKET_SUCCESS,
  15. BIND_ERROR,
  16. BIND_SUCCESS,
  17. DATA_CONNECTION,
  18. HOST_SERVER_ERROR,
  19. HOST_SERVER_SUCCESS,
  20. KILL_ALL_LISTENERS,
  21. LISTEN,
  22. UNLISTEN,
  23. UNLISTEN_ERROR,
  24. UNLISTEN_SUCCESS,
  25. };
  26. } // namespace command
  27. bool ReadCommand(Socket* socket,
  28. int* port_out,
  29. command::Type* command_type_out);
  30. bool ReadCommandWithTimeout(Socket* socket,
  31. int* port_out,
  32. command::Type* command_type_out,
  33. int timeout_secs);
  34. // Helper function to read the command from the |socket| and return true if the
  35. // |command| is equal to the given command parameter.
  36. bool ReceivedCommand(command::Type command, Socket* socket);
  37. bool ReceivedCommandWithTimeout(command::Type command,
  38. Socket* socket,
  39. int timeout_secs);
  40. bool SendCommand(command::Type command, int port, Socket* socket);
  41. } // namespace forwarder
  42. #endif // TOOLS_ANDROID_FORWARDER2_COMMAND_H_