Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Header Nesting #2751

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ endif(CYGWIN)
add_library(libgerbera STATIC
src/action_request.cc
src/action_request.h
src/cds_objects.cc
src/cds_objects.h
src/cds_resource.cc
src/cds_resource.h
src/cds/cds_container.cc
src/cds/cds_container.h
src/cds/cds_item.cc
src/cds/cds_item.h
src/cds/cds_objects.cc
src/cds/cds_objects.h
src/cds/cds_resource.cc
src/cds/cds_resource.h
src/common.h
src/config/client_config.h
src/config/client_config.cc
Expand Down Expand Up @@ -221,6 +225,8 @@ add_library(libgerbera STATIC
src/util/grb_fs.h
src/util/grb_net.cc
src/util/grb_net.h
src/util/grb_time.cc
src/util/grb_time.h
src/util/jpeg_resolution.cc
src/util/logger.h
src/util/logger.cc
Expand Down
63 changes: 63 additions & 0 deletions src/cds/cds_container.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*GRB*
Gerbera - https://gerbera.io/

cds_container.cc - this file is part of Gerbera.

Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>

Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
Leonhard Wimmer <leo@mediatomb.cc>

Copyright (C) 2016-2022 Gerbera Contributors

Gerbera is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.

Gerbera 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 Gerbera. If not, see <http://www.gnu.org/licenses/>.
*/

/// \file cds_container.cc

#include "cds_container.h" // API

#include "util/grb_time.h"

CdsContainer::CdsContainer()
{
objectType = OBJECT_TYPE_CONTAINER;
upnpClass = UPNP_CLASS_CONTAINER;
mtime = currentTime();
}

void CdsContainer::copyTo(const std::shared_ptr<CdsObject>& obj)
{
CdsObject::copyTo(obj);
if (!obj->isContainer())
return;
auto cont = std::static_pointer_cast<CdsContainer>(obj);
cont->setUpdateID(updateID);
}
bool CdsContainer::equals(const std::shared_ptr<CdsObject>& obj, bool exactly) const
{
auto cont = std::static_pointer_cast<CdsContainer>(obj);
return CdsObject::equals(obj, exactly) && isSearchable() == cont->isSearchable();
}

/*
void CdsContainer::validate() const
{
CdsObject::validate();
/// \todo well.. we have to know if a container is a real directory or just a virtual container in the database
if (!fs::is_directory(this->location, true))
throw_std_runtime_error("validation failed");
}
*/
Comment on lines +55 to +63

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
96 changes: 96 additions & 0 deletions src/cds/cds_container.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*GRB*
Gerbera - https://gerbera.io/

cds_container.h - this file is part of Gerbera.

Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>

Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
Leonhard Wimmer <leo@mediatomb.cc>

Copyright (C) 2016-2022 Gerbera Contributors

Gerbera is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.

Gerbera 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 Gerbera. If not, see <http://www.gnu.org/licenses/>.
*/

/// \file cds_container.h
/// \brief Definition for the CdsContainer class.
#ifndef __CDS_CONTAINER_H__
#define __CDS_CONTAINER_H__

#include "cds_objects.h"

/// \brief A container in the content directory.
class CdsContainer final : public CdsObject {
protected:
/// \brief container update id.
int updateID {};

/// \brief childCount attribute
int childCount { -1 };

/// \brief whether this container is an autoscan start point.
int autoscanType { OBJECT_AUTOSCAN_NONE };

public:
/// \brief Constructor, initializes default values for the flags and sets the object type.
CdsContainer();
explicit CdsContainer(const std::string& title, const std::string& upnpClass = UPNP_CLASS_CONTAINER)
{
this->title = title;
this->upnpClass = upnpClass;
}

bool isContainer() const override { return true; }

/// \brief Set the searchable flag.
void setSearchable(bool searchable) { changeFlag(OBJECT_FLAG_SEARCHABLE, searchable); }

/// \brief Query searchable flag.
int isSearchable() const { return getFlag(OBJECT_FLAG_SEARCHABLE); }

/// \brief Set the container update ID value.
void setUpdateID(int updateID) { this->updateID = updateID; }

/// \brief Query container update ID value.
int getUpdateID() const { return updateID; }

/// \brief Set container childCount attribute.
void setChildCount(int childCount) { this->childCount = childCount; }

/// \brief Retrieve number of children
int getChildCount() const { return childCount; }

/// \brief returns whether this container is an autoscan start point.
int getAutoscanType() const { return autoscanType; }

/// \brief sets whether this container is an autoscan start point.
void setAutoscanType(int type) { autoscanType = type; }

/// \brief Copies all object properties to another object.
/// \param obj target object (clone)
void copyTo(const std::shared_ptr<CdsObject>& obj) override;

/// \brief Checks if current object is equal to obj.
///
/// See description for CdsObject::equals() for details.
bool equals(const std::shared_ptr<CdsObject>& obj, bool exactly = false) const override;
/*
/// \brief Checks if the minimum required parameters for the object have been set and are valid.
void validate() const override;
*/
};

#endif // __CDS_CONTAINER_H__
103 changes: 103 additions & 0 deletions src/cds/cds_item.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*GRB*
Gerbera - https://gerbera.io/

cds_item.cc - this file is part of Gerbera.

Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>

Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
Leonhard Wimmer <leo@mediatomb.cc>

Copyright (C) 2016-2022 Gerbera Contributors

Gerbera is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.

Gerbera 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 Gerbera. If not, see <http://www.gnu.org/licenses/>.
*/

/// \file cds_item.cc

#include "cds_item.h" // API

#include <array>
#include <numeric>

#include "util/grb_time.h"
#include "util/upnp_clients.h"

CdsItem::CdsItem()
{
objectType = OBJECT_TYPE_ITEM;
upnpClass = "object.item";
mtime = currentTime();
}

void CdsItem::copyTo(const std::shared_ptr<CdsObject>& obj)
{
CdsObject::copyTo(obj);
if (!obj->isItem())
return;
auto item = std::static_pointer_cast<CdsItem>(obj);
// item->setDescription(description);

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
item->setMimeType(mimeType);
item->setTrackNumber(trackNumber);
item->setPartNumber(partNumber);
item->setServiceID(serviceID);
if (playStatus)
item->setPlayStatus(playStatus->clone());
}

bool CdsItem::equals(const std::shared_ptr<CdsObject>& obj, bool exactly) const
{
auto item = std::static_pointer_cast<CdsItem>(obj);
if (!CdsObject::equals(obj, exactly))
return false;
return (mimeType == item->getMimeType() && partNumber == item->getPartNumber() && trackNumber == item->getTrackNumber() && serviceID == item->getServiceID());
}

void CdsItem::validate() const
{
CdsObject::validate();
// log_info("mime: [{}] loc [{}]", this->mimeType.c_str(), this->location.c_str());

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
if (this->mimeType.empty())
throw_std_runtime_error("Item validation failed: missing mimetype");

if (this->location.empty())
throw_std_runtime_error("Item validation failed: missing location");

if (isExternalItem())
return;

std::error_code ec;
if (!isRegularFile(location, ec))
throw_std_runtime_error("Item validation failed: file {} not found", location.c_str());
}

//---------

CdsItemExternalURL::CdsItemExternalURL()
{
objectType |= OBJECT_TYPE_ITEM_EXTERNAL_URL;

upnpClass = UPNP_CLASS_ITEM;
}

void CdsItemExternalURL::validate() const
{
CdsItem::validate();
if (this->mimeType.empty())
throw_std_runtime_error("URL Item validation failed: missing mimetype");

if (this->location.empty())
throw_std_runtime_error("URL Item validation failed: missing URL");
}