1/* 2 * Copyright (c) 2008 - 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#ifndef RPC_HELPERS_HPP_142C40C1_6E87_4460_9641_01748A09BDC3 25#define RPC_HELPERS_HPP_142C40C1_6E87_4460_9641_01748A09BDC3 26 27#include <vector> 28 29extern "C" { 30#include <dce/dcethread.h> 31} 32 33struct rpc_mempool 34{ 35 typedef std::vector<void *> ptr_list_type; 36 37 rpc_mempool(); 38 ~rpc_mempool(); 39 40 void * alloc(size_t sz); 41 void free(void * ptr); 42 43 static inline unsigned block_size() { 44 return roundup(sizeof(struct rpc_mempool), 16); 45 } 46 47 static rpc_mempool * allocate(size_t); 48 static void destroy(rpc_mempool *); 49 50private: 51 ptr_list_type ptrs; 52}; 53 54template <typename T> 55std::pair<rpc_mempool *, T *> 56allocate_rpc_mempool(void) 57{ 58 std::pair<rpc_mempool *, T *> ret; 59 60 ret.first = rpc_mempool::allocate(sizeof(T)); 61 ret.second = (T *)(void *)((uint8_t *)ret.first + rpc_mempool::block_size()); 62 63 return ret; 64} 65 66idl_void_p_t 67rpc_pool_allocate( 68 idl_void_p_t context, 69 idl_size_t sz 70 ); 71 72void 73rpc_pool_free( 74 idl_void_p_t context, 75 idl_void_p_t ptr 76 ); 77 78struct rpc_binding 79{ 80 rpc_binding() : binding_handle(0) {} 81 rpc_binding(const rpc_binding&); 82 ~rpc_binding(); 83 84 explicit rpc_binding(const char * string_binding); 85 86 rpc_binding_handle_t get() const { 87 return binding_handle; 88 } 89 90 void swap(rpc_binding& rhs) { 91 std::swap(this->binding_handle, rhs.binding_handle); 92 } 93 94 rpc_binding& operator=(const rpc_binding& rhs) { 95 rpc_binding tmp(rhs); 96 this->swap(tmp); 97 return *this; 98 } 99 100private: 101 rpc_binding_handle_t binding_handle; 102}; 103 104// Return an appropriate binding for the given ServerName. 105rpc_binding 106make_rpc_binding( 107 const char * ServerName, 108 const char * EndPoint 109 ); 110 111// Convert a DCE exception into an error code. 112error_status_t 113rpc_exception_status( 114 dcethread_exc * 115 ); 116 117#endif /* RPC_HELPERS_HPP_142C40C1_6E87_4460_9641_01748A09BDC3 */ 118/* vim: set sw=4 ts=4 tw=79 et: */