servlib/session/Subscriber.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2007 Intel Corporation
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifndef _SUBSCRIBER_H_
       
    18 #define _SUBSCRIBER_H_
       
    19 
       
    20 #include <vector>
       
    21 
       
    22 #include <oasys/debug/DebugUtils.h>
       
    23 #include <oasys/debug/Formatter.h>
       
    24 
       
    25 #include "naming/EndpointID.h"
       
    26 
       
    27 namespace dtn {
       
    28 
       
    29 class Registration;
       
    30 
       
    31 /**
       
    32  * A subscriber for a session is either a local registration or a next
       
    33  * hop destination.
       
    34  */
       
    35 class Subscriber : public oasys::Formatter {
       
    36 public:
       
    37     /// Constructor for a NULL subscriber (used for 
       
    38     Subscriber()
       
    39         : reg_(NULL), nexthop_(EndpointID::NULL_EID()) {}
       
    40     
       
    41     /// Constructor for a local subscriber
       
    42     Subscriber(Registration* reg)
       
    43         : reg_(reg), nexthop_(EndpointID::NULL_EID()) {}
       
    44 
       
    45     /// Constructor for a remote subscriber
       
    46     Subscriber(const EndpointID& nexthop)
       
    47         : reg_(NULL), nexthop_(nexthop) {}
       
    48 
       
    49     /// Destructor
       
    50     virtual ~Subscriber();
       
    51 
       
    52     /// Virtual from Formatter
       
    53     int format(char* buf, size_t sz) const;
       
    54 
       
    55     /// Comparison operator
       
    56     bool operator==(const Subscriber& other) const;
       
    57 
       
    58     /// @{ Accessors
       
    59     bool              is_null()  const;
       
    60     bool              is_local() const { return reg_ != NULL; }
       
    61     Registration*  reg()         const { ASSERT(is_local()); return reg_; }
       
    62     const EndpointID& nexthop()  const { ASSERT(!is_local()); return nexthop_; }
       
    63     /// @}
       
    64 
       
    65 protected:
       
    66     Registration* reg_;
       
    67     EndpointID    nexthop_;
       
    68 };
       
    69 
       
    70 //----------------------------------------------------------------------
       
    71 inline bool
       
    72 Subscriber::is_null() const
       
    73 {
       
    74     return (reg_ == NULL && nexthop_ == EndpointID::NULL_EID());
       
    75 }
       
    76 
       
    77 /**
       
    78  * Type for a vector of subscriber objects.
       
    79  */
       
    80 typedef std::vector<Subscriber> SubscriberList;
       
    81 
       
    82 } // namespace dtn
       
    83 
       
    84 #endif /* _SUBSCRIBER_H_ */