Changeset 2473 for source/ariba/utility/misc
- Timestamp:
- Feb 23, 2009, 2:21:49 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/misc/Demultiplexer.hpp
r2472 r2473 41 41 42 42 #include <list> 43 #include <iostream> 43 44 #include <map> 44 45 #include <boost/thread/mutex.hpp> … … 46 47 #include "ariba/utility/messages/Message.h" 47 48 49 using std::cout; 48 50 using std::list; 49 51 using std::map; … … 73 75 boost::mutex mapMutex; 74 76 77 void debugprint() { 78 cout << "-------------start--------" << std::endl; 79 { 80 LISTENER_SERVICE_MAP_CITERATOR i = mapListenerService.begin(); 81 LISTENER_SERVICE_MAP_CITERATOR iend = mapListenerService.end(); 82 83 for( ; i != iend; i++ ) 84 cout << "xxx" << i->first.toString() << " -> " << i->second << std::endl; 85 } 86 cout << "-----------------------" << std::endl; 87 { 88 SERVICE_LISTENER_MAP_CITERATOR i = mapServiceListener.begin(); 89 SERVICE_LISTENER_MAP_CITERATOR iend = mapServiceListener.end(); 90 91 for( ; i != iend; i++ ) 92 cout << "xxx" << i->first << " -> " << i->second.toString() << std::endl; 93 } 94 cout << "-------------end---------" << std::endl; 95 } 96 75 97 public: 76 98 … … 83 105 void registerItem( S id, T listener ) { 84 106 boost::mutex::scoped_lock lock( mapMutex ); 85 { 86 mapServiceListener.insert( SERVICE_LISTENER_PAIR( id, listener ) ); 87 mapListenerService.insert( LISTENER_SERVICE_PAIR( listener, id ) ); 88 } 107 108 mapServiceListener.insert( SERVICE_LISTENER_PAIR( id, listener ) ); 109 mapListenerService.insert( LISTENER_SERVICE_PAIR( listener, id ) ); 89 110 } 90 111 91 void unregisterItem( S id ) {112 void unregisterItem( S id ) { 92 113 T listener = get( id ); 93 94 boost::mutex::scoped_lock lock( mapMutex ); 114 95 115 { 116 boost::mutex::scoped_lock lock( mapMutex ); 96 117 mapServiceListener.erase( id ); 97 118 mapListenerService.erase( listener ); … … 100 121 101 122 void unregisterItem( T listener ) { 102 S id = get (listener);123 S id = get( listener ); 103 124 unregisterItem( id ); 104 125 } … … 106 127 S get( T listener ) { 107 128 boost::mutex::scoped_lock lock( mapMutex ); 108 { 109 LISTENER_SERVICE_MAP_CITERATOR it = mapListenerService.find( listener ); 110 return it->second; 111 } 129 130 LISTENER_SERVICE_MAP_CITERATOR it = mapListenerService.find( listener ); 131 return it->second; 112 132 } 113 133 114 134 T get( S id ) { 115 135 boost::mutex::scoped_lock lock( mapMutex ); 116 {117 SERVICE_LISTENER_MAP_CITERATOR it = mapServiceListener.find( id );118 136 119 if( it == mapServiceListener.end() ) return NULL;120 else return it->second;121 }137 SERVICE_LISTENER_MAP_CITERATOR it = mapServiceListener.find( id ); 138 if( it == mapServiceListener.end() ) return NULL; 139 else return it->second; 122 140 } 123 141 124 142 bool contains( T listener ) { 125 143 boost::mutex::scoped_lock lock( mapMutex ); 126 { 127 LISTENER_SERVICE_MAP_CITERATOR it = mapListenerService.find( listener ); 128 return ( it != mapListenerService.end() ); 129 } 144 145 LISTENER_SERVICE_MAP_CITERATOR it = mapListenerService.find( listener ); 146 return ( it != mapListenerService.end() ); 130 147 } 131 148 132 149 bool contains( S id ) { 133 150 boost::mutex::scoped_lock lock( mapMutex ); 134 { 135 SERVICE_LISTENER_MAP_CITERATOR it = mapServiceListener.find( id ); 136 return ( it != mapServiceListener.end() ); 137 } 151 152 SERVICE_LISTENER_MAP_CITERATOR it = mapServiceListener.find( id ); 153 return ( it != mapServiceListener.end() ); 138 154 } 139 155 … … 141 157 typedef list<T> TwoList; 142 158 143 OneList getOneList() const { 159 OneList getOneList() { 160 boost::mutex::scoped_lock lock( mapMutex ); 144 161 OneList ret; 145 162 … … 151 168 } 152 169 153 TwoList getTwoList() const { 170 TwoList getTwoList() { 171 boost::mutex::scoped_lock lock( mapMutex ); 154 172 TwoList ret; 155 173
Note:
See TracChangeset
for help on using the changeset viewer.