change project name
[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.\+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       , [](json\_object *\textcolor{keywordtype}{object})\{
147 163     \textcolor{keyword}{const} \textcolor{keywordtype}{char} *application\_name = json\_object\_get\_string(
148 164         json\_object\_object\_get(\textcolor{keywordtype}{object}, \textcolor{stringliteral}{"application\_name"}));
149 165     cout << \textcolor{stringliteral}{"set\_event\_handler Event\_TapShortcut application\_name = "} << application\_name << endl;
150 166   \});
151 167 
152 168   \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs}->\hyperlink{class_lib_home_screen_ab1b0e08bf35415de9064afed899e9f85}{set\_event\_handler}(\hyperlink{class_lib_home_screen_a82616c91ac211d2ad08e709b524bf154aea56fa32a124a8ddcbea127755280a1d}{LibHomeScreen::Event\_OnScreenMessage}
153       , [](json\_object *\textcolor{keywordtype}{object})\{
154 169     \textcolor{keyword}{const} \textcolor{keywordtype}{char} *display\_message = json\_object\_get\_string(
155 170         json\_object\_object\_get(\textcolor{keywordtype}{object}, \textcolor{stringliteral}{"display\_message"}));
156 171     cout << \textcolor{stringliteral}{"set\_event\_handler Event\_OnScreenMessage display\_message = "} << display\_message << endl;
157 172   \});
158 173 
159 174   \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs}->\hyperlink{class_lib_home_screen_ab1b0e08bf35415de9064afed899e9f85}{set\_event\_handler}(\hyperlink{class_lib_home_screen_a82616c91ac211d2ad08e709b524bf154acae91db4efc2394fd701f581d277a3fd}{LibHomeScreen::Event\_OnScreenReply}
160       , [](json\_object *\textcolor{keywordtype}{object})\{
161 175     \textcolor{keyword}{const} \textcolor{keywordtype}{char} *reply\_message = json\_object\_get\_string(
162 176         json\_object\_object\_get(\textcolor{keywordtype}{object}, \textcolor{stringliteral}{"reply\_message"}));
163 177     cout << \textcolor{stringliteral}{"set\_event\_handler Event\_OnScreenReply reply\_message = "} << reply\_message << endl;
164 178   \});
165 179 
166 180     \textcolor{keywordflow}{if} (ret < 0) \{
167 181         printf(\textcolor{stringliteral}{"failed to create event loop"});
168 182         \textcolor{keywordflow}{return} -1;
169 183     \}
170 184 
171 185     \hyperlink{test_8cpp_aa9b3c43c212b49edee82ac30a11aa255}{call\_test}();
172 186 
173 187     \textcolor{keywordflow}{return} 0;
174 188 \}
175 \end{DoxyCode}
176 \mbox{\Hypertarget{test_8cpp_a6a2874c419fe5936fcccadc7e6cf268e}\label{test_8cpp_a6a2874c419fe5936fcccadc7e6cf268e}} 
177 \index{test.\+cpp@{test.\+cpp}!on\+Ev@{on\+Ev}}
178 \index{on\+Ev@{on\+Ev}!test.\+cpp@{test.\+cpp}}
179 \subsubsection{\texorpdfstring{on\+Ev()}{onEv()}}
180 {\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]}}
181
182
183
184 Definition at line 98 of file test.\+cpp.
185
186
187 \begin{DoxyCode}
188 99 \{
189 100     \textcolor{keyword}{const} \textcolor{keywordtype}{char}* str = json\_object\_to\_json\_string(event\_contents);
190 101     cout << \textcolor{stringliteral}{"test.cpp [CB onEvent]: event:  "} << \textcolor{keyword}{event}.c\_str() << \textcolor{stringliteral}{"  contents: "} << str << endl;
191 102     \textcolor{comment}{//json\_object\_put(event\_contents); do not release!!!}
192 103 \}
193 \end{DoxyCode}
194 \mbox{\Hypertarget{test_8cpp_a6d3cb4886e7afd45bd56b49800da932d}\label{test_8cpp_a6d3cb4886e7afd45bd56b49800da932d}} 
195 \index{test.\+cpp@{test.\+cpp}!on\+Rep@{on\+Rep}}
196 \index{on\+Rep@{on\+Rep}!test.\+cpp@{test.\+cpp}}
197 \subsubsection{\texorpdfstring{on\+Rep()}{onRep()}}
198 {\footnotesize\ttfamily static void on\+Rep (\begin{DoxyParamCaption}\item[{struct json\+\_\+object $\ast$}]{reply\+\_\+contents }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}
199
200
201
202 Definition at line 91 of file test.\+cpp.
203
204
205 \begin{DoxyCode}
206 92 \{
207 93     \textcolor{keyword}{const} \textcolor{keywordtype}{char}* str = json\_object\_to\_json\_string(reply\_contents);
208 94     cout << \textcolor{stringliteral}{"test.cpp [CB onRep]: "} << str << endl;
209 95     \textcolor{comment}{//json\_object\_put(reply\_contents); do not release!!!}
210 96 \}
211 \end{DoxyCode}
212 \mbox{\Hypertarget{test_8cpp_aafb7f182b8bb6ba92354dde1658d86a4}\label{test_8cpp_aafb7f182b8bb6ba92354dde1658d86a4}} 
213 \index{test.\+cpp@{test.\+cpp}!split@{split}}
214 \index{split@{split}!test.\+cpp@{test.\+cpp}}
215 \subsubsection{\texorpdfstring{split()}{split()}}
216 {\footnotesize\ttfamily static vector$<$ string $>$ split (\begin{DoxyParamCaption}\item[{const string \&}]{str,  }\item[{char}]{sep }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}
217
218
219
220 Definition at line 105 of file test.\+cpp.
221
222
223 \begin{DoxyCode}
224 106 \{
225 107     vector<string> v;
226 108     stringstream ss(str);
227 109     \textcolor{keywordtype}{string} buffer;
228 110     \textcolor{keywordflow}{while}( getline(ss, buffer, sep) ) \{
229 111         \textcolor{keywordflow}{if}(!buffer.empty())
230 112             v.push\_back(buffer);
231 113     \}
232 114     \textcolor{keywordflow}{return} v;
233 115 \}
234 \end{DoxyCode}
235 \mbox{\Hypertarget{test_8cpp_a64a6014565bb3e03294ec4a952d5add0}\label{test_8cpp_a64a6014565bb3e03294ec4a952d5add0}} 
236 \index{test.\+cpp@{test.\+cpp}!usage@{usage}}
237 \index{usage@{usage}!test.\+cpp@{test.\+cpp}}
238 \subsubsection{\texorpdfstring{usage()}{usage()}}
239 {\footnotesize\ttfamily static void usage (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}
240
241
242
243 Definition at line 35 of file test.\+cpp.
244
245
246 \begin{DoxyCode}
247 36 \{
248 37     cout << \textcolor{stringliteral}{"verb "}<< \textcolor{stringliteral}{"key:arg"} << endl;
249 38     cout << \textcolor{stringliteral}{"example:"} << endl;
250 39     cout << \textcolor{stringliteral}{"ping"} << endl;
251 40     cout << \textcolor{stringliteral}{"------- -------- --- "} << endl;
252 41     cout << \textcolor{stringliteral}{"  verb    key    value"} << endl;
253 42     cout << \textcolor{stringliteral}{"verb list:"} << endl;
254 43     \textcolor{keywordflow}{for}(\textcolor{keyword}{auto} itr = \hyperlink{class_lib_home_screen_a5593ff5ac78f6495ccb649904cf0ab08}{LibHomeScreen::api\_list}.begin(); itr != 
255       \hyperlink{class_lib_home_screen_a5593ff5ac78f6495ccb649904cf0ab08}{LibHomeScreen::api\_list}.end(); ++itr)
256 44     \{
257 45         cout << \textcolor{stringliteral}{"  "} << *itr << endl;
258 46     \}
259 47     \textcolor{comment}{// Todo output api list}
260 48     exit(0);
261 49 \}
262 \end{DoxyCode}
263
264
265 \subsection{Variable Documentation}
266 \mbox{\Hypertarget{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}\label{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}} 
267 \index{test.\+cpp@{test.\+cpp}!hs@{hs}}
268 \index{hs@{hs}!test.\+cpp@{test.\+cpp}}
269 \subsubsection{\texorpdfstring{hs}{hs}}
270 {\footnotesize\ttfamily \hyperlink{class_lib_home_screen}{Lib\+Home\+Screen}$\ast$ hs}
271
272
273
274 Definition at line 33 of file test.\+cpp.
275