AWS SDK for C++  0.12.9
AWS SDK for C++
ScopedResourceSet.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License").
6  * You may not use this file except in compliance with the License.
7  * A copy of the License is located at
8  *
9  * http://aws.amazon.com/apache2.0
10  *
11  * or in the "license" file accompanying this file. This file is distributed
12  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 
17 #pragma once
18 
20 
22 
23 namespace Aws
24 {
25 namespace Transfer
26 {
27 
28 template< typename T >
30 {
31  public:
32 
33  ScopedResourceSet(uint32_t resourceCount, const std::shared_ptr< ResourceManagerInterface< T > >& resourceManager);
35 
36  void TryReacquire();
37 
38  const typename ResourceManagerInterface< T >::ResourceListType& GetResources() const { return m_resources; }
39 
40  private:
41 
42  uint32_t m_desiredResourceCount;
43 
45 
46  std::shared_ptr< ResourceManagerInterface< T > > m_resourceOwner;
47 };
48 
49 template< typename T >
50 ScopedResourceSet< T >::ScopedResourceSet(uint32_t resourceCount, const std::shared_ptr< ResourceManagerInterface< T > >& resourceManager) :
51  m_desiredResourceCount(resourceCount),
52  m_resources(),
53  m_resourceOwner(resourceManager)
54 {
55  m_resourceOwner->AcquireResources(m_desiredResourceCount, m_resources);
56 }
57 
58 template< typename T >
60 {
61  m_resourceOwner->ReleaseResources(m_resources);
62 }
63 
64 template< typename T >
66 {
67  if(m_desiredResourceCount > m_resources.size())
68  {
69  m_resourceOwner->TryAcquireResources(m_desiredResourceCount, m_resources);
70  }
71 }
72 
73 } // namespace Transfer
74 } // namespace Aws
const ResourceManagerInterface< T >::ResourceListType & GetResources() const
ScopedResourceSet(uint32_t resourceCount, const std::shared_ptr< ResourceManagerInterface< T > > &resourceManager)
JSON (JavaScript Object Notation).