x86UNIXUtils.h

Engine/source/platformX86UNIX/x86UNIXUtils.h

More...

Classes:

Public Variables

Detailed Description

Public Variables

UnixUtils * UUtils 
 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _X86UNIXUTILS_H_
25#define _X86UNIXUTILS_H_
26
27struct utsname;
28
29class UnixUtils
30{
31public:
32   UnixUtils();
33   virtual ~UnixUtils();
34
35   /**
36      Returns true if we're running in the background, false otherwise.
37      There's no "standard" way to determine this in unix, but 
38      modern job control unices should support the method described
39      here:
40
41      http://www.faqs.org/faqs/unix-faq/faq/part3/
42
43      (question 3.7)
44    */
45   bool inBackground();
46
47   /**
48      Returns the name of the OS, as reported by uname.
49    */
50   const char* getOSName();
51
52private:
53   struct utsname* mUnameInfo;
54};
55
56extern UnixUtils *UUtils;
57
58// utility class for running a unix command and capturing its output
59class UnixCommandExecutor
60{
61   private:
62      int mRet;
63      int mStdoutSave;
64      int mStderrSave;
65      int mPipeFiledes[2];
66      int mChildPID;
67      int mBytesRead;
68      bool mStdoutClosed;
69      bool mStderrClosed;
70      bool mChildExited;
71
72      void clearFields();
73      void cleanup();
74
75   public:
76      UnixCommandExecutor();
77      ~UnixCommandExecutor();
78
79      // Runs the specified command.  
80      // - args is a null terminated list of the command and its arguments,
81      // e.g: "ps", "-aux", NULL
82      // - stdoutCapture is the buffer where stdout data will be stored
83      // - stdoutCaptureSize is the size of the buffer
84      // None of these parameters may be null.  stdoutCaptureSize must be > 0
85      //
86      // returns -2 if the parameters are bad.  returns -1 if some other
87      // error occurs, check errno for the exact error.
88      int exec(char* args[], char* stdoutCapture, int stdoutCaptureSize);
89};
90
91#endif
92