tasn pushed a commit to branch master.

http://git.enlightenment.org/bindings/cxx/eflxx.git/commit/?id=b35eae7bf9798b22ee4f1dc760b7e78d5893ac43

commit b35eae7bf9798b22ee4f1dc760b7e78d5893ac43
Author: Andreas Volz <[email protected]>
Date:   Mon Dec 3 16:53:38 2012 +0000

    - more stable Exe API, but I don't really it :-(
    - inital Event wrapper
    - removed exceptions because currently not needed
    
    SVN revision: 80083
---
 ecorexx/include/ecorexx/Ecorexx.h                  |   1 +
 ecorexx/include/ecorexx/Event.h                    | 155 +++++++++++++++++++++
 ecorexx/include/ecorexx/Exe.h                      |  13 +-
 ecorexx/include/ecorexx/Makefile.am                |   3 +-
 .../exception/ProcessNotExistingException.h        |  26 ----
 ecorexx/src/Event.cpp                              |  31 +++++
 ecorexx/src/Exe.cpp                                |  75 +---------
 ecorexx/src/Makefile.am                            |   3 +-
 .../src/exception/ProcessNotExistingException.cpp  |  25 ----
 9 files changed, 202 insertions(+), 130 deletions(-)

diff --git a/ecorexx/include/ecorexx/Ecorexx.h 
b/ecorexx/include/ecorexx/Ecorexx.h
index d5793d2..21ca68f 100644
--- a/ecorexx/include/ecorexx/Ecorexx.h
+++ b/ecorexx/include/ecorexx/Ecorexx.h
@@ -18,6 +18,7 @@
 #include "XWindow.h"
 #include "Job.h"
 #include "Exe.h"
+#include "Event.h"
 
 /* exceptions */
 #include "exception/ProcessNotExistingException.h"
diff --git a/ecorexx/include/ecorexx/Event.h b/ecorexx/include/ecorexx/Event.h
new file mode 100644
index 0000000..d820e5f
--- /dev/null
+++ b/ecorexx/include/ecorexx/Event.h
@@ -0,0 +1,155 @@
+#ifndef ECOREXX_EVENT_H
+#define ECOREXX_EVENT_H
+
+/* EFL */
+#include <Ecore.h>
+
+/* SIGC */
+#include <sigc++/sigc++.h>
+
+namespace Ecorexx {
+
+class Event
+{
+public:
+  Event(int type, sigc::slot<bool, int, void*> handler);
+  virtual ~Event();
+  
+  /**
+   * @brief Add an event to the event queue.
+   * @param type The event type to add to the end of the event queue
+   * @param ev The data structure passed as @c event to event handlers
+   * @param func_free The function to be called to free @a ev
+   * @param data The data pointer to be passed to the free function
+   * @return A Handle for that event on success, otherwise NULL
+   *
+   * If it succeeds, an event of type @a type will be added to the queue for
+   * processing by event handlers added by ecore_event_handler_add(). The @a ev
+   * parameter will be passed as the @c event parameter of the handler. When 
the
+   * event is no longer needed, @a func_free will be called and passed @a ev 
for
+   * cleaning up. If @p func_free is NULL, free() will be called with the 
private
+   * structure pointer.
+   */
+  //EAPI Ecore_Event *ecore_event_add(int type, void *ev, Ecore_End_Cb 
func_free, void *data);
+  
+  /**
+   * @brief Delete an event from the queue.
+   * @param event The event handle to delete
+   * @return The data pointer originally set for the event free function
+   *
+   * This deletes the event @p event from the event queue, and returns the
+   * @p data parameter originally set when adding it with ecore_event_add(). 
This
+   * does not immediately call the free function, and it may be called later on
+   * cleanup, and so if the free function depends on the data pointer to work,
+   * you should defer cleaning of this till the free function is called later.
+   */
+  //EAPI void *ecore_event_del(Ecore_Event *event);
+  
+  /**
+   * @brief Get the data associated with an #Ecore_Event_Handler
+   * @param eh The event handler
+   * @return The data
+   *
+   * This function returns the data previously associated with @p eh by
+   * ecore_event_handler_add().
+   */
+  //EAPI void *ecore_event_handler_data_get(Ecore_Event_Handler *eh);
+  
+  /**
+   * @brief Set the data associated with an #Ecore_Event_Handler
+   * @param eh The event handler
+   * @param data The data to associate
+   * @return The previous data
+   *
+   * This function sets @p data to @p eh and returns the old data pointer
+   * which was previously associated with @p eh by ecore_event_handler_add().
+   */
+  //EAPI void *ecore_event_handler_data_set(Ecore_Event_Handler *eh, const 
void *data);
+  
+  /**
+   * @brief Allocate a new event type id sensibly and return the new id.
+   * @return A new event type id.
+   *
+   * This function allocates a new event type id and returns it. Once an event
+   * type has been allocated it can never be de-allocated during the life of
+   * the program. There is no guarantee of the contents of this event ID, or 
how
+   * it is calculated, except that the ID will be unique to the current 
instance
+   * of the process.
+   */
+  //EAPI int ecore_event_type_new(void);
+  
+  /**
+   * @brief Add a filter the current event queue.
+   *
+   * @param func_start Function to call just before filtering and return data
+   * @param func_filter Function to call on each event
+   * @param func_end Function to call after the queue has been filtered
+   * @param data Data to pass to the filter functions
+   * @return A filter handle on success, @c NULL otherwise.
+   *
+   * Adds a callback to filter events from the event queue. Filters are called 
on
+   * the queue just before Event handler processing to try and remove redundant
+   * events. Just as processing is about to start @a func_start is called and
+   * passed the @a data pointer, the return value of this functions is passed 
to
+   * @a func_filter as loop_data. @a func_filter is also passed @a data and the
+   * event type and event structure. If this @a func_filter returns
+   * @c EINA_FALSE, the event is removed from the queue, if it returns
+   * @c EINA_TRUE, the event is kept. When processing is finished @p func_end 
is
+   * called and is passed the loop_data(returned by @c func_start) and @p data
+   * pointer to clean up.
+   */
+  //EAPI Ecore_Event_Filter *ecore_event_filter_add(Ecore_Data_Cb func_start, 
Ecore_Filter_Cb func_filter, Ecore_End_Cb func_end, const void *data);
+  
+  /**
+   * @brief Delete an event filter.
+   * @param ef The event filter handle
+   * @return The data set for the filter on success, @c NULL otherwise.
+   *
+   * Delete a filter that has been added by its @p ef handle.
+   */
+  //EAPI void *ecore_event_filter_del(Ecore_Event_Filter *ef);
+  
+  /**
+   * @brief Return the current event type being handled.
+   * @return The current event type being handled if inside a handler callback,
+   * ECORE_EVENT_NONE otherwise
+   *
+   * If the program is currently inside an Ecore event handler callback this
+   * will return the type of the current event being processed.
+   *
+   * This is useful when certain Ecore modules such as Ecore_Evas "swallow"
+   * events and not all the original information is passed on. In special cases
+   * this extra information may be useful or needed and using this call can let
+   * the program know if the event type being handled is one it wants to get 
more
+   * information about.
+   */
+  //EAPI int ecore_event_current_type_get(void);
+  
+  /**
+   * @brief Return the current event type pointer handled.
+   * @return The current event pointer being handled if inside a handler 
callback,
+   * @c NULL otherwise.
+   *
+   * If the program is currently inside an Ecore event handler callback this
+   * will return the pointer of the current event being processed.
+   *
+   * This is useful when certain Ecore modules such as Ecore_Evas "swallow"
+   * events and not all the original information is passed on. In special cases
+   * this extra information may be useful or needed and using this call can let
+   * the program access the event data if the type of the event is handled by
+   * the program.
+   */
+  //EAPI void *ecore_event_current_event_get(void);
+
+  sigc::slot<bool, int, void*> mHandler;
+  
+private:
+  static Eina_Bool eventHandler(void *data, int type, void *event);
+  
+  Ecore_Event_Handler *mEventHandler;
+  
+};
+
+} // end namespace Ecorexx
+
+#endif // ECOREXX_EVENT_H
diff --git a/ecorexx/include/ecorexx/Exe.h b/ecorexx/include/ecorexx/Exe.h
index 08b4c65..173538b 100644
--- a/ecorexx/include/ecorexx/Exe.h
+++ b/ecorexx/include/ecorexx/Exe.h
@@ -1,6 +1,9 @@
 #ifndef ECOREXX_EXE_H
 #define ECOREXX_EXE_H
 
+/* STD */
+#include <map>
+
 /* EFL */
 #include <Ecore.h>
 
@@ -33,6 +36,8 @@ public:
     
   virtual ~Exe();
 
+  void free();
+
   static void setRunPriority(int pri);
 
   static int getRunPriority();
@@ -81,18 +86,10 @@ public:
 
   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);
-
-  void exceptionCheck();
-  
   Ecore_Exe *mExe;
-
-  pid_t mDeathPid;
 };
 
 } // end namespace Ecorexx
diff --git a/ecorexx/include/ecorexx/Makefile.am 
b/ecorexx/include/ecorexx/Makefile.am
index f9c6c4e..12fb686 100644
--- a/ecorexx/include/ecorexx/Makefile.am
+++ b/ecorexx/include/ecorexx/Makefile.am
@@ -12,7 +12,8 @@ libecorexx_HEADERS = \
        EvasWindowSoftwareX11.h \
        EvasWindowXRenderX11.h \
        Exe.h \
-       exception/ProcessNotExistingException.h
+       exception/ProcessNotExistingException.h \
+       Event.h
 
 libecorexxdir = \
        $(pkgincludedir)
diff --git a/ecorexx/include/ecorexx/exception/ProcessNotExistingException.h 
b/ecorexx/include/ecorexx/exception/ProcessNotExistingException.h
deleted file mode 100644
index a8cf372..0000000
--- a/ecorexx/include/ecorexx/exception/ProcessNotExistingException.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#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/Event.cpp b/ecorexx/src/Event.cpp
new file mode 100644
index 0000000..087057a
--- /dev/null
+++ b/ecorexx/src/Event.cpp
@@ -0,0 +1,31 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* STD */
+#include <cassert>
+
+#include "ecorexx/Event.h"
+
+namespace Ecorexx {
+
+Event::Event(int type, sigc::slot<bool, int, void*> handler) :
+  mHandler(handler),
+  mEventHandler(ecore_event_handler_add(type, Event::eventHandler, this))
+{
+}
+
+Event::~Event()
+{
+  assert(ecore_event_handler_del(mEventHandler));
+}
+
+Eina_Bool Event::eventHandler(void *data, int type, void *event)
+{
+  Event *event_obj = static_cast<Event*>(data);
+  assert(event_obj);
+  
+  return event_obj->mHandler(type, event);
+}
+
+} // end namespace Ecorexx
diff --git a/ecorexx/src/Exe.cpp b/ecorexx/src/Exe.cpp
index 2137592..e5069b0 100644
--- a/ecorexx/src/Exe.cpp
+++ b/ecorexx/src/Exe.cpp
@@ -8,64 +8,28 @@
 #include <iostream>
 
 #include "ecorexx/Exe.h"
-#include "ecorexx/exception/ProcessNotExistingException.h"
 
 using namespace std;
 
 namespace Ecorexx {
-
-static Ecore_Event_Handler *gDelHandler = NULL;
-static unsigned int gExeRunning = 0;
-    
-Exe::Exe(const std::string &exe_cmd, const void *data) :
-  mDeathPid(0)
-{
-  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, const void *data)
+{  
+  mExe = ecore_exe_run(exe_cmd.c_str(), data);
 }
 
-Exe::Exe(const std::string &exe_cmd, Ecore_Exe_Flags flags, const void *data) :
-  mDeathPid(0)
+Exe::Exe(const std::string &exe_cmd, Ecore_Exe_Flags flags, const void *data)
 {  
-  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)
+void Exe::free()
 {
-  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;
+  ecore_exe_free(mExe);
 }
 
 void Exe::setRunPriority(int pri)
@@ -80,19 +44,16 @@ int Exe::getRunPriority()
 
 bool Exe::send(const void *data, int size)
 {
-  exceptionCheck();
   return ecore_exe_send(mExe, data, size);
 }
 
 void Exe::stdinClose()
 {
-  exceptionCheck();
   ecore_exe_close_stdin(mExe);
 }
 
 void Exe::setAutoLimits(int start_bytes, int end_bytes, int start_lines, int 
end_lines)
 {
-  exceptionCheck();
   ecore_exe_auto_limits_set(mExe, start_bytes, end_bytes, start_lines, 
end_lines);
 }
 
@@ -103,101 +64,77 @@ void Exe::freeData(Ecore_Exe_Event_Data *data)
 
 pid_t Exe::getPid()
 {
-  exceptionCheck();
   return ecore_exe_pid_get(mExe);
 }
 
 void Exe::setTag(const std::string &tag)
 {
-  exceptionCheck();
   ecore_exe_tag_set(mExe, tag.c_str());
 }
 
 std::string Exe::getTag()
 {
-  exceptionCheck();
   return ecore_exe_tag_get(mExe);
 }
 
 std::string Exe::getCmd()
 {
-  exceptionCheck();
   return ecore_exe_cmd_get(mExe);
 }
 
 void *Exe::getData()
 {
-  exceptionCheck();
   return ecore_exe_data_get(mExe);
 }
 
 void *Exe::setData(void *data)
 {
-  exceptionCheck();
   return ecore_exe_data_set(mExe, data);
 }
 
 Ecore_Exe_Flags Exe::getFlags()
 {
-  exceptionCheck();
   return ecore_exe_flags_get(mExe);
 }
 
 void Exe::pause()
 {
-  exceptionCheck();
   ecore_exe_pause(mExe);
 }
 
 void Exe::cont()
 {
-  exceptionCheck();
   ecore_exe_continue(mExe);
 }
 
 void Exe::interrupt()
 {
-  exceptionCheck();
   ecore_exe_interrupt(mExe);
 }
 
 void Exe::quit()
 {
-  exceptionCheck();
   ecore_exe_quit(mExe);
 }
 
 void Exe::terminate()
 {
-  exceptionCheck();
   ecore_exe_terminate(mExe);
 }
 
 void Exe::kill()
 {
-  exceptionCheck();
   ecore_exe_kill(mExe);
 }
 
 void Exe::signal(int num)
 {
-  exceptionCheck();
   ecore_exe_signal(mExe, num);
 }
 
 void Exe::hup()
 {
-  exceptionCheck();
   ecore_exe_hup(mExe);
 }
 
-void Exe::exceptionCheck()
-{
-  if (!mExe)
-  {
-    assert(mDeathPid);
-    throw ProcessNotExistingException(mDeathPid);
-  }
-}
-
 } // end namespace Ecorexx
diff --git a/ecorexx/src/Makefile.am b/ecorexx/src/Makefile.am
index bbf5720..be7e6f2 100644
--- a/ecorexx/src/Makefile.am
+++ b/ecorexx/src/Makefile.am
@@ -28,7 +28,8 @@ libecorexx_la_SOURCES = \
        EvasWindowSoftwareX11.cpp \
        EvasWindowXRenderX11.cpp \
        Exe.cpp \
-       exception/ProcessNotExistingException.cpp
+       exception/ProcessNotExistingException.cpp \
+       Event.cpp
 
 libecorexx_la_LIBADD = \
        $(EFL_LIBS)
diff --git a/ecorexx/src/exception/ProcessNotExistingException.cpp 
b/ecorexx/src/exception/ProcessNotExistingException.cpp
deleted file mode 100644
index 499d531..0000000
--- a/ecorexx/src/exception/ProcessNotExistingException.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#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());
-}

-- 


Reply via email to