apps/tca_admin/TcaEndpointID.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2005-2006 University of Waterloo
       
     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 
       
    18 #ifndef _TCA_ENDPOINTID_H_
       
    19 #define _TCA_ENDPOINTID_H_
       
    20 
       
    21 
       
    22 #include <string>
       
    23 #include "dtn_types.h"
       
    24 
       
    25 
       
    26 // Warning: This is a special version of the TcaEndpointID class for use
       
    27 // on the client side of the interface. The difference is that the other
       
    28 // TcaEndpointID class (used in the servlib source tree) is subclassed from
       
    29 // EndpointID, which isn't available here.  
       
    30 // The interface is almost identical.
       
    31 
       
    32 class TcaEndpointID
       
    33 {
       
    34 public:
       
    35     TcaEndpointID() : valid_(false), host_(""), app_("") { }
       
    36     TcaEndpointID(const dtn_endpoint_id_t& eid);
       
    37     TcaEndpointID(const std::string& str);
       
    38     TcaEndpointID(const std::string& host, const std::string& app);
       
    39     TcaEndpointID(const TcaEndpointID& eid);
       
    40 
       
    41     const std::string& host() const { return host_; }
       
    42     const std::string& app() const { return app_; }
       
    43     
       
    44     const std::string str() const { return "tca://" + host_ + "/" + app_; }
       
    45     const char* c_str() const { return str().c_str(); }
       
    46 
       
    47     void set_host(const std::string& host);
       
    48     void set_app(const std::string& app);
       
    49 
       
    50     const std::string get_hostid() const
       
    51         { return std::string("tca://") + host_; }
       
    52 
       
    53     static inline std::string
       
    54     build(const std::string& host, const std::string& app)
       
    55         { return std::string("tca://") + host + "/" + app; }
       
    56     
       
    57 protected:
       
    58     // TcaEndpointID caches host part and app part for easy lookup, but
       
    59     // always maintains the base class strings as well.
       
    60     bool valid_;
       
    61     std::string host_;
       
    62     std::string app_;
       
    63     void parse(const std::string& str);
       
    64     
       
    65 };
       
    66 
       
    67 
       
    68 
       
    69 #endif /* _TCA_ENDPOINTID_H_ */