\hypertarget{ecore_poller_example_8c-example}{\section{ecore\+\_\+poller\+\_\+example.\+c}
}
This example shows how to setup and use a poller. See \hyperlink{ecore_poller_example_c}{the explanation here}.


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// gcc -o ecore\_poller\_example ecore\_poller\_example.c `pkg-config --libs --cflags ecore eo`}

\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{comment}{//#include <Ecore\_Eo.h>}
\textcolor{preprocessor}{#include <unistd.h>}

\textcolor{keyword}{static} \textcolor{keywordtype}{double} \_initial\_time = 0;

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_poller\_print\_cb(\textcolor{keywordtype}{void} *data)
\{
   \textcolor{keywordtype}{char} *str = data;
   printf(\textcolor{stringliteral}{"Ecore Poller '%s' callback called after %0.3f seconds.\(\backslash\)n"},
          str, \hyperlink{group__Ecore__Time__Group_ga98f2439b5d3e7114a75bfe2f0c22c4e9}{ecore\_time\_get}() - \_initial\_time);

   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW};
\}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_poller\_quit\_cb(\textcolor{keywordtype}{void} *data \hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED})
\{

   \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();
   \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE};
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{void})
\{
   \textcolor{keywordtype}{double} interval = 0.3; \textcolor{comment}{// tick each 0.3 seconds}
   \hyperlink{group__Ecore__Poller__Group_ga437f925a7a71ee670bbf8cdd4a258f53}{Ecore\_Poller} *poller1, *poller2, *poller3;
   \textcolor{keywordtype}{char} *str1 = \textcolor{stringliteral}{"poller1"};
   \textcolor{keywordtype}{char} *str2 = \textcolor{stringliteral}{"poller2"};
   \textcolor{keywordtype}{char} *str3 = \textcolor{stringliteral}{"poller3"};

   \textcolor{keywordflow}{if} (!\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}())
     \{
        printf(\textcolor{stringliteral}{"ERROR: Cannot init Ecore!\(\backslash\)n"});
        \textcolor{keywordflow}{return} -1;
     \}

   \_initial\_time = \hyperlink{group__Ecore__Time__Group_ga98f2439b5d3e7114a75bfe2f0c22c4e9}{ecore\_time\_get}();

   \hyperlink{group__Ecore__Poller__Group_ga466dff0c7fb7eb0f5b4e5a3825fa10ac}{ecore\_poller\_poll\_interval\_set}(
      \hyperlink{group__Ecore__Poller__Group_gga50dcd2652ba68fe4aac51c70c3fa1e2ca022dfec751388e380cf01621bd0f797f}{ECORE\_POLLER\_CORE}, interval);

   poller1 = \hyperlink{group__Ecore__Poller__Group_gadd8ee7135864da4313bc88faa0a2d7c9}{ecore\_poller\_add}(\hyperlink{group__Ecore__Poller__Group_gga50dcd2652ba68fe4aac51c70c3fa1e2ca022dfec751388e380cf01621bd0f797f}{ECORE\_POLLER\_CORE}, 4, \_poller\_print\_cb, str1
      );
   poller2 = \hyperlink{group__Ecore__Poller__Group_gadd8ee7135864da4313bc88faa0a2d7c9}{ecore\_poller\_add}(\hyperlink{group__Ecore__Poller__Group_gga50dcd2652ba68fe4aac51c70c3fa1e2ca022dfec751388e380cf01621bd0f797f}{ECORE\_POLLER\_CORE}, 8, \_poller\_print\_cb, str2
      );
   poller3 = \hyperlink{group__Ecore__Poller__Group_gadd8ee7135864da4313bc88faa0a2d7c9}{ecore\_poller\_add}(\hyperlink{group__Ecore__Poller__Group_gga50dcd2652ba68fe4aac51c70c3fa1e2ca022dfec751388e380cf01621bd0f797f}{ECORE\_POLLER\_CORE}, 30, \_poller\_quit\_cb, str3
      );

\textcolor{comment}{//   poller1 = eo\_add(ECORE\_POLLER\_CLASS, NULL,}
\textcolor{comment}{//         ecore\_poller\_constructor(ECORE\_POLLER\_CORE, 4, \_poller\_print\_cb, str1));}
\textcolor{comment}{//   poller2 = eo\_add(ECORE\_POLLER\_CLASS, NULL,}
\textcolor{comment}{//         ecore\_poller\_constructor(ECORE\_POLLER\_CORE, 8, \_poller\_print\_cb, str2));}
\textcolor{comment}{//   poller3 = eo\_add(ECORE\_POLLER\_CLASS, NULL,}
\textcolor{comment}{//         ecore\_poller\_constructor(ECORE\_POLLER\_CORE, 20, \_poller\_quit\_cb, str3));}


   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

   printf(\textcolor{stringliteral}{"changing poller2 interval to 16\(\backslash\)n"});

   ecore\_poller\_poller\_interval\_set(poller2, 16);
\textcolor{comment}{//   eo\_do(poller2, ecore\_poller\_interval\_set(16, NULL));}
   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

\textcolor{comment}{//   eo\_unref(poller1);}
\textcolor{comment}{//   eo\_unref(poller2);}
\textcolor{comment}{//   eo\_unref(poller3);}
   \hyperlink{group__Ecore__Poller__Group_ga52e6245cfbceaed9b721a1addd29d311}{ecore\_poller\_del}(poller1);
   \hyperlink{group__Ecore__Poller__Group_ga52e6245cfbceaed9b721a1addd29d311}{ecore\_poller\_del}(poller2);
   \hyperlink{group__Ecore__Poller__Group_ga52e6245cfbceaed9b721a1addd29d311}{ecore\_poller\_del}(poller3);

   \hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}();
\}

\end{DoxyCodeInclude}
 