SNode.C
Loading...
Searching...
No Matches
web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT > Class Template Referenceabstract

#include <SocketContextUpgradeFactorySelector.h>

Collaboration diagram for web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >:

Classes

struct  SocketContextPlugin
 

Public Types

using SocketContextUpgradeFactory = SocketContextUpgradeFactoryT
 
using Request = typename SocketContextUpgradeFactory::Request
 
using Response = typename SocketContextUpgradeFactory::Response
 

Public Member Functions

virtual SocketContextUpgradeFactoryselect (Request &req, Response &res)=0
 
bool add (SocketContextUpgradeFactory *socketContextUpgradeFactory)
 
void link (const std::string &socketContextUpgradeName, SocketContextUpgradeFactory *(*linkedPlugin)())
 
void allowDlOpen ()
 
void unload (SocketContextUpgradeFactory *socketContextUpgradeFactory)
 

Protected Member Functions

 SocketContextUpgradeFactorySelector ()=default
 
virtual ~SocketContextUpgradeFactorySelector ()=default
 
SocketContextUpgradeFactoryselect (const std::string &socketContextUpgradeName)
 
virtual SocketContextUpgradeFactoryload (const std::string &socketContextUpgradeName)=0
 
SocketContextUpgradeFactoryload (const std::string &socketContextUpgradeName, const std::string &socketContextUpgradeFactoryLibraryFile, const std::string &socketContextUpgradeFactoryFunctionName)
 
bool add (SocketContextUpgradeFactory *socketContextUpgradeFactory, void *handler)
 

Private Attributes

std::map< std::string, SocketContextPluginsocketContextUpgradePlugins
 
std::map< std::string, SocketContextUpgradeFactory *(*)()> linkedSocketContextUpgradePlugins
 
bool onlyLinked = false
 

Detailed Description

template<typename SocketContextUpgradeFactoryT>
class web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >

Definition at line 35 of file SocketContextUpgradeFactorySelector.h.

Member Typedef Documentation

◆ Request

template<typename SocketContextUpgradeFactoryT >
using web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::Request = typename SocketContextUpgradeFactory::Request

Definition at line 38 of file SocketContextUpgradeFactorySelector.h.

◆ Response

template<typename SocketContextUpgradeFactoryT >
using web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::Response = typename SocketContextUpgradeFactory::Response

Definition at line 39 of file SocketContextUpgradeFactorySelector.h.

◆ SocketContextUpgradeFactory

template<typename SocketContextUpgradeFactoryT >
using web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::SocketContextUpgradeFactory = SocketContextUpgradeFactoryT

Definition at line 37 of file SocketContextUpgradeFactorySelector.h.

Constructor & Destructor Documentation

◆ SocketContextUpgradeFactorySelector()

template<typename SocketContextUpgradeFactoryT >
web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::SocketContextUpgradeFactorySelector ( )
protecteddefault

◆ ~SocketContextUpgradeFactorySelector()

template<typename SocketContextUpgradeFactoryT >
virtual web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::~SocketContextUpgradeFactorySelector ( )
protectedvirtualdefault

Member Function Documentation

◆ add() [1/2]

Definition at line 51 of file SocketContextUpgradeFactorySelector.hpp.

51 {
52 return add(socketContextUpgradeFactory, nullptr);
53 }
bool add(SocketContextUpgradeFactory *socketContextUpgradeFactory)

◆ add() [2/2]

template<typename SocketContextUpgradeFactory >
bool web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactory >::add ( SocketContextUpgradeFactory * socketContextUpgradeFactory,
void * handler )
protected

Definition at line 38 of file SocketContextUpgradeFactorySelector.hpp.

39 {
40 bool success = false;
41
42 if (socketContextUpgradeFactory != nullptr) {
43 SocketContextPlugin socketContextPlugin = {.socketContextUpgradeFactory = socketContextUpgradeFactory, .handle = handle};
44 std::tie(std::ignore, success) = socketContextUpgradePlugins.insert({socketContextUpgradeFactory->name(), socketContextPlugin});
45 }
46
47 return success;
48 }
std::map< std::string, SocketContextPlugin > socketContextUpgradePlugins

◆ allowDlOpen()

◆ link()

template<typename SocketContextUpgradeFactory >
void web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactory >::link ( const std::string & socketContextUpgradeName,
SocketContextUpgradeFactory *(* linkedPlugin )() )

Definition at line 117 of file SocketContextUpgradeFactorySelector.hpp.

118 {
119 if (!linkedSocketContextUpgradePlugins.contains(socketContextUpgradeName)) {
120 linkedSocketContextUpgradePlugins[socketContextUpgradeName] = linkedPlugin;
121 }
122
123 onlyLinked = true;
124 }
std::map< std::string, SocketContextUpgradeFactory *(*)()> linkedSocketContextUpgradePlugins

◆ load() [1/2]

template<typename SocketContextUpgradeFactoryT >
virtual SocketContextUpgradeFactory * web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::load ( const std::string & socketContextUpgradeName)
protectedpure virtual

◆ load() [2/2]

template<typename SocketContextUpgradeFactory >
SocketContextUpgradeFactory * web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactory >::load ( const std::string & socketContextUpgradeName,
const std::string & socketContextUpgradeFactoryLibraryFile,
const std::string & socketContextUpgradeFactoryFunctionName )
protected

Definition at line 62 of file SocketContextUpgradeFactorySelector.hpp.

64 {
65 SocketContextUpgradeFactory* socketContextUpgradeFactory = nullptr;
66
67 void* handle = core::DynamicLoader::dlOpen(socketContextUpgradeFactoryLibraryFile);
68
69 if (handle != nullptr) {
70 SocketContextUpgradeFactory* (*getSocketContextUpgradeFactory)() = reinterpret_cast<SocketContextUpgradeFactory* (*) ()>(
71 core::DynamicLoader::dlSym(handle, socketContextUpgradeFactoryFunctionName));
72
73 if (getSocketContextUpgradeFactory != nullptr) {
74 socketContextUpgradeFactory = getSocketContextUpgradeFactory();
75
76 if (socketContextUpgradeFactory != nullptr) {
77 if (add(socketContextUpgradeFactory, handle)) {
78 LOG(DEBUG) << "HTTP: SocketContextUpgradeFactory created successful: " << socketContextUpgradeName;
79 } else {
80 LOG(DEBUG) << "HTTP: UpgradeSocketContext already existing. Not using: " << socketContextUpgradeName;
81 delete socketContextUpgradeFactory;
82 socketContextUpgradeFactory = nullptr;
84 }
85 } else {
86 LOG(ERROR) << "HTTP: SocketContextUpgradeFactory not created: " << socketContextUpgradeName;
88 }
89 } else {
90 LOG(ERROR) << "HTTP: Optaining function \"" << socketContextUpgradeFactoryFunctionName
91 << "\" in plugin failed: " << core::DynamicLoader::dlError();
93 }
94 }
95
96 return socketContextUpgradeFactory;
97 }
static char * dlError()
static int dlClose(void *handle)
static void * dlSym(void *handle, const std::string &symbol)

◆ select() [1/2]

template<typename SocketContextUpgradeFactory >
SocketContextUpgradeFactory * web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactory >::select ( const std::string & socketContextUpgradeName)
protected

Definition at line 101 of file SocketContextUpgradeFactorySelector.hpp.

101 {
102 SocketContextUpgradeFactory* socketContextUpgradeFactory = nullptr;
103
104 if (socketContextUpgradePlugins.contains(socketContextUpgradeName)) {
105 socketContextUpgradeFactory = socketContextUpgradePlugins[socketContextUpgradeName].socketContextUpgradeFactory;
106 } else if (linkedSocketContextUpgradePlugins.contains(socketContextUpgradeName)) {
107 socketContextUpgradeFactory = linkedSocketContextUpgradePlugins[socketContextUpgradeName]();
108 add(socketContextUpgradeFactory);
109 } else if (!onlyLinked) {
110 socketContextUpgradeFactory = load(socketContextUpgradeName);
111 }
112
113 return socketContextUpgradeFactory;
114 }
virtual SocketContextUpgradeFactory * load(const std::string &socketContextUpgradeName)=0

◆ select() [2/2]

template<typename SocketContextUpgradeFactoryT >
virtual SocketContextUpgradeFactory * web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::select ( Request & req,
Response & res )
pure virtual

◆ unload()

Definition at line 128 of file SocketContextUpgradeFactorySelector.hpp.

128 {
129 std::string upgradeContextNames = socketContextUpgradeFactory->name();
130
131 if (socketContextUpgradePlugins.contains(upgradeContextNames)) {
132 SocketContextPlugin socketContextPlugin = socketContextUpgradePlugins[upgradeContextNames];
133 socketContextUpgradePlugins.erase(upgradeContextNames);
134
135 delete socketContextUpgradeFactory;
136
137 if (socketContextPlugin.handle != nullptr) {
138 core::DynamicLoader::dlCloseDelayed(socketContextPlugin.handle);
139 }
140 }
141 }
static void dlCloseDelayed(void *handle)

Member Data Documentation

◆ linkedSocketContextUpgradePlugins

template<typename SocketContextUpgradeFactoryT >
std::map<std::string, SocketContextUpgradeFactory* (*) ()> web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::linkedSocketContextUpgradePlugins
private

Definition at line 75 of file SocketContextUpgradeFactorySelector.h.

◆ onlyLinked

template<typename SocketContextUpgradeFactoryT >
bool web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::onlyLinked = false
private

Definition at line 77 of file SocketContextUpgradeFactorySelector.h.

◆ socketContextUpgradePlugins

template<typename SocketContextUpgradeFactoryT >
std::map<std::string, SocketContextPlugin> web::http::SocketContextUpgradeFactorySelector< SocketContextUpgradeFactoryT >::socketContextUpgradePlugins
private

Definition at line 74 of file SocketContextUpgradeFactorySelector.h.


The documentation for this class was generated from the following files: