00001 /* 00002 * Copyright 2007 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifdef HAVE_CONFIG_H 00018 #include <dtn-config.h> 00019 #endif 00020 00021 #include <oasys/util/StringBuffer.h> 00022 00023 #include "SessionTable.h" 00024 #include "Session.h" 00025 #include "naming/EndpointID.h" 00026 00027 namespace dtn { 00028 00029 //---------------------------------------------------------------------- 00030 SessionTable::SessionTable() 00031 { 00032 } 00033 00034 //---------------------------------------------------------------------- 00035 Session* 00036 SessionTable::lookup_session(const EndpointID& eid) const 00037 { 00038 SessionMap::const_iterator iter = table_.find(eid); 00039 if (iter == table_.end()) 00040 return NULL; 00041 00042 return iter->second; 00043 } 00044 00045 //---------------------------------------------------------------------- 00046 void 00047 SessionTable::add_session(Session* s) 00048 { 00049 ASSERT(lookup_session(s->eid()) == NULL); 00050 00051 table_[s->eid()] = s; 00052 } 00053 00054 //---------------------------------------------------------------------- 00055 Session* 00056 SessionTable::get_session(const EndpointID& eid) 00057 { 00058 Session* session = lookup_session(eid); 00059 if (! session) { 00060 session = new Session(eid); 00061 add_session(session); 00062 } 00063 return session; 00064 } 00065 00066 //---------------------------------------------------------------------- 00067 void 00068 SessionTable::dump(oasys::StringBuffer* buf) const 00069 { 00070 SessionMap::const_iterator i; 00071 SubscriberList::const_iterator j; 00072 for (i = table_.begin(); i != table_.end(); ++i) { 00073 00074 Session* session = i->second; 00075 buf->appendf(" %s upstream=*%p subscribers=", 00076 session->eid().c_str(), &session->upstream()); 00077 00078 for (j = session->subscribers().begin(); 00079 j != session->subscribers().end(); ++j) { 00080 00081 const Subscriber& sub = *j; 00082 if (sub == session->upstream()) { 00083 continue; 00084 } 00085 buf->appendf("*%p ", &sub); 00086 } 00087 buf->appendf("\n"); 00088 } 00089 } 00090 00091 } // namespace dtn 00092