00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _ENDPOINT_ID_H_
00018 #define _ENDPOINT_ID_H_
00019
00020 #include <string>
00021 #include <oasys/serialize/Serialize.h>
00022 #include <oasys/serialize/SerializableVector.h>
00023 #include <oasys/util/URI.h>
00024
00025 struct dtn_endpoint_id_t;
00026
00027 namespace dtn {
00028
00029 typedef oasys::URI URI;
00030
00031 class EndpointID;
00032 class EndpointIDPattern;
00033 class Scheme;
00034
00035 class EndpointID : public oasys::SerializableObject {
00036 public:
00040 EndpointID() : scheme_(NULL), valid_(false), is_pattern_(false) {}
00041
00045 EndpointID(const oasys::Builder&)
00046 : scheme_(NULL), valid_(false), is_pattern_(false) {}
00047
00051 EndpointID(const std::string& str)
00052 : uri_(str), scheme_(NULL), valid_(false), is_pattern_(false)
00053 {
00054 validate();
00055 }
00056
00060 EndpointID(const char* str, size_t len)
00061 : uri_(), scheme_(NULL), valid_(false), is_pattern_(false)
00062 {
00063 uri_.assign(str, len);
00064 validate();
00065 }
00069 EndpointID(const EndpointID& other)
00070 : SerializableObject(other)
00071 {
00072 if (&other != this)
00073 assign(other);
00074 }
00075
00079 virtual ~EndpointID() {}
00080
00084 bool assign(const EndpointID& other)
00085 {
00086 uri_ = other.uri_;
00087 scheme_ = other.scheme_;
00088 valid_ = other.valid_;
00089 is_pattern_ = other.is_pattern_;
00090 return true;
00091 }
00092
00097 bool assign(const std::string& str)
00098 {
00099 uri_.assign(str);
00100 return validate();
00101 }
00102
00107 bool assign(const char* str, size_t len)
00108 {
00109 uri_.assign(str, len);
00110 return validate();
00111 }
00112
00117 bool assign(const std::string& scheme, const std::string& ssp)
00118 {
00119 uri_.assign(scheme + ":" + ssp);
00120 return validate();
00121 }
00122
00126 bool equals(const EndpointID& other) const
00127 {
00128 return uri_ == other.uri_;
00129 }
00130
00134 bool operator==(const EndpointID& other) const
00135 {
00136 return uri_ == other.uri_;
00137 }
00138
00142 bool operator!=(const EndpointID& other) const
00143 {
00144 return uri_ != other.uri_;
00145 }
00146
00151 bool operator<(const EndpointID& other) const
00152 {
00153 return uri_ < other.uri_;
00154 }
00155
00159 int compare(const EndpointID& other) const
00160 {
00161 return uri_.compare(other.uri_);
00162 }
00163
00169 bool assign(const dtn_endpoint_id_t* eid);
00170
00175 bool subsume(const EndpointID& other) const
00176 { return uri_.subsume(other.uri_); }
00177
00185 bool append_service_tag(const char* tag);
00186
00194 bool append_service_wildcard();
00195
00201 bool remove_service_tag();
00202
00206 typedef enum { UNKNOWN, SINGLETON, MULTINODE } singleton_info_t;
00207
00212 singleton_info_t is_singleton() const;
00213
00217 static singleton_info_t is_singleton_default_;
00218
00222 static bool glob_unknown_schemes_;
00223
00228 void copyto(dtn_endpoint_id_t* eid) const;
00229
00233 bool known_scheme() const
00234 {
00235 return (scheme_ != NULL);
00236 }
00237
00242 inline static const EndpointID& NULL_EID();
00243
00247 static const size_t MAX_EID_PART_LENGTH = 1023;
00248
00252 virtual void serialize(oasys::SerializeAction* a);
00253
00257 const URI& uri() const { return uri_; }
00258 const std::string& str() const { return uri_.uri(); }
00259 const std::string scheme_str() const { return uri_.scheme(); }
00260 const std::string ssp() const { return uri_.ssp(); }
00261 Scheme* scheme() const { return scheme_; }
00262 bool valid() const { return valid_; }
00263 bool is_pattern() const { return is_pattern_; }
00264 const char* c_str() const { return uri_.uri().c_str(); }
00265 const char* data() const { return uri_.uri().data(); }
00266 size_t length() const { return uri_.uri().length(); }
00268
00269 protected:
00275 bool validate();
00276
00277 URI uri_;
00278
00279 Scheme* scheme_;
00280
00281 bool valid_;
00282 bool is_pattern_;
00283 };
00284
00290 class EndpointIDPattern : public EndpointID {
00291 public:
00295 EndpointIDPattern() : EndpointID()
00296 {
00297 is_pattern_ = true;
00298 uri_.set_validate(false);
00299 }
00300
00304 EndpointIDPattern(const std::string& str) : EndpointID()
00305 {
00306 is_pattern_ = true;
00307 uri_.set_validate(false);
00308 assign(str);
00309 }
00310
00314 EndpointIDPattern(const EndpointIDPattern& other)
00315 : EndpointID(other) {}
00316
00321 EndpointIDPattern(const EndpointID& other) : EndpointID(other)
00322 {
00323 is_pattern_ = true;
00324 uri_.set_validate(false);
00325 validate();
00326 }
00327
00332 bool match(const EndpointID& eid) const;
00333
00339 inline static const EndpointIDPattern& WILDCARD_EID();
00340 };
00341
00345 class EndpointIDVector : public oasys::SerializableVector<EndpointID> {};
00346
00351 struct GlobalEndpointIDs {
00352 static EndpointID null_eid_;
00353 static EndpointIDPattern wildcard_eid_;
00354 };
00355
00356
00357 inline const EndpointID&
00358 EndpointID::NULL_EID()
00359 {
00360 if (GlobalEndpointIDs::null_eid_.scheme_ == NULL) {
00361 GlobalEndpointIDs::null_eid_.assign("dtn:none");
00362 }
00363 return GlobalEndpointIDs::null_eid_;
00364 }
00365
00366
00367 inline const EndpointIDPattern&
00368 EndpointIDPattern::WILDCARD_EID()
00369 {
00370 if (GlobalEndpointIDs::wildcard_eid_.scheme_ == NULL) {
00371 GlobalEndpointIDs::wildcard_eid_.assign("*:*");
00372 }
00373
00374 return GlobalEndpointIDs::wildcard_eid_;
00375 }
00376
00377 }
00378
00379 #endif