Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_UDPTRANSPORT_HPP |
| 9 | #define NDN_UDPTRANSPORT_HPP |
| 10 | |
| 11 | #include <string> |
| 12 | #include "transport.hpp" |
| 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | class UnixTransport : public Transport { |
| 17 | public: |
| 18 | UnixTransport(const std::string &unixSocket = "/tmp/.ndnd.sock"); |
| 19 | ~UnixTransport(); |
| 20 | |
| 21 | /** |
| 22 | * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener. |
| 23 | * @param connectionInfo A reference to a TcpTransport::ConnectionInfo. |
| 24 | * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object. |
| 25 | */ |
| 26 | virtual void |
| 27 | connect(ElementListener& elementListener); |
| 28 | |
| 29 | /** |
| 30 | * Set data to the host |
| 31 | * @param data A pointer to the buffer of data to send. |
| 32 | * @param dataLength The number of bytes in data. |
| 33 | */ |
| 34 | virtual void |
| 35 | send(const uint8_t *data, size_t dataLength); |
| 36 | |
| 37 | /** |
| 38 | * Process any data to receive. For each element received, call elementListener.onReceivedElement. |
| 39 | * This is non-blocking and will return immediately if there is no data to receive. |
| 40 | * You should normally not call this directly since it is called by Face.processEvents. |
| 41 | * @throw This may throw an exception for reading data or in the callback for processing the data. If you |
| 42 | * call this from an main event loop, you may want to catch and log/disregard all exceptions. |
| 43 | */ |
| 44 | virtual void |
| 45 | processEvents(); |
| 46 | |
| 47 | virtual bool |
| 48 | getIsConnected(); |
| 49 | |
| 50 | /** |
| 51 | * Close the connection to the host. |
| 52 | */ |
| 53 | virtual void |
| 54 | close(); |
| 55 | |
| 56 | private: |
| 57 | std::string unixSocket_; |
| 58 | bool isConnected_; |
| 59 | |
| 60 | class Impl; |
| 61 | std::auto_ptr<Impl> impl_; |
| 62 | }; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | #endif |