00001 #ifndef RDMA_FACTORIES_H
00002 #define RDMA_FACTORIES_H
00003
00004 #include "rdma_exception.h"
00005
00006 #include <rdma/rdma_cma.h>
00007
00008 #include <boost/shared_ptr.hpp>
00009
00010 namespace Rdma {
00011
00012 void acker(::rdma_cm_event* e) throw ();
00013 void destroyEChannel(::rdma_event_channel* c) throw ();
00014 void destroyId(::rdma_cm_id* i) throw ();
00015 void deallocPd(::ibv_pd* p) throw ();
00016 void destroyCChannel(::ibv_comp_channel* c) throw ();
00017 void destroyCq(::ibv_cq* cq) throw ();
00018
00019 inline boost::shared_ptr< ::rdma_event_channel > mkEChannel() {
00020 return
00021 boost::shared_ptr< ::rdma_event_channel >(::rdma_create_event_channel(), destroyEChannel);
00022 }
00023
00024 inline boost::shared_ptr< ::rdma_cm_id >
00025 mkId(::rdma_event_channel* ec, void* context, ::rdma_port_space ps) {
00026 ::rdma_cm_id* i;
00027 CHECK(::rdma_create_id(ec, &i, context, ps));
00028 return boost::shared_ptr< ::rdma_cm_id >(i, destroyId);
00029 }
00030
00031 inline boost::shared_ptr< ::ibv_pd > allocPd(::ibv_context* c) {
00032 ::ibv_pd* pd = CHECK_NULL(ibv_alloc_pd(c));
00033 return boost::shared_ptr< ::ibv_pd >(pd, deallocPd);
00034 }
00035
00036 inline boost::shared_ptr< ::ibv_comp_channel > mkCChannel(::ibv_context* c) {
00037 ::ibv_comp_channel* cc = CHECK_NULL(::ibv_create_comp_channel(c));
00038 return boost::shared_ptr< ::ibv_comp_channel >(cc, destroyCChannel);
00039 }
00040
00041 inline boost::shared_ptr< ::ibv_cq >
00042 mkCq(::ibv_context* c, int cqe, void* context, ::ibv_comp_channel* cc) {
00043 ::ibv_cq* cq = CHECK_NULL(ibv_create_cq(c, cqe, context, cc, 0));
00044 return boost::shared_ptr< ::ibv_cq >(cq, destroyCq);
00045 }
00046 }
00047
00048 #endif // RDMA_FACTORIES_H