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

Revision 2803, 4.2 kB (checked in by jwoithe, 3 years ago)

Cosmetic: capitalise "L" in "Linux".

"Linux" is a proper noun so it should start with a capital letter. These
changes are almost all within comments.

This patch was originally proposed by pander on the ffado-devel mailing
list. It has been expanded to cover all similar cases to maintain
consistency throughout the source tree.

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