* [exmpl]: keep image_display responsive while editing ICC options
authorKai-Uwe Behrmann <[email protected]>
Fri, 24 Jan 2014 16:47:38 +0000 (17:47 +0100)
committerKai-Uwe Behrmann <[email protected]>
Fri, 24 Jan 2014 16:47:38 +0000 (17:47 +0100)
CMakeLists.txt
src/examples/image_display/image_display.cpp
src/include_private/oyranos_threads.h [new file with mode: 0644]
src/liboyranos_core/oyranos_threads.c [new file with mode: 0644]

index 44c6a86..7be7042 100644 (file)
@@ -6,8 +6,8 @@ SET (OYRANOS_VERSION_MAJOR 0)
 SET (OYRANOS_VERSION_MINOR 9)
 SET (OYRANOS_VERSION_MICRO 5)
 
-SET (OYRANOS_DEVEL_MONTH 12)
-SET (OYRANOS_DEVEL_YEAR 2013)
+SET (OYRANOS_DEVEL_MONTH 01)
+SET (OYRANOS_DEVEL_YEAR 2014)
 
 SET (PACKAGE_NAME "oyranos")
 SET (PACKAGE_DESCRIPTION "Oyranos is a Color Management System (CMS) on operating system level. It allows to match predictably input device colors to output device colors across supporting applications. One goal is to make color management useful for all users in a automated fashion and regardless of any technical knowledge.")
index 5fcc1f5..f6cb8f4 100644 (file)
@@ -186,18 +186,26 @@ struct box_n_opts {
   Oy_Fl_Image_Widget * box;
 };
 
-void callback ( Fl_Widget* w, void* daten )
+#include "../../liboyranos_core/oyranos_threads.c"
+void update(void*daten)
+{
+  struct box_n_opts * arg = (box_n_opts*) daten;
+
+#if 0
+  ((Fl_Widget*)arg->box)->damage(FL_DAMAGE_ALL,arg->box->x(),arg->box->y(),arg->box->w(),arg->box->h());
+  arg->box->damage_resize(arg->box->x(),arg->box->y(),arg->box->w(),arg->box->h());
+#else
+  arg->box->deactivate();
+  arg->box->activate();
+#endif
+}
+
+extern "C" {
+void * id_worker ( void* daten )
 {
   struct box_n_opts * arg = (box_n_opts*) daten;
   oyStruct_s * object = (oyStruct_s*) arg->node;
 
-  if(!w->parent())
-    printf("Could not find parents.\n");
-  else
-  if(!object)
-    printf("Oyranos argument missed.\n");
-  else
-  if(object && object->type_ == oyOBJECT_FILTER_NODE_S)
   {
     oyFilterNode_s * node = (oyFilterNode_s*) object;
     oyOptions_s * opts = 0,
@@ -248,8 +256,28 @@ void callback ( Fl_Widget* w, void* daten )
      */
     arg->box->damage( FL_DAMAGE_USER1 );
 
+    Fl::awake(update,arg);
+
     delete [] command;
   }
+  return NULL;
+}
+}
+
+void callback ( Fl_Widget* w, void* daten )
+{
+  struct box_n_opts * arg = (box_n_opts*) daten;
+  oyStruct_s * object = (oyStruct_s*) arg->node;
+  oyThread_t thread;
+
+  if(!w->parent())
+    printf("Could not find parents.\n");
+  else
+  if(!object)
+    printf("Oyranos argument missed.\n");
+  else
+  if(object && object->type_ == oyOBJECT_FILTER_NODE_S)
+    oyThreadCreate( id_worker, daten, &thread );
   else
     printf("could not find a suitable program structure\n");
 }
diff --git a/src/include_private/oyranos_threads.h b/src/include_private/oyranos_threads.h
new file mode 100644 (file)
index 0000000..261ac39
--- /dev/null
@@ -0,0 +1,51 @@
+/** @file oyranos_threads.h
+ *
+ *  Oyranos is an open source Color Management System 
+ *
+ *  @par Copyright:
+ *            2014 (C) Kai-Uwe Behrmann
+ *
+ *  @brief    thread methods
+ *  @internal
+ *  @author   Kai-Uwe Behrmann <[email protected]>
+ *  @par License:
+ *            new BSD <http://www.opensource.org/licenses/bsd-license.php>
+ *  @since    2014/01/24
+ *
+ *  This file contains functions for thread handling.
+ */
+
+#ifndef OYRANOS_THREADS_H
+#define OYRANOS_THREADS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#if defined(WIN32) && !defined(__GNU__)
+# include <process.h>
+typedef CRITICAL_SECTION oyMutex_t;
+# define oyMutexInit_m(m,a) InitializeCriticalSection(m)
+# define oyMutexLock_m(m) EnterCriticalSection(m)
+# define oyMutexUnLock_m(m) LeaveCriticalSection(m)
+# define oyMutexDestroy_m(m) DeleteCriticalSection(m)
+typedef unsigned long oyThread_t;
+#else
+# include <pthread.h>
+typedef pthread_mutex_t oyMutex_t;
+# define oyMutexInit_m(m,a) pthread_mutex_init(m,a)
+# define oyMutexLock_m(m) pthread_mutex_lock(m)
+# define oyMutexUnLock_m(m) pthread_mutex_unlock(m)
+# define oyMutexDestroy_m(m) pthread_mutex_destroy(m)
+typedef pthread_t oyThread_t;
+int oyThreadCreate                   ( void             *(*func) (void * data),
+                                       void              * data,
+                                       oyThread_t        * thread );
+#endif 
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* __cplusplus */
+
+#endif /* OYRANOS_THREADS_H */
diff --git a/src/liboyranos_core/oyranos_threads.c b/src/liboyranos_core/oyranos_threads.c
new file mode 100644 (file)
index 0000000..e88b8be
--- /dev/null
@@ -0,0 +1,61 @@
+/** @file oyranos_threads.c
+ *
+ *  Oyranos is an open source Color Management System 
+ *
+ *  @par Copyright:
+ *            2014 (C) Kai-Uwe Behrmann
+ *
+ *  @brief    thread methods
+ *  @internal
+ *  @author   Kai-Uwe Behrmann <[email protected]>
+ *  @par License:
+ *            new BSD <http://www.opensource.org/licenses/bsd-license.php>
+ *  @since    2014/01/24
+ *
+ *  This file contains functions for thread handling.
+ */
+
+#include "oyranos_threads.h"
+
+#include "oyranos_internal.h"
+#include "oyranos_helper.h"
+#include "oyranos_debug.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ *  @brief   start a thread with a given function
+ *
+ *  @version Oyranos: 0.9.5
+ *  @date    2014/01/25
+ *  @since   2014/01/25 (Oyranos: 0.9.5)
+ */
+int oyThreadCreate                   ( void             *(*func) (void * ptr),
+                                       void              * data,
+                                       oyThread_t        * thread )
+{
+  int error = !thread || !func;
+
+  if(!error)
+  {
+#if defined(WIN32) && !defined(__GNU__)
+    *thread = (oyThread_t) _beginthread( func, 0, data );
+    if(!(*thread))
+      error = 1;
+#else
+    pthread_attr_t attr;
+    error = pthread_attr_init( &attr );
+    error = pthread_create( thread, &attr, func, data );
+    error = pthread_attr_destroy( &attr );
+#endif
+  }
+
+  return error;
+}
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* __cplusplus */
+