- add new exception structure

- modify Exe to report Exception


SVN revision: 79954
This commit is contained in:
Andreas Volz 2012-11-30 23:55:39 +00:00
parent 723eb72803
commit 2a3a0ae658
9 changed files with 146 additions and 6 deletions

View File

@ -19,5 +19,8 @@
#include "Job.h"
#include "Exe.h"
/* exceptions */
#include "exception/ProcessNotExistingException.h"
#endif // ECOREXX_H

View File

@ -4,6 +4,9 @@
/* EFL */
#include <Ecore.h>
/* SIGC */
#include <sigc++/sigc++.h>
namespace Ecorexx {
/**
@ -77,11 +80,17 @@ public:
void signal(int num);
void hup();
sigc::signal <void, Ecore_Exe_Event_Del*> signalDelete;
private:
Exe(const Exe&); // forbid copy constructor
static Eina_Bool delhandler (void *data, int type, void *event);
Ecore_Exe *mExe;
pid_t mDeathPid;
};
} // end namespace Ecorexx

View File

@ -4,6 +4,7 @@
/* EFL */
#include <Ecore.h>
/* SIGC */
#include <sigc++/sigc++.h>
namespace Ecorexx {

View File

@ -11,7 +11,8 @@ libecorexx_HEADERS = \
EvasWindowGLX11.h \
EvasWindowSoftwareX11.h \
EvasWindowXRenderX11.h \
Exe.h
Exe.h \
exception/ProcessNotExistingException.h
libecorexxdir = \
$(pkgincludedir)

View File

@ -0,0 +1,26 @@
#ifndef PROCESS_NOT_EXISTING_EXCEPTION_H
#define PROCESS_NOT_EXISTING_EXCEPTION_H
#include <exception>
#include <Ecore.h>
namespace Ecorexx {
class ProcessNotExistingException : public std::exception
{
public:
ProcessNotExistingException(pid_t pid) : mPid(pid) {}
virtual ~ProcessNotExistingException() throw() {}
const char *what() const throw();
private:
pid_t mPid;
};
} // end namespace Ecorexx
#endif // PROCESS_NOT_EXISTING_EXCEPTION_H

View File

@ -5,29 +5,69 @@
/* STL */
#include <string>
#include <cassert>
#include <iostream>
#include "ecorexx/Exe.h"
#include "ecorexx/exception/ProcessNotExistingException.h"
using namespace std;
namespace Ecorexx {
Exe::Exe(const std::string &exe_cmd, const void *data)
static Ecore_Event_Handler *gDelHandler = NULL;
static unsigned int gExeRunning = 0;
Exe::Exe(const std::string &exe_cmd, const void *data) :
mDeathPid(0)
{
mExe = ecore_exe_run(exe_cmd.c_str(), data);
if (gExeRunning == 0)
{
gDelHandler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, Exe::delhandler, this);
}
++gExeRunning;
mExe = ecore_exe_run(exe_cmd.c_str(), data);
}
Exe::Exe(const std::string &exe_cmd, Ecore_Exe_Flags flags, const void *data)
{
Exe::Exe(const std::string &exe_cmd, Ecore_Exe_Flags flags, const void *data) :
mDeathPid(0)
{
if (gExeRunning == 0)
{
gDelHandler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, Exe::delhandler, this);
}
gExeRunning++;
mExe = ecore_exe_pipe_run(exe_cmd.c_str(), flags, data);
}
Exe::~Exe()
{
if (gExeRunning == 1)
{
ecore_event_handler_del(gDelHandler);
}
if(mExe)
{
ecore_exe_free(mExe);
}
--gExeRunning;
}
Eina_Bool Exe::delhandler (void *data, int type, void *event)
{
Exe *exe = static_cast<Exe*>(data);
exe->mExe = NULL;
Ecore_Exe_Event_Del *delEvent = static_cast<Ecore_Exe_Event_Del*>(event);
exe->mDeathPid = delEvent->pid;
exe->signalDelete.emit (delEvent);
return true;
}
void Exe::setRunPriority(int pri)
{
ecore_exe_run_priority_set(pri);
@ -40,6 +80,8 @@ int Exe::getRunPriority()
bool Exe::send(const void *data, int size)
{
return ecore_exe_send(mExe, data, size);
}
@ -120,6 +162,12 @@ void Exe::terminate()
void Exe::kill()
{
if (!mExe)
{
assert(mDeathPid);
throw ProcessNotExistingException(mDeathPid);
}
ecore_exe_kill(mExe);
}

View File

@ -27,7 +27,8 @@ libecorexx_la_SOURCES = \
EvasWindowGLX11.cpp \
EvasWindowSoftwareX11.cpp \
EvasWindowXRenderX11.cpp \
Exe.cpp
Exe.cpp \
exception/ProcessNotExistingException.cpp
libecorexx_la_LIBADD = \
$(EFL_LIBS)

View File

@ -0,0 +1,25 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/* STD */
#include <string>
/* EFL */
#include <Ecore.h>
/* Project */
#include "ecorexx/exception/ProcessNotExistingException.h"
#include "util.h"
using namespace std;
const char *Ecorexx::ProcessNotExistingException::what() const throw()
{
static string s;
s = "Process with pid '";
s += toString<pid_t>(mPid);
s += "' not longer living!";
return static_cast <const char *>(s.c_str());
}

26
ecorexx/src/util.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef UTIL_H
#define UTIL_H
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
/// create std::string from any number
template <typename T>
std::string toString(const T &thing, int w = 0, int p = 0)
{
std::ostringstream os;
os << std::setw(w) << std::setprecision(p) << thing;
return os.str();
}
template <typename T>
std::string toStringWide(const T &thing, int w = 0)
{
std::ostringstream os;
os << std::setw(w) << thing;
return os.str();
}
#endif // UTIL_H