00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __PANA_DEVICE_ID_H__
00035 #define __PANA_DEVICE_ID_H__
00036
00037 #include <string>
00038 #include <list>
00039 #include "ace/OS.h"
00040
00058 class PANA_DeviceId
00059 {
00060 public:
00061 typedef enum {
00062 UNKNOWN = 0,
00063 IPV4_ADDRESS = 1,
00064 IPV6_ADDRESS = 2,
00065 LL_ADDRESS = 3
00066 } TYPE;
00067
00068 public:
00069 PANA_DeviceId(PANA_DeviceId::TYPE type, std::string &id) :
00070 m_Type(type), m_Id(id) {
00071 }
00072 PANA_DeviceId(PANA_DeviceId::TYPE type) : m_Type(type) {
00073 }
00074 PANA_DeviceId() {
00075 }
00076 void type(PANA_DeviceId::TYPE t) {
00077 m_Type = t;
00078 }
00079 PANA_DeviceId::TYPE type() {
00080 return m_Type;
00081 }
00082 const std::string &id() {
00083 return m_Id;
00084 }
00085 bool operator==(PANA_DeviceId &cmp) {
00086 return (ACE_OS::memcmp(m_Id.data(), cmp.id().data(),
00087 m_Id.size()) == 0);
00088 }
00089 PANA_DeviceId &operator=(PANA_DeviceId &src) {
00090 m_Type = src.type();
00091 m_Id.assign(src.id().data(), src.id().size());
00092 return (*this);
00093 }
00094
00095 protected:
00096 TYPE m_Type;
00097 std::string m_Id;
00098 };
00099
00100 typedef std::list<PANA_DeviceId*>::iterator PANA_DeviceIdIterator;
00101
00102 class PANA_DeviceIdContainer : public std::list<PANA_DeviceId*>
00103 {
00104 public:
00105 virtual ~PANA_DeviceIdContainer() {
00106 clear();
00107 }
00108 PANA_DeviceId *search(PANA_DeviceId::TYPE type) {
00109 PANA_DeviceId *id;
00110 PANA_DeviceIdIterator i;
00111 for (i = begin(); i != end(); i++) {
00112 id = *i;
00113 if (id->type() == type) {
00114 return id;
00115 }
00116 }
00117 return (NULL);
00118 }
00119 void replace(PANA_DeviceId &id) {
00120 PANA_DeviceId *old = search(id.type());
00121 if (old) {
00122 const_cast<std::string&>(old->id()).assign
00123 (id.id().data(), id.id().size());
00124 }
00125 }
00126 void move(PANA_DeviceIdContainer &c) {
00127 while (! c.empty()) {
00128 PANA_DeviceId *id = c.front();
00129 c.pop_front();
00130 push_back(id);
00131 }
00132 }
00133 void move(PANA_DeviceIdContainer &c,
00134 PANA_DeviceId &id) {
00135 PANA_DeviceId *entry;
00136 PANA_DeviceIdIterator i;
00137 for (i = c.begin(); i != c.end(); i++) {
00138 entry = *i;
00139 if (entry == &id) {
00140 c.erase(i);
00141 push_back(entry);
00142 return;
00143 }
00144 }
00145 }
00146 void clone(PANA_DeviceIdContainer &c) {
00147 PANA_DeviceId *id;
00148 PANA_DeviceIdIterator i;
00149 for (i = c.begin(); i != c.end(); i++) {
00150 id = *i;
00151 clone(*id);
00152 }
00153 }
00154 void clone(PANA_DeviceId &id) {
00155 PANA_DeviceId *newId;
00156 ACE_NEW_NORETURN(newId, PANA_DeviceId(id.type()));
00157 if (newId) {
00158 const_cast<std::string&>(newId->id()).assign
00159 (id.id().data(), id.id().size());
00160 }
00161 push_back(newId);
00162 }
00163 void clear() {
00164 while (! empty()) {
00165 PANA_DeviceId *id = front();
00166 pop_front();
00167 delete id;
00168 }
00169 }
00170 };
00171
00172 #endif // __PANA_DEVICE_ID_H__
00173