|
1 /* |
|
2 * Copyright 2007 Baylor University |
|
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 _PROPHET_LINK_FACADE_H_ |
|
18 #define _PROPHET_LINK_FACADE_H_ |
|
19 |
|
20 #include <string.h> |
|
21 #include <string> |
|
22 |
|
23 #include "AckList.h" |
|
24 |
|
25 namespace prophet |
|
26 { |
|
27 |
|
28 class Link |
|
29 { |
|
30 public: |
|
31 /** |
|
32 * Destructor |
|
33 */ |
|
34 virtual ~Link() {} |
|
35 |
|
36 ///@{ Accessors |
|
37 virtual const char* nexthop() const = 0; |
|
38 virtual const char* remote_eid() const = 0; |
|
39 AckList* acks() { return &acks_; } |
|
40 ///@} |
|
41 |
|
42 ///@{ Operators |
|
43 virtual bool operator==(const Link* l) const |
|
44 { return strncmp(nexthop(),l->nexthop(),strlen(nexthop())) == 0; } |
|
45 virtual bool operator<(const Link* l) const |
|
46 { return strncmp(nexthop(),l->nexthop(),strlen(nexthop())) < 0; } |
|
47 virtual bool operator==(const Link& l) const |
|
48 { return strncmp(nexthop(),l.nexthop(),strlen(nexthop())) == 0; } |
|
49 virtual bool operator<(const Link& l) const |
|
50 { return strncmp(nexthop(),l.nexthop(),strlen(nexthop())) < 0; } |
|
51 ///@} |
|
52 |
|
53 protected: |
|
54 mutable AckList acks_; ///< track what's been sent, so we don't send more than once |
|
55 |
|
56 }; // class Link |
|
57 |
|
58 class LinkImpl : public Link |
|
59 { |
|
60 public: |
|
61 /** |
|
62 * Constructor |
|
63 */ |
|
64 LinkImpl(const std::string& nexthop = "") : |
|
65 next_hop_(nexthop) {} |
|
66 |
|
67 /** |
|
68 * Destructor |
|
69 */ |
|
70 virtual ~LinkImpl() {} |
|
71 |
|
72 ///@{ Accessors |
|
73 const char* nexthop() const { return next_hop_.c_str(); } |
|
74 const char* remote_eid() const { return next_hop_.c_str(); } |
|
75 ///@} |
|
76 |
|
77 ///@{ Mutators |
|
78 void set_nexthop( const std::string& nexthop ) |
|
79 { |
|
80 next_hop_.assign(nexthop); |
|
81 } |
|
82 ///@} |
|
83 |
|
84 protected: |
|
85 std::string next_hop_; |
|
86 }; // class LinkImpl |
|
87 |
|
88 }; // namespace prophet |
|
89 |
|
90 #endif // _PROPHET_LINK_FACADE_H_ |