\hypertarget{ecore_poller_example_8c-example}{}\section{ecore\+\_\+poller\+\_\+example.\+c}
This example shows how to setup and use a poller. See \mbox{\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} \mbox{\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, \mbox{\hyperlink{group__Ecore__Time__Group_ga98f2439b5d3e7114a75bfe2f0c22c4e9}{ecore\_time\_get}}() - \_initial\_time);

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

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

   \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();
   \textcolor{keywordflow}{return} \mbox{\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}
   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} (!\mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}())
     \{
        printf(\textcolor{stringliteral}{"ERROR: Cannot init Ecore!\(\backslash\)n"});
        \textcolor{keywordflow}{return} -1;
     \}

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

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

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

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


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

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

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

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

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

\end{DoxyCodeInclude}
 