From 81f46ff41ff53d15c2a4b0bd2e4aed4189e6e67d Mon Sep 17 00:00:00 2001 From: badaix Date: Thu, 8 Jun 2017 00:04:09 +0200 Subject: [PATCH] configurable client ID --- client/controller.cpp | 21 ++++++++++++--------- client/controller.h | 3 ++- client/snapClient.cpp | 4 +++- common/utils.h | 5 +++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/client/controller.cpp b/client/controller.cpp index d65342c6..68ad2116 100644 --- a/client/controller.cpp +++ b/client/controller.cpp @@ -34,14 +34,15 @@ using namespace std; -Controller::Controller(size_t instance) : MessageReceiver(), - instance_(instance), - active_(false), - latency_(0), - stream_(nullptr), - decoder_(nullptr), - player_(nullptr), - serverSettings_(nullptr), +Controller::Controller(const std::string& clientId, size_t instance) : MessageReceiver(), + clientId_(clientId), + instance_(instance), + active_(false), + latency_(0), + stream_(nullptr), + decoder_(nullptr), + player_(nullptr), + serverSettings_(nullptr), asyncException_(false) { } @@ -184,7 +185,9 @@ void Controller::worker() /// Say hello to the server string macAddress = clientConnection_->getMacAddress(); - msg::Hello hello(macAddress, ::getHostId(macAddress), instance_); + if (clientId_.empty()) + clientId_ = ::getHostId(macAddress); + msg::Hello hello(macAddress, clientId_, instance_); clientConnection_->send(&hello); /// Do initial time sync with the server diff --git a/client/controller.h b/client/controller.h index d3fed9e5..8a0ace08 100644 --- a/client/controller.h +++ b/client/controller.h @@ -46,7 +46,7 @@ class Controller : public MessageReceiver { public: - Controller(size_t instance); + Controller(const std::string& clientId, size_t instance); void start(const PcmDevice& pcmDevice, const std::string& host, size_t port, int latency); void stop(); @@ -61,6 +61,7 @@ public: private: void worker(); bool sendTimeSyncMessage(long after = 1000); + std::string clientId_; size_t instance_; std::atomic active_; std::thread controllerThread_; diff --git a/client/snapClient.cpp b/client/snapClient.cpp index a567bfa0..1b630bdb 100644 --- a/client/snapClient.cpp +++ b/client/snapClient.cpp @@ -89,6 +89,7 @@ int main (int argc, char **argv) Implicit daemonOption("d", "daemon", "daemonize, optional process priority [-20..19]", -3, &processPriority); Value latencyValue("", "latency", "latency of the soundcard", 0, &latency); Value instanceValue("i", "instance", "instance id", 1, &instance); + Value clientIdValue("", "clientID", "unique client id", ""); Value userValue("", "user", "the user[:group] to run snapclient as when daemonized"); OptionParser op("Allowed options"); @@ -105,6 +106,7 @@ int main (int argc, char **argv) .add(userValue) #endif .add(latencyValue) + .add(clientIdValue) .add(instanceValue); try @@ -222,7 +224,7 @@ int main (int argc, char **argv) #endif } - std::unique_ptr controller(new Controller(instance)); + std::unique_ptr controller(new Controller(clientIdValue.getValue(), instance)); if (!g_terminated) { logO << "Latency: " << latency << "\n"; diff --git a/common/utils.h b/common/utils.h index 0cda89b5..f4ed774c 100644 --- a/common/utils.h +++ b/common/utils.h @@ -325,7 +325,12 @@ static std::string getHostId(const std::string defaultId = "") CFRelease(uuidCf); #elif ANDROID result = getProp("ro.serialno"); +#else + std::ifstream infile("/var/lib/dbus/machine-id"); + if (infile.good()) + std::getline(infile, result); #endif + strutils::trim(result); if (!result.empty()) return result;