#pragma once #include #include #include #include #include "log.h" const inline char *argp_program_version = "PipwireAudioWatcher"; const inline char *argp_program_bug_address = ""; static char doc[] = "Application Monitors a Pipewire sink for activity and reports it"; static char args_doc[] = ""; static struct argp_option options[] = { {"verbose", 'v', 0, 0, "Show debug messages" }, {"quiet", 'q', 0, 0, "only output data" }, {"sink name", 'n', "[NAME]", 0, "Name of the sink to connect to" }, {"use-active", 'a', 0, 0, "Use active state instead of samples to determine if sink is active" }, {"host", 'h', "[HOST]", 0, "host to send events to" }, {"port", 'p', "[PORT]", 0, "port to send events to" }, {"id", 'i', "[ID]", 0, "the id the sensor associated with the sink should have" }, {"timeout", 't', "[SECONDS]", 0, "the lenght of time that has to pass with no sounds for the stream to be determined inactive" }, { 0 } }; struct Config { std::string sink_name; bool use_active = false; std::string host = "localhost"; unsigned short port = 6856; uint8_t id = 0; unsigned int timeout = 60; }; static error_t parse_opt (int key, char *arg, struct argp_state *state) { Config *config = reinterpret_cast(state->input); switch (key) { case 'q': Log::level = Log::ERROR; break; case 'v': Log::level = Log::DEBUG; break; case 'n': config->sink_name.assign(arg); break; case 'a': config->use_active = true; break; case 'h': config->host.assign(arg); break; case 'p': config->port = atoi(arg); break; case 'i': config->id = strtoul(arg, NULL, 0); break; default: return ARGP_ERR_UNKNOWN; } return 0; } static inline struct argp argp = {options, parse_opt, args_doc, doc};