save config

This commit is contained in:
badaix 2015-09-03 23:02:30 +02:00
parent 8a684233a2
commit 9200fec700
4 changed files with 24 additions and 1 deletions

View file

@ -17,16 +17,34 @@
***/ ***/
#include "config.h" #include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fstream> #include <fstream>
using namespace std; using namespace std;
Config::Config() Config::Config()
{ {
string dir = getenv("HOME") + string("/.config/SnapCast/");
mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
filename_ = dir + "settings.json";
cerr << filename_ << "\n";
// fs::create_directory(filename_.parent_path());
} }
void Config::save()
{
std::ofstream ofs(filename_.c_str(), std::ofstream::out|std::ofstream::trunc);
json clients = {
{"Client", getClientInfos()}
};
ofs << std::setw(4) << clients;
ofs.close();
}
void Config::test() void Config::test()
{ {

View file

@ -139,8 +139,11 @@ public:
std::vector<ClientInfoPtr> clients; std::vector<ClientInfoPtr> clients;
json getClientInfos() const; json getClientInfos() const;
void save();
private: private:
Config(); Config();
std::string filename_;
}; };

View file

@ -105,6 +105,7 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
Config::instance();
std::clog.rdbuf(new Log("snapserver", LOG_DAEMON)); std::clog.rdbuf(new Log("snapserver", LOG_DAEMON));
signal(SIGHUP, signal_handler); signal(SIGHUP, signal_handler);

View file

@ -152,6 +152,7 @@ void StreamServer::onMessageReceived(ServerSession* connection, const msg::BaseM
client->version = helloMsg.getVersion(); client->version = helloMsg.getVersion();
client->connected = true; client->connected = true;
gettimeofday(&client->lastSeen, NULL); gettimeofday(&client->lastSeen, NULL);
Config::instance().save();
json notification = JsonNotification::getJson("Client.OnConnect", client->toJson()); json notification = JsonNotification::getJson("Client.OnConnect", client->toJson());
controlServer->send(notification.dump(4)); controlServer->send(notification.dump(4));