added: start a thread for connecting to Kodi when requested
This commit is contained in:
parent
3d56ee20a8
commit
0e5becf050
5 changed files with 87 additions and 4 deletions
|
@ -51,6 +51,7 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[])
|
|||
m_jackshutdown = false;
|
||||
m_switchedon = false;
|
||||
m_samplecounter = 0;
|
||||
m_usekodi = false;
|
||||
|
||||
struct option longoptions[] =
|
||||
{
|
||||
|
@ -58,11 +59,12 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[])
|
|||
{"off-command", required_argument, NULL, 'f'},
|
||||
{"switch-time", required_argument, NULL, 's'},
|
||||
{"trigger-level", required_argument, NULL, 't'},
|
||||
{"kodi", no_argument, NULL, 'k'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
const char* shortoptions = "n:f:s:t:h";
|
||||
const char* shortoptions = "n:f:s:t:kh";
|
||||
int c;
|
||||
int optionindex = 0;
|
||||
while ((c = getopt_long(argc, argv, shortoptions, longoptions, &optionindex)) != -1)
|
||||
|
@ -102,6 +104,10 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[])
|
|||
|
||||
m_triggerlevel = triggerlevel;
|
||||
}
|
||||
else if (c == 'k')
|
||||
{
|
||||
m_usekodi = true;
|
||||
}
|
||||
else if (c == '?')
|
||||
{
|
||||
exit(1);
|
||||
|
@ -131,6 +137,9 @@ bool CAmpSwitch::Setup()
|
|||
if (m_offcommand)
|
||||
printf("off command: \"%s\"\n", m_offcommand);
|
||||
|
||||
if (m_usekodi)
|
||||
m_kodiclient.Start(); //start a thread that connects to Kodi's JSONRPC
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -212,6 +221,7 @@ void CAmpSwitch::PrintHelpMessage()
|
|||
" -f, --off-command command to execute when switching off\n"
|
||||
" -s, --switch-time minimum number of seconds between switches\n"
|
||||
" -t, --trigger-level absolute value of trigger level\n"
|
||||
" -k, --kodi use Kodi's JSONRPC to switch on when playback starts\n"
|
||||
" -h, --help print this message\n"
|
||||
"\n"
|
||||
);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define AMPSWITCH_H
|
||||
|
||||
#include <jack/jack.h>
|
||||
#include "kodiclient.h"
|
||||
|
||||
class CAmpSwitch
|
||||
{
|
||||
|
@ -64,6 +65,9 @@ class CAmpSwitch
|
|||
|
||||
bool m_switchedon;
|
||||
int m_samplecounter;
|
||||
|
||||
bool m_usekodi;
|
||||
CKodiClient m_kodiclient;
|
||||
};
|
||||
|
||||
#endif //AMPSWITCH_H
|
||||
|
|
35
src/kodiclient.cpp
Normal file
35
src/kodiclient.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* ampswitch
|
||||
* Copyright (C) Bob 2021
|
||||
*
|
||||
* ampswitch 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, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ampswitch 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "kodiclient.h"
|
||||
#include <cstdio>
|
||||
|
||||
void CKodiClient::Start()
|
||||
{
|
||||
m_thread = std::thread(SProcess, this);
|
||||
}
|
||||
|
||||
void CKodiClient::SProcess(CKodiClient* kodiclient)
|
||||
{
|
||||
kodiclient->Process();
|
||||
}
|
||||
|
||||
void CKodiClient::Process()
|
||||
{
|
||||
printf("Kodi client started\n");
|
||||
}
|
31
src/kodiclient.h
Normal file
31
src/kodiclient.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* ampswitch
|
||||
* Copyright (C) Bob 2021
|
||||
*
|
||||
* ampswitch 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, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ampswitch 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <thread>
|
||||
|
||||
class CKodiClient
|
||||
{
|
||||
public:
|
||||
void Start();
|
||||
|
||||
private:
|
||||
static void SProcess(CKodiClient* kodiclient);
|
||||
void Process();
|
||||
|
||||
std::thread m_thread;
|
||||
};
|
9
wscript
9
wscript
|
@ -16,15 +16,18 @@ def configure(conf):
|
|||
conf.load('compiler_cxx')
|
||||
|
||||
conf.check(header_name='jack/jack.h')
|
||||
conf.check(header_name='boost/asio.hpp')
|
||||
|
||||
conf.check(lib='jack', uselib_store='jack', mandatory=False)
|
||||
conf.check(lib='jack', uselib_store='jack', mandatory=True)
|
||||
conf.check(lib='pthread', uselib_store='pthread', mandatory=False)
|
||||
|
||||
conf.write_config_header('config.h')
|
||||
|
||||
def build(bld):
|
||||
bld.program(source='src/main.cpp\
|
||||
src/ampswitch.cpp',
|
||||
use=['jack'],
|
||||
src/ampswitch.cpp\
|
||||
src/kodiclient.cpp',
|
||||
use=['jack', 'pthread'],
|
||||
includes='./src',
|
||||
cxxflags='-Wall -g',
|
||||
target='ampswitch')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue