Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

one config file per plugin

  • Loading branch information...
commit 35acca6155c001d9809888ac876a75682ff8f9de 1 parent 1d55e91
@RJ authored
View
3  includes/playdar/auth.h
@@ -44,7 +44,8 @@ class auth
private:
void check_db();
void create_db_schema();
-
+
+ std::string m_dbfilepath;
std::set<std::string> m_formtokens;
sqlite3pp::database m_db;
boost::mutex m_mut;
View
11 includes/playdar/config.hpp
@@ -30,6 +30,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
+#include "boost/filesystem.hpp"
#define DEFAULT_HTTP_PORT 60210
@@ -37,14 +38,24 @@ namespace playdar {
// wrapper around JSON config file
// instance of this is also passed to plugins.
+
class Config
{
public:
+ Config(){}
+
Config(const std::string& f) : m_filename(f)
{
reload();
}
+ // gets directory where config files are located
+ std::string config_dir() const
+ {
+ boost::filesystem::path p(m_filename);
+ return p.parent_path().string();
+ }
+
void reload()
{
std::fstream ifs;
View
29 includes/playdar/pluginadaptor_impl.hpp
@@ -19,18 +19,8 @@
#ifndef _PLUGIN_ADAPTOR_IMPL_H_
#define _PLUGIN_ADAPTOR_IMPL_H_
-//// must be first because ossp uuid.h is stubborn and name-conflicts with
-//// the uuid_t in unistd.h. It gets round this with preprocessor magic. But
-//// this causes PAIN and HEARTACHE for everyone else in the world, so well done
-//// to you guys at OSSP. *claps*
-//#ifdef HAS_OSSP_UUID_H
-//#include <ossp/uuid.h>
-//#else
-//// default source package for ossp-uuid doesn't namespace itself
-//#include <uuid.h>
-//#endif
-
#include <boost/shared_ptr.hpp>
+#include <boost/filesystem.hpp>
#include <vector>
#include <string>
@@ -45,10 +35,23 @@ class PluginAdaptorImpl : public PluginAdaptor
{
public:
PluginAdaptorImpl(Config * c, Resolver * r, const std::string& className)
- : m_config(c),
- m_resolver(r),
+ : m_resolver(r),
m_className( className )
{
+ boost::filesystem::path p(c->config_dir());
+ std::string confname(className);
+ confname+=".conf";
+ p /= confname;
+ if( boost::filesystem::exists( p ) )
+ {
+ m_config = new Config( p.string() );
+ std::cout << "Using plugin config file: "<< p.string() << std::endl;
+ }
+ else
+ {
+ std::cout << "Using default config for " << className << std::endl;
+ m_config = new Config();
+ }
}
virtual std::string playdar_version() const
View
6 resolvers/boffin/boffin.cpp
@@ -130,7 +130,7 @@ boffin::init( pa_ptr pap )
m_thread = new boost::thread( boost::bind(&boffin::thread_run, this) );
std::string playdarDb = pap->get<string>( "db", "collection.db" );
- std::string boffinDb = pap->get<string>( "plugins.boffin.db", "boffin.db" );
+ std::string boffinDb = pap->get<string>( "db", "boffin.db" );
m_db = boost::shared_ptr<BoffinDb>( new BoffinDb(boffinDb, playdarDb) );
m_sa = boost::shared_ptr<SimilarArtists>( new SimilarArtists() );
@@ -297,7 +297,7 @@ boffin::resolve(boost::shared_ptr<ResolverQuery> rq)
"SELECT name, sum(weight), count(weight), sum(pd.file.duration) "
"FROM track_tag "
"INNER JOIN tag ON track_tag.tag = tag.rowid "
- "INNER JOIN pd.file_join ON track_tag.track = pd.file_join.track "
+ "INNER JOIN pd.file_join ON track_tag.track = pd.file_join.track "
"INNER JOIN pd.file ON pd.file_join.file = pd.file.id "
"WHERE track_tag.track IN ",
"GROUP BY tag.rowid",
@@ -338,7 +338,7 @@ boffin::resolve(boost::shared_ptr<ResolverQuery> rq)
bool ok = RqlDbProcessor::parseAndProcess(
rql,
"SELECT count(pd.file.duration), sum(pd.file.duration) "
- "FROM pd.file_join "
+ "FROM pd.file_join "
"INNER JOIN pd.file ON pd.file_join.file = pd.file.id "
"WHERE pd.file_join.track IN ",
"",
View
10 resolvers/lan/lan.cpp
@@ -78,7 +78,7 @@ lan::~lan() throw()
void
lan::setup_endpoints()
{
- Value endpoints = m_pap->get_json("plugins.lan.endpoints");
+ Value endpoints = m_pap->get_json("endpoints");
if( endpoints == Value::null || endpoints.type() != array_type )
{
// nothing specified, default is just the multicast address:
@@ -159,8 +159,8 @@ lan::run()
start_listening(*m_io_service,
boost::asio::ip::address::from_string("0.0.0.0"),
boost::asio::ip::address::from_string
- ( m_pap->get<string>("plugins.lan.listenip", DEFAULT_LAN_ENDPOINT) ),
- m_pap->get<int>("plugins.lan.listenport", DEFAULT_LAN_PORT) );
+ ( m_pap->get<string>("listenip", DEFAULT_LAN_ENDPOINT) ),
+ m_pap->get<int>("listenport", DEFAULT_LAN_PORT) );
cout << "LAN Resolver is online udp://"
<< socket_->local_endpoint().address() << ":"
@@ -209,7 +209,7 @@ lan::async_send( const string& message )
/// send to specific endpoints:
void
lan::async_send(boost::asio::ip::udp::endpoint * remote_endpoint,
- const string& message)
+ const string& message)
{
if(message.length()>max_length)
{
@@ -221,7 +221,7 @@ lan::async_send(boost::asio::ip::udp::endpoint * remote_endpoint,
// << "(" << message << ")" << endl;
// you can set numcopies to 2 or 3 for lossy networks:
- int copies = m_pap->get<int>("plugins.lan.numcopies", 1);
+ int copies = m_pap->get<int>("numcopies", 1);
if(copies<1) copies=1;
for(int j = 0; j<copies; j++)
{
View
4 resolvers/local/rs_local_library.cpp
@@ -41,8 +41,8 @@ bool
local::init(pa_ptr pap)
{
m_pap = pap;
-
- m_library = new Library( pap->getstring( "db", "" ).get_str());
+ string default_db_path = "collection.db";
+ m_library = new Library( m_pap->getstring( "database", default_db_path ).get_str());
m_exiting = false;
cout << "Local library resolver: " << m_library->num_files()
View
83 src/main.cpp
@@ -54,46 +54,8 @@ ostream& operator<<(ostream& os, const vector<T>& v)
return os;
}
-
-string default_config_path()
-{
- using boost::filesystem::path;
-
-#if __APPLE__
- if(getenv("HOME"))
- {
- path home = getenv("HOME");
- return (home/"Library/Preferences/org.playdar.json").string();
- }
- else
- {
- cerr << "Error, $HOME not set." << endl;
- throw;
- }
-#elif _WIN32
- return ""; //TODO refer to Qt documentation to get code to do this
-#else
- string p;
- if(getenv("XDG_CONFIG_HOME"))
- {
- p = getenv("XDG_CONFIG_HOME");
- }
- else if(getenv("HOME"))
- {
- p = string(getenv("HOME")) + "/.config";
- }
- else
- {
- cerr << "Error, $HOME or $XDG_CONFIG_HOME not set." << endl;
- throw;
- }
- path config_base = p;
- return (config_base/"playdar/playdar.conf").string();
-#endif
-}
-
-/// finds full path to config file, checks default locations etc
-string find_config_file()
+/// finds config dir, checks default locations etc
+string find_config_dir()
{
using boost::filesystem::path;
@@ -101,7 +63,7 @@ string find_config_file()
if(getenv("HOME"))
{
path home = getenv("HOME");
- return (home/"Library/Preferences/org.playdar.json").string();
+ return (home/"Library/Preferences/playdar").string();
}
else
{
@@ -126,11 +88,11 @@ string find_config_file()
throw;
}
path config_base = p;
- string confpath = (config_base/"playdar/playdar.conf").string();
+ string confpath = (config_base/"playdar").string();
if( boost::filesystem::exists(confpath) )
return confpath;
- if( boost::filesystem::exists("/etc/playdar/playdar.conf") )
- return "/etc/playdar/playdar.conf";
+ if( boost::filesystem::exists("/etc/playdar") )
+ return "/etc/playdar";
// fail
return "";
#endif
@@ -138,6 +100,7 @@ string find_config_file()
void start_http_server(string ip, int port, int conc, MyApplication* app)
{
+ if(conc<1) conc=1;
cout << "HTTP server starting on: http://" << ip << ":" << port << "/" << " with " << conc << " threads" << endl;
moost::http::server<playdar_request_handler> s(ip, port, conc);
s.request_handler().init(app);
@@ -185,8 +148,8 @@ int main(int ac, char *av[])
{
po::options_description generic("Generic options");
generic.add_options()
- ("config,c", po::value<string>(), "use specified config file")
- ("version,v", "print version string")
+ ("config,c", po::value<string>(), "use specified config directory")
+ ("version,v", "print version information")
("help,h", "print this message")
;
po::options_description cmdline_options;
@@ -219,16 +182,23 @@ int main(int ac, char *av[])
return 0;
}
- string configfile;
+ string configdir, configfile;
+
if( vm.count("config") )
{
- configfile = vm["config"].as<string>();
+ configdir = vm["config"].as<string>();
}else{
- configfile = find_config_file();
+ configdir = find_config_dir();
+ }
+ if( !boost::filesystem::is_directory( configdir ) )
+ {
+ cerr << "config directory not found: " << configdir << endl;
+ return -5;
}
+ configfile = configdir += "/playdar.conf";
if( !boost::filesystem::exists(configfile) )
{
- cerr << "Config file not found" << endl;
+ cerr << "Config file not found: " << configfile << endl;
return 1;
}
@@ -238,20 +208,17 @@ int main(int ac, char *av[])
Config conf(configfile);
if(conf.get<string>("name", "YOURNAMEHERE")=="YOURNAMEHERE")
{
- cerr << "Please edit " << configfile << endl;
- cerr << "YOURNAMEHERE is not a valid name." << endl;
- cerr << "Autodetecting name: " << conf.name() << endl;
+ cout << "Autodetecting name: " << conf.name() << endl;
}
#ifndef WIN32
- /// this might not compile on windows?
+ //TODO we need a shutdown/signal handler for windows too.
struct sigaction setmask;
sigemptyset( &setmask.sa_mask );
setmask.sa_handler = sigfunc;
setmask.sa_flags = 0;
- sigaction( SIGHUP, &setmask, (struct sigaction *) NULL );
+ sigaction( SIGHUP, &setmask, (struct sigaction *) NULL );
sigaction( SIGINT, &setmask, (struct sigaction *) NULL );
- /// probably need to look for WM_BLAHWTFMSG or something.
#endif
try
@@ -270,8 +237,8 @@ int main(int ac, char *av[])
string ip = "0.0.0.0";
boost::thread http_thread(
boost::bind( &start_http_server,
- ip, app->conf()->get<int>("http_port", 0),
- boost::thread::hardware_concurrency()+1,
+ ip, app->conf()->get<int>("http_port", 60210),
+ app->conf()->get<int>("http_threads", boost::thread::hardware_concurrency()+1),
app )
);
Please sign in to comment.
Something went wrong with that request. Please try again.