Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 1 | #ifndef CCNX_WRAPPER_H |
| 2 | #define CCNX_WRAPPER_H |
| 3 | |
| 4 | extern "C" { |
| 5 | #include <ccn/ccn.h> |
| 6 | #include <ccn/charbuf.h> |
| 7 | #include <ccn/keystore.h> |
| 8 | #include <ccn/uri.h> |
| 9 | #include <ccn/bloom.h> |
| 10 | #include <ccn/signing.h> |
| 11 | } |
| 12 | |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 13 | #include <boost/thread/recursive_mutex.hpp> |
| 14 | #include <boost/thread/thread.hpp> |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 15 | |
| 16 | #include "ccnx-common.h" |
Zhenkai Zhu | 9bad2bf | 2012-12-28 15:31:46 -0800 | [diff] [blame^] | 17 | #include "ccnx-interest.h" |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 18 | #include "ccnx-closure.h" |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 19 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 20 | using namespace std; |
| 21 | |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 22 | namespace Ccnx { |
| 23 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 24 | struct CcnxOperationException : virtual boost::exception, virtual exception { }; |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 25 | |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 26 | class CcnxWrapper |
| 27 | { |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 28 | public: |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 29 | typedef boost::function<void (const string &)> InterestCallback; |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 30 | |
| 31 | CcnxWrapper(); |
| 32 | virtual ~CcnxWrapper(); |
| 33 | |
| 34 | virtual int |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 35 | setInterestFilter (const string &prefix, const InterestCallback &interestCallback); |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 36 | |
| 37 | virtual void |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 38 | clearInterestFilter (const string &prefix); |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 39 | |
| 40 | virtual int |
Zhenkai Zhu | 9bad2bf | 2012-12-28 15:31:46 -0800 | [diff] [blame^] | 41 | sendInterest (const Interest &interest, Closure *closure); |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 42 | |
| 43 | virtual int |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 44 | publishData (const string &name, const unsigned char *buf, size_t len, int freshness); |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 45 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 46 | int |
| 47 | publishData (const string &name, const Bytes &content, int freshness); |
| 48 | |
| 49 | static string |
| 50 | getLocalPrefix (); |
| 51 | |
| 52 | static string |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 53 | extractName(const unsigned char *data, const ccn_indexbuf *comps); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 54 | |
| 55 | protected: |
| 56 | Bytes |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 57 | createContentObject(const string &name, const unsigned char *buf, size_t len, int freshness); |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 58 | |
| 59 | int |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 60 | putToCcnd (const Bytes &contentObject); |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 61 | |
| 62 | protected: |
| 63 | void |
| 64 | connectCcnd(); |
| 65 | |
| 66 | /// @cond include_hidden |
| 67 | void |
| 68 | createKeyLocator (); |
| 69 | |
| 70 | void |
| 71 | initKeyStore (); |
| 72 | |
| 73 | const ccn_pkey * |
| 74 | getPrivateKey (); |
| 75 | |
| 76 | const unsigned char * |
| 77 | getPublicKeyDigest (); |
| 78 | |
| 79 | ssize_t |
| 80 | getPublicKeyDigestLength (); |
| 81 | |
| 82 | void |
| 83 | ccnLoop (); |
| 84 | |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 85 | /// @endcond |
| 86 | |
| 87 | protected: |
| 88 | ccn* m_handle; |
| 89 | ccn_keystore *m_keyStore; |
| 90 | ccn_charbuf *m_keyLoactor; |
| 91 | // to lock, use "boost::recursive_mutex::scoped_lock scoped_lock(mutex); |
| 92 | boost::recursive_mutex m_mutex; |
| 93 | boost::thread m_thread; |
| 94 | bool m_running; |
| 95 | bool m_connected; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 96 | map<string, InterestCallback> m_registeredInterests; |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 97 | // std::list< std::pair<std::string, InterestCallback> > m_registeredInterests; |
| 98 | }; |
| 99 | |
| 100 | typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr; |
| 101 | |
Zhenkai Zhu | 1ddeb6f | 2012-12-27 14:04:18 -0800 | [diff] [blame] | 102 | |
| 103 | } // Ccnx |
| 104 | |
| 105 | #endif |