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