servlib/naming/Scheme.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2005-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 _SCHEME_H_
       
    18 #define _SCHEME_H_
       
    19 
       
    20 #include <string>
       
    21 
       
    22 #include <oasys/util/URI.h>
       
    23 #include "EndpointID.h"
       
    24 
       
    25 namespace dtn {
       
    26 
       
    27 typedef oasys::URI URI;
       
    28 
       
    29 class EndpointID;
       
    30 class EndpointIDPattern;
       
    31 
       
    32 /**
       
    33  * The base class for various endpoint id schemes. The class provides
       
    34  * two pure virtual methods -- validate() and match() -- that are
       
    35  * overridden by the various scheme implementations.
       
    36  */
       
    37 class Scheme {
       
    38 public:
       
    39     /**
       
    40      * Destructor -- should be called only at shutdown time.
       
    41      */
       
    42     virtual ~Scheme();
       
    43 
       
    44     /**
       
    45      * Validate that the SSP within the given URI is legitimate for
       
    46      * this scheme. If the 'is_pattern' paraemeter is true, then the
       
    47      * ssp is being validated as an EndpointIDPattern.
       
    48      *
       
    49      * @return true if valid
       
    50      */
       
    51     virtual bool validate(const URI& uri, bool is_pattern = false) = 0;
       
    52 
       
    53     /**
       
    54      * Match the pattern to the endpoint id in a scheme-specific
       
    55      * manner.
       
    56      */
       
    57     virtual bool match(const EndpointIDPattern& pattern,
       
    58                        const EndpointID& eid) = 0;
       
    59     
       
    60     /**
       
    61      * Append the given service tag to the uri in a scheme-specific
       
    62      * manner. By default, the scheme is not capable of this.
       
    63      *
       
    64      * @return true if this scheme is capable of service tags and the
       
    65      * tag is a legal one, false otherwise.
       
    66      */
       
    67     virtual bool append_service_tag(URI* uri, const char* tag)
       
    68     {
       
    69         (void)uri;
       
    70         (void)tag;
       
    71         return false;
       
    72     }
       
    73 
       
    74     /**
       
    75      * Append wildcard to the uri in a scheme-specific manner. The
       
    76      * default scheme is not capable of this.
       
    77      *
       
    78      * @return true if this scheme is capable of wildcards and the
       
    79      * wildcard is successfully appended, else false.
       
    80      */
       
    81     virtual bool append_service_wildcard(URI* uri)
       
    82     {
       
    83         (void)uri;
       
    84         return false;
       
    85     }
       
    86 
       
    87     /**
       
    88      * Reduce URI to node ID in a scheme specific manner. The default
       
    89      * scheme is not capable of this.
       
    90      *
       
    91      * @return true if this scheme is capable of this reduction and 
       
    92      * the reduction is successful, else false.
       
    93      */
       
    94     virtual bool remove_service_tag(URI* uri)
       
    95     {
       
    96         (void)uri;
       
    97         return false;
       
    98     }
       
    99 
       
   100     /**
       
   101      * Copy of the EndpointID's type structure for determining if the
       
   102      * endpoint is, is not, or may be a singleton.
       
   103      */
       
   104     typedef EndpointID::singleton_info_t singleton_info_t;
       
   105     
       
   106     /**
       
   107      * Check if the given URI is a singleton endpoint id.
       
   108      */
       
   109     virtual singleton_info_t is_singleton(const URI& uri) = 0;
       
   110 };
       
   111     
       
   112 }
       
   113 
       
   114 #endif /* _SCHEME_H_ */