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);
}
}