XRootD
Loading...
Searching...
No Matches
XrdClFSExecutor.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
20#include "XrdCl/XrdClLog.hh"
23
24#include <iterator>
25
26namespace XrdCl
27{
28 //----------------------------------------------------------------------------
29 // Constructor
30 //----------------------------------------------------------------------------
31 FSExecutor::FSExecutor( const URL &url, Env *env ):
32 pFS( 0 )
33 {
34 pFS = new FileSystem( url );
35 if( env )
36 pEnv = env;
37 else
38 pEnv = new Env();
39
40 pEnv->PutString( "ServerURL", url.GetURL() );
41 }
42
43 //----------------------------------------------------------------------------
44 // Destructor
45 //----------------------------------------------------------------------------
47 {
48 delete pFS;
49 delete pEnv;
50 }
51
52 //---------------------------------------------------------------------------
53 // Add a command to the set of known commands
54 //---------------------------------------------------------------------------
55 bool FSExecutor::AddCommand( const std::string &name, Command command )
56 {
57 Log *log = DefaultEnv::GetLog();
58 CommandMap::iterator it = pCommands.find( name );
59 if( it != pCommands.end() )
60 {
61 log->Error( AppMsg, "Unable to register command %s. Already exists.",
62 name.c_str() );
63 return false;
64 }
65 pCommands.insert( std::make_pair( name, command ) );
66 return true;
67 }
68
70 {
71 std::stringstream cmdline;
72 std::ostream_iterator<std::string> oit(cmdline, " ");
73 std::copy(args.begin(), args.end(), oit);
74
75 Log *log = DefaultEnv::GetLog();
76 log->Debug( AppMsg, "Executing: %s", cmdline.str().c_str() );
77
78 if( args.empty() )
79 {
80 log->Dump( AppMsg, "Empty commandline." );
81 return 1;
82 }
83
84 CommandParams::const_iterator parIt;
85 int i = 0;
86 for( parIt = args.begin(); parIt != args.end(); ++parIt, ++i )
87 log->Dump( AppMsg, " Param #%02d: '%s'", i, parIt->c_str() );
88
89 //--------------------------------------------------------------------------
90 // Extract the command name
91 //--------------------------------------------------------------------------
92 std::string commandName = args.front();
93 CommandMap::iterator it = pCommands.find( commandName );
94 if( it == pCommands.end() )
95 {
96 log->Error( AppMsg, "Unknown command: %s", commandName.c_str() );
98 }
99
100 return it->second( pFS, pEnv, args );
101 }
102}
static Log * GetLog()
Get default log.
bool PutString(const std::string &key, const std::string &value)
Definition XrdClEnv.cc:52
std::vector< std::string > CommandParams
Definition of command argument list.
~FSExecutor()
Destructor.
FSExecutor(const URL &url, Env *env=0)
XRootDStatus Execute(const CommandParams &args)
bool AddCommand(const std::string &name, Command command)
Send file/filesystem queries to an XRootD cluster.
Handle diagnostics.
Definition XrdClLog.hh:101
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition XrdClLog.cc:231
void Dump(uint64_t topic, const char *format,...)
Print a dump message.
Definition XrdClLog.cc:299
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition XrdClLog.cc:282
URL representation.
Definition XrdClURL.hh:31
std::string GetURL() const
Get the URL.
Definition XrdClURL.hh:86
const uint16_t errUnknownCommand
const uint16_t stError
An error occurred that could potentially be retried.
const uint64_t AppMsg