diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..3fd79c37 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +.PHONY: client server + +all: client server + +server: + $(MAKE) -C server + +client: + $(MAKE) -C client + +clean: + $(MAKE) clean -C client + $(MAKE) clean -C server + rm *~ + + diff --git a/Snap.workspace b/Snap.workspace deleted file mode 100644 index aef105ff..00000000 --- a/Snap.workspace +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/Snap.workspace.layout b/Snap.workspace.layout deleted file mode 100644 index a73b9f3e..00000000 --- a/Snap.workspace.layout +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/SnapClient.cbp b/SnapClient.cbp deleted file mode 100644 index 4f7da6e0..00000000 --- a/SnapClient.cbp +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - diff --git a/SnapClient.layout b/SnapClient.layout deleted file mode 100644 index 5093c06c..00000000 --- a/SnapClient.layout +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SnapServer.cbp b/SnapServer.cbp deleted file mode 100644 index 07465f69..00000000 --- a/SnapServer.cbp +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - diff --git a/SnapServer.layout b/SnapServer.layout deleted file mode 100644 index 91a3282d..00000000 --- a/SnapServer.layout +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/client/alsaPlayer.cpp b/client/alsaPlayer.cpp index 13c9fc73..2678861a 100644 --- a/client/alsaPlayer.cpp +++ b/client/alsaPlayer.cpp @@ -109,6 +109,7 @@ void Player::start() // snd_pcm_sw_params_set_stop_threshold(pcm_handle, swparams, frames); snd_pcm_sw_params(pcm_handle, swparams); + active_ = true; playerThread = new thread(&Player::worker, this); } @@ -147,7 +148,7 @@ void Player::worker() { unsigned int pcm; snd_pcm_sframes_t framesAvail; snd_pcm_sframes_t framesDelay; - active_ = true; +// active_ = true; while (active_) { snd_pcm_avail_delay(pcm_handle, &framesAvail, &framesDelay); diff --git a/client/controller.cpp b/client/controller.cpp index 416e2afe..e1f4517d 100644 --- a/client/controller.cpp +++ b/client/controller.cpp @@ -132,6 +132,7 @@ void Controller::worker() double latency = (reply->received.sec - reply->sent.sec) + (reply->received.usec - reply->sent.usec) / 1000000.; TimeProvider::getInstance().setDiffToServer((reply->latency - latency) * 1000 / 2); } +//throw std::exception(); } } catch (const std::exception& e) diff --git a/client/snapClient.cpp b/client/snapClient.cpp index 54207275..ed97574d 100644 --- a/client/snapClient.cpp +++ b/client/snapClient.cpp @@ -98,6 +98,11 @@ int main (int argc, char *argv[]) daemonize(); std::clog << kLogNotice << "daemon started" << std::endl; } + logS(kLogNotice) << "daemon started" << std::endl; + logD << "debug test" << std::endl; + logO << "out test" << std::endl; + logE << "error test" << std::endl; + log << "test" << std::endl; PcmDevice pcmDevice = getPcmDevice(soundcard); if (pcmDevice.idx == -1) diff --git a/common/log.cpp b/common/log.cpp index 5d17078d..307575ba 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -1,4 +1,6 @@ #include "log.h" +#include +#include Log::Log(std::string ident, int facility) { @@ -10,20 +12,49 @@ Log::Log(std::string ident, int facility) openlog(ident_, LOG_PID, facility_); } + +std::string Log::LogPriorityToString(const LogPriority& priority) +{ + switch(priority) + { + case kLog: return "dbg"; + case kOut: return "out"; + case kErr: return "err"; + default: return std::to_string((int)priority); + } + return std::to_string((int)priority); +} + + +std::string Log::Timestamp() +{ + struct tm * dt; + char buffer [30]; + std::time_t t = std::time(nullptr); + dt = localtime(&t); + strftime(buffer, sizeof(buffer), "%Y-%m-%d %H-%M-%S", dt); + return std::string(buffer); +} + + int Log::sync() { if (buffer_.length()) { - if (priority_ == dbg) - std::cout << buffer_.c_str(); - else +// if (priority_ == kLog) +// std::cout << Timestamp() << " [" << LogPriorityToString(priority_) << "] " << buffer_.c_str(); +// else + { + std::cout << Timestamp() << " [" << LogPriorityToString((LogPriority)priority_) << "] " << buffer_.c_str(); syslog(priority_, "%s", buffer_.c_str()); + } buffer_.erase(); priority_ = LOG_DEBUG; // default to debug for each message } return 0; } + int Log::overflow(int c) { if (c != EOF) @@ -40,8 +71,8 @@ int Log::overflow(int c) std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority) { static_cast(os.rdbuf())->priority_ = (int)log_priority; - if (log_priority == dbg) - os.flush(); +// if (log_priority == dbg) +// os.flush(); return os; } diff --git a/common/log.h b/common/log.h index 48501bcb..4bb8b865 100644 --- a/common/log.h +++ b/common/log.h @@ -5,7 +5,11 @@ #include #include -#define logd std::clog << dbg +#define logD std::clog << kLog +#define logO std::clog << kOut +#define logE std::clog << kErr +#define logS(P) std::clog << P +#define log logO enum LogPriority { @@ -16,8 +20,8 @@ enum LogPriority kLogWarning = LOG_WARNING, // warning conditions kLogNotice = LOG_NOTICE, // normal, but significant, condition kLogInfo = LOG_INFO, // informational message - kLogDebug = LOG_DEBUG, // debug-level message - dbg + kLogDebug = LOG_DEBUG, // debug-level message + kLog, kOut, kErr }; std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority); @@ -33,6 +37,8 @@ protected: private: friend std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority); + std::string Timestamp(); + std::string LogPriorityToString(const LogPriority& priority); std::string buffer_; int facility_; int priority_;