1 // Copyright 2021 The gRPC Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #include <grpc/support/port_platform.h> 15 16 #include "grpc/event_engine/slice_allocator.h" 17 18 #include <functional> 19 20 #include "absl/status/status.h" 21 22 #include "src/core/lib/iomgr/resource_quota.h" 23 24 namespace grpc_event_engine { 25 namespace experimental { 26 SliceAllocator(grpc_resource_user * user)27SliceAllocator::SliceAllocator(grpc_resource_user* user) 28 : resource_user_(user) { 29 grpc_resource_user_ref(resource_user_); 30 }; 31 ~SliceAllocator()32SliceAllocator::~SliceAllocator() { grpc_resource_user_unref(resource_user_); }; 33 Allocate(size_t size,SliceBuffer * dest,SliceAllocator::AllocateCallback cb)34absl::Status SliceAllocator::Allocate(size_t size, SliceBuffer* dest, 35 SliceAllocator::AllocateCallback cb) { 36 // TODO(hork): implement 37 (void)size; 38 (void)dest; 39 (void)cb; 40 return absl::OkStatus(); 41 }; 42 SliceAllocatorFactory(grpc_resource_quota * quota)43SliceAllocatorFactory::SliceAllocatorFactory(grpc_resource_quota* quota) 44 : resource_quota_(quota) { 45 grpc_resource_quota_ref_internal(resource_quota_); 46 }; 47 ~SliceAllocatorFactory()48SliceAllocatorFactory::~SliceAllocatorFactory() { 49 grpc_resource_quota_unref_internal(resource_quota_); 50 } 51 CreateSliceAllocator(absl::string_view peer_name)52SliceAllocator SliceAllocatorFactory::CreateSliceAllocator( 53 absl::string_view peer_name) { 54 return SliceAllocator( 55 grpc_resource_user_create(resource_quota_, peer_name.data())); 56 } 57 58 } // namespace experimental 59 } // namespace grpc_event_engine 60