# HG changeset patch # User František Kučera # Date 1601412788 -7200 # Node ID 8ef1980db90793903a320809888a714a1638618f # Parent a6337902e2ca823e22140796126ea51240466de6 configurable JACK client name diff -r a6337902e2ca -r 8ef1980db907 bash-completion.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bash-completion.sh Tue Sep 29 22:53:08 2020 +0200 @@ -0,0 +1,40 @@ +# Relational pipes +# Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +_relpipe_in_jack_completion() { + local w0 w1 w2 w3 + + COMPREPLY=() + w0=${COMP_WORDS[COMP_CWORD]} + w1=${COMP_WORDS[COMP_CWORD-1]} + w2=${COMP_WORDS[COMP_CWORD-2]} + w3=${COMP_WORDS[COMP_CWORD-3]} + + BOOLEAN=( + "true" + "false" + ) + + if [[ "$w1" == "--TODO" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN[*]}" -- "$w0")) + elif [[ "$w1" == "--jack-client-name" && "x$w0" == "x" ]]; then COMPREPLY=("'relpipe-in-jack'") + else + OPTIONS=( + "--jack-client-name" + ) + COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) + fi +} + +complete -F _relpipe_in_jack_completion relpipe-in-jack diff -r a6337902e2ca -r 8ef1980db907 src/CLIParser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CLIParser.h Tue Sep 29 22:53:08 2020 +0200 @@ -0,0 +1,75 @@ +/** + * Relational pipes + * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include +#include + +#include +#include +#include + +#include "Configuration.h" + +namespace relpipe { +namespace in { +namespace jack { + +class CLIParser { +private: + + relpipe::common::type::StringX readNext(const std::vector& arguments, int& i) { + if (i < arguments.size()) return arguments[i++]; + else throw relpipe::cli::RelpipeCLIException(L"Missing CLI argument" + (i > 0 ? (L" after " + arguments[i - 1]) : L""), relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); + } + + /** + * TODO: use a common method + */ + bool parseBoolean(const relpipe::common::type::StringX& value) { + if (value == L"true") return true; + else if (value == L"false") return false; + else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); + } + +public: + + static const relpipe::common::type::StringX OPTION_JACK_CLIENT_NAME; + + Configuration parse(const std::vector& arguments) { + Configuration c; + + for (int i = 0; i < arguments.size();) { + relpipe::common::type::StringX option = readNext(arguments, i); + + if (option == OPTION_JACK_CLIENT_NAME) { + c.jackClientName = readNext(arguments, i); + } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); + } + + return c; + } + + virtual ~CLIParser() { + } +}; + +const relpipe::common::type::StringX CLIParser::OPTION_JACK_CLIENT_NAME = L"--jack-client-name"; + +} +} +} diff -r a6337902e2ca -r 8ef1980db907 src/Configuration.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Configuration.h Tue Sep 29 22:53:08 2020 +0200 @@ -0,0 +1,39 @@ +/** + * Relational pipes + * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include +#include + +#include + + +namespace relpipe { +namespace in { +namespace jack { + +class Configuration { +public: + relpipe::common::type::StringX jackClientName = L"relpipe-in-jack"; + + virtual ~Configuration() { + } +}; + +} +} +} \ No newline at end of file diff -r a6337902e2ca -r 8ef1980db907 src/JackCommand.h --- a/src/JackCommand.h Sat Jun 06 01:50:42 2020 +0200 +++ b/src/JackCommand.h Tue Sep 29 22:53:08 2020 +0200 @@ -50,6 +50,9 @@ class JackCommand { private: + Configuration& configuration; + std::wstring_convert> convertor; // TODO: local system encoding + jack_port_t* jackPort = nullptr; jack_ringbuffer_t* ringBuffer = nullptr; pthread_mutex_t messageThreadLock = PTHREAD_MUTEX_INITIALIZER; @@ -155,6 +158,9 @@ public: + JackCommand(Configuration& configuration) : configuration(configuration) { + } + void finish(int sig) { continueProcessing = false; } @@ -174,7 +180,7 @@ relationalWriterFlush(); // Initialize JACK connection: - std::string clientName = "relpipe-in-jack"; + std::string clientName = convertor.to_bytes(configuration.jackClientName); jack_client_t* client = jack_client_open(clientName.c_str(), JackNullOption, nullptr); if (client == nullptr) throw JackException(L"Could not create JACK client."); diff -r a6337902e2ca -r 8ef1980db907 src/relpipe-in-jack.cpp --- a/src/relpipe-in-jack.cpp Sat Jun 06 01:50:42 2020 +0200 +++ b/src/relpipe-in-jack.cpp Tue Sep 29 22:53:08 2020 +0200 @@ -21,6 +21,8 @@ #include #include +#include "Configuration.h" +#include "CLIParser.h" #include "JackException.h" #include "JackCommand.h" @@ -44,7 +46,9 @@ try { signal(SIGHUP, finish); signal(SIGINT, finish); - jackCommand.reset(new JackCommand()); + CLIParser cliParser; + Configuration configuration = cliParser.parse(cli.arguments()); + jackCommand.reset(new JackCommand(configuration)); std::shared_ptr writer(Factory::create(std::cout)); jackCommand->processJackStream(writer, std::bind(fflush, stdout)); // std::bind(fflush, XXX) Factory::create(XXX) must be the same stream XXX resultCode = CLI::EXIT_CODE_SUCCESS;