LCOV - code coverage report
Current view: top level - core/network - SPNetworkHandle.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2024-05-12 00:16:13 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /**
       2             : Copyright (c) 2016-2022 Roman Katuntsev <sbkarr@stappler.org>
       3             : Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       4             : 
       5             : Permission is hereby granted, free of charge, to any person obtaining a copy
       6             : of this software and associated documentation files (the "Software"), to deal
       7             : in the Software without restriction, including without limitation the rights
       8             : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9             : copies of the Software, and to permit persons to whom the Software is
      10             : furnished to do so, subject to the following conditions:
      11             : 
      12             : The above copyright notice and this permission notice shall be included in
      13             : all copies or substantial portions of the Software.
      14             : 
      15             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18             : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19             : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20             : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21             : THE SOFTWARE.
      22             : **/
      23             : 
      24             : #ifndef STAPPLER_NETWORK_SPNETWORKHANDLE_H_
      25             : #define STAPPLER_NETWORK_SPNETWORKHANDLE_H_
      26             : 
      27             : #include "SPNetworkData.h"
      28             : 
      29             : namespace STAPPLER_VERSIONIZED stappler::network {
      30             : 
      31             : template <typename Interface>
      32             : class Handle : private HandleData<Interface> {
      33             : public:
      34             :         using Method = network::Method;
      35             : 
      36             :         using DataType = HandleData<Interface>;
      37             : 
      38             :         using DataType::Vector;
      39             :         using DataType::Function;
      40             :         using DataType::Map;
      41             :         using String = typename DataType::String;
      42             :         using StringStream = typename DataType::StringStream;
      43             :         using Bytes = typename DataType::Bytes;
      44             :         using Value = typename DataType::Value;
      45             :         using ProgressCallback = typename DataType::ProgressCallback;
      46             :         using IOCallback = typename DataType::IOCallback;
      47             : 
      48        3025 :         Handle() { }
      49             : 
      50             :         Handle(Handle &&) = default;
      51             :         Handle &operator=(Handle &&) = default;
      52             : 
      53             :         bool init(Method method, StringView url);
      54             : 
      55             :         bool perform();
      56             : 
      57             :         using DataType::getResponseCode;
      58             :         using DataType::getErrorCode;
      59             :         using DataType::getError;
      60             :         using DataType::setCookieFile;
      61             :         using DataType::setUserAgent;
      62             :         using DataType::clearHeaders;
      63             :         using DataType::addHeader;
      64             :         using DataType::getRequestHeaders;
      65             :         using DataType::setMailFrom;
      66             :         using DataType::clearMailTo;
      67             :         using DataType::addMailTo;
      68             :         using DataType::setAuthority;
      69             :         using DataType::setPrivateKeyAuth;
      70             :         using DataType::setProxy;
      71             :         using DataType::setReceiveFile;
      72             :         using DataType::setReceiveCallback;
      73             :         using DataType::setResumeOffset;
      74             :         using DataType::getReceiveDataSource;
      75             :         using DataType::setSendFile;
      76             :         using DataType::setSendCallback;
      77             :         using DataType::setSendData;
      78             :         using DataType::setHeaderCallback;
      79             :         using DataType::getHeaderCallback;
      80             :         using DataType::getSendDataSource;
      81             :         using DataType::getReceivedHeaderString;
      82             :         using DataType::getReceivedHeaderInt;
      83             :         using DataType::getRecievedHeaders;
      84             :         using DataType::getMethod;
      85             :         using DataType::getUrl;
      86             :         using DataType::getCookieFile;
      87             :         using DataType::getUserAgent;
      88             :         using DataType::getResponseContentType;
      89             :         using DataType::setDebug;
      90             :         using DataType::setReuse;
      91             :         using DataType::setShared;
      92             :         using DataType::setSilent;
      93             :         using DataType::getDebugData;
      94             :         using DataType::setDownloadProgress;
      95             :         using DataType::setUploadProgress;
      96             :         using DataType::setConnectTimeout;
      97             :         using DataType::setLowSpeedLimit;
      98             :         using DataType::setVerifyTls;
      99             : 
     100             :         using Interface::AllocBaseType::operator new;
     101             :         using Interface::AllocBaseType::operator delete;
     102             : 
     103             : protected:
     104             :         template <typename I>
     105             :         friend class MultiHandle;
     106             : 
     107          42 :         HandleData<Interface> *getData() { return this; }
     108             : };
     109             : 
     110             : template <typename Interface>
     111             : class MultiHandle : public Interface::AllocBaseType {
     112             : public:
     113             :         // handle should be preserved until operation ends
     114             :         // multihandle do not stores handles by itself
     115             :         void addHandle(Handle<Interface> *handle, RefBase<Interface> *userdata) {
     116             :                 pending.emplace_back(pair(handle, userdata));
     117             :         }
     118             : 
     119             :         // sync interface:
     120             :         // returns completed handles, so it can be immediately recharged with addHandle
     121             :         bool perform(const Callback<bool(Handle<Interface> *, RefBase<Interface> *)> &);
     122             : 
     123             : protected:
     124             :         typename Interface::template VectorType<Pair<Handle<Interface> *, Rc<RefBase<Interface>>>> pending;
     125             : };
     126             : 
     127             : }
     128             : 
     129             : namespace STAPPLER_VERSIONIZED stappler::mem_std {
     130             : 
     131             : using NetworkHandle = network::Handle<memory::StandartInterface>;
     132             : 
     133             : }
     134             : 
     135             : namespace STAPPLER_VERSIONIZED stappler::mem_pool {
     136             : 
     137             : using NetworkHandle = network::Handle<memory::PoolInterface>;
     138             : 
     139             : }
     140             : 
     141             : #endif /* STAPPLER_NETWORK_SPNETWORKHANDLE_H_ */

Generated by: LCOV version 1.14