Skip to content

Commit

Permalink
Working on execution context
Browse files Browse the repository at this point in the history
  • Loading branch information
k-wasniowski committed Sep 30, 2023
1 parent 45cf93e commit 61e30d2
Show file tree
Hide file tree
Showing 31 changed files with 441 additions and 29 deletions.
4 changes: 3 additions & 1 deletion App/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ target_link_libraries(ArdaLiveMediaServer
PUBLIC
MediaServer::MediaManager
MediaServer::RtspClient
Http::Server
MediaServer::GenericRtpClient
HttpServer::Server
MediaServer::MediaServer
)
2 changes: 2 additions & 0 deletions App/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <HttpServer/Server.hpp>
#include <MediaServer/MediaManager/MediaManager.hpp>
#include <MediaServer/RtspClient/RtspClient.hpp>
#include <MediaServer/GenericRtpClient/GenericRtpClient.hpp>

#include <iostream>

Expand All @@ -11,6 +12,7 @@ int main()
boost::asio::io_context ioContext{};

auto pRtspClient = MediaServer::Rtsp::RtspClient::Create(ioContext);
auto pGenericRtpClient = MediaServer::Rtp::GenericRtpClient::Create(ioContext);

auto pMediaManager = MediaServer::MediaManager::Create();

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ find_package(LibDataChannel CONFIG REQUIRED)
find_package(opentelemetry-cpp CONFIG REQUIRED)
find_package(Boost REQUIRED)

add_subdirectory(Gondor)
add_subdirectory(Media)
add_subdirectory(MediaServer)
add_subdirectory(HttpServer)
Expand Down
12 changes: 12 additions & 0 deletions Gondor/AppInfo/include/Gondor/AppInfo/AppInfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by admin on 9/28/2023.
//

#ifndef ARDALIVEMEDIASERVER_APPINFO_HPP
#define ARDALIVEMEDIASERVER_APPINFO_HPP

class AppInfo
{
};

#endif // ARDALIVEMEDIASERVER_APPINFO_HPP
5 changes: 5 additions & 0 deletions Gondor/AppInfo/src/AppInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Created by admin on 9/28/2023.
//

#include "AppInfo.hpp"
1 change: 1 addition & 0 deletions Gondor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Execution)
12 changes: 12 additions & 0 deletions Gondor/Execution/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
add_library(Execution
STATIC
${CMAKE_CURRENT_SOURCE_DIR}/src/ExecutionContext.cpp
)

target_include_directories(Execution
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${Boost_INCLUDE_DIR}
)

add_library(Gondor::Execution ALIAS Execution)
20 changes: 20 additions & 0 deletions Gondor/Execution/include/Gondor/Execution/ExecutionContext.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <Gondor/Execution/ITasksExecutor.hpp>

#include <memory>

namespace Gondor
{
namespace Execution
{
class ExecutionContext : public ITasksExecutor
{
public:
ExecutionContext(uint32_t threadsCount = 1);
~ExecutionContext() override;

private:
class Impl;
std::unique_ptr<Impl> m_pImpl;
};
}
}
12 changes: 12 additions & 0 deletions Gondor/Execution/include/Gondor/Execution/ITasksExecutor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

namespace Gondor
{
namespace Execution
{
class ITasksExecutor
{
public:
virtual ~ITasksExecutor() = default;
};
}
}
39 changes: 39 additions & 0 deletions Gondor/Execution/src/ExecutionContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <Gondor/Execution/ExecutionContext.hpp>

#include <boost/asio.hpp>

#include <iostream>

namespace Gondor
{
namespace Execution
{
class ExecutionContext::Impl
{
public:
static std::unique_ptr<Impl> Create(uint32_t threadsCount)
{
return std::make_unique<Impl>(threadsCount);
}

Impl(uint32_t threadsCount)
: m_pool{1}
, m_executor{m_pool.executor()}
{
std::cout << "Creating ExecutionContext!" << std::endl;
}

~Impl() {}

private:
boost::asio::thread_pool m_pool;
boost::asio::executor m_executor;
};

ExecutionContext::ExecutionContext(uint32_t threadsCount)
: m_pImpl{Impl::Create(threadsCount)}
{}

ExecutionContext::~ExecutionContext() {}
}
}
2 changes: 1 addition & 1 deletion HttpServer/HealthCheck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ target_include_directories(HealthCheck
${CMAKE_CURRENT_SOURCE_DIR}/include
)

add_library(Http::HealthCheck ALIAS HealthCheck)
add_library(HttpServer::HealthCheck ALIAS HealthCheck)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <memory>

namespace Http
namespace HttpServer
{
class HealthCheckController;
using HealthCheckControllerSharedPtr_t = std::shared_ptr<HealthCheckController>;
Expand Down
14 changes: 12 additions & 2 deletions HttpServer/HealthCheck/src/HealthCheckController.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <HealthCheck/HealthCheckController.hpp>
#include <HttpServer/HealthCheck/HealthCheckController.hpp>

#include <iostream>

namespace Http
namespace HttpServer
{
HealthCheckControllerSharedPtr_t HealthCheckController::Create()
{
Expand All @@ -23,6 +23,16 @@ namespace Http
std::function<void(const drogon::HttpResponsePtr&)>&& callback)
{
std::cout << "HealthCheckController::GetHealthCheck" << std::endl;
if (!pHttpRequest)
{
std::cout << "HealthCheckController::GetHealthCheck - pHttpRequest is nullptr" << std::endl;

auto pHttpResponse = drogon::HttpResponse::newHttpResponse();
pHttpResponse->setStatusCode(drogon::HttpStatusCode::k500InternalServerError);

callback(pHttpResponse);
return;
}

auto pHttpResponse = drogon::HttpResponse::newHttpResponse();
pHttpResponse->setStatusCode(drogon::HttpStatusCode::k200OK);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <MediaServer/MediaManager/MediaManager.hpp>

#include <drogon/HttpController.h>

#include <memory>
Expand All @@ -14,18 +16,24 @@ namespace HttpServer
class GenericRtpController : public drogon::HttpController<GenericRtpController, false>
{
public:
static GenericRtpControllerSharedPtr_t Create();
static GenericRtpControllerSharedPtr_t Create(MediaServer::MediaManagerSharedPtr_t pMediaManager);

GenericRtpController();
GenericRtpController(MediaServer::MediaManagerSharedPtr_t pMediaManager);
~GenericRtpController() override;

METHOD_LIST_BEGIN
ADD_METHOD_TO(GenericRtpController::PostResource, "/api/v1/resources/generic-rtp/{resource}", drogon::Post);
METHOD_LIST_END

void PostResource(const drogon::HttpRequestPtr &req, std::function<void(const drogon::HttpResponsePtr &)> &&callback, std::string&& resource);
void PostResource(const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& callback,
std::string&& resource);

private:
void SendHttpSuccessResponse_(std::function<void(const drogon::HttpResponsePtr&)>&& callback);

private:
MediaServer::MediaManagerSharedPtr_t m_pMediaManager;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by admin on 9/28/2023.
//

#ifndef ARDALIVEMEDIASERVER_POSTRESOURCEHANDLER_HPP
#define ARDALIVEMEDIASERVER_POSTRESOURCEHANDLER_HPP

class PostResourceHandler
{
};

#endif // ARDALIVEMEDIASERVER_POSTRESOURCEHANDLER_HPP
19 changes: 15 additions & 4 deletions HttpServer/Resources/src/GenericRtpController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ namespace HttpServer
{
namespace Resources
{
GenericRtpControllerSharedPtr_t GenericRtpController::Create()
GenericRtpControllerSharedPtr_t GenericRtpController::Create(MediaServer::MediaManagerSharedPtr_t pMediaManager)
{
return std::make_shared<GenericRtpController>();
return std::make_shared<GenericRtpController>(pMediaManager);
}

GenericRtpController::GenericRtpController()
GenericRtpController::GenericRtpController(MediaServer::MediaManagerSharedPtr_t pMediaManager)
: m_pMediaManager{std::move(pMediaManager)}
{
std::cout << "Creating GenericRtpController" << std::endl;
}
Expand All @@ -25,10 +26,20 @@ namespace HttpServer
std::function<void(const drogon::HttpResponsePtr&)>&& callback,
std::string&& resource)
{
std::cout << "GenericRtpController::PostResource" << std::endl;
std::cout << "GenericRtpController::PostResource - " << resource << std::endl;

auto pMediaResource = m_pMediaManager->GetMediaResource(resource);
if (!pMediaResource)
{
pMediaResource = MediaServer::MediaResource::Create(std::move(resource));
m_pMediaManager->AddMediaResource(pMediaResource);
}

SendHttpSuccessResponse_(std::move(callback));
}

void GenericRtpController::SendHttpSuccessResponse_(std::function<void(const drogon::HttpResponsePtr&)>&& callback)
{
auto pHttpResponse = drogon::HttpResponse::newHttpResponse();
pHttpResponse->setStatusCode(drogon::HttpStatusCode::k200OK);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Created by admin on 9/28/2023.
//

#include "PostResourceHandler.hpp"
5 changes: 3 additions & 2 deletions HttpServer/Server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ target_include_directories(Server
target_link_libraries(Server
PUBLIC
MediaServer::MediaManager
Http::HealthCheck
MediaServer::GenericRtpClient
HttpServer::HealthCheck
Http::Resources
)

add_library(Http::Server ALIAS Server)
add_library(HttpServer::Server ALIAS Server)
7 changes: 4 additions & 3 deletions HttpServer/Server/src/Server.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <HttpServer/Server.hpp>

#include <HealthCheck/HealthCheckController.hpp>
#include <HttpServer/HealthCheck/HealthCheckController.hpp>
#include <HttpServer/Resources/WebRtcController.hpp>
#include <HttpServer/Resources/GenericRtpController.hpp>

Expand Down Expand Up @@ -46,14 +46,15 @@ namespace HttpServer
void Run()
{
std::cout << "Running Server Impl" << std::endl;
auto pHealthCheckController = Http::HealthCheckController::Create();
auto pHealthCheckController = HttpServer::HealthCheckController::Create();
auto pWebRtcController = HttpServer::Resources::WebRtcController::Create(m_pMediaManager);
auto pGenericRtpController = HttpServer::Resources::GenericRtpController::Create();
auto pGenericRtpController = HttpServer::Resources::GenericRtpController::Create(m_pMediaManager);

drogon::app()
.addListener("127.0.0.1", 80)
.registerController(pHealthCheckController)
.registerController(pWebRtcController)
.registerController(pGenericRtpController)
.run();
}

Expand Down
3 changes: 2 additions & 1 deletion MediaServer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(MediaManager)
add_subdirectory(GenericRtpClient)
add_subdirectory(RtspClient)
add_subdirectory(RtspClient)
add_subdirectory(MediaServer)
5 changes: 5 additions & 0 deletions MediaServer/GenericRtpClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ target_link_libraries(GenericRtpClient
Media::Sdp
)

target_link_libraries(GenericRtpClient
PRIVATE
MediaServer::MediaManager
)

add_library(MediaServer::GenericRtpClient ALIAS GenericRtpClient)
20 changes: 10 additions & 10 deletions MediaServer/MediaManager/src/MediaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ namespace MediaServer

MediaResourceSharedPtr_t MediaManager::GetMediaResource(std::string resourceName)
{
// auto it = std::find_if(std::begin(m_mediaResources), std::end(m_mediaResources), [resourceName = std::move(resourceName)](const auto& resource) -> bool {
// return resource->ResourceName() == resourceName;
// });
//
// if(it == std::end(m_mediaResources))
// {
// return nullptr;
// }

return m_mediaResources.front();
auto it = std::find_if(std::begin(m_mediaResources), std::end(m_mediaResources), [resourceName = std::move(resourceName)](const auto& resource) -> bool {
return resource->ResourceName() == resourceName;
});

if(it == std::end(m_mediaResources))
{
return nullptr;
}

return *it;
}

void MediaManager::RemoveMediaResource(MediaResourceSharedPtr_t pMediaResource)
Expand Down
24 changes: 24 additions & 0 deletions MediaServer/MediaServer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
add_library(MediaServer
STATIC
${CMAKE_CURRENT_SOURCE_DIR}/src/Server.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/GenericRtpClientProxy.cpp
)

target_include_directories(MediaServer
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${Boost_INCLUDE_DIR}
)

target_link_libraries(MediaServer
PUBLIC
Gondor::Execution
)

target_link_libraries(MediaServer
PUBLIC
MediaServer::MediaManager
MediaServer::GenericRtpClient
)

add_library(MediaServer::MediaServer ALIAS MediaServer)
Loading

0 comments on commit 61e30d2

Please sign in to comment.