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 57 of file SocketContextUpgradeFactorySelector.h.

Member Typedef Documentation

◆ Request

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

Definition at line 60 of file SocketContextUpgradeFactorySelector.h.

◆ Response

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

Definition at line 61 of file SocketContextUpgradeFactorySelector.h.

◆ SocketContextUpgradeFactory

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

Definition at line 59 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 73 of file SocketContextUpgradeFactorySelector.hpp.

73 {
74 return add(socketContextUpgradeFactory, nullptr);
75 }
bool add(SocketContextUpgradeFactory *socketContextUpgradeFactory)

◆ add() [2/2]

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

Definition at line 60 of file SocketContextUpgradeFactorySelector.hpp.

61 {
62 bool success = false;
63
64 if (socketContextUpgradeFactory != nullptr) {
65 SocketContextPlugin socketContextPlugin = {.socketContextUpgradeFactory = socketContextUpgradeFactory, .handle = handle};
66 std::tie(std::ignore, success) = socketContextUpgradePlugins.insert({socketContextUpgradeFactory->name(), socketContextPlugin});
67 }
68
69 return success;
70 }
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 139 of file SocketContextUpgradeFactorySelector.hpp.

140 {
141 if (!linkedSocketContextUpgradePlugins.contains(socketContextUpgradeName)) {
142 linkedSocketContextUpgradePlugins[socketContextUpgradeName] = linkedPlugin;
143 }
144
145 onlyLinked = true;
146 }
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 84 of file SocketContextUpgradeFactorySelector.hpp.

86 {
87 SocketContextUpgradeFactory* socketContextUpgradeFactory = nullptr;
88
89 void* handle = core::DynamicLoader::dlOpen(socketContextUpgradeFactoryLibraryFile);
90
91 if (handle != nullptr) {
92 SocketContextUpgradeFactory* (*getSocketContextUpgradeFactory)() = reinterpret_cast<SocketContextUpgradeFactory* (*) ()>(
93 core::DynamicLoader::dlSym(handle, socketContextUpgradeFactoryFunctionName));
94
95 if (getSocketContextUpgradeFactory != nullptr) {
96 socketContextUpgradeFactory = getSocketContextUpgradeFactory();
97
98 if (socketContextUpgradeFactory != nullptr) {
99 if (add(socketContextUpgradeFactory, handle)) {
100 LOG(DEBUG) << "HTTP: SocketContextUpgradeFactory created successful: " << socketContextUpgradeName;
101 } else {
102 LOG(DEBUG) << "HTTP: UpgradeSocketContext already existing. Not using: " << socketContextUpgradeName;
103 delete socketContextUpgradeFactory;
104 socketContextUpgradeFactory = nullptr;
106 }
107 } else {
108 LOG(ERROR) << "HTTP: SocketContextUpgradeFactory not created: " << socketContextUpgradeName;
110 }
111 } else {
112 LOG(ERROR) << "HTTP: Optaining function \"" << socketContextUpgradeFactoryFunctionName
113 << "\" in plugin failed: " << core::DynamicLoader::dlError();
115 }
116 }
117
118 return socketContextUpgradeFactory;
119 }
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 123 of file SocketContextUpgradeFactorySelector.hpp.

123 {
124 SocketContextUpgradeFactory* socketContextUpgradeFactory = nullptr;
125
126 if (socketContextUpgradePlugins.contains(socketContextUpgradeName)) {
127 socketContextUpgradeFactory = socketContextUpgradePlugins[socketContextUpgradeName].socketContextUpgradeFactory;
128 } else if (linkedSocketContextUpgradePlugins.contains(socketContextUpgradeName)) {
129 socketContextUpgradeFactory = linkedSocketContextUpgradePlugins[socketContextUpgradeName]();
130 add(socketContextUpgradeFactory);
131 } else if (!onlyLinked) {
132 socketContextUpgradeFactory = load(socketContextUpgradeName);
133 }
134
135 return socketContextUpgradeFactory;
136 }
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 150 of file SocketContextUpgradeFactorySelector.hpp.

150 {
151 std::string upgradeContextNames = socketContextUpgradeFactory->name();
152
153 if (socketContextUpgradePlugins.contains(upgradeContextNames)) {
154 SocketContextPlugin socketContextPlugin = socketContextUpgradePlugins[upgradeContextNames];
155 socketContextUpgradePlugins.erase(upgradeContextNames);
156
157 delete socketContextUpgradeFactory;
158
159 if (socketContextPlugin.handle != nullptr) {
160 core::DynamicLoader::dlCloseDelayed(socketContextPlugin.handle);
161 }
162 }
163 }
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 97 of file SocketContextUpgradeFactorySelector.h.

◆ onlyLinked

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

Definition at line 99 of file SocketContextUpgradeFactorySelector.h.

◆ socketContextUpgradePlugins

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

Definition at line 96 of file SocketContextUpgradeFactorySelector.h.


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