|
||||
File indexing completed on 2025-01-31 10:12:01
0001 // Protocol Buffers - Google's data interchange format 0002 // Copyright 2008 Google Inc. All rights reserved. 0003 // 0004 // Use of this source code is governed by a BSD-style 0005 // license that can be found in the LICENSE file or at 0006 // https://developers.google.com/open-source/licenses/bsd 0007 0008 // Author: kenton@google.com (Kenton Varda) 0009 0010 #ifndef GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ 0011 #define GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ 0012 0013 #ifdef _WIN32 0014 #ifndef WIN32_LEAN_AND_MEAN 0015 #define WIN32_LEAN_AND_MEAN // right... 0016 #endif 0017 #include <windows.h> 0018 #else // _WIN32 0019 #include <sys/types.h> 0020 #include <unistd.h> 0021 #endif // !_WIN32 0022 #include <string> 0023 0024 #include "google/protobuf/port.h" 0025 0026 // Must be included last. 0027 #include "google/protobuf/port_def.inc" 0028 0029 namespace google { 0030 namespace protobuf { 0031 0032 class Message; 0033 0034 namespace compiler { 0035 0036 // Utility class for launching sub-processes. 0037 class PROTOC_EXPORT Subprocess { 0038 public: 0039 Subprocess(); 0040 ~Subprocess(); 0041 0042 enum SearchMode { 0043 SEARCH_PATH, // Use PATH environment variable. 0044 EXACT_NAME // Program is an exact file name; don't use the PATH. 0045 }; 0046 0047 // Start the subprocess. Currently we don't provide a way to specify 0048 // arguments as protoc plugins don't have any. 0049 void Start(const std::string& program, SearchMode search_mode); 0050 0051 // Serialize the input message and pipe it to the subprocess's stdin, then 0052 // close the pipe. Meanwhile, read from the subprocess's stdout and parse 0053 // the data into *output. All this is done carefully to avoid deadlocks. 0054 // Returns true if successful. On any sort of error, returns false and sets 0055 // *error to a description of the problem. 0056 bool Communicate(const Message& input, Message* output, std::string* error); 0057 0058 #ifdef _WIN32 0059 // Given an error code, returns a human-readable error message. This is 0060 // defined here so that CommandLineInterface can share it. 0061 static std::string Win32ErrorMessage(DWORD error_code); 0062 #endif 0063 0064 private: 0065 #ifdef _WIN32 0066 DWORD process_start_error_; 0067 HANDLE child_handle_; 0068 0069 // The file handles for our end of the child's pipes. We close each and 0070 // set it to NULL when no longer needed. 0071 HANDLE child_stdin_; 0072 HANDLE child_stdout_; 0073 0074 #else // _WIN32 0075 pid_t child_pid_; 0076 0077 // The file descriptors for our end of the child's pipes. We close each and 0078 // set it to -1 when no longer needed. 0079 int child_stdin_; 0080 int child_stdout_; 0081 0082 #endif // !_WIN32 0083 }; 0084 0085 } // namespace compiler 0086 } // namespace protobuf 0087 } // namespace google 0088 0089 #include "google/protobuf/port_undef.inc" 0090 0091 #endif // GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |