| # arts Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kartsserver.cpp

    00001 // Copyright (c) 2000-2001 Charles Samuels <charles@kde.org>
    00002 //                         Neil Stevens <neil@qualityassistant.com>
    00003 //
    00004 // Permission is hereby granted, free of charge, to any person obtaining a copy
    00005 // of this software and associated documentation files (the "Software"), to deal
    00006 // in the Software without restriction, including without limitation the rights
    00007 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00008 // copies of the Software, and to permit persons to whom the Software is
    00009 // furnished to do so, subject to the following conditions:
    00010 //
    00011 // The above copyright notice and this permission notice shall be included in
    00012 // all copies or substantial portions of the Software.
    00013 //
    00014 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00015 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00016 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    00017 // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIAB\ILITY, WHETHER IN
    00018 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    00019 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00020
    00021 #include <flowsystem.h>
    00022 #include <ksimpleconfig.h>
    00023 #include <kprocess.h>
    00024 #include <kstandarddirs.h>
    00025 #include <qdir.h>
    00026 #include <qfile.h>
    00027 #include "kartsserver.h"
    00028
    00029 struct KArtsServer::Data
    00030 {
    00031     Arts::SoundServerV2 server;
    00032 };
    00033
    00034 KArtsServer::KArtsServer(QObject *parent, const char *name)
    00035     : QObject(parent, name)
    00036     , d(new Data)
    00037 {
    00038     d->server = Arts::SoundServerV2::null();
    00039 }
    00040
    00041 KArtsServer::~KArtsServer(void)
    00042 {
    00043     d->server = Arts::SoundServerV2::null();
    00044     delete d;
    00045 }
    00046
    00047 Arts::SoundServerV2 KArtsServer::server(void)
    00048 {
    00049     bool error = d->server.error();
    00050     if( d->server.isNull() || error )
    00051     {
    00052         d->server = Arts::Reference("global:Arts_SoundServerV2");
    00053         if( error && !d->server.isNull() && !d->server.error() )
    00054             emit restartedServer();
    00055     }
    00056
    00057     if(!d->server.isNull() && !d->server.error())
    00058         return d->server;
    00059
    00060     // aRts seems not to be running, let's try to run it
    00061     // First, let's read the configuration as in kcmarts
    00062     KConfig config("kcmartsrc", false /*bReadOnly*/, false /*bUseKDEGlobals*/);
    00063     KProcess proc;
    00064
    00065     config.setGroup("Arts");
    00066
    00067     bool rt = config.readBoolEntry("StartRealtime", false);
    00068     bool x11Comm = config.readBoolEntry("X11GlobalComm", false);
    00069
    00070     // put the value of x11Comm into .mcoprc
    00071     KSimpleConfig X11CommConfig(QDir::homeDirPath()+"/.mcoprc");
    00072
    00073     if(x11Comm)
    00074         X11CommConfig.writeEntry("GlobalComm", "Arts::X11GlobalComm");
    00075     else
    00076         X11CommConfig.writeEntry("GlobalComm", "Arts::TmpGlobalComm");
    00077
    00078     X11CommConfig.sync();
    00079
    00080     proc << QFile::encodeName(KStandardDirs::findExe(QString::fromLatin1("kdeinit_wrapper")));
    00081
    00082     if(rt)
    00083         proc << QFile::encodeName(KStandardDirs::findExe(QString::fromLatin1("artswrapper")));
    00084     else
    00085         proc << QFile::encodeName(KStandardDirs::findExe(QString::fromLatin1("artsd")));
    00086
    00087     proc << QStringList::split( " ", config.readEntry( "Arguments", "-F 10 -S 4096 -s 60 -m artsmessage -l 3 -f" ) );
    00088
    00089     if(proc.start(KProcess::Block) && proc.normalExit())
    00090     {
    00091         // We could have a race-condition here.
    00092         // The correct way to do it is to make artsd fork-and-exit
    00093         // after starting to listen to connections (and running artsd
    00094         // directly instead of using kdeinit), but this is better
    00095         // than nothing.
    00096         int time = 0;
    00097         do
    00098         {
    00099             sleep(1);
    00100             d->server = Arts::Reference("global:Arts_SoundServerV2");
    00101         } while(++time < 5 && (d->server.isNull()));
    00102
    00103         emit restartedServer();
    00104     }
    00105     // TODO else what?
    00106
    00107     return d->server;
    00108 }
    00109
    00110 // vim: sw=4 ts=4 noet
    00111 #include "kartsserver.moc"

This file is part of the documentation for arts Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:27:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003