From 09143a0949dee0077cd9681356877b71ec4c99fb Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Mon, 23 Oct 2017 14:06:12 +0900 Subject: Add reply message for homescreen-service Add a new event named OnScreenReply for application, Application can use this event reply to homescreen. Update docment for this event. Change-Id: Iea0c321731fa62cd94fc08fc5e303c20847fd525 Signed-off-by: zheng_wenlong --- doc/api-ref/html/df/d43/libhomescreen_8hpp.html | 2 +- .../html/df/d43/libhomescreen_8hpp_source.html | 43 +- doc/api-ref/html/df/d76/hmi-debug_8h.html | 435 +++++++++++++++++++++ doc/api-ref/html/df/d76/hmi-debug_8h_source.html | 87 +++++ doc/api-ref/html/df/d7d/structevent.html | 2 +- doc/api-ref/html/df/dac/test_8cpp.html | 14 +- doc/api-ref/html/df/dac/test_8cpp_source.html | 14 +- 7 files changed, 560 insertions(+), 37 deletions(-) create mode 100644 doc/api-ref/html/df/d76/hmi-debug_8h.html create mode 100644 doc/api-ref/html/df/d76/hmi-debug_8h_source.html (limited to 'doc/api-ref/html/df') diff --git a/doc/api-ref/html/df/d43/libhomescreen_8hpp.html b/doc/api-ref/html/df/d43/libhomescreen_8hpp.html index 631034d..c164aaf 100644 --- a/doc/api-ref/html/df/d43/libhomescreen_8hpp.html +++ b/doc/api-ref/html/df/d43/libhomescreen_8hpp.html @@ -58,7 +58,7 @@ $(function() {
diff --git a/doc/api-ref/html/df/d43/libhomescreen_8hpp_source.html b/doc/api-ref/html/df/d43/libhomescreen_8hpp_source.html index 2722975..5e2f196 100644 --- a/doc/api-ref/html/df/d43/libhomescreen_8hpp_source.html +++ b/doc/api-ref/html/df/d43/libhomescreen_8hpp_source.html @@ -58,7 +58,7 @@ $(function() {
@@ -66,30 +66,31 @@ $(function() {
libhomescreen.hpp
-Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIBHOMESCREEN_H
18 #define LIBHOMESCREEN_H
19 #include <vector>
20 #include <map>
21 #include <string>
22 #include <functional>
23 #include <json-c/json.h>
24 #include <systemd/sd-event.h>
25 extern "C"
26 {
27 #include <afb/afb-binding.h>
28 #include <afb/afb-wsj1.h>
29 #include <afb/afb-ws-client.h>
30 }
31 
33 {
34 public:
35  LibHomeScreen();
37 
38  LibHomeScreen(const LibHomeScreen &) = delete;
39  LibHomeScreen &operator=(const LibHomeScreen &) = delete;
40 
41  using handler_func = std::function<void(const char*)>;
42 
43  enum EventType {
46  };
47 
48  static const std::vector<std::string> api_list;
49  static const std::vector<std::string> event_list;
50 
51  /* Method */
52  int init(const int port, const std::string& token);
53  int runEventloop();
54 
55  int tapShortcut(const char* application_name);
56  int onScreenMessage(const char* display_message);
57 
58  void set_event_handler(enum EventType et, handler_func f);
59 
60  void registerCallback(
61  void (*event_cb)(const std::string& event, struct json_object* event_contents),
62  void (*reply_cb)(struct json_object* reply_contents),
63  void (*hangup_cb)(void) = nullptr);
64 
65  int call(const std::string& verb, struct json_object* arg);
66  int call(const char* verb, struct json_object* arg);
67  int subscribe(const std::string& event_name);
68  int unsubscribe(const std::string& event_name);
69 
70 private:
71  int initialize_websocket();
72  void (*onEvent)(const std::string& event, struct json_object* event_contents);
73  void (*onReply)(struct json_object* reply);
74  void (*onHangup)(void);
75 
76  struct afb_wsj1* sp_websock;
77  struct afb_wsj1_itf minterface;
78  sd_event* mploop;
79  std::string muri;
80 
81  int mport = 2000;
82  std::string mtoken = "hs";
83 
84  std::map<EventType, handler_func> handlers;
85 
86 public:
87  /* Don't use/ Internal only */
88  void on_hangup(void *closure, struct afb_wsj1 *wsj);
89  void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
90  void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
91  void on_reply(void *closure, struct afb_wsj1_msg *msg);
92 };
93 
94 #endif /* LIBHOMESCREEN_H */
void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)
-
void on_reply(void *closure, struct afb_wsj1_msg *msg)
+Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIBHOMESCREEN_H
18 #define LIBHOMESCREEN_H
19 #include <vector>
20 #include <map>
21 #include <string>
22 #include <functional>
23 #include <json-c/json.h>
24 #include <systemd/sd-event.h>
25 extern "C"
26 {
27 #include <afb/afb-binding.h>
28 #include <afb/afb-wsj1.h>
29 #include <afb/afb-ws-client.h>
30 }
31 
33 {
34 public:
35  LibHomeScreen();
37 
38  LibHomeScreen(const LibHomeScreen &) = delete;
39  LibHomeScreen &operator=(const LibHomeScreen &) = delete;
40 
41  // using handler_func = std::function<void(const char*)>;
42  using handler_func = std::function<void(json_object*)>;
43 
44  enum EventType {
48  };
49 
50  static const std::vector<std::string> api_list;
51  static const std::vector<std::string> event_list;
52 
53  /* Method */
54  int init(const int port, const std::string& token);
55 
56  int tapShortcut(const char* application_name);
57  int onScreenMessage(const char* display_message);
58  int onScreenReply(const char* reply_message);
59 
60  void set_event_handler(enum EventType et, handler_func f);
61 
62  void registerCallback(
63  void (*event_cb)(const std::string& event, struct json_object* event_contents),
64  void (*reply_cb)(struct json_object* reply_contents),
65  void (*hangup_cb)(void) = nullptr);
66 
67  int call(const std::string& verb, struct json_object* arg);
68  int call(const char* verb, struct json_object* arg);
69  int subscribe(const std::string& event_name);
70  int unsubscribe(const std::string& event_name);
71 
72 private:
73  int initialize_websocket();
74 
75  void (*onEvent)(const std::string& event, struct json_object* event_contents);
76  void (*onReply)(struct json_object* reply);
77  void (*onHangup)(void);
78 
79  struct afb_wsj1* sp_websock;
80  struct afb_wsj1_itf minterface;
81  sd_event* mploop;
82  std::string muri;
83 
84  int mport = 2000;
85  std::string mtoken = "hs";
86 
87  std::map<EventType, handler_func> handlers;
88 
89 public:
90  /* Don't use/ Internal only */
91  void on_hangup(void *closure, struct afb_wsj1 *wsj);
92  void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
93  void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
94  void on_reply(void *closure, struct afb_wsj1_msg *msg);
95 };
96 
97 #endif /* LIBHOMESCREEN_H */
void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)
+
void on_reply(void *closure, struct afb_wsj1_msg *msg)
+
int onScreenReply(const char *reply_message)
LibHomeScreen & operator=(const LibHomeScreen &)=delete
-
void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
+
std::function< void(json_object *)> handler_func
+
void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
- + +
int call(const std::string &verb, struct json_object *arg)
-
void on_hangup(void *closure, struct afb_wsj1 *wsj)
-
int tapShortcut(const char *application_name)
-
int subscribe(const std::string &event_name)
- - - -
static const std::vector< std::string > event_list
-
std::function< void(const char *)> handler_func
-
int init(const int port, const std::string &token)
-
int onScreenMessage(const char *display_message)
+
void on_hangup(void *closure, struct afb_wsj1 *wsj)
+
int tapShortcut(const char *application_name)
+
int subscribe(const std::string &event_name)
+ + +
static const std::vector< std::string > event_list
+
int init(const int port, const std::string &token)
+
int onScreenMessage(const char *display_message)
- -
static const std::vector< std::string > api_list
-
int unsubscribe(const std::string &event_name)
-
void set_event_handler(enum EventType et, handler_func f)
-
void registerCallback(void(*event_cb)(const std::string &event, struct json_object *event_contents), void(*reply_cb)(struct json_object *reply_contents), void(*hangup_cb)(void)=nullptr)
- + +
static const std::vector< std::string > api_list
+
int unsubscribe(const std::string &event_name)
+
void set_event_handler(enum EventType et, handler_func f)
+
void registerCallback(void(*event_cb)(const std::string &event, struct json_object *event_contents), void(*reply_cb)(struct json_object *reply_contents), void(*hangup_cb)(void)=nullptr)
+

The documentation for this struct was generated from the following file: diff --git a/doc/api-ref/html/df/dac/test_8cpp.html b/doc/api-ref/html/df/dac/test_8cpp.html index 7995dcb..00f9515 100644 --- a/doc/api-ref/html/df/dac/test_8cpp.html +++ b/doc/api-ref/html/df/dac/test_8cpp.html @@ -162,15 +162,15 @@ Variables

Definition at line 117 of file test.cpp.

-
118 {
119  int ret;
120  if(argc == 1)
121  {
122  printf("Please input port num in first argument, and token in second argument");
123  usage();
124  return 0;
125  }
126  if(argc == 2)
127  {
128  string av(argv[1]);
129  if( (av == "-h") || (av == "--help"))
130  {
131  usage();
132  return 0;
133  }
134  }
135 
136  string port_string(argv[1]);
137  string token(argv[2]);
138  char* endptr;
139  long port = strtol(port_string.c_str(),&endptr,10);
140 
141  /* error check of range */
142  if( (port > 20000) || (port < 0) )
143  {
144  printf("input under 20000(temporary number)");
145  return 0;
146  }
147  if(*endptr != '\0')
148  {
149  printf("not number");
150  return 0;
151  }
152 
153  cout << "Call test for LibHomeScreen" << endl;
154  hs = new LibHomeScreen();
155  hs->init(port, token);
156 
157  // hs->registerCallback(&onEv, &onRep);
158  //
159  // hs->subscribe(event_list[0]); // tap_shortcut event subscribe
160  // hs->subscribe(event_list[1]);
161 
162  hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [](const char* application_name){
163  cout << "set_event_handler Event_TapShortcut application_name = " << application_name << endl;
164  });
165 
166  hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [](const char* display_message){
167  cout << "set_event_handler Event_OnScreenMessage display_message = " << display_message << endl;
168  });
169 
170 
171  if (ret < 0) {
172  printf("failed to create event loop");
173  return -1;
174  }
175  hs->runEventloop();
176 
177  call_test();
178 
179  return 0;
180 }
static void usage()
Definition: test.cpp:35
+
118 {
119  int ret;
120  if(argc == 1)
121  {
122  printf("Please input port num in first argument, and token in second argument");
123  usage();
124  return 0;
125  }
126  if(argc == 2)
127  {
128  string av(argv[1]);
129  if( (av == "-h") || (av == "--help"))
130  {
131  usage();
132  return 0;
133  }
134  }
135 
136  string port_string(argv[1]);
137  string token(argv[2]);
138  char* endptr;
139  long port = strtol(port_string.c_str(),&endptr,10);
140 
141  /* error check of range */
142  if( (port > 20000) || (port < 0) )
143  {
144  printf("input under 20000(temporary number)");
145  return 0;
146  }
147  if(*endptr != '\0')
148  {
149  printf("not number");
150  return 0;
151  }
152 
153  cout << "Call test for LibHomeScreen" << endl;
154  hs = new LibHomeScreen();
155  hs->init(port, token);
156 
157  // hs->registerCallback(&onEv, &onRep);
158  //
159  // hs->subscribe(event_list[0]); // tap_shortcut event subscribe
160  // hs->subscribe(event_list[1]);
161 
162  hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [](json_object *object){
163  const char *application_name = json_object_get_string(
164  json_object_object_get(object, "application_name"));
165  cout << "set_event_handler Event_TapShortcut application_name = " << application_name << endl;
166  });
167 
169  const char *display_message = json_object_get_string(
170  json_object_object_get(object, "display_message"));
171  cout << "set_event_handler Event_OnScreenMessage display_message = " << display_message << endl;
172  });
173 
174  hs->set_event_handler(LibHomeScreen::Event_OnScreenReply, [](json_object *object){
175  const char *reply_message = json_object_get_string(
176  json_object_object_get(object, "reply_message"));
177  cout << "set_event_handler Event_OnScreenReply reply_message = " << reply_message << endl;
178  });
179 
180  if (ret < 0) {
181  printf("failed to create event loop");
182  return -1;
183  }
184 
185  call_test();
186 
187  return 0;
188 }
static void usage()
Definition: test.cpp:35
LibHomeScreen * hs
Definition: test.cpp:33
- + +
static void call_test()
Definition: test.cpp:51
- -
int init(const int port, const std::string &token)
+
int init(const int port, const std::string &token)
-
void set_event_handler(enum EventType et, handler_func f)
- +
void set_event_handler(enum EventType et, handler_func f)
+
@@ -302,7 +302,7 @@ Variables

Definition at line 35 of file test.cpp.

-
36 {
37  cout << "verb "<< "key:arg" << endl;
38  cout << "example:" << endl;
39  cout << "ping" << endl;
40  cout << "------- -------- --- " << endl;
41  cout << " verb key value" << endl;
42  cout << "verb list:" << endl;
43  for(auto itr = LibHomeScreen::api_list.begin(); itr != LibHomeScreen::api_list.end(); ++itr)
44  {
45  cout << " " << *itr << endl;
46  }
47  // Todo output api list
48  exit(0);
49 }
static const std::vector< std::string > api_list
+
36 {
37  cout << "verb "<< "key:arg" << endl;
38  cout << "example:" << endl;
39  cout << "ping" << endl;
40  cout << "------- -------- --- " << endl;
41  cout << " verb key value" << endl;
42  cout << "verb list:" << endl;
43  for(auto itr = LibHomeScreen::api_list.begin(); itr != LibHomeScreen::api_list.end(); ++itr)
44  {
45  cout << " " << *itr << endl;
46  }
47  // Todo output api list
48  exit(0);
49 }
static const std::vector< std::string > api_list
diff --git a/doc/api-ref/html/df/dac/test_8cpp_source.html b/doc/api-ref/html/df/dac/test_8cpp_source.html index 4726190..2a5c650 100644 --- a/doc/api-ref/html/df/dac/test_8cpp_source.html +++ b/doc/api-ref/html/df/dac/test_8cpp_source.html @@ -66,24 +66,24 @@ $(function() {
test.cpp
-Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <libhomescreen.hpp>
18 #include <iostream>
19 #include <glib-2.0/glib.h>
20 #include <fcntl.h>
21 #include <string>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <thread>
25 #include <exception>
26 #include <vector>
27 #include <sstream>
28 #include <functional>
29 
30 using namespace std;
31 
32 static vector<string> split(const string& str, char sep);
34 
35 static void usage()
36 {
37  cout << "verb "<< "key:arg" << endl;
38  cout << "example:" << endl;
39  cout << "ping" << endl;
40  cout << "------- -------- --- " << endl;
41  cout << " verb key value" << endl;
42  cout << "verb list:" << endl;
43  for(auto itr = LibHomeScreen::api_list.begin(); itr != LibHomeScreen::api_list.end(); ++itr)
44  {
45  cout << " " << *itr << endl;
46  }
47  // Todo output api list
48  exit(0);
49 }
50 
51 static void call_test()
52 {
53  string command;
54 
55  cout << "input verb and argments" << endl;
56 
57  /* read the buffer */
58  for(;;){
59  char line[1023];
60  cin.getline(line, sizeof(line));
61  command = line;
62  if(command.empty()){
63  continue;
64  }
65 
66  vector<string> v_command = split(command, ' ');
67  /*for(auto itr = v_command.begin(); itr != v_command.end(); ++itr)
68  {
69  cout << *itr <<endl;
70  }*/
71  size_t num = v_command.size();
72  if(num % 2 == 0){
73  cout << "If command contains args, please input <key,value> in argument part" << endl;
74  continue;
75  }
76  /* create json object */
77  struct json_object* j_obj = json_object_new_object();
78  for(int i = 1;i < (v_command.size()) ;++i){
79  struct json_object* val = json_object_new_string(v_command[i+1].c_str());
80  json_object_object_add(j_obj, v_command[i].c_str(), val);
81  ++i;
82  }
83  /* call verb via LibHomeScreen */
84  hs->call(v_command[0], j_obj);
85  /* free vector */
86  vector<string>().swap(v_command);
87  string().swap(command);
88  }
89 }
90 
91 static void onRep(struct json_object* reply_contents)
92 {
93  const char* str = json_object_to_json_string(reply_contents);
94  cout << "test.cpp [CB onRep]: " << str << endl;
95  //json_object_put(reply_contents); do not release!!!
96 }
97 
98 static void onEv(const string& event, struct json_object* event_contents)
99 {
100  const char* str = json_object_to_json_string(event_contents);
101  cout << "test.cpp [CB onEvent]: event: " << event.c_str() << " contents: " << str << endl;
102  //json_object_put(event_contents); do not release!!!
103 }
104 
105 static vector<string> split(const string& str, char sep)
106 {
107  vector<string> v;
108  stringstream ss(str);
109  string buffer;
110  while( getline(ss, buffer, sep) ) {
111  if(!buffer.empty())
112  v.push_back(buffer);
113  }
114  return v;
115 }
116 
117 int main(int argc, char **argv)
118 {
119  int ret;
120  if(argc == 1)
121  {
122  printf("Please input port num in first argument, and token in second argument");
123  usage();
124  return 0;
125  }
126  if(argc == 2)
127  {
128  string av(argv[1]);
129  if( (av == "-h") || (av == "--help"))
130  {
131  usage();
132  return 0;
133  }
134  }
135 
136  string port_string(argv[1]);
137  string token(argv[2]);
138  char* endptr;
139  long port = strtol(port_string.c_str(),&endptr,10);
140 
141  /* error check of range */
142  if( (port > 20000) || (port < 0) )
143  {
144  printf("input under 20000(temporary number)");
145  return 0;
146  }
147  if(*endptr != '\0')
148  {
149  printf("not number");
150  return 0;
151  }
152 
153  cout << "Call test for LibHomeScreen" << endl;
154  hs = new LibHomeScreen();
155  hs->init(port, token);
156 
157  // hs->registerCallback(&onEv, &onRep);
158  //
159  // hs->subscribe(event_list[0]); // tap_shortcut event subscribe
160  // hs->subscribe(event_list[1]);
161 
162  hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [](const char* application_name){
163  cout << "set_event_handler Event_TapShortcut application_name = " << application_name << endl;
164  });
165 
166  hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [](const char* display_message){
167  cout << "set_event_handler Event_OnScreenMessage display_message = " << display_message << endl;
168  });
169 
170 
171  if (ret < 0) {
172  printf("failed to create event loop");
173  return -1;
174  }
175  hs->runEventloop();
176 
177  call_test();
178 
179  return 0;
180 }
static void usage()
Definition: test.cpp:35
+Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <libhomescreen.hpp>
18 #include <iostream>
19 #include <glib-2.0/glib.h>
20 #include <fcntl.h>
21 #include <string>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <thread>
25 #include <exception>
26 #include <vector>
27 #include <sstream>
28 #include <functional>
29 
30 using namespace std;
31 
32 static vector<string> split(const string& str, char sep);
34 
35 static void usage()
36 {
37  cout << "verb "<< "key:arg" << endl;
38  cout << "example:" << endl;
39  cout << "ping" << endl;
40  cout << "------- -------- --- " << endl;
41  cout << " verb key value" << endl;
42  cout << "verb list:" << endl;
43  for(auto itr = LibHomeScreen::api_list.begin(); itr != LibHomeScreen::api_list.end(); ++itr)
44  {
45  cout << " " << *itr << endl;
46  }
47  // Todo output api list
48  exit(0);
49 }
50 
51 static void call_test()
52 {
53  string command;
54 
55  cout << "input verb and argments" << endl;
56 
57  /* read the buffer */
58  for(;;){
59  char line[1023];
60  cin.getline(line, sizeof(line));
61  command = line;
62  if(command.empty()){
63  continue;
64  }
65 
66  vector<string> v_command = split(command, ' ');
67  /*for(auto itr = v_command.begin(); itr != v_command.end(); ++itr)
68  {
69  cout << *itr <<endl;
70  }*/
71  size_t num = v_command.size();
72  if(num % 2 == 0){
73  cout << "If command contains args, please input <key,value> in argument part" << endl;
74  continue;
75  }
76  /* create json object */
77  struct json_object* j_obj = json_object_new_object();
78  for(int i = 1;i < (v_command.size()) ;++i){
79  struct json_object* val = json_object_new_string(v_command[i+1].c_str());
80  json_object_object_add(j_obj, v_command[i].c_str(), val);
81  ++i;
82  }
83  /* call verb via LibHomeScreen */
84  hs->call(v_command[0], j_obj);
85  /* free vector */
86  vector<string>().swap(v_command);
87  string().swap(command);
88  }
89 }
90 
91 static void onRep(struct json_object* reply_contents)
92 {
93  const char* str = json_object_to_json_string(reply_contents);
94  cout << "test.cpp [CB onRep]: " << str << endl;
95  //json_object_put(reply_contents); do not release!!!
96 }
97 
98 static void onEv(const string& event, struct json_object* event_contents)
99 {
100  const char* str = json_object_to_json_string(event_contents);
101  cout << "test.cpp [CB onEvent]: event: " << event.c_str() << " contents: " << str << endl;
102  //json_object_put(event_contents); do not release!!!
103 }
104 
105 static vector<string> split(const string& str, char sep)
106 {
107  vector<string> v;
108  stringstream ss(str);
109  string buffer;
110  while( getline(ss, buffer, sep) ) {
111  if(!buffer.empty())
112  v.push_back(buffer);
113  }
114  return v;
115 }
116 
117 int main(int argc, char **argv)
118 {
119  int ret;
120  if(argc == 1)
121  {
122  printf("Please input port num in first argument, and token in second argument");
123  usage();
124  return 0;
125  }
126  if(argc == 2)
127  {
128  string av(argv[1]);
129  if( (av == "-h") || (av == "--help"))
130  {
131  usage();
132  return 0;
133  }
134  }
135 
136  string port_string(argv[1]);
137  string token(argv[2]);
138  char* endptr;
139  long port = strtol(port_string.c_str(),&endptr,10);
140 
141  /* error check of range */
142  if( (port > 20000) || (port < 0) )
143  {
144  printf("input under 20000(temporary number)");
145  return 0;
146  }
147  if(*endptr != '\0')
148  {
149  printf("not number");
150  return 0;
151  }
152 
153  cout << "Call test for LibHomeScreen" << endl;
154  hs = new LibHomeScreen();
155  hs->init(port, token);
156 
157  // hs->registerCallback(&onEv, &onRep);
158  //
159  // hs->subscribe(event_list[0]); // tap_shortcut event subscribe
160  // hs->subscribe(event_list[1]);
161 
162  hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [](json_object *object){
163  const char *application_name = json_object_get_string(
164  json_object_object_get(object, "application_name"));
165  cout << "set_event_handler Event_TapShortcut application_name = " << application_name << endl;
166  });
167 
168  hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [](json_object *object){
169  const char *display_message = json_object_get_string(
170  json_object_object_get(object, "display_message"));
171  cout << "set_event_handler Event_OnScreenMessage display_message = " << display_message << endl;
172  });
173 
174  hs->set_event_handler(LibHomeScreen::Event_OnScreenReply, [](json_object *object){
175  const char *reply_message = json_object_get_string(
176  json_object_object_get(object, "reply_message"));
177  cout << "set_event_handler Event_OnScreenReply reply_message = " << reply_message << endl;
178  });
179 
180  if (ret < 0) {
181  printf("failed to create event loop");
182  return -1;
183  }
184 
185  call_test();
186 
187  return 0;
188 }
static void usage()
Definition: test.cpp:35
static vector< string > split(const string &str, char sep)
Definition: test.cpp:105
LibHomeScreen * hs
Definition: test.cpp:33
- + +
int call(const std::string &verb, struct json_object *arg)
static void onEv(const string &event, struct json_object *event_contents)
Definition: test.cpp:98
int main(int argc, char **argv)
Definition: test.cpp:117
static void call_test()
Definition: test.cpp:51
static void onRep(struct json_object *reply_contents)
Definition: test.cpp:91
- -
int init(const int port, const std::string &token)
+
int init(const int port, const std::string &token)
-
static const std::vector< std::string > api_list
-
void set_event_handler(enum EventType et, handler_func f)
- +
static const std::vector< std::string > api_list
+
void set_event_handler(enum EventType et, handler_func f)
+