Oyranos  0.9.7
Oyranos is a full featured Color Management System
Macros
oyranos_dbus_macros.h File Reference

DBus helper macros. More...

#include "oyranos.h"
#include <dbus/dbus.h>
#include <unistd.h>

Macros

#define oyDBusFilter_m
 
#define oyDbusReceiveMessage_m
 
#define oyWatchDBus_m(filter_function)
 
#define oyFinishDBus_m
 
#define oyCallbackDBusCli_m(check_var)
 
#define oyStartDBusObserver(watch_, finish_, callback_, key_fragment, cb_context_)
 
#define oyLoopDBusObserver(hour, repeat_hour, check_var, update)
 

Detailed Description

DBus helper macros.

Macro Definition Documentation

◆ oyCallbackDBusCli_m

#define oyCallbackDBusCli_m (   check_var)
Value:
static void oyCallbackDBus ( double progress_zero_till_one, \
char * status_text, \
int thread_id_, \
int job_id, \
oyStruct_s * cb_progress_context OY_UNUSED ) \
{ fprintf( stderr,"%s():%d %02f %s %d/%d\n",__func__,__LINE__, \
progress_zero_till_one, \
status_text?status_text:"",thread_id_,job_id); \
/* Clear the changed state, before a new check. */ \
check_var = 1; \
}
Oyranos base structure.
Definition: oyStruct_s.h:78

oyJob_s::cb_progress for the main thread;

will be called inside oyJobResult()

◆ oyDBusFilter_m

#define oyDBusFilter_m

DBus filter function

◆ oyDbusReceiveMessage_m

#define oyDbusReceiveMessage_m

borrowed from libelektra project receivemessage.c BSD License

◆ oyFinishDBus_m

#define oyFinishDBus_m
Value:
static int oyFinishDBus( oyJob_s * job ) \
{ \
char * t = NULL; \
const char * tmp = oyOption_GetRegistration((oyOption_s*)job->context); \
if(job->cb_progress) \
{ \
if(tmp) \
{ \
t = (char*) malloc(80+strlen(__func__)+strlen(tmp)); \
sprintf( t, "%s():%d --->\n%s\n<--- finished", __func__,__LINE__, tmp ); \
} \
/* send a final message from inside the managing thread */ \
oyMsg_Add(job, 0.9, &t); \
} \
return 0; \
}
Asynchron job ticket.
Definition: oyranos_threads.h:46
Option object.
Definition: oyOption_s.h:148
const char * oyOption_GetRegistration(oyOption_s *option)
get the registration
Definition: oyOption_s.c:848

oyJob_s::finish for the main thread

◆ oyLoopDBusObserver

#define oyLoopDBusObserver (   hour,
  repeat_hour,
  check_var,
  update 
)
Value:
double hour_diff = hour_old - hour; \
\
if(hour_diff < 0.0) \
hour_diff += 24.0; \
if(hour_diff > 12) \
hour_diff = 24.0 - hour_diff; \
\
/* Here in the main/managing thread we wait for a changed state. */ \
oyJobResult(); \
\
if(check_var || hour_diff > repeat_hour ) \
/* check the sunrise / sunset state */ \
{ \
error = update; \
hour_old = hour; \
} \
\
/* Clear the changed state, before a new check. */ \
check_var = 0;

poll for updates double hour: current time double repeat_hour: repeat a full update in h int check_var: 1 means check, 0 means no check needed function update: will be called, when check_var is 1

◆ oyStartDBusObserver

#define oyStartDBusObserver (   watch_,
  finish_,
  callback_,
  key_fragment,
  cb_context_ 
)
Value:
/* use asynchron DBus observation \
* It is unknown when DBus message stream ends. Our DBus observer needs to \
* collect all messages and sends one update event after a reasonable time. \
*/ \
oyJob_s * job = oyJob_New( NULL ); \
/* This observer function keeps alive during the process run. */ \
job->work = watch_; \
/* Just a informational callback in case DBus quits. */ \
job->finish = finish_; \
oyOption_s * o = oyOption_FromRegistration( key_fragment, NULL ); \
oyOption_SetFromString( o, key_fragment, 0 ); \
job->context = (oyStruct_s*)o; \
/* The callback informs about DBus events now from inside the main thread. \
* Here we should set a update state. */ \
job->cb_progress = callback_; \
job->cb_progress_context = (oyStruct_s*)cb_context_; \
id = oyJob_Add( &job, 0, oyJOB_ADD_PERSISTENT_JOB );
oyJob_s * oyJob_New(oyObject_s object OY_UNUSED)
Allocate a new oyJob_s object.
Definition: oyranos_threads.c:298
oyJob_Add_f oyJob_Add
Add one unique oyJob_s to the job qeue.
Definition: oyranos_threads.c:202
oyOption_s * oyOption_FromRegistration(const char *registration, oyObject_s object)
new option with registration and value filled from DB if available
Definition: oyOption_s.c:122

setup the thread running the DBus observer simple version: oyStartDBusObserver( oyWatchDBus, oyFinishDBus, oyCallbackDBus, OY_STD )

◆ oyWatchDBus_m

#define oyWatchDBus_m (   filter_function)
Value:
oyDbusReceiveMessage_m \
static int oyWatchDBus( oyJob_s * job ) \
{ \
char * t = NULL; \
const char * tmp = oyOption_GetRegistration((oyOption_s*)job->context); \
if(job->cb_progress) \
{ \
if(tmp) \
{ \
t = (char*) malloc(80+strlen(__func__)+strlen(tmp)); \
sprintf( t, "%s():%d --->\n%s", __func__,__LINE__, tmp ); \
} \
/* send a first message from inside the worker thread */ \
oyMsg_Add(job, .1, &t); \
oyDbusReceiveMessage(DBUS_BUS_SESSION, filter_function, job); \
} \
return 0; \
}

covers oyDbusReceiveMessage_m oyJob_s::work for the processing thread