cbc5bcedadddf942d505f35f3a8fa18237883c7b
[apps/agl-service-homescreen.git] / doc / api-ref / latex / df / dac / test_8cpp.tex
1 \hypertarget{test_8cpp}{}\section{libhomescreen/test.cpp File Reference}
2 \label{test_8cpp}\index{libhomescreen/test.\+cpp@{libhomescreen/test.\+cpp}}
3 {\ttfamily \#include $<$libhomescreen/libhomescreen.\+hpp$>$}\newline
4 {\ttfamily \#include $<$iostream$>$}\newline
5 {\ttfamily \#include $<$glib-\/2.\+0/glib.\+h$>$}\newline
6 {\ttfamily \#include $<$fcntl.\+h$>$}\newline
7 {\ttfamily \#include $<$string$>$}\newline
8 {\ttfamily \#include $<$sys/types.\+h$>$}\newline
9 {\ttfamily \#include $<$sys/stat.\+h$>$}\newline
10 {\ttfamily \#include $<$thread$>$}\newline
11 {\ttfamily \#include $<$exception$>$}\newline
12 {\ttfamily \#include $<$vector$>$}\newline
13 {\ttfamily \#include $<$sstream$>$}\newline
14 {\ttfamily \#include $<$functional$>$}\newline
15 \subsection*{Functions}
16 \begin{DoxyCompactItemize}
17 \item 
18 static vector$<$ string $>$ \hyperlink{test_8cpp_aafb7f182b8bb6ba92354dde1658d86a4}{split} (const string \&str, char sep)
19 \item 
20 static void \hyperlink{test_8cpp_a64a6014565bb3e03294ec4a952d5add0}{usage} ()
21 \item 
22 static void \hyperlink{test_8cpp_aa9b3c43c212b49edee82ac30a11aa255}{call\+\_\+test} ()
23 \item 
24 static void \hyperlink{test_8cpp_a6d3cb4886e7afd45bd56b49800da932d}{on\+Rep} (struct json\+\_\+object $\ast$reply\+\_\+contents)
25 \item 
26 static void \hyperlink{test_8cpp_a6a2874c419fe5936fcccadc7e6cf268e}{on\+Ev} (const string \&\hyperlink{structevent}{event}, struct json\+\_\+object $\ast$event\+\_\+contents)
27 \item 
28 int \hyperlink{test_8cpp_a3c04138a5bfe5d72780bb7e82a18e627}{main} (int argc, char $\ast$$\ast$argv)
29 \end{DoxyCompactItemize}
30 \subsection*{Variables}
31 \begin{DoxyCompactItemize}
32 \item 
33 \hyperlink{class_lib_home_screen}{Lib\+Home\+Screen} $\ast$ \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs}
34 \end{DoxyCompactItemize}
35
36
37 \subsection{Function Documentation}
38 \mbox{\Hypertarget{test_8cpp_aa9b3c43c212b49edee82ac30a11aa255}\label{test_8cpp_aa9b3c43c212b49edee82ac30a11aa255}} 
39 \index{test.\+cpp@{test.\+cpp}!call\+\_\+test@{call\+\_\+test}}
40 \index{call\+\_\+test@{call\+\_\+test}!test.\+cpp@{test.\+cpp}}
41 \subsubsection{\texorpdfstring{call\+\_\+test()}{call\_test()}}
42 {\footnotesize\ttfamily static void call\+\_\+test (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}
43
44
45
46 Definition at line 51 of file test.\+cpp.
47
48
49 \begin{DoxyCode}
50 52 \{
51 53     \textcolor{keywordtype}{string} command;
52 54 
53 55     cout << \textcolor{stringliteral}{"input verb and argments"} << endl;
54 56 
55 57     \textcolor{comment}{/* read the buffer */}
56 58     \textcolor{keywordflow}{for}(;;)\{
57 59         \textcolor{keywordtype}{char} line[1023];
58 60         cin.getline(line, \textcolor{keyword}{sizeof}(line));
59 61         command = line;
60 62         \textcolor{keywordflow}{if}(command.empty())\{
61 63             \textcolor{keywordflow}{continue};
62 64         \}
63 65 
64 66         vector<string> v\_command = \hyperlink{test_8cpp_aafb7f182b8bb6ba92354dde1658d86a4}{split}(command, \textcolor{charliteral}{' '});
65 67         \textcolor{comment}{/*for(auto itr = v\_command.begin(); itr != v\_command.end(); ++itr)}
66 68 \textcolor{comment}{        \{}
67 69 \textcolor{comment}{            cout << *itr <<endl;}
68 70 \textcolor{comment}{        \}*/}
69 71         \textcolor{keywordtype}{size\_t} num = v\_command.size();
70 72         \textcolor{keywordflow}{if}(num % 2 == 0)\{
71 73             cout << \textcolor{stringliteral}{"If command contains args, please input <key,value> in argument part"} << endl;
72 74             \textcolor{keywordflow}{continue};
73 75         \}
74 76         \textcolor{comment}{/* create json object */}
75 77         \textcolor{keyword}{struct }json\_object* j\_obj = json\_object\_new\_object();
76 78         \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int} i = 1;i < (v\_command.size()) ;++i)\{
77 79             \textcolor{keyword}{struct }json\_object* val     = json\_object\_new\_string(v\_command[i+1].c\_str());
78 80             json\_object\_object\_add(j\_obj, v\_command[i].c\_str(), val);
79 81             ++i;
80 82         \}
81 83         \textcolor{comment}{/* call verb via LibHomeScreen */}
82 84         \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs}->\hyperlink{class_lib_home_screen_a527b49dcfe581be6275d0eb2236ba37f}{call}(v\_command[0], j\_obj);
83 85         \textcolor{comment}{/* free vector */}
84 86         vector<string>().swap(v\_command);
85 87         string().swap(command);
86 88     \}
87 89 \}
88 \end{DoxyCode}
89 \mbox{\Hypertarget{test_8cpp_a3c04138a5bfe5d72780bb7e82a18e627}\label{test_8cpp_a3c04138a5bfe5d72780bb7e82a18e627}} 
90 \index{test.\+cpp@{test.\+cpp}!main@{main}}
91 \index{main@{main}!test.\+cpp@{test.\+cpp}}
92 \subsubsection{\texorpdfstring{main()}{main()}}
93 {\footnotesize\ttfamily int main (\begin{DoxyParamCaption}\item[{int}]{argc,  }\item[{char $\ast$$\ast$}]{argv }\end{DoxyParamCaption})}
94
95
96
97 Definition at line 117 of file test.\+cpp.
98
99
100 \begin{DoxyCode}
101 118 \{
102 119     \textcolor{keywordtype}{int} ret;
103 120     \textcolor{keywordflow}{if}(argc == 1)
104 121     \{
105 122         printf(\textcolor{stringliteral}{"Please input port num in first argument, and token in second argument"});
106 123         \hyperlink{test_8cpp_a64a6014565bb3e03294ec4a952d5add0}{usage}();
107 124         \textcolor{keywordflow}{return} 0;
108 125     \}
109 126     \textcolor{keywordflow}{if}(argc == 2)
110 127     \{
111 128         \textcolor{keywordtype}{string} av(argv[1]);
112 129         \textcolor{keywordflow}{if}( (av == \textcolor{stringliteral}{"-h"}) || (av == \textcolor{stringliteral}{"--help"}))
113 130         \{
114 131             \hyperlink{test_8cpp_a64a6014565bb3e03294ec4a952d5add0}{usage}();
115 132             \textcolor{keywordflow}{return} 0;
116 133         \}
117 134     \}
118 135 
119 136     \textcolor{keywordtype}{string} port\_string(argv[1]);
120 137     \textcolor{keywordtype}{string} token(argv[2]);
121 138     \textcolor{keywordtype}{char}* endptr;
122 139     \textcolor{keywordtype}{long} port = strtol(port\_string.c\_str(),&endptr,10);
123 140 
124 141     \textcolor{comment}{/* error check of range */}
125 142     \textcolor{keywordflow}{if}( (port > 20000) || (port < 0) )
126 143     \{
127 144         printf(\textcolor{stringliteral}{"input under 20000(temporary number)"});
128 145         \textcolor{keywordflow}{return} 0;
129 146     \}
130 147     \textcolor{keywordflow}{if}(*endptr != \textcolor{charliteral}{'\(\backslash\)0'})
131 148     \{
132 149         printf(\textcolor{stringliteral}{"not number"});
133 150         \textcolor{keywordflow}{return} 0;
134 151     \}
135 152 
136 153   cout << \textcolor{stringliteral}{"Call test for LibHomeScreen"} << endl;
137 154     \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs} = \textcolor{keyword}{new} \hyperlink{class_lib_home_screen}{LibHomeScreen}();
138 155   \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs}->\hyperlink{class_lib_home_screen_a6a57b573cc767725762ba9beab032220}{init}(port, token);
139 156 
140 157     \textcolor{comment}{// hs->registerCallback(&onEv, &onRep);}
141 158   \textcolor{comment}{//}
142 159   \textcolor{comment}{// hs->subscribe(event\_list[0]); // tap\_shortcut event subscribe}
143 160   \textcolor{comment}{// hs->subscribe(event\_list[1]);}
144 161 
145 162   \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs}->\hyperlink{class_lib_home_screen_ab1b0e08bf35415de9064afed899e9f85}{set\_event\_handler}(\hyperlink{class_lib_home_screen_a82616c91ac211d2ad08e709b524bf154a4b0a82d501e4db5fbfe25c254c92896f}{LibHomeScreen::Event\_TapShortcut}
146       , [](\textcolor{keyword}{const} \textcolor{keywordtype}{char}* application\_name)\{
147 163     cout << \textcolor{stringliteral}{"set\_event\_handler Event\_TapShortcut application\_name = "} << application\_name << endl;
148 164   \});
149 165 
150 166   \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs}->\hyperlink{class_lib_home_screen_ab1b0e08bf35415de9064afed899e9f85}{set\_event\_handler}(\hyperlink{class_lib_home_screen_a82616c91ac211d2ad08e709b524bf154aea56fa32a124a8ddcbea127755280a1d}{LibHomeScreen::Event\_OnScreenMessage}
151       , [](\textcolor{keyword}{const} \textcolor{keywordtype}{char}* display\_message)\{
152 167     cout << \textcolor{stringliteral}{"set\_event\_handler Event\_OnScreenMessage display\_message = "} << display\_message << endl;
153 168   \});
154 169 
155 170 
156 171     \textcolor{keywordflow}{if} (ret < 0) \{
157 172         printf(\textcolor{stringliteral}{"failed to create event loop"});
158 173         \textcolor{keywordflow}{return} -1;
159 174     \}
160 175     \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs}->\hyperlink{class_lib_home_screen_a32d3282898d0f04151c24b4103511e00}{runEventloop}();
161 176 
162 177     \hyperlink{test_8cpp_aa9b3c43c212b49edee82ac30a11aa255}{call\_test}();
163 178 
164 179     \textcolor{keywordflow}{return} 0;
165 180 \}
166 \end{DoxyCode}
167 \mbox{\Hypertarget{test_8cpp_a6a2874c419fe5936fcccadc7e6cf268e}\label{test_8cpp_a6a2874c419fe5936fcccadc7e6cf268e}} 
168 \index{test.\+cpp@{test.\+cpp}!on\+Ev@{on\+Ev}}
169 \index{on\+Ev@{on\+Ev}!test.\+cpp@{test.\+cpp}}
170 \subsubsection{\texorpdfstring{on\+Ev()}{onEv()}}
171 {\footnotesize\ttfamily static void on\+Ev (\begin{DoxyParamCaption}\item[{const string \&}]{event,  }\item[{struct json\+\_\+object $\ast$}]{event\+\_\+contents }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}
172
173
174
175 Definition at line 98 of file test.\+cpp.
176
177
178 \begin{DoxyCode}
179 99 \{
180 100     \textcolor{keyword}{const} \textcolor{keywordtype}{char}* str = json\_object\_to\_json\_string(event\_contents);
181 101     cout << \textcolor{stringliteral}{"test.cpp [CB onEvent]: event:  "} << \textcolor{keyword}{event}.c\_str() << \textcolor{stringliteral}{"  contents: "} << str << endl;
182 102     \textcolor{comment}{//json\_object\_put(event\_contents); do not release!!!}
183 103 \}
184 \end{DoxyCode}
185 \mbox{\Hypertarget{test_8cpp_a6d3cb4886e7afd45bd56b49800da932d}\label{test_8cpp_a6d3cb4886e7afd45bd56b49800da932d}} 
186 \index{test.\+cpp@{test.\+cpp}!on\+Rep@{on\+Rep}}
187 \index{on\+Rep@{on\+Rep}!test.\+cpp@{test.\+cpp}}
188 \subsubsection{\texorpdfstring{on\+Rep()}{onRep()}}
189 {\footnotesize\ttfamily static void on\+Rep (\begin{DoxyParamCaption}\item[{struct json\+\_\+object $\ast$}]{reply\+\_\+contents }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}
190
191
192
193 Definition at line 91 of file test.\+cpp.
194
195
196 \begin{DoxyCode}
197 92 \{
198 93     \textcolor{keyword}{const} \textcolor{keywordtype}{char}* str = json\_object\_to\_json\_string(reply\_contents);
199 94     cout << \textcolor{stringliteral}{"test.cpp [CB onRep]: "} << str << endl;
200 95     \textcolor{comment}{//json\_object\_put(reply\_contents); do not release!!!}
201 96 \}
202 \end{DoxyCode}
203 \mbox{\Hypertarget{test_8cpp_aafb7f182b8bb6ba92354dde1658d86a4}\label{test_8cpp_aafb7f182b8bb6ba92354dde1658d86a4}} 
204 \index{test.\+cpp@{test.\+cpp}!split@{split}}
205 \index{split@{split}!test.\+cpp@{test.\+cpp}}
206 \subsubsection{\texorpdfstring{split()}{split()}}
207 {\footnotesize\ttfamily static vector$<$ string $>$ split (\begin{DoxyParamCaption}\item[{const string \&}]{str,  }\item[{char}]{sep }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}
208
209
210
211 Definition at line 105 of file test.\+cpp.
212
213
214 \begin{DoxyCode}
215 106 \{
216 107     vector<string> v;
217 108     stringstream ss(str);
218 109     \textcolor{keywordtype}{string} buffer;
219 110     \textcolor{keywordflow}{while}( getline(ss, buffer, sep) ) \{
220 111         \textcolor{keywordflow}{if}(!buffer.empty())
221 112             v.push\_back(buffer);
222 113     \}
223 114     \textcolor{keywordflow}{return} v;
224 115 \}
225 \end{DoxyCode}
226 \mbox{\Hypertarget{test_8cpp_a64a6014565bb3e03294ec4a952d5add0}\label{test_8cpp_a64a6014565bb3e03294ec4a952d5add0}} 
227 \index{test.\+cpp@{test.\+cpp}!usage@{usage}}
228 \index{usage@{usage}!test.\+cpp@{test.\+cpp}}
229 \subsubsection{\texorpdfstring{usage()}{usage()}}
230 {\footnotesize\ttfamily static void usage (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}
231
232
233
234 Definition at line 35 of file test.\+cpp.
235
236
237 \begin{DoxyCode}
238 36 \{
239 37     cout << \textcolor{stringliteral}{"verb "}<< \textcolor{stringliteral}{"key:arg"} << endl;
240 38     cout << \textcolor{stringliteral}{"example:"} << endl;
241 39     cout << \textcolor{stringliteral}{"ping"} << endl;
242 40     cout << \textcolor{stringliteral}{"------- -------- --- "} << endl;
243 41     cout << \textcolor{stringliteral}{"  verb    key    value"} << endl;
244 42     cout << \textcolor{stringliteral}{"verb list:"} << endl;
245 43     \textcolor{keywordflow}{for}(\textcolor{keyword}{auto} itr = \hyperlink{class_lib_home_screen_a5593ff5ac78f6495ccb649904cf0ab08}{LibHomeScreen::api\_list}.begin(); itr != 
246       \hyperlink{class_lib_home_screen_a5593ff5ac78f6495ccb649904cf0ab08}{LibHomeScreen::api\_list}.end(); ++itr)
247 44     \{
248 45         cout << \textcolor{stringliteral}{"  "} << *itr << endl;
249 46     \}
250 47     \textcolor{comment}{// Todo output api list}
251 48     exit(0);
252 49 \}
253 \end{DoxyCode}
254
255
256 \subsection{Variable Documentation}
257 \mbox{\Hypertarget{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}\label{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}} 
258 \index{test.\+cpp@{test.\+cpp}!hs@{hs}}
259 \index{hs@{hs}!test.\+cpp@{test.\+cpp}}
260 \subsubsection{\texorpdfstring{hs}{hs}}
261 {\footnotesize\ttfamily \hyperlink{class_lib_home_screen}{Lib\+Home\+Screen}$\ast$ hs}
262
263
264
265 Definition at line 33 of file test.\+cpp.
266