Skip to content

Commit

Permalink
Services: New method channel/GetAvailableChanid
Browse files Browse the repository at this point in the history
The service that adds a channel requires a chanid but there is no
method of obtaining an unused chanid number. This method returns the
next available number.
  • Loading branch information
bennettpeter committed Feb 22, 2023
1 parent 659a9b6 commit 293adf2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mythtv/programs/mythbackend/servicesv2/v2channel.cpp
Expand Up @@ -283,6 +283,24 @@ bool V2Channel::UpdateDBChannel( uint MplexID,
return bResult;
}


uint V2Channel::GetAvailableChanid ( void ) {
uint chanId = 0;

MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT MAX(chanid) FROM channel");
if (!query.exec())
{
MythDB::DBError("V2Channel::AddDBChannel", query);
throw( QString( "Database Error executing query." ));
}
if (query.next())
chanId = query.value(0).toUInt() + 1;
if (chanId < 1000)
chanId = 1000;
return chanId;
}

bool V2Channel::AddDBChannel( uint MplexID,
uint SourceID,
uint ChannelID,
Expand Down
3 changes: 3 additions & 0 deletions mythtv/programs/mythbackend/servicesv2/v2channel.h
Expand Up @@ -50,6 +50,7 @@ class V2Channel : public MythHTTPService
Q_CLASSINFO("RemoveAllVideoSources", "methods=POST;name=bool")
Q_CLASSINFO("RemoveVideoSource", "methods=POST;name=bool")
Q_CLASSINFO("FetchChannelsFromSource","methods=GET,POST;name=int")
Q_CLASSINFO("GetAvailableChanid", "methods=GET,POST;name=int")
Q_CLASSINFO("GetXMLTVIdList", "methods=GET,POST,HEAD;name=StringList")

public:
Expand Down Expand Up @@ -119,6 +120,8 @@ class V2Channel : public MythHTTPService

static bool RemoveDBChannel ( uint ChannelID );

static uint GetAvailableChanid ( void );

static V2CommMethodList* GetCommMethodList ( void );

/* Video Source Methods */
Expand Down

0 comments on commit 293adf2

Please sign in to comment.