2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <libsoundmanager/libsoundmanager.hpp>
19 #include <glib-2.0/glib.h>
22 #include <sys/types.h>
31 static vector<string> split(const string& str, char sep);
36 cout << "verb "<< "key:arg" << endl;
37 cout << "example:" << endl;
38 cout << "connect sourceID 100 sinkID 100" << endl;
39 cout << "------- -------- --- " << endl;
40 cout << " verb key value" << endl;
41 cout << "verb list:" << endl;
42 for(auto itr = api_list.begin(); itr != api_list.end(); ++itr)
44 cout << " " << *itr << endl;
46 // Todo output api list
50 static void call_test()
54 cout << "input verb and argments" << endl;
59 cin.getline(line, sizeof(line));
65 vector<string> v_command = split(command, ' ');
66 /*for(auto itr = v_command.begin(); itr != v_command.end(); ++itr)
70 size_t num = v_command.size();
72 cout << "If command contains args, please input <key,value> in argument part" << endl;
75 /* create json object */
76 struct json_object* j_obj = json_object_new_object();
77 for(int i = 1;i < (v_command.size()) ;++i){
78 struct json_object* val = json_object_new_string(v_command[i+1].c_str());
79 json_object_object_add(j_obj, v_command[i].c_str(), val);
82 /* call verb via libsoundmanager */
83 sm->call(v_command[0], j_obj);
85 vector<string>().swap(v_command);
86 string().swap(command);
90 static void onRep(struct json_object* reply_contents)
92 const char* str = json_object_to_json_string(reply_contents);
93 cout << "[CB onRep]: " << str << endl;
94 json_object_put(reply_contents);
97 static void onEv(const string& event, struct json_object* event_contents)
99 const char* str = json_object_to_json_string(event_contents);
100 cout << "[CB onEvent]: event" << event.c_str() << " contents:" << str << endl;
101 json_object_put(event_contents);
104 static vector<string> split(const string& str, char sep)
107 stringstream ss(str);
109 while( getline(ss, buffer, sep) ) {
116 int main(int argc, char **argv)
121 printf("Please input port num in first argument, and token in second argument");
128 if( (av == "-h") || (av == "--help"))
135 string port_string(argv[1]);
136 string token(argv[2]);
138 long port = strtol(port_string.c_str(),&endptr,10);
140 /* error check of range */
141 if( (port > 20000) || (port < 0) )
143 printf("input under 20000(temporary number)");
148 printf("not number");
152 cout << "Call test for libsoundmanager" << endl;
153 cout << "Call example: registerSource appname radio" << endl;
154 sm = new LibSoundmanager(port, token);
155 sm->register_callback(&onEv, &onRep);
158 printf("failed to create event loop");