softwarecontainer  0.18.0-739e8d7 2017-05-04
jobabstract.h
1 /*
2  * Copyright (C) 2016-2017 Pelagicore AB
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
11  * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
12  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
13  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
14  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15  * SOFTWARE.
16  *
17  * For further information see LICENSE
18  */
19 #pragma once
20 
21 #include "softwarecontainer-common.h"
22 #include "executable.h"
23 
24 namespace softwarecontainer {
25 
30 {
31 protected:
32  LOG_DECLARE_CLASS_CONTEXT("JOAB", "JobAbstract");
33  typedef std::shared_ptr<Executable> ExecutablePtr;
34 
35 public:
36  static constexpr int UNASSIGNED_STREAM = -1;
37 
38  JobAbstract(ExecutablePtr &executable);
39  virtual ~JobAbstract();
40 
41  void captureStdin();
42  void setOutputFile(const std::string &path);
43  void captureStdout();
44  void captureStderr();
45 
46  int wait();
47 
48  int stdout();
49  int stderr();
50  int stdin();
51 
52  pid_t pid();
53 
60  bool isSuccess();
61 
68  bool isError();
69 
74  bool isRunning();
75  void setEnvironmentVariable(const std::string &key, const std::string &value);
76  void setEnvironmentVariables(const EnvironmentVariables &env);
77 
78 protected:
79  EnvironmentVariables m_env;
80 
81  ExecutablePtr m_executable;
82  int m_exitStatus;
83 
84  pid_t m_pid = 0;
85  int m_stdin[2] = {UNASSIGNED_STREAM, UNASSIGNED_STREAM};
86  int m_stdout[2] = {UNASSIGNED_STREAM, UNASSIGNED_STREAM};
87  int m_stderr[2] = {UNASSIGNED_STREAM, UNASSIGNED_STREAM};
88 };
89 
90 } // namespace softwarecontainer
bool isRunning()
That method always returns true as soon as the start() method has been called, even if the command fa...
Abstract class for jobs which get executed inside a container.
Definition: jobabstract.h:29
Developers guide to adding a config item:
bool isSuccess()
Helper about return value of jobs.
Definition: jobabstract.cpp:85
bool isError()
Helper about return value of jobs.
Definition: jobabstract.cpp:94