XRootD
Loading...
Searching...
No Matches
XrdClPollerFactory.cc
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3// Author: Lukasz Janyst <ljanyst@cern.ch>
4//------------------------------------------------------------------------------
5// XRootD is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// XRootD is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17//------------------------------------------------------------------------------
18
22#include "XrdCl/XrdClLog.hh"
23#include "XrdCl/XrdClUtils.hh"
25#include <map>
26#include <vector>
27
28//------------------------------------------------------------------------------
29// Poller creators
30//------------------------------------------------------------------------------
31namespace
32{
33 XrdCl::Poller *createBuiltIn()
34 {
35 return new XrdCl::PollerBuiltIn();
36 }
37};
38
39namespace XrdCl
40{
41 //------------------------------------------------------------------------
42 // Create a poller object, try in order of preference
43 //------------------------------------------------------------------------
44 Poller *PollerFactory::CreatePoller( const std::string &preference )
45 {
46 Log *log = DefaultEnv::GetLog();
47
48 //--------------------------------------------------------------------------
49 // Create a list of known pollers
50 //--------------------------------------------------------------------------
51 typedef std::map<std::string, Poller *(*)()> PollerMap;
52 PollerMap pollerMap;
53 pollerMap["built-in"] = createBuiltIn;
54
55 //--------------------------------------------------------------------------
56 // Print the list of available pollers
57 //--------------------------------------------------------------------------
58 PollerMap::iterator it;
59 std::string available;
60 for( it = pollerMap.begin(); it != pollerMap.end(); ++it )
61 {
62 available += it->first; available += ", ";
63 }
64 if( !available.empty() )
65 available.erase( available.length()-2, 2 );
66 log->Debug( PollerMsg, "Available pollers: %s", available.c_str() );
67
68 //--------------------------------------------------------------------------
69 // Try to create a poller
70 //--------------------------------------------------------------------------
71 if( preference.empty() )
72 {
73 log->Error( PollerMsg, "Poller preference list is empty" );
74 return 0;
75 }
76 log->Debug( PollerMsg, "Attempting to create a poller according to "
77 "preference: %s", preference.c_str() );
78
79 std::vector<std::string> prefs;
80 std::vector<std::string>::iterator itP;
81 Utils::splitString( prefs, preference, "," );
82 for( itP = prefs.begin(); itP != prefs.end(); ++itP )
83 {
84 it = pollerMap.find( *itP );
85 if( it == pollerMap.end() )
86 {
87 log->Debug( PollerMsg, "Unable to create poller: %s",
88 itP->c_str() );
89 continue;
90 }
91 log->Debug( PollerMsg, "Creating poller: %s", itP->c_str() );
92 return (*it->second)();
93 }
94
95 return 0;
96 }
97}
static Log * GetLog()
Get default log.
Handle diagnostics.
Definition XrdClLog.hh:101
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition XrdClLog.cc:231
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition XrdClLog.cc:282
A poller implementation using the build-in XRootD poller.
static Poller * CreatePoller(const std::string &preference)
Interface for socket pollers.
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
Definition XrdClUtils.hh:56
const uint64_t PollerMsg