root/branches/libffado-2.0/src/bebob/bebob_avdevice.cpp

Revision 1241, 21.7 kB (checked in by ppalmers, 13 years ago)

update BeBoB constructors (thx slack) (closes #129, #127)

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
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 2 of the License, or
12  * (at your option) version 3 of the License.
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 "config.h"
25
26 #include "bebob/bebob_avdevice.h"
27 #include "bebob/bebob_avdevice_subunit.h"
28 #include "bebob/bebob_mixer.h"
29
30 #include "bebob/focusrite/focusrite_saffire.h"
31 #include "bebob/focusrite/focusrite_saffirepro.h"
32 #include "bebob/terratec/terratec_device.h"
33 #include "bebob/mackie/onyxmixer.h"
34 #include "bebob/edirol/edirol_fa101.h"
35 #include "bebob/edirol/edirol_fa66.h"
36 #include "bebob/esi/quatafire610.h"
37
38 #include "libieee1394/configrom.h"
39 #include "libieee1394/ieee1394service.h"
40
41 #include "genericavc/avc_vendormodel.h"
42
43 #include "libavc/general/avc_plug_info.h"
44 #include "libavc/general/avc_extended_plug_info.h"
45 #include "libavc/general/avc_subunit_info.h"
46 #include "libavc/streamformat/avc_extended_stream_format.h"
47 #include "libutil/cmd_serialize.h"
48 #include "libavc/avc_definitions.h"
49
50 #include "debugmodule/debugmodule.h"
51
52 #include <iostream>
53 #include <sstream>
54 #include <unistd.h>
55 #include <cstdlib>
56 #include <cstring>
57 #include <sys/stat.h>
58
59 using namespace AVC;
60
61 namespace BeBoB {
62
63 AvDevice::AvDevice( DeviceManager& d, std::auto_ptr< ConfigRom >( configRom ) )
64     : GenericAVC::AvDevice( d, configRom )
65     , m_Mixer ( 0 )
66 {
67     debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::AvDevice (NodeID %d)\n",
68                  getConfigRom().getNodeId() );
69
70     // DM1500 based devices seem to upset the linux1394 stack when commands are
71     // sent too fast.
72     if (AVC::AVCCommand::getSleepAfterAVCCommand() < 200) {
73         AVC::AVCCommand::setSleepAfterAVCCommand( 200 );
74     }
75
76 }
77
78 AvDevice::~AvDevice()
79 {
80     destroyMixer();
81 }
82
83 bool
84 AvDevice::probe( ConfigRom& configRom, bool generic )
85 {
86     if(generic) {
87         return false;
88         // try a bebob-specific command to check for the firmware
89         ExtendedPlugInfoCmd extPlugInfoCmd( configRom.get1394Service() );
90         UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR,
91                                          configRom.getNodeId() );
92         extPlugInfoCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input,
93                                                     PlugAddress::ePAM_Unit,
94                                                     unitPlugAddress ) );
95         extPlugInfoCmd.setNodeId( configRom.getNodeId() );
96         extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status );
97         extPlugInfoCmd.setVerbose( configRom.getVerboseLevel() );
98         ExtendedPlugInfoInfoType extendedPlugInfoInfoType(
99             ExtendedPlugInfoInfoType::eIT_NoOfChannels );
100         extendedPlugInfoInfoType.initialize();
101         extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType );
102    
103         if ( !extPlugInfoCmd.fire() ) {
104             debugError( "Number of channels command failed\n" );
105             return false;
106         }
107    
108         ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType();
109         if ( infoType
110             && infoType->m_plugNrOfChns )
111         {
112             return true;
113         }
114         return false;
115     } else {
116         // check if device is in supported devices list
117         unsigned int vendorId = configRom.getNodeVendorId();
118         unsigned int modelId = configRom.getModelId();
119
120         GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_bebob.txt" );
121         if ( vendorModel.parse() ) {
122             return vendorModel.isPresent( vendorId, modelId );
123         }
124         return false;
125     }
126 }
127
128 FFADODevice *
129 AvDevice::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ))
130 {
131     unsigned int vendorId = configRom->getNodeVendorId();
132     unsigned int modelId = configRom->getModelId();
133
134     switch (vendorId) {
135         case FW_VENDORID_MACKIE:
136             if (modelId == 0x00010065 ) {
137                 return new Mackie::OnyxMixerDevice(d, configRom);
138             }
139         case FW_VENDORID_EDIROL:
140             switch (modelId) {
141                 case 0x00010048:
142                     return new Edirol::EdirolFa101Device(d, configRom);
143                 case 0x00010049:
144                     return new Edirol::EdirolFa66Device(d, configRom);
145                 default:
146                     return new AvDevice(d, configRom);
147             }
148         case FW_VENDORID_ESI:
149             if (modelId == 0x00010064) {
150                 return new ESI::QuataFireDevice(d, configRom);
151             }
152             break;
153         case FW_VENDORID_TERRATEC:
154             switch(modelId) {
155                 case 0x00000003:
156                     return new Terratec::Phase88Device(d, configRom);
157                 default: // return a plain BeBoB device
158                     return new AvDevice(d, configRom);
159             }
160         case FW_VENDORID_FOCUSRITE:
161             switch(modelId) {
162                 case 0x00000003:
163                 case 0x00000006:
164                     return new Focusrite::SaffireProDevice(d, configRom);
165                 case 0x00000000:
166                     return new Focusrite::SaffireDevice(d, configRom);
167                 default: // return a plain BeBoB device
168                     return new AvDevice(d, configRom);
169            }
170         default:
171             return new AvDevice(d, configRom);
172     }
173     return NULL;
174 }
175
176 bool
177 AvDevice::discover()
178 {
179     unsigned int vendorId = getConfigRom().getNodeVendorId();
180     unsigned int modelId = getConfigRom().getModelId();
181
182     GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_bebob.txt" );
183     if ( vendorModel.parse() ) {
184         m_model = vendorModel.find( vendorId, modelId );
185     }
186
187     if (GenericAVC::VendorModel::isValid(m_model)) {
188         debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n",
189                      m_model.vendor_name.c_str(),
190                      m_model.model_name.c_str());
191     } else {
192         debugWarning("Using generic BeBoB support for unsupported device '%s %s'\n",
193                      getConfigRom().getVendorName().c_str(), getConfigRom().getModelName().c_str());
194     }
195
196     if ( !Unit::discover() ) {
197         debugError( "Could not discover unit\n" );
198         return false;
199     }
200
201     if((getAudioSubunit( 0 ) == NULL)) {
202         debugError( "Unit doesn't have an Audio subunit.\n");
203         return false;
204     }
205     if((getMusicSubunit( 0 ) == NULL)) {
206         debugError( "Unit doesn't have a Music subunit.\n");
207         return false;
208     }
209
210     if(!buildMixer()) {
211         debugWarning("Could not build mixer\n");
212     }
213     return true;
214 }
215
216 bool
217 AvDevice::buildMixer()
218 {
219     debugOutput(DEBUG_LEVEL_VERBOSE, "Building a generic BeBoB mixer...\n");
220     // create a Mixer
221     // this removes the mixer if it already exists
222     // note: a mixer self-registers to it's parent
223     delete m_Mixer;
224
225     // create the mixer & register it
226     if(getAudioSubunit(0) == NULL) {
227         debugWarning("Could not find audio subunit, mixer not available.\n");
228         m_Mixer = NULL;
229     } else {
230         m_Mixer = new Mixer(*this);
231     }
232     if (m_Mixer) m_Mixer->setVerboseLevel(getDebugLevel());
233     return m_Mixer != NULL;
234 }
235
236 bool
237 AvDevice::destroyMixer()
238 {
239     delete m_Mixer;
240     return true;
241 }
242
243 bool
244 AvDevice::setSelectorFBValue(int id, int value) {
245     FunctionBlockCmd fbCmd( get1394Service(),
246                             FunctionBlockCmd::eFBT_Selector,
247                             id,
248                             FunctionBlockCmd::eCA_Current );
249     fbCmd.setNodeId( getNodeId() );
250     fbCmd.setSubunitId( 0x00 );
251     fbCmd.setCommandType( AVCCommand::eCT_Control );
252     fbCmd.m_pFBSelector->m_inputFbPlugNumber = (value & 0xFF);
253     fbCmd.setVerboseLevel( getDebugLevel() );
254
255     if ( !fbCmd.fire() ) {
256         debugError( "cmd failed\n" );
257         return false;
258     }
259
260 //     if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) {
261 //         Util::CoutSerializer se;
262 //         fbCmd.serialize( se );
263 //     }
264 //     
265     if((fbCmd.getResponse() != AVCCommand::eR_Accepted)) {
266         debugWarning("fbCmd.getResponse() != AVCCommand::eR_Accepted\n");
267     }
268
269     return (fbCmd.getResponse() == AVCCommand::eR_Accepted);
270 }
271
272 int
273 AvDevice::getSelectorFBValue(int id) {
274
275     FunctionBlockCmd fbCmd( get1394Service(),
276                             FunctionBlockCmd::eFBT_Selector,
277                             id,
278                             FunctionBlockCmd::eCA_Current );
279     fbCmd.setNodeId( getNodeId() );
280     fbCmd.setSubunitId( 0x00 );
281     fbCmd.setCommandType( AVCCommand::eCT_Status );
282     fbCmd.m_pFBSelector->m_inputFbPlugNumber = 0xFF;
283     fbCmd.setVerboseLevel( getDebugLevel() );
284
285     if ( !fbCmd.fire() ) {
286         debugError( "cmd failed\n" );
287         return -1;
288     }
289    
290 //     if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) {
291 //         Util::CoutSerializer se;
292 //         fbCmd.serialize( se );
293 //     }
294
295     if((fbCmd.getResponse() != AVCCommand::eR_Implemented)) {
296         debugWarning("fbCmd.getResponse() != AVCCommand::eR_Implemented\n");
297     }
298    
299     return fbCmd.m_pFBSelector->m_inputFbPlugNumber;
300 }
301
302 bool
303 AvDevice::setFeatureFBVolumeValue(int id, int channel, int v) {
304
305     FunctionBlockCmd fbCmd( get1394Service(),
306                             FunctionBlockCmd::eFBT_Feature,
307                             id,
308                             FunctionBlockCmd::eCA_Current );
309     fbCmd.setNodeId( getNodeId() );
310     fbCmd.setSubunitId( 0x00 );
311     fbCmd.setCommandType( AVCCommand::eCT_Control );
312     fbCmd.m_pFBFeature->m_audioChannelNumber = channel;
313     fbCmd.m_pFBFeature->m_controlSelector = FunctionBlockFeature::eCSE_Feature_Volume;
314     fbCmd.m_pFBFeature->m_pVolume->m_volume = v;
315     fbCmd.setVerboseLevel( getDebugLevel() );
316
317     if ( !fbCmd.fire() ) {
318         debugError( "cmd failed\n" );
319         return false;
320     }
321
322 //     if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) {
323 //         Util::CoutSerializer se;
324 //         fbCmd.serialize( se );
325 //     }
326    
327     if((fbCmd.getResponse() != AVCCommand::eR_Accepted)) {
328         debugWarning("fbCmd.getResponse() != AVCCommand::eR_Accepted\n");
329     }
330
331     return (fbCmd.getResponse() == AVCCommand::eR_Accepted);
332 }
333
334 int
335 AvDevice::getFeatureFBVolumeValue(int id, int channel) {
336     FunctionBlockCmd fbCmd( get1394Service(),
337                             FunctionBlockCmd::eFBT_Feature,
338                             id,
339                             FunctionBlockCmd::eCA_Current );
340     fbCmd.setNodeId( getNodeId() );
341     fbCmd.setSubunitId( 0x00 );
342     fbCmd.setCommandType( AVCCommand::eCT_Status );
343     fbCmd.m_pFBFeature->m_audioChannelNumber = channel;
344     fbCmd.m_pFBFeature->m_controlSelector = FunctionBlockFeature::eCSE_Feature_Volume;
345     fbCmd.m_pFBFeature->m_pVolume->m_volume = 0;
346     fbCmd.setVerboseLevel( getDebugLevel() );
347
348     if ( !fbCmd.fire() ) {
349         debugError( "cmd failed\n" );
350         return 0;
351     }
352    
353 //     if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) {
354 //         Util::CoutSerializer se;
355 //         fbCmd.serialize( se );
356 //     }
357
358     if((fbCmd.getResponse() != AVCCommand::eR_Implemented)) {
359         debugWarning("fbCmd.getResponse() != AVCCommand::eR_Implemented\n");
360     }
361    
362     int16_t volume=(int16_t)(fbCmd.m_pFBFeature->m_pVolume->m_volume);
363    
364     return volume;
365 }
366
367 void
368 AvDevice::showDevice()
369 {
370     debugOutput(DEBUG_LEVEL_NORMAL, "Device is a BeBoB device\n");
371     GenericAVC::AvDevice::showDevice();
372     flushDebugOutput();
373 }
374
375 void
376 AvDevice::setVerboseLevel(int l)
377 {
378     if (m_Mixer) m_Mixer->setVerboseLevel( l );
379     GenericAVC::AvDevice::setVerboseLevel( l );
380     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
381 }
382
383 AVC::Subunit*
384 AvDevice::createSubunit(AVC::Unit& unit,
385                         AVC::ESubunitType type,
386                         AVC::subunit_t id )
387 {
388     AVC::Subunit* s=NULL;
389     switch (type) {
390         case eST_Audio:
391             s=new BeBoB::SubunitAudio(unit, id );
392             break;
393         case eST_Music:
394             s=new BeBoB::SubunitMusic(unit, id );
395             break;
396         default:
397             s=NULL;
398             break;
399     }
400     if(s) s->setVerboseLevel(getDebugLevel());
401     return s;
402 }
403
404
405 AVC::Plug *
406 AvDevice::createPlug( AVC::Unit* unit,
407                       AVC::Subunit* subunit,
408                       AVC::function_block_type_t functionBlockType,
409                       AVC::function_block_type_t functionBlockId,
410                       AVC::Plug::EPlugAddressType plugAddressType,
411                       AVC::Plug::EPlugDirection plugDirection,
412                       AVC::plug_id_t plugId,
413                       int globalId )
414 {
415
416     Plug *p= new BeBoB::Plug( unit,
417                               subunit,
418                               functionBlockType,
419                               functionBlockId,
420                               plugAddressType,
421                               plugDirection,
422                               plugId,
423                               globalId );
424     if (p) p->setVerboseLevel(getDebugLevel());
425     return p;
426 }
427
428 bool
429 AvDevice::propagatePlugInfo() {
430     // we don't have to propagate since we discover things
431     // another way
432     debugOutput(DEBUG_LEVEL_VERBOSE, "Skip plug info propagation\n");
433     return true;
434 }
435
436
437 uint8_t
438 AvDevice::getConfigurationIdSampleRate()
439 {
440     ExtendedStreamFormatCmd extStreamFormatCmd( get1394Service() );
441     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 );
442     extStreamFormatCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input,
443                                                     PlugAddress::ePAM_Unit,
444                                                     unitPlugAddress ) );
445
446     extStreamFormatCmd.setNodeId( getNodeId() );
447     extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status );
448     extStreamFormatCmd.setVerbose( getDebugLevel() );
449
450     if ( !extStreamFormatCmd.fire() ) {
451         debugError( "Stream format command failed\n" );
452         return false;
453     }
454
455     FormatInformation* formatInfo =
456         extStreamFormatCmd.getFormatInformation();
457     FormatInformationStreamsCompound* compoundStream
458         = dynamic_cast< FormatInformationStreamsCompound* > (
459             formatInfo->m_streams );
460     if ( compoundStream ) {
461         debugOutput(DEBUG_LEVEL_VERBOSE, "Sample rate 0x%02x\n",
462                     compoundStream->m_samplingFrequency );
463         return compoundStream->m_samplingFrequency;
464     }
465
466     debugError( "Could not retrieve sample rate\n" );
467     return 0;
468 }
469
470 uint8_t
471 AvDevice::getConfigurationIdNumberOfChannel( PlugAddress::EPlugDirection ePlugDirection )
472 {
473     ExtendedPlugInfoCmd extPlugInfoCmd( get1394Service() );
474     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR,
475                                      getNodeId() );
476     extPlugInfoCmd.setPlugAddress( PlugAddress( ePlugDirection,
477                                                 PlugAddress::ePAM_Unit,
478                                                 unitPlugAddress ) );
479     extPlugInfoCmd.setNodeId( getNodeId() );
480     extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status );
481     extPlugInfoCmd.setVerbose( getDebugLevel() );
482     ExtendedPlugInfoInfoType extendedPlugInfoInfoType(
483         ExtendedPlugInfoInfoType::eIT_NoOfChannels );
484     extendedPlugInfoInfoType.initialize();
485     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType );
486
487     if ( !extPlugInfoCmd.fire() ) {
488         debugError( "Number of channels command failed\n" );
489         return false;
490     }
491
492     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType();
493     if ( infoType
494          && infoType->m_plugNrOfChns )
495     {
496         debugOutput(DEBUG_LEVEL_VERBOSE, "Number of channels 0x%02x\n",
497                     infoType->m_plugNrOfChns->m_nrOfChannels );
498         return infoType->m_plugNrOfChns->m_nrOfChannels;
499     }
500
501     debugError( "Could not retrieve number of channels\n" );
502     return 0;
503 }
504
505 uint8_t
506 AvDevice::getConfigurationIdSyncMode()
507 {
508     SignalSourceCmd signalSourceCmd( get1394Service() );
509     SignalUnitAddress signalUnitAddr;
510     signalUnitAddr.m_plugId = 0x01;
511     signalSourceCmd.setSignalDestination( signalUnitAddr );
512     signalSourceCmd.setNodeId( getNodeId() );
513     signalSourceCmd.setSubunitType( eST_Unit  );
514     signalSourceCmd.setSubunitId( 0xff );
515     signalSourceCmd.setVerbose( getDebugLevel() );
516
517     signalSourceCmd.setCommandType( AVCCommand::eCT_Status );
518
519     if ( !signalSourceCmd.fire() ) {
520         debugError( "Signal source command failed\n" );
521         return false;
522     }
523
524     SignalAddress* pSyncPlugSignalAddress = signalSourceCmd.getSignalSource();
525     SignalSubunitAddress* pSyncPlugSubunitAddress
526         = dynamic_cast<SignalSubunitAddress*>( pSyncPlugSignalAddress );
527     if ( pSyncPlugSubunitAddress ) {
528         debugOutput(DEBUG_LEVEL_VERBOSE, "Sync mode 0x%02x\n",
529                     ( pSyncPlugSubunitAddress->m_subunitType << 3
530                       | pSyncPlugSubunitAddress->m_subunitId ) << 8
531                     | pSyncPlugSubunitAddress->m_plugId );
532
533         return ( pSyncPlugSubunitAddress->m_subunitType << 3
534                  | pSyncPlugSubunitAddress->m_subunitId ) << 8
535             | pSyncPlugSubunitAddress->m_plugId;
536     }
537
538     SignalUnitAddress* pSyncPlugUnitAddress
539       = dynamic_cast<SignalUnitAddress*>( pSyncPlugSignalAddress );
540     if ( pSyncPlugUnitAddress ) {
541         debugOutput(DEBUG_LEVEL_VERBOSE, "Sync mode 0x%02x\n",
542                       0xff << 8 | pSyncPlugUnitAddress->m_plugId );
543
544         return ( 0xff << 8 | pSyncPlugUnitAddress->m_plugId );
545     }
546
547     debugError( "Could not retrieve sync mode\n" );
548     return 0;
549 }
550
551 uint64_t
552 AvDevice::getConfigurationId()
553 {
554     // create a unique configuration id.
555     uint64_t id = 0;
556     id = getConfigurationIdSampleRate();
557     id |= ( getConfigurationIdNumberOfChannel( PlugAddress::ePD_Input )
558             + getConfigurationIdNumberOfChannel( PlugAddress::ePD_Output ) ) << 8;
559     id |= getConfigurationIdSyncMode() << 16;
560
561     return id;
562 }
563
564 bool
565 AvDevice::serialize( std::string basePath,
566                      Util::IOSerialize& ser ) const
567 {
568     bool result;
569     result  = GenericAVC::AvDevice::serialize( basePath, ser );
570     return result;
571 }
572
573 bool
574 AvDevice::deserialize( std::string basePath,
575                        Util::IODeserialize& deser )
576 {
577     bool result;
578     result  = GenericAVC::AvDevice::deserialize( basePath, deser );
579     return result;
580 }
581
582 std::string
583 AvDevice::getCachePath()
584 {
585     std::string cachePath;
586     char* pCachePath;
587
588     string path = CACHEDIR;
589     if ( path.size() && path[0] == '~' ) {
590         path.erase( 0, 1 ); // remove ~
591         path.insert( 0, getenv( "HOME" ) ); // prepend the home path
592     }
593
594     if ( asprintf( &pCachePath, "%s/cache/",  path.c_str() ) < 0 ) {
595         debugError( "Could not create path string for cache pool (trying '/var/cache/libffado' instead)\n" );
596         cachePath == "/var/cache/libffado/";
597     } else {
598         cachePath = pCachePath;
599         free( pCachePath );
600     }
601     return cachePath;
602 }
603
604 bool
605 AvDevice::loadFromCache()
606 {
607     std::string sDevicePath = getCachePath() + getConfigRom().getGuidString();
608
609     char* configId;
610     asprintf(&configId, "%016llx", getConfigurationId() );
611     if ( !configId ) {
612         debugError( "could not create id string\n" );
613         return false;
614     }
615
616     std::string sFileName = sDevicePath + "/" + configId + ".xml";
617     free( configId );
618     debugOutput( DEBUG_LEVEL_NORMAL, "filename %s\n", sFileName.c_str() );
619
620     struct stat buf;
621     if ( stat( sFileName.c_str(), &buf ) != 0 ) {
622         debugOutput( DEBUG_LEVEL_NORMAL,  "\"%s\" does not exist\n",  sFileName.c_str() );
623         return false;
624     } else {
625         if ( !S_ISREG( buf.st_mode ) ) {
626             debugOutput( DEBUG_LEVEL_NORMAL,  "\"%s\" is not a regular file\n",  sFileName.c_str() );
627             return false;
628         }
629     }
630
631     Util::XMLDeserialize deser( sFileName, getDebugLevel() );
632
633     if (!deser.isValid()) {
634         debugOutput( DEBUG_LEVEL_NORMAL, "cache not valid: %s\n",
635                      sFileName.c_str() );
636         return false;
637     }
638
639     bool result = deserialize( "", deser );
640     if ( result ) {
641         debugOutput( DEBUG_LEVEL_NORMAL, "could create valid bebob driver from %s\n",
642                      sFileName.c_str() );
643     }
644
645     if(result) {
646         buildMixer();
647     }
648
649     return result;
650 }
651
652 bool
653 AvDevice::saveCache()
654 {
655     // the path looks like this:
656     // PATH_TO_CACHE + GUID + CONFIGURATION_ID
657     string tmp_path = getCachePath() + getConfigRom().getGuidString();
658
659     // the following piece should do something like
660     // 'mkdir -p some/path/with/some/dirs/which/do/not/exist'
661     vector<string> tokens;
662     tokenize( tmp_path, tokens, "/" );
663     string path;
664     for ( vector<string>::const_iterator it = tokens.begin();
665           it != tokens.end();
666           ++it )
667     {
668         path +=  "/" + *it;
669
670         struct stat buf;
671         if ( stat( path.c_str(), &buf ) == 0 ) {
672             if ( !S_ISDIR( buf.st_mode ) ) {
673                 debugError( "\"%s\" is not a directory\n",  path.c_str() );
674                 return false;
675             }
676         } else {
677             if (  mkdir( path.c_str(), S_IRWXU | S_IRWXG ) != 0 ) {
678                 debugError( "Could not create \"%s\" directory\n", path.c_str() );
679                 return false;
680             }
681         }
682     }
683
684     // come up with an unique file name for the current settings
685     char* configId;
686     asprintf(&configId, "%016llx", BeBoB::AvDevice::getConfigurationId() );
687     if ( !configId ) {
688         debugError( "Could not create id string\n" );
689         return false;
690     }
691     string filename = path + "/" + configId + ".xml";
692     free( configId );
693     debugOutput( DEBUG_LEVEL_NORMAL, "filename %s\n", filename.c_str() );
694
695     Util::XMLSerialize ser( filename );
696     return serialize( "", ser );
697 }
698
699 } // end of namespace
Note: See TracBrowser for help on using the browser.