tasn pushed a commit to branch master. http://git.enlightenment.org/bindings/cxx/eflxx.git/commit/?id=2a3a0ae6588be4c25c03f24c0658333bf56f4edc
commit 2a3a0ae6588be4c25c03f24c0658333bf56f4edc Author: Andreas Volz <li...@brachttal.net> Date: Fri Nov 30 23:55:39 2012 +0000 - add new exception structure - modify Exe to report Exception SVN revision: 79954 --- ecorexx/include/ecorexx/Ecorexx.h | 3 ++ ecorexx/include/ecorexx/Exe.h | 9 ++++ ecorexx/include/ecorexx/Job.h | 1 + ecorexx/include/ecorexx/Makefile.am | 3 +- .../exception/ProcessNotExistingException.h | 26 ++++++++++ ecorexx/src/Exe.cpp | 56 ++++++++++++++++++++-- ecorexx/src/Makefile.am | 3 +- .../src/exception/ProcessNotExistingException.cpp | 25 ++++++++++ ecorexx/src/util.h | 26 ++++++++++ 9 files changed, 146 insertions(+), 6 deletions(-) diff --git a/ecorexx/include/ecorexx/Ecorexx.h b/ecorexx/include/ecorexx/Ecorexx.h index 16f5ffd..d5793d2 100644 --- a/ecorexx/include/ecorexx/Ecorexx.h +++ b/ecorexx/include/ecorexx/Ecorexx.h @@ -19,5 +19,8 @@ #include "Job.h" #include "Exe.h" +/* exceptions */ +#include "exception/ProcessNotExistingException.h" + #endif // ECOREXX_H diff --git a/ecorexx/include/ecorexx/Exe.h b/ecorexx/include/ecorexx/Exe.h index cbb863b..3b183ef 100644 --- a/ecorexx/include/ecorexx/Exe.h +++ b/ecorexx/include/ecorexx/Exe.h @@ -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 diff --git a/ecorexx/include/ecorexx/Job.h b/ecorexx/include/ecorexx/Job.h index 3baed5e..1241d70 100644 --- a/ecorexx/include/ecorexx/Job.h +++ b/ecorexx/include/ecorexx/Job.h @@ -4,6 +4,7 @@ /* EFL */ #include <Ecore.h> +/* SIGC */ #include <sigc++/sigc++.h> namespace Ecorexx { diff --git a/ecorexx/include/ecorexx/Makefile.am b/ecorexx/include/ecorexx/Makefile.am index 3f3ec0d..f9c6c4e 100644 --- a/ecorexx/include/ecorexx/Makefile.am +++ b/ecorexx/include/ecorexx/Makefile.am @@ -11,7 +11,8 @@ libecorexx_HEADERS = \ EvasWindowGLX11.h \ EvasWindowSoftwareX11.h \ EvasWindowXRenderX11.h \ - Exe.h + Exe.h \ + exception/ProcessNotExistingException.h libecorexxdir = \ $(pkgincludedir) diff --git a/ecorexx/include/ecorexx/exception/ProcessNotExistingException.h b/ecorexx/include/ecorexx/exception/ProcessNotExistingException.h new file mode 100644 index 0000000..a8cf372 --- /dev/null +++ b/ecorexx/include/ecorexx/exception/ProcessNotExistingException.h @@ -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 + diff --git a/ecorexx/src/Exe.cpp b/ecorexx/src/Exe.cpp index dffbbea..b8ce448 100644 --- a/ecorexx/src/Exe.cpp +++ b/ecorexx/src/Exe.cpp @@ -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); } diff --git a/ecorexx/src/Makefile.am b/ecorexx/src/Makefile.am index f26809a..bbf5720 100644 --- a/ecorexx/src/Makefile.am +++ b/ecorexx/src/Makefile.am @@ -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) diff --git a/ecorexx/src/exception/ProcessNotExistingException.cpp b/ecorexx/src/exception/ProcessNotExistingException.cpp new file mode 100644 index 0000000..499d531 --- /dev/null +++ b/ecorexx/src/exception/ProcessNotExistingException.cpp @@ -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()); +} diff --git a/ecorexx/src/util.h b/ecorexx/src/util.h new file mode 100644 index 0000000..b990aae --- /dev/null +++ b/ecorexx/src/util.h @@ -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 --