root/trunk/libffado/support/dbus/test-dbus.cpp

Revision 1047, 4.0 kB (checked in by ppalmers, 16 years ago)

remove compiler warnings. change non-critical warnings to debug messages.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include <argp.h>
25 #include <stdlib.h>
26 #include <iostream>
27 #include <signal.h>
28
29 #include "controlclient.h"
30 #include <dbus-c++/dbus.h>
31
32 static const char* SERVER_NAME = "org.ffado.Control";
33 static const char* SERVER_PATH = "/org/ffado/Control/Test/Fader";
34
35 using namespace std;
36
37 DECLARE_GLOBAL_DEBUG_MODULE;
38
39 ////////////////////////////////////////////////
40 // arg parsing
41 ////////////////////////////////////////////////
42 const char *argp_program_version = "test-dbus 0.1";
43 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
44 static char doc[] = "test-dbus -- test client for the DBUS interface";
45 static char args_doc[] = "";
46 static struct argp_option options[] = {
47     {"verbose",   'v', 0,           0,  "Produce verbose output" },
48    { 0 }
49 };
50
51 struct arguments
52 {
53     arguments()
54         : verbose( false )
55         {
56             args[0] = 0;
57         }
58
59     char* args[50];
60     bool  verbose;
61 } arguments;
62
63 // Parse a single option.
64 static error_t
65 parse_opt( int key, char* arg, struct argp_state* state )
66 {
67     // Get the input argument from `argp_parse', which we
68     // know is a pointer to our arguments structure.
69     struct arguments* arguments = ( struct arguments* ) state->input;
70
71 //     char* tail;
72     switch (key) {
73     case 'v':
74         arguments->verbose = true;
75         break;
76     case ARGP_KEY_ARG:
77         if (state->arg_num >= 50) {
78             // Too many arguments.
79             argp_usage (state);
80         }
81         arguments->args[state->arg_num] = arg;
82         break;
83     case ARGP_KEY_END:
84         break;
85     default:
86         return ARGP_ERR_UNKNOWN;
87     }
88     return 0;
89 }
90
91 static struct argp argp = { options, parse_opt, args_doc, doc };
92
93 ///////////////////////////
94 // main
95 //////////////////////////
96
97 DBus::BusDispatcher dispatcher;
98 static const int THREADS = 1;
99 static bool spin = true;
100
101 void leave( int sig )
102 {
103     spin = false;
104     dispatcher.leave();
105 }
106
107 void* worker_thread( void* )
108 {
109     DBus::Connection conn = DBus::Connection::SessionBus();
110
111     DBusControl::ContinuousClient client(conn, SERVER_PATH, SERVER_NAME);
112
113     int i=0;
114     while(spin)
115     {
116         try {
117             client.setValue(i++);
118         } catch(...) {
119             cout << "error on setValue()\n";
120         };
121 //         try {
122 //             std::map< DBus::String, DBus::String > info = client.Info();
123 //             cout << info["testset1"] << " - " << info["testset2"] << std::endl;
124 //         } catch(...) {
125 //             cout << "error on Info()\n";
126 //         };
127
128         cout << "* " << i << "*\n";
129         sleep(1);
130     }
131
132     return NULL;
133 }
134
135 void run_client_tests() {
136     DBus::default_dispatcher = &dispatcher;
137
138     pthread_t thread;
139
140     pthread_create(&thread, NULL, worker_thread, NULL);
141
142     dispatcher.enter();
143
144     pthread_join(thread, NULL);
145 }
146
147 int
148 main(int argc, char **argv)
149 {
150     signal(SIGTERM, leave);
151     signal(SIGINT, leave);
152    
153     setDebugLevel(DEBUG_LEVEL_VERBOSE);
154    
155     // arg parsing
156     argp_parse (&argp, argc, argv, 0, 0, &arguments);
157
158     errno = 0;
159 //     char* tail;
160    
161     if (errno) {
162         perror("argument parsing failed:");
163         return -1;
164     }
165
166     debugOutput(DEBUG_LEVEL_NORMAL, "DBUS test application\n");
167
168     DBus::_init_threading();
169
170     run_client_tests();
171
172     debugOutput(DEBUG_LEVEL_NORMAL, "bye...\n");
173    
174     return 0;
175 }
Note: See TracBrowser for help on using the browser.