PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/thirdparty/breakpad/third_party/protobuf/protobuf/src/google/protobuf/compiler/subprocess.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 108 lines | 44 code | 20 blank | 44 comment | 0 complexity | c86682bf73f84daaa531b913f2bbc418 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // http://code.google.com/p/protobuf/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: kenton@google.com (Kenton Varda)
  31. #ifndef GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__
  32. #define GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__
  33. #ifdef _WIN32
  34. #define WIN32_LEAN_AND_MEAN // right...
  35. #include <windows.h>
  36. #else // _WIN32
  37. #include <sys/types.h>
  38. #include <unistd.h>
  39. #endif // !_WIN32
  40. #include <google/protobuf/stubs/common.h>
  41. #include <string>
  42. namespace google {
  43. namespace protobuf {
  44. class Message;
  45. namespace compiler {
  46. // Utility class for launching sub-processes.
  47. class LIBPROTOC_EXPORT Subprocess {
  48. public:
  49. Subprocess();
  50. ~Subprocess();
  51. enum SearchMode {
  52. SEARCH_PATH, // Use PATH environment variable.
  53. EXACT_NAME // Program is an exact file name; don't use the PATH.
  54. };
  55. // Start the subprocess. Currently we don't provide a way to specify
  56. // arguments as protoc plugins don't have any.
  57. void Start(const string& program, SearchMode search_mode);
  58. // Serialize the input message and pipe it to the subprocess's stdin, then
  59. // close the pipe. Meanwhile, read from the subprocess's stdout and parse
  60. // the data into *output. All this is done carefully to avoid deadlocks.
  61. // Returns true if successful. On any sort of error, returns false and sets
  62. // *error to a description of the problem.
  63. bool Communicate(const Message& input, Message* output, string* error);
  64. #ifdef _WIN32
  65. // Given an error code, returns a human-readable error message. This is
  66. // defined here so that CommandLineInterface can share it.
  67. static string Win32ErrorMessage(DWORD error_code);
  68. #endif
  69. private:
  70. #ifdef _WIN32
  71. DWORD process_start_error_;
  72. HANDLE child_handle_;
  73. // The file handles for our end of the child's pipes. We close each and
  74. // set it to NULL when no longer needed.
  75. HANDLE child_stdin_;
  76. HANDLE child_stdout_;
  77. #else // _WIN32
  78. pid_t child_pid_;
  79. // The file descriptors for our end of the child's pipes. We close each and
  80. // set it to -1 when no longer needed.
  81. int child_stdin_;
  82. int child_stdout_;
  83. #endif // !_WIN32
  84. };
  85. } // namespace compiler
  86. } // namespace protobuf
  87. } // namespace google
  88. #endif // GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__