19 #include <glib-2.0/glib.h> 22 #include <sys/types.h> 32 static vector<string>
split(
const string& str,
char sep);
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;
45 cout <<
" " << *itr << endl;
55 cout <<
"input verb and argments" << endl;
60 cin.getline(line,
sizeof(line));
66 vector<string> v_command =
split(command,
' ');
71 size_t num = v_command.size();
73 cout <<
"If command contains args, please input <key,value> in argument part" << endl;
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);
84 hs->
call(v_command[0], j_obj);
86 vector<string>().swap(v_command);
87 string().swap(command);
91 static void onRep(
struct json_object* reply_contents)
93 const char* str = json_object_to_json_string(reply_contents);
94 cout <<
"test.cpp [CB onRep]: " << str << endl;
98 static void onEv(
const string&
event,
struct json_object* event_contents)
100 const char* str = json_object_to_json_string(event_contents);
101 cout <<
"test.cpp [CB onEvent]: event: " <<
event.c_str() <<
" contents: " << str << endl;
105 static vector<string>
split(
const string& str,
char sep)
108 stringstream ss(str);
110 while( getline(ss, buffer, sep) ) {
117 int main(
int argc,
char **argv)
122 printf(
"Please input port num in first argument, and token in second argument");
129 if( (av ==
"-h") || (av ==
"--help"))
136 string port_string(argv[1]);
137 string token(argv[2]);
139 long port = strtol(port_string.c_str(),&endptr,10);
142 if( (port > 20000) || (port < 0) )
144 printf(
"input under 20000(temporary number)");
149 printf(
"not number");
153 cout <<
"Call test for LibHomeScreen" << endl;
155 hs->
init(port, token);
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;
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;
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;
181 printf(
"failed to create event loop");
static vector< string > split(const string &str, char sep)
int call(const std::string &verb, struct json_object *arg)
static void onEv(const string &event, struct json_object *event_contents)
int main(int argc, char **argv)
static void onRep(struct json_object *reply_contents)
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)