make: Global change: Move all public headers to include folder. Change source to including public headers using #include <ndn-cpp/*>. Split some header files to minimize exposing C .h files.
diff --git a/ndn-cpp/transport/tcp-transport.cpp b/ndn-cpp/transport/tcp-transport.cpp
index 9a712fb..cb8c1e6 100644
--- a/ndn-cpp/transport/tcp-transport.cpp
+++ b/ndn-cpp/transport/tcp-transport.cpp
@@ -1,3 +1,4 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (C) 2013 Regents of the University of California.
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
@@ -5,9 +6,11 @@
*/
#include <stdexcept>
-#include "../node.hpp"
+#include <ndn-cpp/node.hpp>
+#include "../c/transport/tcp-transport.h"
+#include "../c/encoding/binary-xml-element-reader.h"
#include "../c/util/ndn_realloc.h"
-#include "tcp-transport.hpp"
+#include <ndn-cpp/transport/tcp-transport.hpp>
using namespace std;
@@ -17,20 +20,27 @@
{
}
+TcpTransport::TcpTransport()
+ : elementListener_(0), isConnected_(false), transport_(new struct ndn_TcpTransport), elementReader_(new struct ndn_BinaryXmlElementReader)
+{
+ ndn_TcpTransport_initialize(transport_.get());
+ elementReader_->partialData.array = 0;
+}
+
void
TcpTransport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
{
const TcpTransport::ConnectionInfo& tcpConnectionInfo = dynamic_cast<const TcpTransport::ConnectionInfo&>(connectionInfo);
ndn_Error error;
- if ((error = ndn_TcpTransport_connect(&transport_, (char *)tcpConnectionInfo.getHost().c_str(), tcpConnectionInfo.getPort())))
+ if ((error = ndn_TcpTransport_connect(transport_.get(), (char *)tcpConnectionInfo.getHost().c_str(), tcpConnectionInfo.getPort())))
throw std::runtime_error(ndn_getErrorString(error));
// TODO: This belongs in the socket listener.
const size_t initialLength = 1000;
// Automatically cast elementReader_ to (struct ndn_ElementListener *)
ndn_BinaryXmlElementReader_initialize
- (&elementReader_, &elementListener, (uint8_t *)malloc(initialLength), initialLength, ndn_realloc);
+ (elementReader_.get(), &elementListener, (uint8_t *)malloc(initialLength), initialLength, ndn_realloc);
isConnected_ = true;
elementListener_ = &elementListener;
@@ -40,7 +50,7 @@
TcpTransport::send(const uint8_t *data, size_t dataLength)
{
ndn_Error error;
- if ((error = ndn_TcpTransport_send(&transport_, (uint8_t *)data, dataLength)))
+ if ((error = ndn_TcpTransport_send(transport_.get(), (uint8_t *)data, dataLength)))
throw std::runtime_error(ndn_getErrorString(error));
}
@@ -49,17 +59,17 @@
{
int receiveIsReady;
ndn_Error error;
- if ((error = ndn_TcpTransport_receiveIsReady(&transport_, &receiveIsReady)))
+ if ((error = ndn_TcpTransport_receiveIsReady(transport_.get(), &receiveIsReady)))
throw std::runtime_error(ndn_getErrorString(error));
if (!receiveIsReady)
return;
uint8_t buffer[8000];
size_t nBytes;
- if ((error = ndn_TcpTransport_receive(&transport_, buffer, sizeof(buffer), &nBytes)))
+ if ((error = ndn_TcpTransport_receive(transport_.get(), buffer, sizeof(buffer), &nBytes)))
throw std::runtime_error(ndn_getErrorString(error));
- ndn_BinaryXmlElementReader_onReceivedData(&elementReader_, buffer, nBytes);
+ ndn_BinaryXmlElementReader_onReceivedData(elementReader_.get(), buffer, nBytes);
}
bool
@@ -72,15 +82,15 @@
TcpTransport::close()
{
ndn_Error error;
- if ((error = ndn_TcpTransport_close(&transport_)))
+ if ((error = ndn_TcpTransport_close(transport_.get())))
throw std::runtime_error(ndn_getErrorString(error));
}
TcpTransport::~TcpTransport()
{
- if (elementReader_.partialData.array)
+ if (elementReader_->partialData.array)
// Free the memory allocated in connect.
- free(elementReader_.partialData.array);
+ free(elementReader_->partialData.array);
}
}
diff --git a/ndn-cpp/transport/tcp-transport.hpp b/ndn-cpp/transport/tcp-transport.hpp
deleted file mode 100644
index e6c2a73..0000000
--- a/ndn-cpp/transport/tcp-transport.hpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_TCPTRANSPORT_HPP
-#define NDN_TCPTRANSPORT_HPP
-
-#include <string>
-#include "../c/transport/tcp-transport.h"
-#include "../c/encoding/binary-xml-element-reader.h"
-#include "transport.hpp"
-
-namespace ndn {
-
-class TcpTransport : public Transport {
-public:
- /**
- * A TcpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info for the TCP connection.
- */
- class ConnectionInfo : public Transport::ConnectionInfo {
- public:
- /**
- * Create a ConnectionInfo with the given host and port.
- * @param host The host for the connection.
- * @param port The port number for the connection. If omitted, use 6363.
- */
- ConnectionInfo(const char *host, unsigned short port = 6363)
- : host_(host), port_(port)
- {
- }
-
- /**
- * Get the host given to the constructor.
- * @return A string reference for the host.
- */
- const std::string&
- getHost() const { return host_; }
-
- /**
- * Get the port given to the constructor.
- * @return The port number.
- */
- unsigned short
- getPort() const { return port_; }
-
- virtual
- ~ConnectionInfo();
-
- private:
- std::string host_;
- unsigned short port_;
- };
-
- TcpTransport()
- : elementListener_(0), isConnected_(false)
- {
- ndn_TcpTransport_initialize(&transport_);
- elementReader_.partialData.array = 0;
- }
-
- /**
- * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
- * @param connectionInfo A reference to a TcpTransport::ConnectionInfo.
- * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
- */
- virtual void connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
-
- /**
- * Set data to the host
- * @param data A pointer to the buffer of data to send.
- * @param dataLength The number of bytes in data.
- */
- virtual void send(const uint8_t *data, size_t dataLength);
-
- /**
- * Process any data to receive. For each element received, call elementListener.onReceivedElement.
- * This is non-blocking and will return immediately if there is no data to receive.
- * You should normally not call this directly since it is called by Face.processEvents.
- * @throw This may throw an exception for reading data or in the callback for processing the data. If you
- * call this from an main event loop, you may want to catch and log/disregard all exceptions.
- */
- virtual void processEvents();
-
- virtual bool getIsConnected();
-
- /**
- * Close the connection to the host.
- */
- virtual void close();
-
- ~TcpTransport();
-
-private:
- struct ndn_TcpTransport transport_;
- bool isConnected_;
- ElementListener *elementListener_;
- // TODO: This belongs in the socket listener.
- ndn_BinaryXmlElementReader elementReader_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/transport/transport.cpp b/ndn-cpp/transport/transport.cpp
index b36b119..0dcf518 100644
--- a/ndn-cpp/transport/transport.cpp
+++ b/ndn-cpp/transport/transport.cpp
@@ -1,3 +1,4 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (C) 2013 Regents of the University of California.
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
@@ -5,7 +6,7 @@
*/
#include <stdexcept>
-#include "transport.hpp"
+#include <ndn-cpp/transport/transport.hpp>
using namespace std;
diff --git a/ndn-cpp/transport/transport.hpp b/ndn-cpp/transport/transport.hpp
deleted file mode 100644
index 512a003..0000000
--- a/ndn-cpp/transport/transport.hpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_TRANSPORT_HPP
-#define NDN_TRANSPORT_HPP
-
-#include <vector>
-
-namespace ndn {
-
-class ElementListener;
-
-class Transport {
-public:
- /**
- * A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transport.
- */
- class ConnectionInfo {
- public:
- virtual ~ConnectionInfo();
- };
-
- /**
- * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
- * @param connectionInfo A reference to an object of a subclass of ConnectionInfo.
- * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
- */
- virtual void
- connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
-
- /**
- * Set data to the host
- * @param data A pointer to the buffer of data to send.
- * @param dataLength The number of bytes in data.
- */
- virtual void
- send(const uint8_t *data, size_t dataLength);
-
- void
- send(const std::vector<uint8_t>& data)
- {
- send(&data[0], data.size());
- }
-
- /**
- * Process any data to receive. For each element received, call elementListener.onReceivedElement.
- * This is non-blocking and will silently time out after a brief period if there is no data to receive.
- * You should repeatedly call this from an event loop.
- * @throw This may throw an exception for reading data or in the callback for processing the data. If you
- * call this from an main event loop, you may want to catch and log/disregard all exceptions.
- */
- virtual void
- processEvents() = 0;
-
- virtual bool
- getIsConnected();
-
- /**
- * Close the connection. This base class implementation does nothing, but your derived class can override.
- */
- virtual void
- close();
-
- virtual ~Transport();
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/transport/udp-transport.cpp b/ndn-cpp/transport/udp-transport.cpp
index 4e65375..17250d4 100644
--- a/ndn-cpp/transport/udp-transport.cpp
+++ b/ndn-cpp/transport/udp-transport.cpp
@@ -1,3 +1,4 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (C) 2013 Regents of the University of California.
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
@@ -5,9 +6,11 @@
*/
#include <stdexcept>
-#include "../face.hpp"
+#include <ndn-cpp/face.hpp>
+#include "../c/transport/udp-transport.h"
+#include "../c/encoding/binary-xml-element-reader.h"
#include "../c/util/ndn_realloc.h"
-#include "udp-transport.hpp"
+#include <ndn-cpp/transport/udp-transport.hpp>
using namespace std;
@@ -17,20 +20,27 @@
{
}
+UdpTransport::UdpTransport()
+ : elementListener_(0), isConnected_(false), transport_(new struct ndn_UdpTransport), elementReader_(new struct ndn_BinaryXmlElementReader)
+{
+ ndn_UdpTransport_initialize(transport_.get());
+ elementReader_->partialData.array = 0;
+}
+
void
UdpTransport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
{
const UdpTransport::ConnectionInfo& udpConnectionInfo = dynamic_cast<const UdpTransport::ConnectionInfo&>(connectionInfo);
ndn_Error error;
- if ((error = ndn_UdpTransport_connect(&transport_, (char *)udpConnectionInfo.getHost().c_str(), udpConnectionInfo.getPort())))
+ if ((error = ndn_UdpTransport_connect(transport_.get(), (char *)udpConnectionInfo.getHost().c_str(), udpConnectionInfo.getPort())))
throw std::runtime_error(ndn_getErrorString(error));
// TODO: This belongs in the socket listener.
const size_t initialLength = 1000;
// Automatically cast elementReader_ to (struct ndn_ElementListener *)
ndn_BinaryXmlElementReader_initialize
- (&elementReader_, &elementListener, (uint8_t *)malloc(initialLength), initialLength, ndn_realloc);
+ (elementReader_.get(), &elementListener, (uint8_t *)malloc(initialLength), initialLength, ndn_realloc);
isConnected_ = true;
elementListener_ = &elementListener;
@@ -40,7 +50,7 @@
UdpTransport::send(const uint8_t *data, size_t dataLength)
{
ndn_Error error;
- if ((error = ndn_UdpTransport_send(&transport_, (uint8_t *)data, dataLength)))
+ if ((error = ndn_UdpTransport_send(transport_.get(), (uint8_t *)data, dataLength)))
throw std::runtime_error(ndn_getErrorString(error));
}
@@ -49,17 +59,17 @@
{
int receiveIsReady;
ndn_Error error;
- if ((error = ndn_UdpTransport_receiveIsReady(&transport_, &receiveIsReady)))
+ if ((error = ndn_UdpTransport_receiveIsReady(transport_.get(), &receiveIsReady)))
throw std::runtime_error(ndn_getErrorString(error));
if (!receiveIsReady)
return;
uint8_t buffer[8000];
size_t nBytes;
- if ((error = ndn_UdpTransport_receive(&transport_, buffer, sizeof(buffer), &nBytes)))
+ if ((error = ndn_UdpTransport_receive(transport_.get(), buffer, sizeof(buffer), &nBytes)))
throw std::runtime_error(ndn_getErrorString(error));
- ndn_BinaryXmlElementReader_onReceivedData(&elementReader_, buffer, nBytes);
+ ndn_BinaryXmlElementReader_onReceivedData(elementReader_.get(), buffer, nBytes);
}
bool
@@ -72,15 +82,15 @@
UdpTransport::close()
{
ndn_Error error;
- if ((error = ndn_UdpTransport_close(&transport_)))
+ if ((error = ndn_UdpTransport_close(transport_.get())))
throw std::runtime_error(ndn_getErrorString(error));
}
UdpTransport::~UdpTransport()
{
- if (elementReader_.partialData.array)
+ if (elementReader_->partialData.array)
// Free the memory allocated in connect.
- free(elementReader_.partialData.array);
+ free(elementReader_->partialData.array);
}
}
diff --git a/ndn-cpp/transport/udp-transport.hpp b/ndn-cpp/transport/udp-transport.hpp
deleted file mode 100644
index a7a40b1..0000000
--- a/ndn-cpp/transport/udp-transport.hpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_UDPTRANSPORT_HPP
-#define NDN_UDPTRANSPORT_HPP
-
-#include <string>
-#include "../c/transport/udp-transport.h"
-#include "../c/encoding/binary-xml-element-reader.h"
-#include "transport.hpp"
-
-namespace ndn {
-
-class UdpTransport : public Transport {
-public:
- /**
- * A UdpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info for the UDP connection.
- */
- class ConnectionInfo : public Transport::ConnectionInfo {
- public:
- /**
- * Create a ConnectionInfo with the given host and port.
- * @param host The host for the connection.
- * @param port The port number for the connection. If omitted, use 6363.
- */
- ConnectionInfo(const char *host, unsigned short port = 6363)
- : host_(host), port_(port)
- {
- }
-
- /**
- * Get the host given to the constructor.
- * @return A string reference for the host.
- */
- const std::string&
- getHost() const { return host_; }
-
- /**
- * Get the port given to the constructor.
- * @return The port number.
- */
- unsigned short
- getPort() const { return port_; }
-
- virtual
- ~ConnectionInfo();
-
- private:
- std::string host_;
- unsigned short port_;
- };
-
- UdpTransport()
- : elementListener_(0), isConnected_(false)
- {
- ndn_UdpTransport_initialize(&transport_);
- elementReader_.partialData.array = 0;
- }
-
- /**
- * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
- * @param connectionInfo A reference to a TcpTransport::ConnectionInfo.
- * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
- */
- virtual void
- connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
-
- /**
- * Set data to the host
- * @param data A pointer to the buffer of data to send.
- * @param dataLength The number of bytes in data.
- */
- virtual void
- send(const uint8_t *data, size_t dataLength);
-
- /**
- * Process any data to receive. For each element received, call elementListener.onReceivedElement.
- * This is non-blocking and will return immediately if there is no data to receive.
- * You should normally not call this directly since it is called by Face.processEvents.
- * @throw This may throw an exception for reading data or in the callback for processing the data. If you
- * call this from an main event loop, you may want to catch and log/disregard all exceptions.
- */
- virtual void
- processEvents();
-
- virtual bool
- getIsConnected();
-
- /**
- * Close the connection to the host.
- */
- virtual void
- close();
-
- ~UdpTransport();
-
-private:
- struct ndn_UdpTransport transport_;
- bool isConnected_;
- ElementListener *elementListener_;
- // TODO: This belongs in the socket listener.
- ndn_BinaryXmlElementReader elementReader_;
-};
-
-}
-
-#endif