Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

child.hpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /// \file child.hpp
  2. //
  3. // Copyright (C) 2014 MicroNeil Research Corporation.
  4. //
  5. // This program is part of the MicroNeil Research Open Library Project. For
  6. // more information go to http://www.microneil.com/OpenLibrary/index.html
  7. //
  8. // This program is free software; you can redistribute it and/or modify it
  9. // under the terms of the GNU General Public License as published by the
  10. // Free Software Foundation; either version 2 of the License, or (at your
  11. // option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful, but WITHOUT
  14. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. // more details.
  17. //
  18. // You should have received a copy of the GNU General Public License along with
  19. // this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  20. // Place, Suite 330, Boston, MA 02111-1307 USA
  21. //==============================================================================
  22. /*
  23. \brief The child module provides classes to spawn and communicate
  24. with child processes.
  25. */
  26. #ifndef CHILD_HPP
  27. #define CHILD_HPP
  28. #include <cstdint>
  29. #include <istream>
  30. #include <ostream>
  31. #include <string>
  32. #include <vector>
  33. namespace CodeDweller {
  34. /**
  35. \namespace CodeDweller
  36. The CodeDweller namespace contains components providing high-level
  37. functionality for applications.
  38. */
  39. /** Class that abstracts the creation of child processes.
  40. This class provides functionality to create a child process,
  41. communicate with the child process via streams and signals, and
  42. obtain the exit code of the child process.
  43. */
  44. class Child {
  45. public:
  46. /** Constructor for spawning with command-line parameters.
  47. The constructor configures the object, but doesn't spawn the
  48. child process.
  49. \param[in] args contains the child executable file name and
  50. command-line parameters. args[0] contains the full path of the
  51. executable, and args[1] thru args[n] are the command-line
  52. parameters.
  53. */
  54. Child(std::vector<std::string> args);
  55. /** Constructor for spawning without command-line parameters.
  56. The constructor configures the object, but doesn't spawn the
  57. child process.
  58. \param[in] childpath contains the child executable file name.
  59. */
  60. Child(std::string childpath);
  61. /** Destructor terminates the child process. */
  62. ~Child();
  63. /// Stream that is seen by the child as standard output.
  64. std::istream reader;
  65. /// Stream that is seen by the child as standard input.
  66. std::ostream writer;
  67. /** Spawn the child process.
  68. If an error occurs, an exception is thrown.
  69. */
  70. void run();
  71. /** Terminite the child process.
  72. If an error occurs, an exception is thrown.
  73. */
  74. void terminate();
  75. /** Get the exit value of the child process.
  76. \returns The exit value of the child process if the child
  77. process has exited. If the child process has not exited, an
  78. exception is thrown.
  79. */
  80. int32_t result();
  81. };
  82. }
  83. #endif // CHILD_HPP