|
|
@@ -0,0 +1,118 @@ |
|
|
|
/// \file child.hpp |
|
|
|
// |
|
|
|
// Copyright (C) 2014 MicroNeil Research Corporation. |
|
|
|
// |
|
|
|
// This program is part of the MicroNeil Research Open Library Project. For |
|
|
|
// more information go to http://www.microneil.com/OpenLibrary/index.html |
|
|
|
// |
|
|
|
// This program is free software; you can redistribute it and/or modify it |
|
|
|
// under the terms of the GNU General Public License as published by the |
|
|
|
// Free Software Foundation; either version 2 of the License, or (at your |
|
|
|
// option) any later version. |
|
|
|
// |
|
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT |
|
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|
|
|
// more details. |
|
|
|
// |
|
|
|
// You should have received a copy of the GNU General Public License along with |
|
|
|
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|
|
|
// Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
//============================================================================== |
|
|
|
|
|
|
|
/* |
|
|
|
\brief The child module provides classes to spawn and communicate |
|
|
|
with child processes. |
|
|
|
*/ |
|
|
|
|
|
|
|
#ifndef CHILD_HPP |
|
|
|
#define CHILD_HPP |
|
|
|
|
|
|
|
#include <cstdint> |
|
|
|
#include <istream> |
|
|
|
#include <ostream> |
|
|
|
#include <string> |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
namespace CodeDweller { |
|
|
|
|
|
|
|
/** |
|
|
|
\namespace CodeDweller |
|
|
|
|
|
|
|
The CodeDweller namespace contains components providing high-level |
|
|
|
functionality for applications. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
/** Class that abstracts the creation of child processes. |
|
|
|
|
|
|
|
This class provides functionality to create a child process, |
|
|
|
communicate with the child process via streams and signals, and |
|
|
|
obtain the exit code of the child process. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
class Child { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
/** Constructor for spawning with command-line parameters. |
|
|
|
|
|
|
|
The constructor configures the object, but doesn't spawn the |
|
|
|
child process. |
|
|
|
|
|
|
|
\param[in] args contains the child executable file name and |
|
|
|
command-line parameters. args[0] contains the full path of the |
|
|
|
executable, and args[1] thru args[n] are the command-line |
|
|
|
parameters. |
|
|
|
|
|
|
|
*/ |
|
|
|
Child(std::vector<std::string> args); |
|
|
|
|
|
|
|
/** Constructor for spawning without command-line parameters. |
|
|
|
|
|
|
|
The constructor configures the object, but doesn't spawn the |
|
|
|
child process. |
|
|
|
|
|
|
|
\param[in] childpath contains the child executable file name. |
|
|
|
|
|
|
|
*/ |
|
|
|
Child(std::string childpath); |
|
|
|
|
|
|
|
/** Destructor terminates the child process. */ |
|
|
|
~Child(); |
|
|
|
|
|
|
|
/// Stream that is seen by the child as standard output. |
|
|
|
std::istream reader; |
|
|
|
|
|
|
|
/// Stream that is seen by the child as standard input. |
|
|
|
std::ostream writer; |
|
|
|
|
|
|
|
/** Spawn the child process. |
|
|
|
|
|
|
|
If an error occurs, an exception is thrown. |
|
|
|
|
|
|
|
*/ |
|
|
|
void run(); |
|
|
|
|
|
|
|
/** Terminite the child process. |
|
|
|
|
|
|
|
If an error occurs, an exception is thrown. |
|
|
|
|
|
|
|
*/ |
|
|
|
void terminate(); |
|
|
|
|
|
|
|
/** Get the exit value of the child process. |
|
|
|
|
|
|
|
\returns The exit value of the child process if the child |
|
|
|
process has exited. If the child process has not exited, an |
|
|
|
exception is thrown. |
|
|
|
|
|
|
|
*/ |
|
|
|
int32_t result(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif // CHILD_HPP |