Skip to content

Commit

Permalink
VNSIClient: Reworked threading
Browse files Browse the repository at this point in the history
- All VDR interaction is done in a separate thread by processing ICommand objects
- Created class VNSISpocket reading in a separate thread
- Minor refactoring
- Streamer: Automatically retuning in case of "no data"
  • Loading branch information
mdre77 authored and Max Drechsler committed Dec 29, 2020
1 parent 6d9a4c9 commit e3ae587
Show file tree
Hide file tree
Showing 30 changed files with 1,499 additions and 681 deletions.
25 changes: 25 additions & 0 deletions ICommand.h
@@ -0,0 +1,25 @@
/*
* ICommand.h
*
* Created on: 26.12.2020
* Author: mdrechsler
*/

#pragma once

#include "tools.h"

class ICommandVisitor;

class ICommand
{
public:
/**
* Execute a command
*/
virtual void
execute( ICommandVisitor& ) = 0;


VNSI_INTERFACE( ICommand );
};
30 changes: 30 additions & 0 deletions ICommandProcessor.h
@@ -0,0 +1,30 @@
/*
* ICommandProcessor.h
*
* Created on: 26.12.2020
* Author: mdrechsler
*/

#pragma once

#include <chrono>

#include "tools.h"

class ICommand;

class ICommandProcessor
{
public:
/**
* Process a command
*
* @param [in] command The command to process
*/
virtual bool
process( const ICommand& command,
const std::chrono::milliseconds& timeout ) = 0;


VNSI_INTERFACE( ICommandProcessor );
};
23 changes: 23 additions & 0 deletions ICommandQueue.h
@@ -0,0 +1,23 @@
/*
* CommandQueue.h
*
* Created on: 26.12.2020
* Author: mdrechsler
*/
#include <chrono>

#include "tools.h"

#pragma once

VNSI_DECLARE_POINTER( ICommand );

class ICommandQueue
{
public:
virtual void
enqueue( const ICommandSharedPtr& command ) = 0;


VNSI_INTERFACE( ICommandQueue );
};
54 changes: 54 additions & 0 deletions ICommandVisitor.h
@@ -0,0 +1,54 @@
/*
* ICommandVisitor.h
*
* Created on: 26.12.2020
* Author: mdrechsler
*/

#pragma once

#include "tools.h"

class cRequestPacket;
class SocketError;
class StatusRecording;
class StatusOsdStatusMessage;
class StatusChannelChange;
class StatusChannelsChange;
class StatusRecordingsChange;
class StatusSignalTimerChange;
class StatusEpgChange;


class ICommandVisitor
{
public:
virtual void
visit( SocketError& command ) = 0;

virtual void
visit( cRequestPacket& command ) = 0;

virtual void
visit( StatusRecording& command ) = 0;

virtual void
visit( StatusOsdStatusMessage& command ) = 0;

virtual void
visit( StatusChannelChange& command ) = 0;

virtual void
visit( StatusChannelsChange& command ) = 0;

virtual void
visit( StatusRecordingsChange& command ) = 0;

virtual void
visit( StatusSignalTimerChange& command ) = 0;

virtual void
visit( StatusEpgChange& command ) = 0;

VNSI_INTERFACE( ICommandVisitor );
};
42 changes: 42 additions & 0 deletions ISocket.h
@@ -0,0 +1,42 @@
/*
* ISocket.h
*
* Created on: 26.12.2020
* Author: mdrechsler
*/

#pragma once

#include "tools.h"

class ISocket
{
public:
virtual void
Shutdown() = 0;

virtual void
lock() = 0;

virtual void
unlock() = 0;

virtual void
Invalidate() = 0;

virtual int
GetHandle() const = 0;

virtual ssize_t
read( void* buffer,
size_t size,
int timeout_ms = -1 ) = 0;

virtual ssize_t
write( const void* buffer,
size_t size,
int timeout_ms = -1,
bool more_data = false ) = 0;

VNSI_INTERFACE( ISocket );
};
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -69,7 +69,7 @@ OBJS = vnsi.o bitstream.o vnsiclient.o channelscancontrol.o config.o cxsocket.o
parser_AC3.o parser_DTS.o parser_h264.o parser_hevc.o parser_MPEGAudio.o parser_MPEGVideo.o \
parser_Subtitle.o parser_Teletext.o streamer.o recplayer.o requestpacket.o responsepacket.o \
vnsiserver.o hash.o recordingscache.o setup.o vnsiosd.o demuxer.o videobuffer.o \
videoinput.o channelfilter.o status.o vnsitimer.o
videoinput.o channelfilter.o status.o vnsitimer.o vnsisocket.o StatusCommands.o

### The main target:

Expand Down
115 changes: 115 additions & 0 deletions StatusCommands.c
@@ -0,0 +1,115 @@
/*
* StatusCommans.c
*
* Created on: 26.12.2020
* Author: mdrechsler
*/

#include "StatusCommands.h"

#include "ICommandVisitor.h"

void
SocketError::execute( ICommandVisitor& visitor )
{
visitor.visit(*this);
}

StatusRecording::StatusRecording( int deviceIndex,
const std::string& name,
const std::string& fileName,
bool on )
: mDeviceIndex( deviceIndex )
, mName( name )
, mFileName( fileName )
, mOn( on )
{
}

int
StatusRecording::getDeviceIndex() const
{
return mDeviceIndex;
}

const std::string&
StatusRecording::getName() const
{
return mName;
}

const std::string&
StatusRecording::getFileName() const
{
return mFileName;
}

bool
StatusRecording::isOn() const
{
return mOn;
}

void
StatusRecording::execute( ICommandVisitor& visitor )
{
visitor.visit( *this );
}

StatusOsdStatusMessage::StatusOsdStatusMessage( const std::string& message )
: mMessage( message )
{
}

std::string
StatusOsdStatusMessage::getMessage() const
{
return mMessage;
}

void
StatusOsdStatusMessage::execute( ICommandVisitor& visitor )
{
visitor.visit( *this );
}

StatusChannelChange::StatusChannelChange( const cChannel& channel )
: mChannel( channel )
{
}

const cChannel&
StatusChannelChange::getChannel() const
{
return mChannel;
}

void
StatusChannelChange::execute( ICommandVisitor& visitor )
{
visitor.visit(*this);
}

void
StatusChannelsChange::execute( ICommandVisitor& visitor )
{
visitor.visit(*this);
}

void
StatusRecordingsChange::execute( ICommandVisitor& visitor )
{
visitor.visit(*this);
}

void
StatusSignalTimerChange::execute( ICommandVisitor& visitor )
{
visitor.visit(*this);
}

void
StatusEpgChange::execute( ICommandVisitor& visitor )
{
visitor.visit(*this);
}

0 comments on commit e3ae587

Please sign in to comment.