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

Revision 582, 4.0 kB (checked in by ppalmers, 17 years ago)

see prev commit

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