Belle II Software development
Executor Class Reference

Public Member Functions

 Executor (const std::string &path)
 
void setExecutable (const char *format,...)
 
void setExecutable (const std::string &path)
 
void addArg (const char *format,...)
 
void addArg (const std::string &arg)
 
void addArg (int arg)
 
void addArg (short arg)
 
void addArg (float arg)
 
void addArg (double arg)
 
bool execute (bool isdaemon=false)
 

Private Attributes

std::string m_path
 
std::vector< std::string > m_arg_v
 

Detailed Description

Definition at line 20 of file Executor.h.

Constructor & Destructor Documentation

◆ Executor() [1/2]

Executor ( )
inline

Definition at line 23 of file Executor.h.

23{}

◆ Executor() [2/2]

Executor ( const std::string &  path)
inline

Definition at line 24 of file Executor.h.

24: m_path(path) {}

Member Function Documentation

◆ addArg() [1/6]

void addArg ( const char *  format,
  ... 
)

Definition at line 33 of file Executor.cc.

34{
35 va_list ap;
36 static char ss[1024];
37 va_start(ap, format);
38 vsprintf(ss, format, ap);
39 va_end(ap);
40 m_arg_v.push_back(ss);
41}

◆ addArg() [2/6]

void addArg ( const std::string &  arg)

Definition at line 43 of file Executor.cc.

44{
45 m_arg_v.push_back(arg);
46}

◆ addArg() [3/6]

void addArg ( double  arg)
inline

Definition at line 34 of file Executor.h.

34{ addArg("%f", arg); }

◆ addArg() [4/6]

void addArg ( float  arg)
inline

Definition at line 33 of file Executor.h.

33{ addArg("%f", arg); }

◆ addArg() [5/6]

void addArg ( int  arg)
inline

Definition at line 31 of file Executor.h.

31{ addArg("%d", arg); }

◆ addArg() [6/6]

void addArg ( short  arg)
inline

Definition at line 32 of file Executor.h.

32{ addArg("%d", arg); }

◆ execute()

bool execute ( bool  isdaemon = false)

Definition at line 48 of file Executor.cc.

49{
50 char* argv[256];
51 argv[0] = (char*)m_path.c_str();
52 std::cerr << "" << argv[0] << " ";
53 for (size_t i = 0; i < m_arg_v.size(); i++) {
54 argv[i + 1] = (char*)m_arg_v[i].c_str();
55 std::cerr << "" << argv[i + 1] << " ";
56 }
57 std::cerr << std::endl;
58 argv[m_arg_v.size() + 1] = NULL;
59 if (isdaemon) daemon(0, 0);
60 if (execvp(m_path.c_str(), argv) == -1) {
61 LogFile::error("Faield to start %s", argv[0]);
62 return false;
63 }
64
65 return true;
66}

◆ setExecutable() [1/2]

void setExecutable ( const char *  format,
  ... 
)

Definition at line 18 of file Executor.cc.

19{
20 va_list ap;
21 static char ss[1024];
22 va_start(ap, format);
23 vsprintf(ss, format, ap);
24 va_end(ap);
25 m_path = ss;
26}

◆ setExecutable() [2/2]

void setExecutable ( const std::string &  path)

Definition at line 28 of file Executor.cc.

29{
30 m_path = path;
31}

Member Data Documentation

◆ m_arg_v

std::vector<std::string> m_arg_v
private

Definition at line 39 of file Executor.h.

◆ m_path

std::string m_path
private

Definition at line 38 of file Executor.h.


The documentation for this class was generated from the following files: