cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
osaPipeExec.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Martin Kelly
7  Created on: 2010-09-23
8 
9  (C) Copyright 2010 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12  --- begin cisst license - do not edit ---
13 
14  This software is provided "as is" under an open source license, with
15  no warranty. The complete license can be found in license.txt and
16  http://www.cisst.org/cisst/license.txt.
17 
18  --- end cisst license ---
19 
20 */
21 
22 #ifndef _osaPipeExec_h
23 #define _osaPipeExec_h
24 
25 #include <vector>
26 #include <string>
27 
28 // Always include last
30 
33  enum {INTERNALS_SIZE = 32};
34  char Internals[INTERNALS_SIZE];
35 
38  static unsigned int SizeOfInternals(void);
39  friend class osaPipeExecTest;
40 
41  char ** Command;
42  int ToProgram[2];
43  int FromProgram[2];
44  bool Connected;
45  bool ReadFlag;
46  bool WriteFlag;
47  std::string Name;
48 
51  void CloseAllPipes(void);
52 
55  char ** ParseCommand(const std::string & executable,
56  const std::vector<std::string> & arguments);
57 
58 #if (CISST_OS == CISST_WINDOWS)
59 
62  void RestoreIO(int newStdin, int newStdout);
63 #endif
64 
65  public:
67  osaPipeExec(const std::string & name = "unnamed");
68 
70  ~osaPipeExec(void);
71 
76  bool Open(const std::string & executable, const std::string & mode);
77 
82  bool Open(const std::string & executable,
83  const std::vector<std::string> & parameters,
84  const std::string & mode);
85 
88  bool Close(bool killProcess = true);
89 
92  int Read(char * buffer, int maxLength) const;
93 
97  std::string Read(int maxLength) const;
98 
101  int ReadUntil(char * buffer, int maxLength, char stopChar) const;
102 
105  std::string ReadUntil(int maxLength, char stopChar) const;
106 
108  std::string ReadString(int maxLength) const;
109 
112  int Write(const char * buffer);
113 
116  int Write(const char * buffer, int n);
117 
120  int Write(const std::string & s);
121 
124  int Write(const std::string & s, int n);
125 
128  bool IsConnected(void) const;
129 
131  const std::string & GetName(void) const;
132 };
133 
134 #endif // _osaPipeExec_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
Macros to export the symbols of cisstOSAbstraction (in a Dll).
Definition: osaPipeExec.h:31