00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #ifndef _BINDER_H_
00013 #define _BINDER_H_
00014
00015
00016 #include "ace/Thread_Mutex.h"
00017
00018 #include "ace/Synch.h"
00019 #include "ace/OS.h"
00020
00021 #include <map>
00022
00023 #include <BaseDef.h>
00024
00025 namespace channel {
00026
00027 class ConnInfo;
00028
00040 template <class IdType, class IdTrait>
00041 class Filter {
00042 public:
00043 virtual bool block_inward (IdType id) {
00044 ACE_UNUSED_ARG(id);
00045 return false;
00046 }
00047 virtual bool block_outward (IdType id) {
00048 ACE_UNUSED_ARG(id);
00049 return false;
00050 }
00051 };
00052
00061 template <class IdType, class IdTrait>
00062 class Translator {
00063 public:
00064 virtual Status translate_inward (IdType &id) {
00065 ACE_UNUSED_ARG(id);
00066 return SUCCESS;
00067 }
00068 virtual Status translate_outward (IdType &id) {
00069 ACE_UNUSED_ARG(id);
00070 return SUCCESS;
00071 }
00072 };
00073
00081 template <class IdType, class IdTrait>
00082 class Binder {
00083 public:
00084 typedef Filter<IdType, IdTrait> Filter;
00085 typedef Translator<IdType, IdTrait> Translator;
00086 Filter *filter;
00087 Translator *translator;
00088 Binder (Filter *f = NULL, Translator *t = NULL) {
00089 filter = f;
00090 translator = t;
00091 }
00092 };
00093
00100 template <class IdType, class IdTrait>
00101 class BinderRegistry {
00102 private:
00103
00104 typedef Binder<IdType, IdTrait> Binder;
00105 std::map<ConnInfo, Binder*> binder_tbl_;
00106 ACE_Thread_Mutex binder_tbl_lock_;
00107 public:
00108 BinderRegistry () {
00109 }
00110
00111 Status register_binder(ConnInfo ci, Binder *b)
00112 {
00113 ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, binder_tbl_lock_, FAILURE);
00114 binder_tbl_[ci] = b;
00115 return SUCCESS;
00116 }
00117
00118 Binder * get_binder(ConnInfo ci)
00119 {
00120 ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, binder_tbl_lock_, NULL);
00121 if (binder_tbl_.find(ci) != binder_tbl_.end())
00122 return binder_tbl_[ci];
00123 else
00124 return NULL;
00125 }
00126 };
00127
00128 };
00129
00130 #endif