\doxysection{ecore\+\_\+exe\+\_\+example.\+c}
\hypertarget{ecore_exe_example_8c-example}{}\label{ecore_exe_example_8c-example}This is a process that will send messages to a child and it will stop when it receives "{}quit"{}.

This is a process that will send messages to a child and it will stop when it receives "{}quit"{}.Check the \doxysectlink{Ecore_exe_simple_example_c}{Full tutorial}{0}


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Ecore.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#define\ BUFFER\_SIZE\ 1024}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_msg\_from\_child\_handler(\textcolor{keywordtype}{void}\ *data\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{int}\ type\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *event)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Ecore__Exe__Event__Data}{Ecore\_Exe\_Event\_Data}}\ *dataFromProcess\ =\ (\mbox{\hyperlink{struct__Ecore__Exe__Event__Data}{Ecore\_Exe\_Event\_Data}}\ *)event;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ msg[BUFFER\_SIZE];}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (dataFromProcess-\/>\mbox{\hyperlink{struct__Ecore__Exe__Event__Data_a7d28f61d1dc37d2582ed1028c692c46f}{size}}\ >=\ (BUFFER\_SIZE\ -\/\ 1))}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}Data\ too\ big\ for\ bugger.\ error\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga780091d7d49a4bb6cb753f12e1a3b19d}{ECORE\_CALLBACK\_DONE}};}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ strncpy(msg,\ dataFromProcess-\/>\mbox{\hyperlink{struct__Ecore__Exe__Event__Data_a5af41c740afab1ba763ba2dc14807802}{data}},\ dataFromProcess-\/>\mbox{\hyperlink{struct__Ecore__Exe__Event__Data_a7d28f61d1dc37d2582ed1028c692c46f}{size}});}
\DoxyCodeLine{\ \ \ msg[dataFromProcess-\/>\mbox{\hyperlink{struct__Ecore__Exe__Event__Data_a7d28f61d1dc37d2582ed1028c692c46f}{size}}]\ =\ 0;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (strcmp(msg,\ \textcolor{stringliteral}{"{}quit"{}})\ ==\ 0)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}My\ child\ said\ to\ me,\ QUIT!\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{\ \ \ \ \ printf(\textcolor{stringliteral}{"{}I\ received\ a\ message\ from\ my\ child:\ \%s\(\backslash\)n"{}},\ msg);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga780091d7d49a4bb6cb753f12e1a3b19d}{ECORE\_CALLBACK\_DONE}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_sendMessage(\textcolor{keywordtype}{void}\ *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ numberOfMessages\ =\ 0;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{structEcore__Exe}{Ecore\_Exe}}\ *childHandle\ =\ (\mbox{\hyperlink{structEcore__Exe}{Ecore\_Exe}}\ *)data;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ msg[BUFFER\_SIZE];}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ sprintf(msg,\ \textcolor{stringliteral}{"{}\ Message:\ \%d\(\backslash\)n"{}},\ numberOfMessages);}
\DoxyCodeLine{\ \ \ numberOfMessages++;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (\mbox{\hyperlink{group__Ecore__Exe__Group_gac5a7d73f64baf6b752154836ff4123b9}{ecore\_exe\_send}}(childHandle,\ msg,\ strlen(msg))\ !=\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}})}
\DoxyCodeLine{\ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Could\ not\ send\ my\ name\ to\ the\ child\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{\ \ \ \ \ printf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}I'm\ the\ father\ and\ I\ sent\ this\ message\ to\ the\ child:\ \%s\(\backslash\)n"{}},\ msg);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ pid\_t\ childPid;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{structEcore__Exe}{Ecore\_Exe}}\ *childHandle;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!\mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}())}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{goto}\ exit;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ childHandle\ =\ \mbox{\hyperlink{group__Ecore__Exe__Group_ga3446e8232234ab6a72b5b486304fa527}{ecore\_exe\_pipe\_run}}(\textcolor{stringliteral}{"{}./ecore\_exe\_example\_child"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore_gga26f57bfa7ecfa8eee5fc053e342880c5a83dcb150caa9f5f4ce548eaa4a92c6af}{ECORE\_EXE\_PIPE\_WRITE}}\ |}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore_gga26f57bfa7ecfa8eee5fc053e342880c5ae97566413d58b792e92369966ffeece5}{ECORE\_EXE\_PIPE\_READ\_LINE\_BUFFERED}}\ |}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore_gga26f57bfa7ecfa8eee5fc053e342880c5a76bc9e447a456727dc2d686b4682b512}{ECORE\_EXE\_PIPE\_READ}},\ NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (childHandle\ ==\ NULL)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Could\ not\ create\ a\ child\ process!\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}};}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ childPid\ =\ \mbox{\hyperlink{group__Ecore__Exe__Group_ga31fa4d88303d0dc45b3dfdb55fb53883}{ecore\_exe\_pid\_get}}(childHandle);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (childPid\ ==\ -\/1)}
\DoxyCodeLine{\ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Could\ not\ retrieve\ the\ PID!\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{\ \ \ \ \ printf(\textcolor{stringliteral}{"{}The\ child\ process\ has\ PID:\%u\(\backslash\)n"{}},\ (\textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int})childPid);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Event__Group_ga886c90c3f917f87b3b4c931adcbc41c5}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Exe__Group_ga3a5071bbc714abfbcede55c39c6ecf8a}{ECORE\_EXE\_EVENT\_DATA}},\ \_msg\_from\_child\_handler,\ NULL);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Timer__Group_ga926423e464d7ef71105dd822d90e1187}{ecore\_timer\_add}}(1,\ \_sendMessage,\ childHandle);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Exe__Group_ga85f063784945f235f231155b2e86be3d}{ecore\_exe\_free}}(childHandle);\ \textcolor{comment}{//This\ will\ not\ affect\ the\ child\ process}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ EXIT\_SUCCESS;}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}:}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{exit:}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ EXIT\_FAILURE;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 