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

Revision 2019, 4.1 kB (checked in by jwoithe, 12 years ago)

From Orcan via trac ticket #344. Writes Orcan:

It is that time of the year that the gcc folks decide to impose the
standards at a higher level. Attached is a trivial patch that will make
libffado compile against new gcc.

Thanks for the patch Orcan.

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 <unistd.h>
28 #include <signal.h>
29
30 #include "controlclient.h"
31 #include <dbus-c++/dbus.h>
32
33 static const char* SERVER_NAME = "org.ffado.Control";
34 static const char* SERVER_PATH = "/org/ffado/Control/Test/Fader";
35
36 using namespace std;
37
38 DECLARE_GLOBAL_DEBUG_MODULE;
39
40 ////////////////////////////////////////////////
41 // arg parsing
42 ////////////////////////////////////////////////
43 const char *argp_program_version = "test-dbus 0.1";
44 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
45 static char doc[] = "test-dbus -- test client for the DBUS interface";
46 static char args_doc[] = "";
47 static struct argp_option options[] = {
48     {"verbose",   'v', 0,           0,  "Produce verbose output" },
49    { 0 }
50 };
51
52 struct arguments
53 {
54     arguments()
55         : verbose( false )
56         {
57             args[0] = 0;
58         }
59
60     char* args[50];
61     bool  verbose;
62 } arguments;
63
64 // Parse a single option.
65 static error_t
66 parse_opt( int key, char* arg, struct argp_state* state )
67 {
68     // Get the input argument from `argp_parse', which we
69     // know is a pointer to our arguments structure.
70     struct arguments* arguments = ( struct arguments* ) state->input;
71
72 //     char* tail;
73     switch (key) {
74     case 'v':
75         arguments->verbose = true;
76         break;
77     case ARGP_KEY_ARG:
78         if (state->arg_num >= 50) {
79             // Too many arguments.
80             argp_usage (state);
81         }
82         arguments->args[state->arg_num] = arg;
83         break;
84     case ARGP_KEY_END:
85         break;
86     default:
87         return ARGP_ERR_UNKNOWN;
88     }
89     return 0;
90 }
91
92 static struct argp argp = { options, parse_opt, args_doc, doc };
93
94 ///////////////////////////
95 // main
96 //////////////////////////
97
98 DBus::BusDispatcher dispatcher;
99 static const int THREADS = 1;
100 static bool spin = true;
101
102 void leave( int sig )
103 {
104     spin = false;
105     dispatcher.leave();
106 }
107
108 void* worker_thread( void* )
109 {
110     DBus::Connection conn = DBus::Connection::SessionBus();
111
112     DBusControl::ContinuousClient client(conn, SERVER_PATH, SERVER_NAME);
113
114     int i=0;
115     while(spin)
116     {
117         try {
118             client.setValue(i++);
119         } catch(...) {
120             cout << "error on setValue()\n";
121         };
122 //         try {
123 //             std::map< DBus::String, DBus::String > info = client.Info();
124 //             cout << info["testset1"] << " - " << info["testset2"] << std::endl;
125 //         } catch(...) {
126 //             cout << "error on Info()\n";
127 //         };
128
129         cout << "* " << i << "*\n";
130         sleep(1);
131     }
132
133     return NULL;
134 }
135
136 void run_client_tests() {
137     DBus::default_dispatcher = &dispatcher;
138
139     pthread_t thread;
140
141     pthread_create(&thread, NULL, worker_thread, NULL);
142
143     dispatcher.enter();
144
145     pthread_join(thread, NULL);
146 }
147
148 int
149 main(int argc, char **argv)
150 {
151     signal(SIGTERM, leave);
152     signal(SIGINT, leave);
153    
154     setDebugLevel(DEBUG_LEVEL_VERBOSE);
155    
156     // arg parsing
157     argp_parse (&argp, argc, argv, 0, 0, &arguments);
158
159     errno = 0;
160 //     char* tail;
161    
162     if (errno) {
163         perror("argument parsing failed:");
164         return -1;
165     }
166
167     debugOutput(DEBUG_LEVEL_NORMAL, "DBUS test application\n");
168
169     DBus::_init_threading();
170
171     run_client_tests();
172
173     debugOutput(DEBUG_LEVEL_NORMAL, "bye...\n");
174    
175     return 0;
176 }
Note: See TracBrowser for help on using the browser.