\hypertarget{ecore_pipe_simple_example_8c-example}{}\doxysection{ecore\+\_\+pipe\+\_\+simple\+\_\+example.\+c}

\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile\ with:}}
\DoxyCodeLine{\textcolor{comment}{//gcc\ -\/g\ -\/Wall\ -\/o\ ecore\_pipe\_simple\_example\ ecore\_pipe\_simple\_example.c\ `pkg-\/config\ -\/-\/cflags\ -\/-\/libs\ ecore`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <unistd.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Ecore.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{do\_lengthy\_task(\mbox{\hyperlink{group__Ecore__Pipe__Group_ga0092a6b764881362d1a051d7af215b3f}{Ecore\_Pipe}}\ *pipe)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ i,\ j;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ *buffer;}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ 20;\ i++)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ sleep(1);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ buffer\ =\ malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char})\ *\ i);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ i;\ j++)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ buffer[j]\ =\ \textcolor{charliteral}{'a'}\ +\ j;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_ga5336bc71e829c391926c26750ae0f407}{ecore\_pipe\_write}}(pipe,\ buffer,\ i);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ free(buffer);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_ga5336bc71e829c391926c26750ae0f407}{ecore\_pipe\_write}}(pipe,\ \textcolor{stringliteral}{"{}close"{}},\ 5);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{handler(\textcolor{keywordtype}{void}\ *data\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *buf,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ len)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ *str\ =\ malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char})\ *\ len\ +\ 1);}
\DoxyCodeLine{\ \ \ memcpy(str,\ buf,\ len);}
\DoxyCodeLine{\ \ \ str[len]\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}received\ \%u\ bytes\(\backslash\)n"{}},\ len);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}content:\ \%s\(\backslash\)n"{}},\ (\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *)str);}
\DoxyCodeLine{\ \ \ free(str);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (len\ \&\&\ !strncmp(buf,\ \textcolor{stringliteral}{"{}close"{}},\ len\ <\ 5\ ?\ len\ :\ 5))}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}close\ requested\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_ga0092a6b764881362d1a051d7af215b3f}{Ecore\_Pipe}}\ *pipe;}
\DoxyCodeLine{\ \ \ pid\_t\ child\_pid;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ pipe\ =\ \mbox{\hyperlink{group__Ecore__Pipe__Group_gaa1fb078d1865197887f558e19532e02d}{ecore\_pipe\_add}}(handler,\ NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ child\_pid\ =\ fork();}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!child\_pid)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_gab9df469d955d67dbcd95fd6f2dabdc79}{ecore\_pipe\_read\_close}}(pipe);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ do\_lengthy\_task(pipe);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_ga60099202e0880dd3de617ca14fa0c58b}{ecore\_pipe\_write\_close}}(pipe);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_gaa7ed35ca29f47097e30ccd83776d5866}{ecore\_pipe\_del}}(pipe);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 