From 09321dd320f2e7b7a6a8fa22086585d78b7e96b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?= <rafael.carre@savoirfairelinux.com> Date: Wed, 27 Jul 2011 09:41:21 -0400 Subject: [PATCH] * #6507 : find codecs dir in build directory No need to set CODECS_PATH when running the daemon from build directory anymore --- sflphone-common/src/Makefile.am | 6 ++- .../src/audio/codecs/audiocodecfactory.cpp | 3 ++ sflphone-common/src/fileutils.cpp | 43 +++++++++++++++++++ sflphone-common/src/fileutils.h | 37 ++++++++++++++++ sflphone-common/src/main.cpp | 3 ++ sflphone-common/test/run_daemon.sh | 2 - 6 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 sflphone-common/src/fileutils.cpp create mode 100644 sflphone-common/src/fileutils.h delete mode 100755 sflphone-common/test/run_daemon.sh diff --git a/sflphone-common/src/Makefile.am b/sflphone-common/src/Makefile.am index adc562ece4..3b2eef2031 100644 --- a/sflphone-common/src/Makefile.am +++ b/sflphone-common/src/Makefile.am @@ -20,7 +20,8 @@ sflphoned_SOURCES = \ call.cpp \ account.cpp \ logger.cpp \ - numbercleaner.cpp + numbercleaner.cpp \ + fileutils.cpp # Redefine the USE_IAX variable here, so that it could be used in managerimpl if USE_IAX @@ -58,7 +59,8 @@ noinst_HEADERS = \ accountcreator.h \ call.h \ logger.h \ - numbercleaner.h + numbercleaner.h \ + fileutils.h libsflphone_la_LIBADD = \ $(src)/libs/utilspp/libutilspp.la \ diff --git a/sflphone-common/src/audio/codecs/audiocodecfactory.cpp b/sflphone-common/src/audio/codecs/audiocodecfactory.cpp index 51d73e2cbc..a38c3535ad 100644 --- a/sflphone-common/src/audio/codecs/audiocodecfactory.cpp +++ b/sflphone-common/src/audio/codecs/audiocodecfactory.cpp @@ -35,6 +35,7 @@ #include <cstdlib> #include "audiocodecfactory.h" +#include "fileutils.h" AudioCodecFactory::AudioCodecFactory() : _CodecsMap(), _defaultCodecOrder(), _Cache(), _nbCodecs(), _CodecInMemory() @@ -192,11 +193,13 @@ std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory (void) std::string libDir = std::string (CODECS_DIR).append ("/"); std::string homeDir = std::string (HOMEDIR) + DIR_SEPARATOR_STR + "." + PROGDIR + "/"; + std::string srcDir = std::string(get_program_dir()) + DIR_SEPARATOR_STR + "audio/codecs/"; // look for a CODECS_PATH environment variable...used in tests const char *envDir = getenv("CODECS_PATH"); std::vector<std::string> dirToScan; dirToScan.push_back (homeDir); dirToScan.push_back (libDir); + dirToScan.push_back (srcDir); if (envDir) dirToScan.push_back(std::string(envDir) + DIR_SEPARATOR_STR); diff --git a/sflphone-common/src/fileutils.cpp b/sflphone-common/src/fileutils.cpp new file mode 100644 index 0000000000..1aae61bb13 --- /dev/null +++ b/sflphone-common/src/fileutils.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011 Savoir-Faire Linux Inc. + * Author: Rafaël Carré <rafael.carre@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +#include <libgen.h> + +static char *program_dir; + +void set_program_dir(char *program_path) +{ + program_dir = dirname(program_path); +} + +const char *get_program_dir(void) +{ + return program_dir; +} diff --git a/sflphone-common/src/fileutils.h b/sflphone-common/src/fileutils.h new file mode 100644 index 0000000000..364e80a233 --- /dev/null +++ b/sflphone-common/src/fileutils.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2011 Savoir-Faire Linux Inc. + * Author: Rafaël Carré <rafael.carre@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +#ifndef __FILEUTILS_H__ +#define __FILEUTILS_H__ + +void set_program_dir(char *program_path); +const char *get_program_dir(void); + +#endif // __FILEUTILS_H__ diff --git a/sflphone-common/src/main.cpp b/sflphone-common/src/main.cpp index ff8fa6261c..414ca35586 100644 --- a/sflphone-common/src/main.cpp +++ b/sflphone-common/src/main.cpp @@ -39,6 +39,7 @@ #include <sys/stat.h> #include <cc++/common.h> #include "global.h" +#include "fileutils.h" #include "dbus/dbusmanager.h" #include "manager.h" @@ -66,6 +67,8 @@ CommandOptionNoArg help ( int main (int argc, char **argv) { + set_program_dir(argv[0]); + int exit_code = 0; Logger::setConsoleLog (false); diff --git a/sflphone-common/test/run_daemon.sh b/sflphone-common/test/run_daemon.sh deleted file mode 100755 index bf350c0b16..0000000000 --- a/sflphone-common/test/run_daemon.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -CODECS_PATH="../src/audio/codecs" ../src/sflphoned -d -c -- GitLab