Some c++ tricks. Not finished
diff --git a/model/ndn_interestpacket.cc b/model/ndn_interestpacket.cc
index 66deaf2..bb3a878 100644
--- a/model/ndn_interestpacket.cc
+++ b/model/ndn_interestpacket.cc
@@ -24,60 +24,61 @@
{
namespace NDNabstraction
{
- InterestPacket::InterestPacket(unsigned char *name, uint32_t size):Packet ((uint8_t const *)name,size)
- {
- maxNameLength = 10240;
- }
+ InterestPacket::InterestPacket(const unsigned char *name, uint32_t size)
+ :Packet(name,size)
+ {
+ maxNameLength = 10240;
+ }
- uint32_t
- InterestPacket::GetName(unsigned char *name)
- {
- //uint32_t Packet::CopyData (uint8_t *buffer, uint32_t size) const
- return CopyData((uint8_t*) name, maxNameLength);
- }
+ uint32_t
+ InterestPacket::GetName(unsigned char *name)
+ {
+ //uint32_t Packet::CopyData (uint8_t *buffer, uint32_t size) const
+ return CopyData((uint8_t*) name, maxNameLength);
+ }
- void
- InterestPacket::AddTimeout(uint32_t milliseconds)
- {
- TimeoutHeader tHeader (milliseconds);
- AddHeader (tHeader);
- }
+ void
+ InterestPacket::AddTimeout(uint32_t milliseconds)
+ {
+ TimeoutHeader tHeader (milliseconds);
+ AddHeader (tHeader);
+ }
- uint32_t
- InterestPacket::GetTimeout(void)
- {
- TimeoutHeader tHeader;
- PeekHeader(tHeader);
- return tHeader.GetValue();
- }
+ uint32_t
+ InterestPacket::GetTimeout(void)
+ {
+ TimeoutHeader tHeader;
+ PeekHeader(tHeader);
+ return tHeader.GetValue();
+ }
- void
- InterestPacket::RemoveTimeout(void)
- {
- TimeoutHeader tHeader;
- RemoveHeader(tHeader);
- }
+ void
+ InterestPacket::RemoveTimeout(void)
+ {
+ TimeoutHeader tHeader;
+ RemoveHeader(tHeader);
+ }
- void
- InterestPacket::AddNonce(uint32_t nonce)
- {
- NonceHeader tHeader (nonce);
- AddHeader (tHeader);
- }
+ void
+ InterestPacket::AddNonce(uint32_t nonce)
+ {
+ NonceHeader tHeader (nonce);
+ AddHeader (tHeader);
+ }
- uint32_t
- InterestPacket::GetNonce(void)
- {
- NonceHeader tHeader;
- PeekHeader(tHeader);
- return tHeader.GetValue();
- }
+ uint32_t
+ InterestPacket::GetNonce(void)
+ {
+ NonceHeader tHeader;
+ PeekHeader(tHeader);
+ return tHeader.GetValue();
+ }
- void
- InterestPacket::RemoveNonce(void)
- {
- NonceHeader tHeader;
- RemoveHeader(tHeader);
- }
+ void
+ InterestPacket::RemoveNonce(void)
+ {
+ NonceHeader tHeader;
+ RemoveHeader(tHeader);
+ }
}
}
diff --git a/model/ndn_interestpacket.h b/model/ndn_interestpacket.h
index 0256132..51f2a9a 100644
--- a/model/ndn_interestpacket.h
+++ b/model/ndn_interestpacket.h
@@ -34,23 +34,25 @@
{
namespace NDNabstraction
{
- class InterestPacket : public Packet
- {
- public:
- InterestPacket(unsigned char *name, uint32_t size);
+
+ class InterestPacket : public Packet
+ {
+ public:
+ InterestPacket(const unsigned char *name, uint32_t size);
- uint32_t GetName(unsigned char *name);
+ uint32_t GetName(unsigned char *name);
- void AddTimeout(uint32_t milliseconds);
- uint32_t GetTimeout(void);
- void RemoveTimeout(void);
+ void AddTimeout(uint32_t milliseconds);
+ uint32_t GetTimeout(void);
+ void RemoveTimeout(void);
- void AddNonce(uint32_t nonce);
- uint32_t GetNonce(void);
- void RemoveNonce(void);
+ void AddNonce(uint32_t nonce);
+ uint32_t GetNonce(void);
+ void RemoveNonce(void);
- uint32_t maxNameLength;
- };
+ uint32_t maxNameLength;
+ };
+
}
}
diff --git a/model/ndn_namebuilder.cc b/model/ndn_namebuilder.cc
index 8f65647..e907e01 100644
--- a/model/ndn_namebuilder.cc
+++ b/model/ndn_namebuilder.cc
@@ -57,5 +57,10 @@
return *this;
}
+NameBuilder::operator const unsigned char* ()
+{
+ return m_value->buf;
+}
+
}
}
diff --git a/model/ndn_namebuilder.h b/model/ndn_namebuilder.h
index 1b54bfe..1198471 100644
--- a/model/ndn_namebuilder.h
+++ b/model/ndn_namebuilder.h
@@ -37,6 +37,8 @@
const ccn_charbuf* GetName () const;
NameBuilder& operator () (const std::string &s);
+
+ operator const unsigned char* ();
private:
ccn_charbuf *m_value;
};
diff --git a/model/ndn_stupidinterestgenerator.cc b/model/ndn_stupidinterestgenerator.cc
index 5bc1861..7c59f6c 100644
--- a/model/ndn_stupidinterestgenerator.cc
+++ b/model/ndn_stupidinterestgenerator.cc
@@ -163,8 +163,9 @@
NameBuilder name;
name("prefix1")("prefix2")("filename");
+
const ccn_charbuf *output = name.GetName();
- Ptr<InterestPacket> packet = Create<InterestPacket>(output->buf,(uint32_t)output->length);
+ Ptr<InterestPacket> packet = Create<InterestPacket>(name,(uint32_t)output->length);
packet->AddTimeout(4000);
UniformVariable var;
packet->AddNonce(var.GetInteger(1,10000));