
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{1 \textcolor{comment}{//Compile with:}}
\DoxyCodeLine{2 \textcolor{comment}{// gcc -\/o eet-\/data-\/simple eet-\/data-\/simple.c `pkg-\/config -\/-\/cflags -\/-\/libs eet eina`}}
\DoxyCodeLine{3 }
\DoxyCodeLine{4 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}}
\DoxyCodeLine{5 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{Eet_8h}{Eet.h}}>}}
\DoxyCodeLine{6 \textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{7 \textcolor{preprocessor}{\#include <limits.h>}}
\DoxyCodeLine{8 \textcolor{preprocessor}{\#include <sys/types.h>}}
\DoxyCodeLine{9 \textcolor{preprocessor}{\#include <sys/stat.h>}}
\DoxyCodeLine{10 \textcolor{preprocessor}{\#include <unistd.h>}}
\DoxyCodeLine{11 }
\DoxyCodeLine{12 \textcolor{comment}{// The struct that will be loaded and saved.}}
\DoxyCodeLine{13 \textcolor{comment}{// note that only the members described in the eet\_data\_descriptor}}
\DoxyCodeLine{14 \textcolor{comment}{// will be automatically handled. The other members will have their}}
\DoxyCodeLine{15 \textcolor{comment}{// space reserved and zeroed (as it uses calloc()), but not}}
\DoxyCodeLine{16 \textcolor{comment}{// saved or loaded from eet files.}}
\DoxyCodeLine{17 \textcolor{keyword}{typedef} \textcolor{keyword}{struct}}
\DoxyCodeLine{18 \{}
\DoxyCodeLine{19    \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} version; \textcolor{comment}{// it is recommended to use versioned configuration!}}
\DoxyCodeLine{20    \textcolor{keyword}{const} \textcolor{keywordtype}{char}  *name;}
\DoxyCodeLine{21    \textcolor{keywordtype}{int}          id;}
\DoxyCodeLine{22    \textcolor{keywordtype}{int}          not\_saved\_value; \textcolor{comment}{// example of not saved data inside!}}
\DoxyCodeLine{23    \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}    enabled;}
\DoxyCodeLine{24 \} My\_Conf\_Type;}
\DoxyCodeLine{25 }
\DoxyCodeLine{26 \textcolor{comment}{// string that represents the entry in eet file, you might like to have}}
\DoxyCodeLine{27 \textcolor{comment}{// different profiles or so in the same file, this is possible with}}
\DoxyCodeLine{28 \textcolor{comment}{// different strings}}
\DoxyCodeLine{29 \textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} MY\_CONF\_FILE\_ENTRY[] = \textcolor{stringliteral}{"{}config"{}};}
\DoxyCodeLine{30 }
\DoxyCodeLine{31 \textcolor{comment}{// keep the descriptor static global, so it can be}}
\DoxyCodeLine{32 \textcolor{comment}{// shared by different functions (load/save) of this and only this}}
\DoxyCodeLine{33 \textcolor{comment}{// file.}}
\DoxyCodeLine{34 \textcolor{keyword}{static} \mbox{\hyperlink{group__Eet__Data__Group_ga4baec0e840012480a0958c5c3bca276d}{Eet\_Data\_Descriptor}} *\_my\_conf\_descriptor;}
\DoxyCodeLine{35 }
\DoxyCodeLine{36 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{37 \_my\_conf\_descriptor\_init(\textcolor{keywordtype}{void})}
\DoxyCodeLine{38 \{}
\DoxyCodeLine{39    \mbox{\hyperlink{struct__Eet__Data__Descriptor__Class}{Eet\_Data\_Descriptor\_Class}} eddc;}
\DoxyCodeLine{40 }
\DoxyCodeLine{41    \textcolor{comment}{// The class describe the functions to use to create the type and its}}
\DoxyCodeLine{42    \textcolor{comment}{// full allocated size.}}
\DoxyCodeLine{43    \textcolor{comment}{//}}
\DoxyCodeLine{44    \textcolor{comment}{// Eina types are very convenient, so use them to create the descriptor,}}
\DoxyCodeLine{45    \textcolor{comment}{// so we get eina\_list,  eina\_hash and eina\_stringshare automatically!}}
\DoxyCodeLine{46    \textcolor{comment}{//}}
\DoxyCodeLine{47    \textcolor{comment}{// The STREAM variant is better for configuration files as the values}}
\DoxyCodeLine{48    \textcolor{comment}{// will likely change a lot.}}
\DoxyCodeLine{49    \textcolor{comment}{//}}
\DoxyCodeLine{50    \textcolor{comment}{// The other variant, FILE, is good for caches and things that are just}}
\DoxyCodeLine{51    \textcolor{comment}{// appended, but needs to take care when changing strings and files must}}
\DoxyCodeLine{52    \textcolor{comment}{// be kept open so mmap()ed strings will be kept alive.}}
\DoxyCodeLine{53    \mbox{\hyperlink{group__Eet__Data__Group_ga941b1fcd6c6c72221d9390f9a0ed751c}{EET\_EINA\_STREAM\_DATA\_DESCRIPTOR\_CLASS\_SET}}(\&eddc, My\_Conf\_Type);}
\DoxyCodeLine{54    \_my\_conf\_descriptor = \mbox{\hyperlink{group__Eet__Data__Group_ga5c2ad8edc9910f201b0dcbdbc5cc2694}{eet\_data\_descriptor\_stream\_new}}(\&eddc);}
\DoxyCodeLine{55 }
\DoxyCodeLine{56    \textcolor{comment}{// Describe the members to be saved:}}
\DoxyCodeLine{57    \textcolor{comment}{// Use a temporary macro so we don't type a lot, also avoid errors:}}
\DoxyCodeLine{58 \textcolor{preprocessor}{\#define MY\_CONF\_ADD\_BASIC(member, eet\_type) \(\backslash\)}}
\DoxyCodeLine{59 \textcolor{preprocessor}{  EET\_DATA\_DESCRIPTOR\_ADD\_BASIC             \(\backslash\)}}
\DoxyCodeLine{60 \textcolor{preprocessor}{    (\_my\_conf\_descriptor, My\_Conf\_Type, \# member, member, eet\_type)}}
\DoxyCodeLine{61 }
\DoxyCodeLine{62    MY\_CONF\_ADD\_BASIC(version, \mbox{\hyperlink{group__Eet__Data__Group_gacf6a3c9f06e10e20be5b02cd8c6a220b}{EET\_T\_UINT}});}
\DoxyCodeLine{63    MY\_CONF\_ADD\_BASIC(name, \mbox{\hyperlink{group__Eet__Data__Group_ga0d2cf409bf3f151156d74d18ac59e3d1}{EET\_T\_STRING}});}
\DoxyCodeLine{64    MY\_CONF\_ADD\_BASIC(\textcolor{keywordtype}{id}, \mbox{\hyperlink{group__Eet__Data__Group_ga4e196733795867f14c6e387af7287baa}{EET\_T\_INT}});}
\DoxyCodeLine{65    MY\_CONF\_ADD\_BASIC(enabled, \mbox{\hyperlink{group__Eet__Data__Group_ga09a1341cc158fda0ba60ad2386ecd795}{EET\_T\_UCHAR}});}
\DoxyCodeLine{66 }
\DoxyCodeLine{67 \textcolor{preprocessor}{\#undef MY\_CONF\_ADD\_BASIC}}
\DoxyCodeLine{68 \} \textcolor{comment}{/* \_my\_conf\_descriptor\_init */}}
\DoxyCodeLine{69 }
\DoxyCodeLine{70 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{71 \_my\_conf\_descriptor\_shutdown(\textcolor{keywordtype}{void})}
\DoxyCodeLine{72 \{}
\DoxyCodeLine{73    \mbox{\hyperlink{group__Eet__Data__Group_ga3e2b601720973d0e1f4683768a593c4d}{eet\_data\_descriptor\_free}}(\_my\_conf\_descriptor);}
\DoxyCodeLine{74 \} \textcolor{comment}{/* \_my\_conf\_descriptor\_shutdown */}}
\DoxyCodeLine{75 }
\DoxyCodeLine{76 \textcolor{keyword}{static} My\_Conf\_Type *}
\DoxyCodeLine{77 \_my\_conf\_new(\textcolor{keywordtype}{void})}
\DoxyCodeLine{78 \{}
\DoxyCodeLine{79    My\_Conf\_Type *my\_conf = calloc(1, \textcolor{keyword}{sizeof}(My\_Conf\_Type));}
\DoxyCodeLine{80    \textcolor{keywordflow}{if} (!my\_conf)}
\DoxyCodeLine{81      \{}
\DoxyCodeLine{82         fprintf(stderr, \textcolor{stringliteral}{"{}ERROR: could not calloc My\_Conf\_Type\(\backslash\)n"{}});}
\DoxyCodeLine{83         \textcolor{keywordflow}{return} NULL;}
\DoxyCodeLine{84      \}}
\DoxyCodeLine{85 }
\DoxyCodeLine{86    my\_conf-\/>version = 0x112233;}
\DoxyCodeLine{87    my\_conf-\/>enabled = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{88    \textcolor{keywordflow}{return} my\_conf;}
\DoxyCodeLine{89 \} \textcolor{comment}{/* \_my\_conf\_new */}}
\DoxyCodeLine{90 }
\DoxyCodeLine{91 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{92 \_my\_conf\_free(My\_Conf\_Type *my\_conf)}
\DoxyCodeLine{93 \{}
\DoxyCodeLine{94    \mbox{\hyperlink{group__Eina__Stringshare__Group_ga5538b4a134987b8a01744fad1a845ba4}{eina\_stringshare\_del}}(my\_conf-\/>name);}
\DoxyCodeLine{95    free(my\_conf);}
\DoxyCodeLine{96 \} \textcolor{comment}{/* \_my\_conf\_free */}}
\DoxyCodeLine{97 }
\DoxyCodeLine{98 \textcolor{keyword}{static} My\_Conf\_Type *}
\DoxyCodeLine{99 \_my\_conf\_load(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *filename)}
\DoxyCodeLine{100 \{}
\DoxyCodeLine{101    My\_Conf\_Type *my\_conf;}
\DoxyCodeLine{102    \mbox{\hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File}} *ef = \mbox{\hyperlink{group__Eet__File__Group_ga675160a758832ee812edf7f64ed30ee6}{eet\_open}}(filename, \mbox{\hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a416f7e9a76b8131a44bbeedb13060c81}{EET\_FILE\_MODE\_READ}});}
\DoxyCodeLine{103    \textcolor{keywordflow}{if} (!ef)}
\DoxyCodeLine{104      \{}
\DoxyCodeLine{105         fprintf(stderr, \textcolor{stringliteral}{"{}ERROR: could not open '\%s' for read\(\backslash\)n"{}}, filename);}
\DoxyCodeLine{106         \textcolor{keywordflow}{return} NULL;}
\DoxyCodeLine{107      \}}
\DoxyCodeLine{108 }
\DoxyCodeLine{109    my\_conf = \mbox{\hyperlink{group__Eet__Data__Group_ga4c09f4dfb051baabc0c0551ea98b6830}{eet\_data\_read}}(ef, \_my\_conf\_descriptor, MY\_CONF\_FILE\_ENTRY);}
\DoxyCodeLine{110    \textcolor{keywordflow}{if} (!my\_conf)}
\DoxyCodeLine{111      \textcolor{keywordflow}{goto} end;}
\DoxyCodeLine{112 }
\DoxyCodeLine{113    \textcolor{keywordflow}{if} (my\_conf-\/>version < 0x112233)}
\DoxyCodeLine{114      \{}
\DoxyCodeLine{115         fprintf(stderr,}
\DoxyCodeLine{116                 \textcolor{stringliteral}{"{}WARNING: version \%\#x was too old, upgrading it to \%\#x\(\backslash\)n"{}},}
\DoxyCodeLine{117                 my\_conf-\/>version, 0x112233);}
\DoxyCodeLine{118 }
\DoxyCodeLine{119         my\_conf-\/>version = 0x112233;}
\DoxyCodeLine{120         my\_conf-\/>enabled = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{121      \}}
\DoxyCodeLine{122 }
\DoxyCodeLine{123 end:}
\DoxyCodeLine{124    \mbox{\hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}}(ef);}
\DoxyCodeLine{125    \textcolor{keywordflow}{return} my\_conf;}
\DoxyCodeLine{126 \} \textcolor{comment}{/* \_my\_conf\_load */}}
\DoxyCodeLine{127 }
\DoxyCodeLine{128 \textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{129 \_my\_conf\_save(\textcolor{keyword}{const} My\_Conf\_Type *my\_conf,}
\DoxyCodeLine{130               \textcolor{keyword}{const} \textcolor{keywordtype}{char}         *filename)}
\DoxyCodeLine{131 \{}
\DoxyCodeLine{132    \textcolor{keywordtype}{char} tmp[PATH\_MAX];}
\DoxyCodeLine{133    \mbox{\hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File}} *ef;}
\DoxyCodeLine{134    \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} ret;}
\DoxyCodeLine{135    \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} i, len;}
\DoxyCodeLine{136    \textcolor{keyword}{struct }stat st;}
\DoxyCodeLine{137 }
\DoxyCodeLine{138    len = \mbox{\hyperlink{group__Eina__String__Group_gae28caa0c42c4e76ae584f22bd3615723}{eina\_strlcpy}}(tmp, filename, \textcolor{keyword}{sizeof}(tmp));}
\DoxyCodeLine{139    \textcolor{keywordflow}{if} (len + 12 >= (\textcolor{keywordtype}{int})\textcolor{keyword}{sizeof}(tmp))}
\DoxyCodeLine{140      \{}
\DoxyCodeLine{141         fprintf(stderr, \textcolor{stringliteral}{"{}ERROR: file name is too big: \%s\(\backslash\)n"{}}, filename);}
\DoxyCodeLine{142         \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{143      \}}
\DoxyCodeLine{144 }
\DoxyCodeLine{145    i = 0;}
\DoxyCodeLine{146    \textcolor{keywordflow}{do}}
\DoxyCodeLine{147      \{}
\DoxyCodeLine{148         snprintf(tmp + len, 12, \textcolor{stringliteral}{"{}.\%u"{}}, i);}
\DoxyCodeLine{149         i++;}
\DoxyCodeLine{150      \}}
\DoxyCodeLine{151    \textcolor{keywordflow}{while} (stat(tmp, \&st) == 0);}
\DoxyCodeLine{152 }
\DoxyCodeLine{153    ef = \mbox{\hyperlink{group__Eet__File__Group_ga675160a758832ee812edf7f64ed30ee6}{eet\_open}}(tmp, \mbox{\hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a8f395f56fba48be007c65be51d799ee9}{EET\_FILE\_MODE\_WRITE}});}
\DoxyCodeLine{154    \textcolor{keywordflow}{if} (!ef)}
\DoxyCodeLine{155      \{}
\DoxyCodeLine{156         fprintf(stderr, \textcolor{stringliteral}{"{}ERROR: could not open '\%s' for write\(\backslash\)n"{}}, tmp);}
\DoxyCodeLine{157         \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{158      \}}
\DoxyCodeLine{159 }
\DoxyCodeLine{160    ret = \mbox{\hyperlink{group__Eet__Data__Group_gac66d1c49e3490bc5d803982d833ff8aa}{eet\_data\_write}}}
\DoxyCodeLine{161        (ef, \_my\_conf\_descriptor, MY\_CONF\_FILE\_ENTRY, my\_conf, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{162    \mbox{\hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}}(ef);}
\DoxyCodeLine{163 }
\DoxyCodeLine{164    \textcolor{keywordflow}{if} (ret)}
\DoxyCodeLine{165      \{}
\DoxyCodeLine{166         unlink(filename);}
\DoxyCodeLine{167         rename(tmp, filename);}
\DoxyCodeLine{168      \}}
\DoxyCodeLine{169 }
\DoxyCodeLine{170    \textcolor{keywordflow}{return} ret;}
\DoxyCodeLine{171 \} \textcolor{comment}{/* \_my\_conf\_save */}}
\DoxyCodeLine{172 }
\DoxyCodeLine{173 \textcolor{keywordtype}{int}}
\DoxyCodeLine{174 main(\textcolor{keywordtype}{int}   argc,}
\DoxyCodeLine{175      \textcolor{keywordtype}{char} *argv[])}
\DoxyCodeLine{176 \{}
\DoxyCodeLine{177    My\_Conf\_Type *my\_conf;}
\DoxyCodeLine{178    \textcolor{keywordtype}{int} ret = 0;}
\DoxyCodeLine{179 }
\DoxyCodeLine{180    \textcolor{keywordflow}{if} (argc != 3)}
\DoxyCodeLine{181      \{}
\DoxyCodeLine{182         fprintf(stderr, \textcolor{stringliteral}{"{}Usage:\(\backslash\)n\(\backslash\)t\%s <input> <output>\(\backslash\)n\(\backslash\)n"{}}, argv[0]);}
\DoxyCodeLine{183         \textcolor{keywordflow}{return} -\/1;}
\DoxyCodeLine{184      \}}
\DoxyCodeLine{185 }
\DoxyCodeLine{186    \mbox{\hyperlink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\_init}}();}
\DoxyCodeLine{187    \mbox{\hyperlink{group__Eet__Group_ga9903687bfa20fe9a9e59d4c1d213e89a}{eet\_init}}();}
\DoxyCodeLine{188    \_my\_conf\_descriptor\_init();}
\DoxyCodeLine{189 }
\DoxyCodeLine{190    my\_conf = \_my\_conf\_load(argv[1]);}
\DoxyCodeLine{191    \textcolor{keywordflow}{if} (!my\_conf)}
\DoxyCodeLine{192      \{}
\DoxyCodeLine{193         printf(\textcolor{stringliteral}{"{}creating new configuration.\(\backslash\)n"{}});}
\DoxyCodeLine{194         my\_conf = \_my\_conf\_new();}
\DoxyCodeLine{195         \textcolor{keywordflow}{if} (!my\_conf)}
\DoxyCodeLine{196           \{}
\DoxyCodeLine{197              ret = -\/2;}
\DoxyCodeLine{198              \textcolor{keywordflow}{goto} end;}
\DoxyCodeLine{199           \}}
\DoxyCodeLine{200      \}}
\DoxyCodeLine{201 }
\DoxyCodeLine{202    printf(\textcolor{stringliteral}{"{}My\_Conf\_Type:\(\backslash\)n"{}}}
\DoxyCodeLine{203           \textcolor{stringliteral}{"{}\(\backslash\)tversion: \%\#x\(\backslash\)n"{}}}
\DoxyCodeLine{204           \textcolor{stringliteral}{"{}\(\backslash\)tname...: '\%s'\(\backslash\)n"{}}}
\DoxyCodeLine{205           \textcolor{stringliteral}{"{}\(\backslash\)tid.....: \%d\(\backslash\)n"{}}}
\DoxyCodeLine{206           \textcolor{stringliteral}{"{}\(\backslash\)tenabled: \%hhu\(\backslash\)n"{}},}
\DoxyCodeLine{207           my\_conf-\/>version,}
\DoxyCodeLine{208           my\_conf-\/>name ? my\_conf-\/>name : \textcolor{stringliteral}{"{}"{}},}
\DoxyCodeLine{209           my\_conf-\/>id,}
\DoxyCodeLine{210           my\_conf-\/>enabled);}
\DoxyCodeLine{211 }
\DoxyCodeLine{212    \textcolor{keywordflow}{if} (!\_my\_conf\_save(my\_conf, argv[2]))}
\DoxyCodeLine{213      ret = -\/3;}
\DoxyCodeLine{214 }
\DoxyCodeLine{215    \_my\_conf\_free(my\_conf);}
\DoxyCodeLine{216 }
\DoxyCodeLine{217 end:}
\DoxyCodeLine{218    \_my\_conf\_descriptor\_shutdown();}
\DoxyCodeLine{219    \mbox{\hyperlink{group__Eet__Group_gacbc7583179399d3b3e7b003e911f866f}{eet\_shutdown}}();}
\DoxyCodeLine{220    \mbox{\hyperlink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\_shutdown}}();}
\DoxyCodeLine{221 }
\DoxyCodeLine{222    \textcolor{keywordflow}{return} ret;}
\DoxyCodeLine{223 \} \textcolor{comment}{/* main */}}
\DoxyCodeLine{224 }

\end{DoxyCodeInclude}
 