servlib/reg/RegistrationTable.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2004-2006 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 _REGISTRATION_TABLE_H_
       
    18 #define _REGISTRATION_TABLE_H_
       
    19 
       
    20 #include <string>
       
    21 #include <oasys/debug/DebugUtils.h>
       
    22 #include <oasys/util/StringBuffer.h>
       
    23 
       
    24 #include "Registration.h"
       
    25 
       
    26 namespace dtn {
       
    27 
       
    28 /**
       
    29  * Class for the in-memory registration table. All changes to the
       
    30  * table are made persistent via the RegistrationStore.
       
    31  */
       
    32 class RegistrationTable : public oasys::Logger {
       
    33 public:
       
    34     /**
       
    35      * Constructor
       
    36      */
       
    37     RegistrationTable();
       
    38 
       
    39     /**
       
    40      * Destructor
       
    41      */
       
    42     virtual ~RegistrationTable();
       
    43 
       
    44     /**
       
    45      * Add a new registration to the database. Returns true if the
       
    46      * registration is successfully added, false if there's another
       
    47      * registration with the same {endpoint,regid}.
       
    48      *
       
    49      * The flag controls whether or not the registration is added to
       
    50      * the persistent store, which is only done for registrations
       
    51      * added from the RPC interface.
       
    52      */
       
    53     bool add(Registration* reg, bool add_to_store = true);
       
    54 
       
    55     /**
       
    56      * Look up a matching registration.
       
    57      */
       
    58     Registration* get(u_int32_t regid) const;
       
    59 
       
    60     /**
       
    61      * Look up the first matching registration for the exact endpoint
       
    62      * id pattern given.
       
    63      */
       
    64     Registration* get(const EndpointIDPattern& eid) const;
       
    65 
       
    66     /**
       
    67      * Remove the registration from the database, returns true if
       
    68      * successful, false if the registration didn't exist.
       
    69      */
       
    70     bool del(u_int32_t regid);
       
    71     
       
    72     /**
       
    73      * Update the registration in the database. Returns true on
       
    74      * success, false on error.
       
    75      */
       
    76     bool update(Registration* reg);
       
    77     
       
    78     /**
       
    79      * Populate the given reglist with all registrations with an
       
    80      * endpoint id that matches the bundle demux string.
       
    81      *
       
    82      * Returns the count of matching registrations.
       
    83      */
       
    84     int get_matching(const EndpointID& eid, RegistrationList* reg_list) const;
       
    85     
       
    86     /**
       
    87      * Delete any expired registrations
       
    88      *
       
    89      * (was sweepOldRegistrations)
       
    90      */
       
    91     int delete_expired(const time_t now);
       
    92 
       
    93     /**
       
    94      * Dump out the registration database.
       
    95      */
       
    96     void dump(oasys::StringBuffer* buf) const;
       
    97 
       
    98     /**
       
    99      * Return the routing table.  Asserts that the RegistrationTable
       
   100      * spin lock is held by the caller.
       
   101      */
       
   102     const RegistrationList *reg_list() const;
       
   103 
       
   104     /**
       
   105      * Accessor for the RouteTable internal lock.
       
   106      */
       
   107     oasys::Lock* lock() const { return &lock_; }
       
   108 
       
   109 protected:
       
   110     /**
       
   111      * Internal method to find the location of the given registration.
       
   112      */
       
   113     bool find(u_int32_t regid, RegistrationList::iterator* iter);
       
   114 
       
   115     /**
       
   116      * All registrations are tabled in-memory in a flat list. It's
       
   117      * non-obvious what else would be better since we need to do a
       
   118      * prefix match on demux strings in matching_registrations.
       
   119      */
       
   120     RegistrationList reglist_;
       
   121 
       
   122     /**
       
   123      * Lock to protect internal data structures.
       
   124      */
       
   125     mutable oasys::SpinLock lock_;
       
   126 };
       
   127 
       
   128 } // namespace dtn
       
   129 
       
   130 #endif /* _REGISTRATION_TABLE_H_ */