\hypertarget{ecore_event_example_02_8c-example}{}\doxysection{ecore\+\_\+event\+\_\+example\+\_\+02.\+c}
This example shows how to setup, change, and delete event handlers.

This example shows how to setup, change, and delete event handlers. See \mbox{\hyperlink{ecore_event_example_02_c}{the explanation here}}.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile\ with:}}
\DoxyCodeLine{\textcolor{comment}{//\ gcc\ -\/g\ -\/Wall\ -\/o\ ecore\_event\_example\_02\ ecore\_event\_example\_02.c\ `pkg-\/config\ -\/-\/cflags\ -\/-\/libs\ ecore`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Ecore.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{keyword}{const}\ \textcolor{keywordtype}{char}\ \ \ \ \ \ \ \ \ \ *str1,\ *str2;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Event__Group_ga252a2566c9c7c9094964ab8e157f0521}{Ecore\_Event\_Handler}}\ *handler1;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Event__Group_ga252a2566c9c7c9094964ab8e157f0521}{Ecore\_Event\_Handler}}\ *handler2;}
\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{\_event\_handler1\_cb(\textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{int}\ type\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *event)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ *number\ =\ event;}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *str\ =\ data;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}event\_handler1:\ number=\%d,\ data=\(\backslash\)"{}\%s\(\backslash\)"{}.\(\backslash\)n"{}},\ *number,\ str);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ ((*number\ \%\ 2)\ ==\ 0)}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga780091d7d49a4bb6cb753f12e1a3b19d}{ECORE\_CALLBACK\_DONE}};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga6a2922b8aa10c60f27c8ab49d84d75f2}{ECORE\_CALLBACK\_PASS\_ON}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_event\_handler2\_cb(\textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{int}\ type\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *event)\ \textcolor{comment}{//\ event\ callback}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{struct\ }context\ *ctxt\ =\ data;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ *number\ =\ event;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}event\_handler2:\ number=\%d.\(\backslash\)n"{}},\ *number);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (*number\ ==\ 5)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *old\ =\ NULL;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ old\ =\ \mbox{\hyperlink{group__Ecore__Event__Group_gaf9345a1d588ea72d5d64c7dbe04969f7}{ecore\_event\_handler\_data\_set}}(ctxt-\/>handler1,\ (\textcolor{keywordtype}{void}\ *)ctxt-\/>str2);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}changed\ handler1\ data\ from\ \(\backslash\)"{}\%s\(\backslash\)"{}\ to\ \(\backslash\)"{}\%s\(\backslash\)"{}.\(\backslash\)n"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ old,\ ctxt-\/>str2);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (*number\ >=\ 10)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}finish\ main\ loop.\(\backslash\)n"{}});}
\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{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{struct\ }context\ ctxt\ =\ \{0\};}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ i;}
\DoxyCodeLine{\ \ \ ctxt.str1\ =\ \textcolor{stringliteral}{"{}dataone"{}};}
\DoxyCodeLine{\ \ \ ctxt.str2\ =\ \textcolor{stringliteral}{"{}datatwo"{}};}
\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.handler1\ =\ \mbox{\hyperlink{group__Ecore__Event__Group_ga886c90c3f917f87b3b4c931adcbc41c5}{ecore\_event\_handler\_add}}(\_event\_type,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_event\_handler1\_cb,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ctxt.str1);}
\DoxyCodeLine{\ \ \ ctxt.handler2\ =\ \mbox{\hyperlink{group__Ecore__Event__Group_ga886c90c3f917f87b3b4c931adcbc41c5}{ecore\_event\_handler\_add}}(\_event\_type,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_event\_handler2\_cb,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \&ctxt);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <=\ 15;\ i++)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ *event\_data\ =\ malloc(\textcolor{keyword}{sizeof}(*event\_data));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ *event\_data\ =\ i;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Event__Group_ga81a4c863503927fb70fa5f35625c4352}{ecore\_event\_add}}(\_event\_type,\ event\_data,\ NULL,\ NULL);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}start\ the\ main\ loop.\(\backslash\)n"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 