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