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

Revision 739, 6.9 kB (checked in by ppalmers, 16 years ago)

- Adapt the ffado external API (upgrade to v3)

NEEDS NEW JACK BACKEND

- simplify FFADODevice constructor even more
- implement first framework support for supporting multiple adapters.

currently all firewire adapters are scanned for supported devices unless specified otherwise
however attaching devices to separate adapters is not supported. using multiple adapters at
that are connected together might work.

Line 
1 /*
2  * Copyright (C) 2005-2007 by by Daniel Wagner
3  * Copyright (C) 2005-2007 by by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
10  * FFADO is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * FFADO 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 FFADO; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA.
23  */
24
25 /*
26  * This version uses the CPP API
27  */
28
29 #include <config.h>
30
31 #include "libffado/ffado.h"
32
33 #include "debugmodule/debugmodule.h"
34 #include "fbtypes.h"
35 #include "devicemanager.h"
36 #include "ffadodevice.h"
37
38 #include <dbus-c++/dbus.h>
39 #include "controlserver.h"
40 #include "libcontrol/BasicElements.h"
41
42 #include <signal.h>
43
44 #include <argp.h>
45 #include <stdlib.h>
46 #include <stdio.h>
47 #include <string.h>
48
49 #include <vector>
50 #include <string>
51 #include <iostream>
52 #include <sstream>
53
54 using namespace std;
55
56 DECLARE_GLOBAL_DEBUG_MODULE;
57
58 // DBUS stuff
59 DBus::BusDispatcher dispatcher;
60
61 // signal handler
62 int run=1;
63 static void sighandler (int sig)
64 {
65     run = 0;
66     dispatcher.leave();
67 }
68
69 // global's
70 const char *argp_program_version = PACKAGE_STRING;
71 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
72
73 // Program documentation.
74 static char doc[] = "ffado-dbus-server -- expose the mixer features of connected FFADO devices through DBus\n\n"
75                     ;
76
77 // A description of the arguments we accept.
78 static char args_doc[] = "";
79
80 struct arguments
81 {
82     short silent;
83     short verbose;
84     int   port;
85     int   node_id;
86     int   node_id_set;
87     char* args[2];
88 };
89
90 // The options we understand.
91 static struct argp_option options[] = {
92     {"quiet",    'q',       0,    0,  "Don't produce any output" },
93     {"silent",   's',       0,    OPTION_ALIAS },
94
95     {"verbose",  'v', "level",    0,  "Produce verbose output" },
96
97
98     {"node",     'n',    "id",    0,  "Only expose mixer of a device on a specific node" },
99     {"port",     'p',    "nr",    0,  "IEEE1394 Port to use" },
100     { 0 }
101 };
102
103 //-------------------------------------------------------------
104
105 // Parse a single option.
106 static error_t
107 parse_opt( int key, char* arg, struct argp_state* state )
108 {
109     // Get the input argument from `argp_parse', which we
110     // know is a pointer to our arguments structure.
111     struct arguments* arguments = ( struct arguments* ) state->input;
112     char* tail;
113
114     switch (key) {
115     case 'q': case 's':
116         arguments->silent = 1;
117         break;
118     case 'v':
119         if (arg) {
120             arguments->verbose = strtol( arg, &tail, 0 );
121             if ( errno ) {
122                 debugError( "Could not parse 'verbose' argument\n" );
123                 return ARGP_ERR_UNKNOWN;
124             }
125         }
126         break;
127     case 'p':
128         if (arg) {
129             arguments->port = strtol( arg, &tail, 0 );
130             if ( errno ) {
131                 debugError( "Could not parse 'port' argument\n" );
132                 return ARGP_ERR_UNKNOWN;
133             }
134         } else {
135             if ( errno ) {
136                 debugError("Could not parse 'port' argumen\n" );
137                 return ARGP_ERR_UNKNOWN;
138             }
139         }
140         break;
141     case 'n':
142         if (arg) {
143             arguments->node_id = strtol( arg, &tail, 0 );
144             if ( errno ) {
145                 debugError( "Could not parse 'node' argument\n" );
146                 return ARGP_ERR_UNKNOWN;
147             }
148             arguments->node_id_set=1;
149         } else {
150             if ( errno ) {
151                 debugError("Could not parse 'node' argumen\n" );
152                 return ARGP_ERR_UNKNOWN;
153             }
154         }
155         break;
156     case ARGP_KEY_ARG:
157         if (state->arg_num >= 1) {
158             // Too many arguments.
159             argp_usage( state );
160         }
161         arguments->args[state->arg_num] = arg;
162         break;
163     case ARGP_KEY_END:
164         if (state->arg_num < 0) {
165         // Not enough arguments.
166         argp_usage( state );
167         }
168         break;
169     default:
170         return ARGP_ERR_UNKNOWN;
171     }
172     return 0;
173 }
174
175 // Our argp parser.
176 static struct argp argp = { options, parse_opt, args_doc, doc };
177
178 int exitfunction( int retval ) {
179     debugOutput( DEBUG_LEVEL_NORMAL, "Debug output flushed...\n" );
180     flushDebugOutput();
181     return retval;
182 }
183
184 int
185 main( int argc, char **argv )
186 {
187     struct arguments arguments;
188
189     // Default values.
190     arguments.silent      = 0;
191     arguments.verbose     = 0;
192     arguments.port        = 0;
193     arguments.node_id     = 0;
194     arguments.node_id_set = 0; // if we don't specify a node, discover all
195     arguments.args[0]     = "";
196     arguments.args[1]     = "";
197
198     setDebugLevel(arguments.verbose);
199
200     // Parse our arguments; every option seen by `parse_opt' will
201     // be reflected in `arguments'.
202     if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) {
203         debugError("Could not parse command line\n" );
204         return exitfunction(-1);
205     }
206
207     debugOutput( DEBUG_LEVEL_NORMAL, "verbose level = %d\n", arguments.verbose);
208     debugOutput( DEBUG_LEVEL_NORMAL, "Using ffado library version: %s\n\n", ffado_get_version() );
209
210         DeviceManager *m_deviceManager = new DeviceManager();
211         if ( !m_deviceManager ) {
212             debugError("Could not allocate device manager\n" );
213             return exitfunction(-1);
214         }
215         if ( !m_deviceManager->initialize() ) {
216             debugError("Could not initialize device manager\n" );
217             delete m_deviceManager;
218             return exitfunction(-1);
219         }
220         if ( arguments.verbose ) {
221             m_deviceManager->setVerboseLevel(arguments.verbose);
222         }
223         if ( !m_deviceManager->discover() ) {
224             debugError("Could not discover devices\n" );
225             delete m_deviceManager;
226             return exitfunction(-1);
227         }
228        
229         signal (SIGINT, sighandler);
230        
231         DBus::_init_threading();
232    
233         // test DBUS stuff
234         DBus::default_dispatcher = &dispatcher;
235    
236         DBus::Connection conn = DBus::Connection::SessionBus();
237         conn.request_name("org.ffado.Control");
238        
239         DBusControl::Container *container
240             = new DBusControl::Container(conn, "/org/ffado/Control/DeviceManager", *m_deviceManager);
241        
242         printMessage("DBUS test service running\n");
243         printMessage("press ctrl-c to stop it & continue\n");
244        
245         dispatcher.enter();
246    
247         delete container;
248
249         signal (SIGINT, SIG_DFL);
250
251         printMessage("server stopped\n");
252         delete m_deviceManager;
253         return exitfunction(0);
254 }
Note: See TracBrowser for help on using the browser.