root/branches/ppalmers-streaming/tests/test-dbus-server.cpp

Revision 582, 4.5 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 "controlserver.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-server 0.1";
40 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
41 static char doc[] = "test-dbus-server -- test server 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
96 void leave( int sig )
97 {
98     dispatcher.leave();
99 }
100
101 static const char* SERVER_NAME = "org.ffado.Control";
102
103 void start_server() {
104
105     // test DBUS stuff
106     DBus::default_dispatcher = &dispatcher;
107
108     DBus::Connection conn = DBus::Connection::SessionBus();
109     conn.request_name(SERVER_NAME);
110    
111     Control::Continuous c0("test0");
112     c0.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
113     DBusControl::Continuous fader(conn, "/org/ffado/Control/Test/Fader", c0);
114
115     Control::Container cont("container1");
116     cont.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
117    
118     Control::Container cont1("container2");
119     cont1.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
120    
121     cont.addElement(&cont1);
122
123     Control::Continuous c1("test1");
124     c1.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
125     cont.addElement(&c1);
126    
127     Control::Continuous c2("test2");
128     c2.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
129     cont.addElement(&c2);
130    
131     Control::Continuous c3("test3");
132     c3.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
133     cont.addElement(&c3);
134
135     Control::Continuous c4("test4");
136     c4.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
137     cont1.addElement(&c4);
138
139     Control::Continuous c5("test5");
140     c5.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
141     cont1.addElement(&c5);
142
143     // Note: create handlers AFTER all children are added
144
145     // we do dynamic allocation such that we are sure
146     // the container is deleted before the children become invalid
147     DBusControl::Container *container
148         = new DBusControl::Container(conn, "/org/ffado/Control/Test/Container", cont);
149
150     dispatcher.enter();
151
152     delete container;
153    
154 }
155
156 int
157 main(int argc, char **argv)
158 {
159     signal(SIGTERM, leave);
160     signal(SIGINT, leave);
161    
162     setDebugLevel(DEBUG_LEVEL_VERBOSE);
163
164     // arg parsing
165     argp_parse (&argp, argc, argv, 0, 0, &arguments);
166
167     errno = 0;
168 //     char* tail;
169    
170     if (errno) {
171         perror("argument parsing failed:");
172         return -1;
173     }
174
175     debugOutput(DEBUG_LEVEL_NORMAL, "DBUS test server\n");
176
177     DBus::_init_threading();
178
179     start_server();
180
181     debugOutput(DEBUG_LEVEL_NORMAL, "bye...\n");
182    
183     return 0;
184 }
Note: See TracBrowser for help on using the browser.