switched to popl

This commit is contained in:
badaix 2015-12-11 08:35:57 +01:00
parent 95f88267ad
commit 5da2308ed4
3 changed files with 58 additions and 80 deletions

View file

@ -3,7 +3,7 @@ TARGET = snapclient
SHELL = /bin/bash SHELL = /bin/bash
CXX = /usr/bin/g++ CXX = /usr/bin/g++
CFLAGS = -std=c++0x -Wall -Wno-unused-function -O3 -pthread -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include CFLAGS = -std=c++0x -Wall -Wno-unused-function -O3 -pthread -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I.. -I../externals/asio/asio/include -I../externals/popl/include
LDFLAGS = -lrt -lasound -logg -lvorbis -lvorbisenc -lFLAC -lavahi-client -lavahi-common LDFLAGS = -lrt -lasound -logg -lvorbis -lvorbisenc -lFLAC -lavahi-client -lavahi-common
OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o player/alsaPlayer.o decoder/oggDecoder.o decoder/pcmDecoder.o decoder/flacDecoder.o controller.o browseAvahi.o ../message/pcmChunk.o ../common/log.o ../message/sampleFormat.o OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o player/alsaPlayer.o decoder/oggDecoder.o decoder/pcmDecoder.o decoder/flacDecoder.o controller.o browseAvahi.o ../message/pcmChunk.o ../common/log.o ../message/sampleFormat.o

View file

@ -18,8 +18,8 @@
#include <iostream> #include <iostream>
#include <sys/resource.h> #include <sys/resource.h>
#include <getopt.h>
#include "popl.hpp"
#include "controller.h" #include "controller.h"
#include "player/alsaPlayer.h" #include "player/alsaPlayer.h"
#include "browseAvahi.h" #include "browseAvahi.h"
@ -29,6 +29,7 @@
using namespace std; using namespace std;
using namespace popl;
bool g_terminated = false; bool g_terminated = false;
@ -65,37 +66,40 @@ int main (int argc, char **argv)
string host(""); string host("");
size_t port(1704); size_t port(1704);
size_t latency(0); size_t latency(0);
bool runAsDaemon(false);
int processPriority(-3); int processPriority(-3);
while (1) Switch helpSwitch("", "help", "produce help message");
{ Switch versionSwitch("v", "version", "show version number");
int option_index = 0; Switch listSwitch("l", "list", "list pcm devices");
static struct option long_options[] = Value<string> hostValue("h", "host", "server hostname or ip address", "", &host);
{ Value<size_t> portValue("p", "port", "server port", 1704, &port);
{"help", no_argument, 0, '?'}, Value<string> soundcardValue("s", "soundcard", "index or name of the soundcard", "default", &soundcard);
{"version", no_argument, 0, 'v'}, Implicit<int> daemonOption("d", "daemon", "daemonize, optional process priority [-20..19]", -3, &processPriority);
{"list", no_argument, 0, 'l'}, Value<size_t> latencyValue("", "latency", "latency of the soundcard", 0, &latency);
{"host", required_argument, 0, 'h'},
{"port", required_argument, 0, 'p'},
{"soundcard", required_argument, 0, 's'},
{"daemon", optional_argument, 0, 'd'},
{"latency", required_argument, 0, 0 },
{0, 0, 0, 0 }
};
char c = getopt_long(argc, argv, "?vlh:p:s:d::", long_options, &option_index); OptionParser op("Allowed options");
if (c == -1) op.add(helpSwitch)
break; .add(versionSwitch)
.add(listSwitch)
.add(hostValue)
.add(portValue)
.add(soundcardValue)
.add(daemonOption)
.add(latencyValue);
switch (c) try
{ {
case 0: op.parse(argc, argv);
if (strcmp(long_options[option_index].name, "latency") == 0) }
latency = atoi(optarg); catch (const std::invalid_argument& e)
break; {
logS(kLogErr) << "Exception: " << e.what() << std::endl;
cout << "\n" << op << "\n";
exit(EXIT_FAILURE);
}
case 'v': if (versionSwitch.isSet())
{
cout << "snapclient v" << VERSION << "\n" cout << "snapclient v" << VERSION << "\n"
<< "Copyright (C) 2014, 2015 BadAix (snapcast@badaix.de).\n" << "Copyright (C) 2014, 2015 BadAix (snapcast@badaix.de).\n"
<< "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n" << "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
@ -103,8 +107,9 @@ int main (int argc, char **argv)
<< "There is NO WARRANTY, to the extent permitted by law.\n\n" << "There is NO WARRANTY, to the extent permitted by law.\n\n"
<< "Written by Johannes M. Pohl.\n\n"; << "Written by Johannes M. Pohl.\n\n";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
}
case 'l': if (listSwitch.isSet())
{ {
vector<PcmDevice> pcmDevices = AlsaPlayer::pcm_list(); vector<PcmDevice> pcmDevices = AlsaPlayer::pcm_list();
for (auto dev: pcmDevices) for (auto dev: pcmDevices)
@ -115,37 +120,10 @@ int main (int argc, char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
case 'h': if (helpSwitch.isSet())
host = optarg; {
break; cout << op << "\n";
exit(EXIT_SUCCESS);
case 'p':
port = atoi(optarg);
break;
case 's':
soundcard = optarg;
break;
case 'd':
runAsDaemon = true;
if (optarg)
processPriority = atoi(optarg);
break;
default: //?
cout << "Allowed options:\n\n"
<< " --help \t\t produce help message\n"
<< " -v, --version \t\t show version number\n"
<< " -l, --list \t\t list pcm devices\n"
<< " -h, --host arg \t\t server hostname or ip address\n"
<< " -p, --port arg (=" << port << ")\t server port\n"
<< " -s, --soundcard arg(=" << soundcard << ")\t index or name of the soundcard\n"
<< " -d, --daemon [arg(=" << processPriority << ")]\t daemonize, optional process priority [-20..19]\n"
<< " --latency arg(=" << latency << ")\t\t latency of the soundcard [ms]\n"
<< "\n";
exit(EXIT_FAILURE);
}
} }
@ -155,7 +133,7 @@ int main (int argc, char **argv)
signal(SIGTERM, signal_handler); signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler); signal(SIGINT, signal_handler);
if (runAsDaemon) if (daemonOption.isSet())
{ {
daemonize("/var/run/snapclient.pid"); daemonize("/var/run/snapclient.pid");
if (processPriority < -20) if (processPriority < -20)

2
externals/popl vendored

@ -1 +1 @@
Subproject commit ed0a3323d84673a61ea4758cf29972c47b882e8e Subproject commit ba037c01fcf1d9b6d05bc726e338f2f2e71c53ac