changed callbacks to use static_cast

This commit is contained in:
kennypm 2022-02-18 02:13:43 -05:00
parent bc8517fd08
commit c7b09eea11
2 changed files with 31 additions and 18 deletions

View File

@ -15,16 +15,20 @@ class JACK : public ALabel {
JACK(const std::string&, const Json::Value&); JACK(const std::string&, const Json::Value&);
~JACK() = default; ~JACK() = default;
auto update() -> void; auto update() -> void;
jack_nframes_t bufsize_;
jack_client_t* client_; int bufSize(unsigned int size);
unsigned int xruns_; int xrun();
std::string state_; void shutdown();
pthread_t jack_thread_;
private: private:
std::string JACKState(); std::string JACKState();
jack_client_t* client_;
jack_nframes_t bufsize_;
jack_nframes_t samplerate_; jack_nframes_t samplerate_;
unsigned int xruns_;
std::string state_;
pthread_t jack_thread_;
util::SleeperThread thread_; util::SleeperThread thread_;
}; };

View File

@ -105,23 +105,32 @@ auto waybar::modules::JACK::update() -> void {
ALabel::update(); ALabel::update();
} }
int bufSizeCallback(unsigned int size, void *obj) { int waybar::modules::JACK::bufSize(unsigned int size) {
waybar::modules::JACK* x = (waybar::modules::JACK*)obj; bufsize_ = size;
x->bufsize_ = size;
return size; return size;
} }
int xrunCallback(void *obj) { int waybar::modules::JACK::xrun() {
waybar::modules::JACK* x = (waybar::modules::JACK*)obj; xruns_ += 1;
x->xruns_ += 1; state_ = "xrun";
x->state_ = "xrun";
return 0; return 0;
} }
void shutdownCallback(void *obj) { void waybar::modules::JACK::shutdown() {
waybar::modules::JACK* x = (waybar::modules::JACK*)obj; pthread_cancel(jack_thread_);
pthread_cancel(x->jack_thread_); client_ = NULL;
x->client_ = NULL; state_ = "disconnected";
x->state_ = "disconnected"; xruns_ = 0;
x->xruns_ = 0; }
int bufSizeCallback(unsigned int size, void *obj) {
return static_cast<waybar::modules::JACK*>(obj)->bufSize(size);
}
int xrunCallback(void *obj) {
return static_cast<waybar::modules::JACK*>(obj)->xrun();
}
void shutdownCallback(void *obj) {
return static_cast<waybar::modules::JACK*>(obj)->shutdown();
} }