\hypertarget{ecore_idler_example_8c-example}{}\doxysection{ecore\+\_\+idler\+\_\+example.\+c}
This example shows when \mbox{\hyperlink{group__Ecore__Idle__Group_gae4e7f2215a6e8cff3e2eab2582b5868e}{Ecore\+\_\+\+Idler}}, \mbox{\hyperlink{group__Ecore__Idle__Group_gadc4e81cb020047be0f8f36db6d942ed3}{Ecore\+\_\+\+Idle\+\_\+\+Enterer}} and \mbox{\hyperlink{group__Ecore__Idle__Group_gaa07d755d135454aa97625464aab4adf8}{Ecore\+\_\+\+Idle\+\_\+\+Exiter}} are called. See \mbox{\hyperlink{ecore_idler_example_c}{the explanation here}}.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile with:}}
\DoxyCodeLine{\textcolor{comment}{// gcc -\/o ecore\_idler\_example ecore\_idler\_example.c `pkg-\/config -\/-\/libs -\/-\/cflags ecore eo`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#ifdef HAVE\_CONFIG\_H}}
\DoxyCodeLine{\textcolor{preprocessor}{\# include <config.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Ecore.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Eo.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <unistd.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{struct }context   \textcolor{comment}{// helper struct to give some context to the callbacks}}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{int}                  count;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Idle__Group_gadc4e81cb020047be0f8f36db6d942ed3}{Ecore\_Idle\_Enterer}}  *enterer;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Idle__Group_gae4e7f2215a6e8cff3e2eab2582b5868e}{Ecore\_Idler}}         *idler;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Idle__Group_gaa07d755d135454aa97625464aab4adf8}{Ecore\_Idle\_Exiter}}   *exiter;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Event__Group_ga252a2566c9c7c9094964ab8e157f0521}{Ecore\_Event\_Handler}} *handler;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Timer__Group_gaf96ffb609956658ec038e54bd39f46f0}{Ecore\_Timer}}         *timer;}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{int} \_event\_type = 0; \textcolor{comment}{// a new type of event will be defined and stored here}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_enterer\_cb(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}) \textcolor{comment}{// the idle enterer callback}}
\DoxyCodeLine{\{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}IDLE ENTERER: Ecore entering in idle state.\(\backslash\)n"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}}; \textcolor{comment}{// same as EINA\_TRUE}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_exiter\_cb(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}) \textcolor{comment}{// the idle exiter callback}}
\DoxyCodeLine{\{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}IDLE EXITER: Ecore exiting idle state.\(\backslash\)n"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}}; \textcolor{comment}{// same as EINA\_TRUE}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_idler\_cb(\textcolor{keywordtype}{void} *data) \textcolor{comment}{// the idler callback -\/ ran while the mainloop is idle}}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{struct }context *ctxt = data;}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}IDLER: executing idler callback while in idle state.\(\backslash\)n"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{   ctxt-\/>count++;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{/* each 10 times that the callback gets called, generate an event that}}
\DoxyCodeLine{\textcolor{comment}{    * will wake up the main loop, triggering idle enterers, exiters, etc. */}}
\DoxyCodeLine{   \textcolor{keywordflow}{if} ((ctxt-\/>count \% 10) == 0)}
\DoxyCodeLine{     \mbox{\hyperlink{group__Ecore__Event__Group_ga81a4c863503927fb70fa5f35625c4352}{ecore\_event\_add}}(\_event\_type, NULL, NULL, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}}; \textcolor{comment}{// same as EINA\_TRUE}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_event\_handler\_cb(\textcolor{keywordtype}{void} *data, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{void} *event \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}) \textcolor{comment}{// event callback}}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{struct }context *ctxt = data;}
\DoxyCodeLine{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}EVENT: processing callback for the event received.\(\backslash\)n"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (ctxt-\/>count > 100)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Ecore__Idle__Group_gabdce29c943a3f6092e6de3d57eec47bc}{ecore\_idle\_enterer\_del}}(ctxt-\/>enterer);}
\DoxyCodeLine{        \mbox{\hyperlink{group__Ecore__Idle__Group_ga32d53388d9eefe74a6f910d7c0e636f2}{ecore\_idle\_exiter\_del}}(ctxt-\/>exiter);}
\DoxyCodeLine{\textcolor{comment}{//        ecore\_idler\_del(ctxt-\/>idler);}}
\DoxyCodeLine{}
\DoxyCodeLine{        ctxt-\/>enterer = NULL;}
\DoxyCodeLine{        ctxt-\/>exiter = NULL;}
\DoxyCodeLine{        ctxt-\/>idler = NULL;}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (ctxt-\/>timer)}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             \mbox{\hyperlink{group__Ecore__Timer__Group_ga7c118b6a6d232b63a6500e599d2a1b47}{ecore\_timer\_del}}(ctxt-\/>timer);}
\DoxyCodeLine{             ctxt-\/>timer = NULL;}
\DoxyCodeLine{          \}}
\DoxyCodeLine{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga780091d7d49a4bb6cb753f12e1a3b19d}{ECORE\_CALLBACK\_DONE}}; \textcolor{comment}{// same as EINA\_FALSE}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_timer\_cb(\textcolor{keywordtype}{void} *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{struct }context *ctxt = data;}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}TIMER: timer callback called.\(\backslash\)n"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (ctxt-\/>timer)}
\DoxyCodeLine{     ctxt-\/>timer = NULL;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gae0c653baad8836232c0dc27f91f875d6}{ECORE\_CALLBACK\_CANCEL}}; \textcolor{comment}{// same as EINA\_FALSE}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{struct }context ctxt = \{0\};}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!\mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}())}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        printf(\textcolor{stringliteral}{"{}ERROR: Cannot init Ecore!\(\backslash\)n"{}});}
\DoxyCodeLine{        \textcolor{keywordflow}{return} -\/1;}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \_event\_type = \mbox{\hyperlink{group__Ecore__Event__Group_ga3fad8d8bfe3776c69d33aff1f056ba89}{ecore\_event\_type\_new}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   ctxt.enterer = \mbox{\hyperlink{group__Ecore__Idle__Group_ga2120fcb2f5a5a3ead1e2c11f5424e4b8}{ecore\_idle\_enterer\_add}}(\_enterer\_cb, \&ctxt);}
\DoxyCodeLine{   ctxt.exiter = \mbox{\hyperlink{group__Ecore__Idle__Group_gade5eb53697d4d4f62d18314f2ce0d42a}{ecore\_idle\_exiter\_add}}(\_exiter\_cb, \&ctxt);}
\DoxyCodeLine{   ctxt.idler = \mbox{\hyperlink{group__Ecore__Idle__Group_gaaf001b1f13fb633d0f486feec76e026b}{ecore\_idler\_add}}(\_idler\_cb, \&ctxt);}
\DoxyCodeLine{\textcolor{comment}{//   ctxt.idler = efl\_add\_ref(ECORE\_IDLER\_CLASS, NULL, ecore\_idler\_constructor(efl\_added, \_idler\_cb, \&ctxt));}}
\DoxyCodeLine{   ctxt.handler = \mbox{\hyperlink{group__Ecore__Event__Group_ga886c90c3f917f87b3b4c931adcbc41c5}{ecore\_event\_handler\_add}}(\_event\_type,}
\DoxyCodeLine{                                          \_event\_handler\_cb,}
\DoxyCodeLine{                                          \&ctxt);}
\DoxyCodeLine{   ctxt.timer = \mbox{\hyperlink{group__Ecore__Timer__Group_ga926423e464d7ef71105dd822d90e1187}{ecore\_timer\_add}}(0.0005, \_timer\_cb, \&ctxt);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 