00001 /* 00002 * Copyright 2005-2006 University of Waterloo 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 00018 #ifndef _TCA_ENDPOINTID_H_ 00019 #define _TCA_ENDPOINTID_H_ 00020 00021 00022 #include <string> 00023 #include "dtn_types.h" 00024 00025 00026 // Warning: This is a special version of the TcaEndpointID class for use 00027 // on the client side of the interface. The difference is that the other 00028 // TcaEndpointID class (used in the servlib source tree) is subclassed from 00029 // EndpointID, which isn't available here. 00030 // The interface is almost identical. 00031 00032 class TcaEndpointID 00033 { 00034 public: 00035 TcaEndpointID() : valid_(false), host_(""), app_("") { } 00036 TcaEndpointID(const dtn_endpoint_id_t& eid); 00037 TcaEndpointID(const std::string& str); 00038 TcaEndpointID(const std::string& host, const std::string& app); 00039 TcaEndpointID(const TcaEndpointID& eid); 00040 00041 const std::string& host() const { return host_; } 00042 const std::string& app() const { return app_; } 00043 00044 const std::string str() const { return "tca://" + host_ + "/" + app_; } 00045 const char* c_str() const { return str().c_str(); } 00046 00047 void set_host(const std::string& host); 00048 void set_app(const std::string& app); 00049 00050 const std::string get_hostid() const 00051 { return std::string("tca://") + host_; } 00052 00053 static inline std::string 00054 build(const std::string& host, const std::string& app) 00055 { return std::string("tca://") + host + "/" + app; } 00056 00057 protected: 00058 // TcaEndpointID caches host part and app part for easy lookup, but 00059 // always maintains the base class strings as well. 00060 bool valid_; 00061 std::string host_; 00062 std::string app_; 00063 void parse(const std::string& str); 00064 00065 }; 00066 00067 00068 00069 #endif /* _TCA_ENDPOINTID_H_ */