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}
18 static vector$<$ string $>$ \hyperlink{test_8cpp_aafb7f182b8bb6ba92354dde1658d86a4}{split} (const string \&str, char sep)
20 static void \hyperlink{test_8cpp_a64a6014565bb3e03294ec4a952d5add0}{usage} ()
22 static void \hyperlink{test_8cpp_aa9b3c43c212b49edee82ac30a11aa255}{call\+\_\+test} ()
24 static void \hyperlink{test_8cpp_a6d3cb4886e7afd45bd56b49800da932d}{on\+Rep} (struct json\+\_\+object $\ast$reply\+\_\+contents)
26 static void \hyperlink{test_8cpp_a6a2874c419fe5936fcccadc7e6cf268e}{on\+Ev} (const string \&\hyperlink{structevent}{event}, struct json\+\_\+object $\ast$event\+\_\+contents)
28 int \hyperlink{test_8cpp_a3c04138a5bfe5d72780bb7e82a18e627}{main} (int argc, char $\ast$$\ast$argv)
29 \end{DoxyCompactItemize}
30 \subsection*{Variables}
31 \begin{DoxyCompactItemize}
33 \hyperlink{class_lib_home_screen}{Lib\+Home\+Screen} $\ast$ \hyperlink{test_8cpp_a529acbd1fed9d98a587edfa62309fa8d}{hs}
34 \end{DoxyCompactItemize}
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]}}
46 Definition at line 51 of file test.\+cpp.
51 53 \textcolor{keywordtype}{string} command;
53 55 cout << \textcolor{stringliteral}{"input verb and argments"} << endl;
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));
60 62 \textcolor{keywordflow}{if}(command.empty())\{
61 63 \textcolor{keywordflow}{continue};
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};
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);
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);
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})}
97 Definition at line 117 of file test.\+cpp.
102 119 \textcolor{keywordtype}{int} ret;
103 120 \textcolor{keywordflow}{if}(argc == 1)
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;
109 126 \textcolor{keywordflow}{if}(argc == 2)
111 128 \textcolor{keywordtype}{string} av(argv[1]);
112 129 \textcolor{keywordflow}{if}( (av == \textcolor{stringliteral}{"-h"}) || (av == \textcolor{stringliteral}{"--help"}))
114 131 \hyperlink{test_8cpp_a64a6014565bb3e03294ec4a952d5add0}{usage}();
115 132 \textcolor{keywordflow}{return} 0;
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);
124 141 \textcolor{comment}{/* error check of range */}
125 142 \textcolor{keywordflow}{if}( (port > 20000) || (port < 0) )
127 144 printf(\textcolor{stringliteral}{"input under 20000(temporary number)"});
128 145 \textcolor{keywordflow}{return} 0;
130 147 \textcolor{keywordflow}{if}(*endptr != \textcolor{charliteral}{'\(\backslash\)0'})
132 149 printf(\textcolor{stringliteral}{"not number"});
133 150 \textcolor{keywordflow}{return} 0;
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);
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]);}
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;
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;
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;
166 180 \textcolor{keywordflow}{if} (ret < 0) \{
167 181 printf(\textcolor{stringliteral}{"failed to create event loop"});
168 182 \textcolor{keywordflow}{return} -1;
171 185 \hyperlink{test_8cpp_aa9b3c43c212b49edee82ac30a11aa255}{call\_test}();
173 187 \textcolor{keywordflow}{return} 0;
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]}}
184 Definition at line 98 of file test.\+cpp.
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!!!}
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]}}
202 Definition at line 91 of file test.\+cpp.
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!!!}
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]}}
220 Definition at line 105 of file test.\+cpp.
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);
232 114 \textcolor{keywordflow}{return} v;
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]}}
243 Definition at line 35 of file test.\+cpp.
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)
257 45 cout << \textcolor{stringliteral}{" "} << *itr << endl;
259 47 \textcolor{comment}{// Todo output api list}
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}
274 Definition at line 33 of file test.\+cpp.