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 #ifndef _SUBSCRIBER_H_ 00018 #define _SUBSCRIBER_H_ 00019 00020 #include <vector> 00021 00022 #include <oasys/debug/DebugUtils.h> 00023 #include <oasys/debug/Formatter.h> 00024 00025 #include "naming/EndpointID.h" 00026 00027 namespace dtn { 00028 00029 class Registration; 00030 00035 class Subscriber : public oasys::Formatter { 00036 public: 00038 Subscriber() 00039 : reg_(NULL), nexthop_(EndpointID::NULL_EID()) {} 00040 00042 Subscriber(Registration* reg) 00043 : reg_(reg), nexthop_(EndpointID::NULL_EID()) {} 00044 00046 Subscriber(const EndpointID& nexthop) 00047 : reg_(NULL), nexthop_(nexthop) {} 00048 00050 virtual ~Subscriber(); 00051 00053 int format(char* buf, size_t sz) const; 00054 00056 bool operator==(const Subscriber& other) const; 00057 00059 bool is_null() const; 00060 bool is_local() const { return reg_ != NULL; } 00061 Registration* reg() const { ASSERT(is_local()); return reg_; } 00062 const EndpointID& nexthop() const { ASSERT(!is_local()); return nexthop_; } 00064 00065 protected: 00066 Registration* reg_; 00067 EndpointID nexthop_; 00068 }; 00069 00070 //---------------------------------------------------------------------- 00071 inline bool 00072 Subscriber::is_null() const 00073 { 00074 return (reg_ == NULL && nexthop_ == EndpointID::NULL_EID()); 00075 } 00076 00080 typedef std::vector<Subscriber> SubscriberList; 00081 00082 } // namespace dtn 00083 00084 #endif /* _SUBSCRIBER_H_ */