1 /* 2 * This File is part of Davix, The IO library for HTTP based protocols 3 * Copyright (C) CERN 2013 4 * Author: Adrien Devresse <adrien.devresse@cern.ch> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * 20 */ 21 22 #ifndef DAVIXCONTEXT_HPP 23 #define DAVIXCONTEXT_HPP 24 25 #include <string> 26 #include <status/davixstatusrequest.hpp> 27 #include <hooks/davix_hooks.hpp> 28 #include <utils/davix_uri.hpp> 29 30 #ifndef __DAVIX_INSIDE__ 31 #error "Only davix.h or davix.hpp should be included." 32 #endif 33 34 35 /// 36 /// @file davixcontext.hpp 37 /// @author Devresse Adrien 38 /// 39 /// Handle of Davix 40 41 namespace Davix{ 42 43 struct ContextInternal; 44 struct ContextExplorer; 45 class HookList; 46 class HttpRequest; 47 class DavPosix; 48 49 50 51 /// @brief Main handle for Davix 52 /// 53 /// Each new davix context contains its own session-reuse pool and set of parameters 54 /// a Context can execute multiple queries in parallels and is thread safe 55 class DAVIX_EXPORT Context 56 { 57 public: 58 /// 59 /// \brief Default constructor 60 /// 61 Context(); 62 /// 63 /// \brief copy constructor 64 /// \param c 65 /// 66 Context(const Context & c); 67 /// 68 /// \brief assignment operator 69 /// \param c 70 /// \return 71 /// 72 Context & operator=(const Context & c); 73 /// 74 /// \brief destructor 75 /// 76 virtual ~Context(); 77 78 /// clone this instance to a new context 79 Context* clone(); 80 81 #ifdef __DAVIX_HAS_STD_FUNCTION 82 83 /// set a new hook (callback) to intercept event in davix 84 /// see davix_hooks.hpp for more details about hooks 85 /// WARNING: setting a new HOOK override exiting ones 86 template<typename HookType> setHook(const HookType & id)87 inline void setHook(const HookType & id){ 88 hookDefine<HookType>(getHookList(), id); 89 } 90 91 /// get the value register for one type of hook 92 template<typename HookType> getHook()93 inline const HookType & getHook(){ 94 return hookGet<HookType>(getHookList()); 95 } 96 97 #endif 98 99 100 /// @brief load a plugin or a profile identified by name 101 /// @param name : name of the plugin or profile to load 102 /// 103 /// Example: loadModule("grid") configure davix 104 /// for a grid environment usage 105 void loadModule(const std::string & name); 106 107 /// enable or disable the session caching 108 void setSessionCaching(bool caching); 109 110 /// get session caching status 111 bool getSessionCaching() const; 112 113 /// clear both redirect and session cache 114 void clearCache(); 115 116 private: 117 // internal context 118 ContextInternal* _intern; 119 120 friend class DavPosix; 121 friend struct ContextExplorer; 122 HookList & getHookList(); 123 public: 124 125 /// @deprecated 126 HttpRequest* createRequest(const Uri & uri, DavixError** err); 127 /// @deprecated 128 HttpRequest* createRequest(const std::string & url, DavixError** err); 129 /// @deprecated 130 DavPosix* createDavPosix(); 131 132 private: 133 134 }; 135 136 137 /// version string of the current davix library 138 /// @return version of davix 139 DAVIX_EXPORT const std::string & version(); 140 141 } 142 143 #endif // DAVIXCONTEXT_HPP 144