Debian Codegraph @

src/neon/neonsessionfactory.hpp

raw
1 /*
2 * This File is part of Davix, The IO library for HTTP based protocols
3 * Copyright (C) CERN 2013
4 * Author: Adrien Devresse <[email protected]>
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 DAVIX_NEONSESSIONFACTORY_H
23 #define DAVIX_NEONSESSIONFACTORY_H
24
25 #include <map>
26 #include <mutex>
27 #include <utils/davix_uri.hpp>
28 #include <neon/neonrequest.hpp>
29 #include <core/SessionPool.hpp>
30
31 namespace Davix {
32
33 class HttpRequest;
34
35 struct NeonHandle {
36 NeonHandle() : session(NULL) {}
37 NeonHandle(const std::string &k, ne_session *s) : key(k), session(s) {}
38 ~NeonHandle();
39
40 std::string key;
41 ne_session *session;
42 };
43
44 typedef std::shared_ptr<NeonHandle> NeonHandlePtr;
45
46 class NEONSessionFactory
47 {
48 public:
49 NEONSessionFactory();
50 virtual ~NEONSessionFactory();
51
52 //--------------------------------------------------------------------------
53 // Create a NEONSession tied to this class.
54 //--------------------------------------------------------------------------
55 std::unique_ptr<NEONSession> provideNEONSession(const Uri &uri, const RequestParams &params, DavixError **err);
56
57 //--------------------------------------------------------------------------
58 // Store a Neon session object for session reuse purposes
59 //--------------------------------------------------------------------------
60 void storeNeonSession(NeonHandlePtr sess);
61
62 //--------------------------------------------------------------------------
63 // Set caching on or off
64 //--------------------------------------------------------------------------
65 void setSessionCaching(bool caching);
66
67 //--------------------------------------------------------------------------
68 // Get caching status
69 //--------------------------------------------------------------------------
70 bool getSessionCaching() const;
71
72 private:
73 //--------------------------------------------------------------------------
74 // Neon session pool
75 //--------------------------------------------------------------------------
76 SessionPool<NeonHandlePtr> _session_pool;
77
78 NeonHandlePtr create_session(const RequestParams & params, const std::string & protocol, const std::string &host, unsigned int port);
79 NeonHandlePtr create_recycled_session(const RequestParams & params, const std::string & protocol, const std::string &host, unsigned int port);
80
81 //--------------------------------------------------------------------------
82 // Create a brand new neon session object, internal use only.
83 //--------------------------------------------------------------------------
84 NeonHandlePtr createNeonSession(const RequestParams & params, const Uri & uri, DavixError** err);
85
86 //--------------------------------------------------------------------------
87 // Variables to control session caching
88 //--------------------------------------------------------------------------
89 mutable std::mutex _session_caching_mtx;
90 bool _session_caching;
91
92 };
93
94 std::string create_map_keys_from_URL(const std::string & protocol, const std::string &host, unsigned int port);
95
96 } // namespace Davix
97
98
99
100 #endif // DAVIX_NEONSESSIONFACTORY_H