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

Revision 742, 4.5 kB (checked in by ppalmers, 13 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 "controlserver.h"
30
31 using namespace std;
32
33 DECLARE_GLOBAL_DEBUG_MODULE;
34
35 ////////////////////////////////////////////////
36 // arg parsing
37 ////////////////////////////////////////////////
38 const char *argp_program_version = "test-dbus-server 0.1";
39 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
40 static char doc[] = "test-dbus-server -- test server for the DBUS interface";
41 static char args_doc[] = "";
42 static struct argp_option options[] = {
43     {"verbose",   'v', 0,           0,  "Produce verbose output" },
44    { 0 }
45 };
46
47 struct arguments
48 {
49     arguments()
50         : verbose( false )
51         {
52             args[0] = 0;
53         }
54
55     char* args[50];
56     bool  verbose;
57 } arguments;
58
59 // Parse a single option.
60 static error_t
61 parse_opt( int key, char* arg, struct argp_state* state )
62 {
63     // Get the input argument from `argp_parse', which we
64     // know is a pointer to our arguments structure.
65     struct arguments* arguments = ( struct arguments* ) state->input;
66
67 //     char* tail;
68     switch (key) {
69     case 'v':
70         arguments->verbose = true;
71         break;
72     case ARGP_KEY_ARG:
73         if (state->arg_num >= 50) {
74             // Too many arguments.
75             argp_usage (state);
76         }
77         arguments->args[state->arg_num] = arg;
78         break;
79     case ARGP_KEY_END:
80         break;
81     default:
82         return ARGP_ERR_UNKNOWN;
83     }
84     return 0;
85 }
86
87 static struct argp argp = { options, parse_opt, args_doc, doc };
88
89 ///////////////////////////
90 // main
91 //////////////////////////
92
93 DBus::BusDispatcher dispatcher;
94
95 void leave( int sig )
96 {
97     dispatcher.leave();
98 }
99
100 static const char* SERVER_NAME = "org.ffado.Control";
101
102 void start_server() {
103
104     // test DBUS stuff
105     DBus::default_dispatcher = &dispatcher;
106
107     DBus::Connection conn = DBus::Connection::SessionBus();
108     conn.request_name(SERVER_NAME);
109    
110     Control::Continuous c0("test0");
111     c0.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
112     DBusControl::Continuous fader(conn, "/org/ffado/Control/Test/Fader", c0);
113
114     Control::Container cont("container1");
115     cont.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
116    
117     Control::Container cont1("container2");
118     cont1.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
119    
120     cont.addElement(&cont1);
121
122     Control::Continuous c1("test1");
123     c1.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
124     cont.addElement(&c1);
125    
126     Control::Continuous c2("test2");
127     c2.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
128     cont.addElement(&c2);
129    
130     Control::Continuous c3("test3");
131     c3.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
132     cont.addElement(&c3);
133
134     Control::Continuous c4("test4");
135     c4.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
136     cont1.addElement(&c4);
137
138     Control::Continuous c5("test5");
139     c5.setVerboseLevel(DEBUG_LEVEL_VERBOSE);
140     cont1.addElement(&c5);
141
142     // Note: create handlers AFTER all children are added
143
144     // we do dynamic allocation such that we are sure
145     // the container is deleted before the children become invalid
146     DBusControl::Container *container
147         = new DBusControl::Container(conn, "/org/ffado/Control/Test/Container", cont);
148
149     dispatcher.enter();
150
151     delete container;
152    
153 }
154
155 int
156 main(int argc, char **argv)
157 {
158     signal(SIGTERM, leave);
159     signal(SIGINT, leave);
160    
161     setDebugLevel(DEBUG_LEVEL_VERBOSE);
162
163     // arg parsing
164     argp_parse (&argp, argc, argv, 0, 0, &arguments);
165
166     errno = 0;
167 //     char* tail;
168    
169     if (errno) {
170         perror("argument parsing failed:");
171         return -1;
172     }
173
174     debugOutput(DEBUG_LEVEL_NORMAL, "DBUS test server\n");
175
176     DBus::_init_threading();
177
178     start_server();
179
180     debugOutput(DEBUG_LEVEL_NORMAL, "bye...\n");
181    
182     return 0;
183 }
Note: See TracBrowser for help on using the browser.