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

Revision 742, 3.9 kB (checked in by ppalmers, 15 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

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